-
Notifications
You must be signed in to change notification settings - Fork 0
/
dotenv-deploy-keys.php
77 lines (39 loc) · 1.22 KB
/
dotenv-deploy-keys.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
* Load global dot file with keys on your server
*
*
*
*/
// require_once( __DIR__ . '/vendor/autoload.php' );
// require_once( __DIR__ . '/config/application.php' );
//Get the .env
if ( file_exists( '.env' ) ) {
$dotenv = file_get_contents( '.env' );
} else {
$dotenv = '';
}
$global_keys_file_path = '/etc/creare/keys.json';
if ( file_exists( $global_keys_file_path ) ) {
$global_keys_file = trim( file_get_contents( $global_keys_file_path ) );
} else {
echo 'Cannot find global keys file.';
return;
}
if ( !empty( $global_keys_file ) ) {
$global_keys = json_decode( $global_keys_file );
$dotenv .= "\n# Global keys from server. Autodeployed by script.\n";
$key_strings = [];
foreach( $global_keys as $key => $val ) {
$key_strings[] = sprintf( '%s=\'%s\'', strtoupper($key), $val );
}
$dotenv .= implode( "\n", $key_strings );
if ( file_put_contents( '.env', $dotenv ) ) {
echo "\nNew .env file written.\n";
} else {
echo "\nThere was an error writing the following contents:";
echo $dotenv . "\n";
}
} else {
echo "\nNo global keys file found at " . $global_keys_file_path . "\n";
}