-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup.php
159 lines (137 loc) · 5.04 KB
/
setup.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
$vars = array(
'WP_BOILERPLATE_SLUG' => 'site slug',
'WP_BOILERPLATE_VENDOR' => 'vendor name',
'WP_BOILERPLATE_USER' => 'admin username',
'WP_BOILERPLATE_EMAIL' => 'admin email address',
'WP_BOILERPLATE_MAIL_FROM' => 'email address to send emails from',
'WP_BOILERPLATE_MAIL_FROM_NAME' => 'name to send emails from',
'WP_BOILERPLATE_REPO' => 'git repository URL',
'WP_BOILERPLATE_DEPLOY_PATH' => 'server deploy path',
'WP_BOILERPLATE_PUBLIC_PATH' => 'server public path',
'WP_BOILERPLATE_STAGING_IP' => 'staging server IP address',
'WP_BOILERPLATE_STAGING_USER' => 'staging server user',
'WP_BOILERPLATE_STAGING_URL' => 'staging website URL',
'WP_BOILERPLATE_STAGING_DB_USER' => 'staging website database user',
'WP_BOILERPLATE_STAGING_DB_PASS' => 'staging website database password',
'WP_BOILERPLATE_PRODUCTION_IP' => 'production server IP address',
'WP_BOILERPLATE_PRODUCTION_USER' => 'production server user',
'WP_BOILERPLATE_PRODUCTION_URL' => 'production website URL',
'WP_BOILERPLATE_PRODUCTION_DOMAIN' => 'production website domain',
'WP_BOILERPLATE_PRODUCTION_DB_USER' => 'production website database user',
'WP_BOILERPLATE_PRODUCTION_DB_PASS' => 'production website database password',
'WP_BOILERPLATE_SOPS_AGE' => 'SOPS AGE public key',
'WP_BOILERPLATE_SOPS_KMS' => 'SOPS KMS value',
'WP_BOILERPLATE_GOOGLE_ANALYTICS_ID' => 'Google Analytics Property ID',
'WP_BOILERPLATE_SENDGRID_API_KEY' => 'SendGrid API key'
);
$var_defaults = array(
'WP_BOILERPLATE_SLUG' => 'my-new-website',
'WP_BOILERPLATE_VENDOR' => 'my-company',
'WP_BOILERPLATE_USER' => 'admin',
'WP_BOILERPLATE_MAIL_FROM' => '{{WP_BOILERPLATE_EMAIL}}',
'WP_BOILERPLATE_MAIL_FROM_NAME' => '{{WP_BOILERPLATE_SLUG}}',
'WP_BOILERPLATE_DEPLOY_PATH' => '/var/www/public_html',
'WP_BOILERPLATE_PUBLIC_PATH' => '/var/www/public',
'WP_BOILERPLATE_STAGING_USER' => 'www-data',
'WP_BOILERPLATE_PRODUCTION_USER' => 'www-data'
);
$file_list = array(
'content/themes/theme/scss/style.scss',
'.lando.yml',
'.sops.yaml',
'.user.ini',
'composer.json',
'config.template.yml',
'site-readme.md',
'watcher.php'
);
$file_delete_list = array(
'.git',
'license.md',
'readme.md',
'setup.php'
);
$file_rename_list = array(
'content/themes/theme' => 'content/themes/{{WP_BOILERPLATE_SLUG}}',
'auth.template.json' => 'auth.json',
'config.template.yml' => 'config.yml',
'site-readme.md' => 'readme.md'
);
if (basename(dirname(__FILE__)) === 'wp-boilerplate') {
echo "\nThis script should only be ran on a new copy of wp-boilerplate.\n\n";
exit;
}
function parse_vars($str) {
global $vars;
foreach($vars as $var => $value) {
$str = str_replace('{{' . $var . '}}', $value, $str);
}
return $str;
}
function remove_directory($path) {
$files = glob(preg_replace('/(\*|\?|\[)/', '[$1]', $path) . '/{,.}*', GLOB_BRACE);
foreach ($files as $file) {
if ($file == $path . '/.' || $file == $path . '/..') continue;
is_dir($file) ? remove_directory($file) : unlink($file);
}
rmdir($path);
}
foreach($vars as $var => &$value) {
if (!($default = getenv($var))) {
if (isset($var_defaults[$var])) {
$default = parse_vars($var_defaults[$var]);
} else {
$default = '';
}
}
if (!($response = readline("Enter the $value ($default): "))) {
$response = $default;
}
$value = $response;
}
foreach($file_list as $file_path) {
if (file_exists($file_path)) {
echo "Processing $file_path...\n";
try {
$file_contents = parse_vars(file_get_contents($file_path));
file_put_contents($file_path, $file_contents);
} catch (Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
}
} else {
echo "Error: Could not find $file_path\n";
}
}
foreach($file_delete_list as $file_path) {
if (file_exists($file_path)) {
echo "Deleting $file_path...\n";
try {
if (is_dir($file_path)) {
remove_directory($file_path);
} else {
unlink($file_path);
}
} catch (Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
}
} else {
echo "Error: Could not find $file_path\n";
}
}
foreach($file_rename_list as $file_path => $new_name) {
if (file_exists($file_path)) {
$new_name = parse_vars($new_name);
echo "Renaming $file_path to $new_name...\n";
try {
rename($file_path, $new_name);
} catch (Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
}
} else {
echo "Error: Could not find $file_path\n";
}
}
echo "\nDone! You should now check out your config.yml file and make any necessary changes.\n";
echo "After that, run `lando start && lando dep setup:local`.\n\n";
?>