forked from msimerson/Mail-Toaster-6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprovision-wordpress.sh
executable file
·195 lines (152 loc) · 4.4 KB
/
provision-wordpress.sh
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/bin/sh
# shellcheck disable=1091
. mail-toaster.sh || exit
export JAIL_START_EXTRA=""
export JAIL_CONF_EXTRA=""
mt6-include php
mt6-include nginx
install_wordpress()
{
install_nginx
install_php 56 "mysql session gd"
stage_pkg_install wordpress
}
configure_nginx_standalone()
{
if [ -f "$STAGE_MNT/data/etc/nginx-locations.conf" ]; then
tell_status "preserving /data/etc/nginx-locations.conf"
return
fi
tee "$STAGE_MNT/data/etc/nginx-locations.conf" <<'EO_WP_NGINX'
server_name wordpress;
index index.php;
root /usr/local/www;
location / {
# include "?$args" so non-default permalinks don't break
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include /usr/local/etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_pass php;
}
location ~* \.(?:css|gif|htc|ico|js|jpe?g|png|swf)$ {
expires max;
log_not_found off;
}
EO_WP_NGINX
}
configure_nginx_with_path()
{
if [ -f "$STAGE_MNT/data/etc/nginx-locations.conf" ]; then
tell_status "preserving /data/etc/nginx-locations.conf"
return
fi
local _uri_path="$1"
if [ -z "$_uri_path" ]; then
tell_status "using /wpn (wordpress network) for WP url path"
_uri_path="/wpn"
fi
tee "$STAGE_MNT/data/etc/nginx-locations.conf" <<'EO_WP_NGINX'
server_name wordpress;
index index.php;
root /usr/local/www/wordpress;
# all PHP scripts, optionally within /wpn/
location ~ ^/(?:wpn/)?(?<script>.+\.php)(?<path_info>.*)$ {
include /usr/local/etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_intercept_errors on;
fastcgi_param SCRIPT_FILENAME $document_root/$script;
fastcgi_param SCRIPT_NAME $script;
fastcgi_param PATH_INFO $path_info;
fastcgi_pass php;
}
# wordpress served with URL path
location /wpn/ {
alias /usr/local/www/wordpress/;
# say "yes we can" to permalinks
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~* \.(?:css|gif|htc|ico|js|jpe?g|png|swf)$ {
expires max;
log_not_found off;
}
EO_WP_NGINX
}
configure_wp_config()
{
local _local_content="$ZFS_DATA_MNT/wordpress/content"
local _wp_install="$ZFS_JAIL_MNT/wordpress/usr/local/www/wordpress"
local _wp_stage="$STAGE_MNT/usr/local/www/wordpress"
if [ ! -d "$_local_content" ]; then
tell_status "copying wp-content to /data"
cp -r "$_wp_stage/wp-content" "$_local_content"
chown -R 80:80 "$_local_content"
else
chown -R 80:80 "$_wp_stage/wp-content"
fi
if [ ! -d "$_local_content/uploads" ]; then
mkdir "$_local_content/uploads"
chown 80:80 "$_local_content/uploads"
fi
local _installed_config="$_wp_install/wp-config.php"
if [ -f "$_installed_config" ]; then
tell_status "installing local wp-config.php"
cp "$_installed_config" "$STAGE_MNT/usr/local/www/wordpress/" || exit
return
else
tell_status "post-install configuration will be required"
sleep 2
fi
tell_status "don't forget to add these to wp-config.php!"
tee /dev/null <<'EO_WP_NGINX'
// define('WP_CONTENT_DIR', '/data/content');
// define('WP_CONTENT_URL', '//www.example.org/wpn/content');
// Proxy settings
if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') $_SERVER['HTTPS']='on';
if ( isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR']) ) {
$ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
$_SERVER['REMOTE_ADDR'] = trim($ips[0]);
} elseif ( isset($_SERVER['HTTP_X_REAL_IP']) && !empty($_SERVER['HTTP_X_REAL_IP']) ) {
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_REAL_IP'];
} elseif ( isset($_SERVER['HTTP_CLIENT_IP']) && !empty($_SERVER['HTTP_CLIENT_IP']) ) {
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CLIENT_IP'];
}
define('WP_ALLOW_MULTISITE', true);
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', true);
define('DOMAIN_CURRENT_SITE', 'example.org');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);
EO_WP_NGINX
}
configure_wordpress()
{
configure_php wordpress
configure_nginx wordpress
configure_nginx_standalone
# configure_nginx_with_path /wpn
configure_wp_config
stage_sysrc nginx_flags='-c /data/etc/nginx.conf'
}
start_wordpress()
{
start_php_fpm
start_nginx
}
test_wordpress()
{
test_php_fpm
test_nginx
echo "it worked"
}
base_snapshot_exists || exit
create_staged_fs wordpress
start_staged_jail wordpress
install_wordpress
configure_wordpress
start_wordpress
test_wordpress
promote_staged_jail wordpress