forked from eugeneware/docker-wordpress-nginx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.sh
executable file
·54 lines (47 loc) · 2.52 KB
/
start.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
#!/bin/bash
if [ ! -f /usr/share/nginx/www/wp-config.php ]; then
cp -r /usr/share/nginx/wordpress/* /usr/share/nginx/www
rm -rf /usr/share/nginx/wordpress
chown -R www-data:www-data /usr/share/nginx/www
# Here we generate random passwords (thank you pwgen!). The first two are for mysql users, the last batch for random keys in wp-config.php
WORDPRESS_DB=${DB_NAME:-wordpress}
WORDPRESS_PASSWORD=${DB_PASSWORD}
#This is so the passwords show up in logs.
echo wordpress password: $WORDPRESS_PASSWORD
echo $WORDPRESS_PASSWORD > /wordpress-db-pw.txt
sed -e "s/database_name_here/$WORDPRESS_DB/
s/username_here/$WORDPRESS_DB/
s/password_here/$WORDPRESS_PASSWORD/
s/localhost/${MYSQL_PORT_3306_TCP_ADDR}/
/'AUTH_KEY'/s/put your unique phrase here/`pwgen -c -n -1 65`/
/'SECURE_AUTH_KEY'/s/put your unique phrase here/`pwgen -c -n -1 65`/
/'LOGGED_IN_KEY'/s/put your unique phrase here/`pwgen -c -n -1 65`/
/'NONCE_KEY'/s/put your unique phrase here/`pwgen -c -n -1 65`/
/'AUTH_SALT'/s/put your unique phrase here/`pwgen -c -n -1 65`/
/'SECURE_AUTH_SALT'/s/put your unique phrase here/`pwgen -c -n -1 65`/
/'LOGGED_IN_SALT'/s/put your unique phrase here/`pwgen -c -n -1 65`/
/'NONCE_SALT'/s/put your unique phrase here/`pwgen -c -n -1 65`/" /usr/share/nginx/www/wp-config-sample.php > /usr/share/nginx/www/wp-config.php
# Download nginx helper plugin
curl -O `curl -i -s https://wordpress.org/plugins/nginx-helper/ | egrep -o "https://downloads.wordpress.org/plugin/nginx-helper.zip"`
unzip -o nginx-helper.zip -d /usr/share/nginx/www/wp-content/plugins
chown -R www-data:www-data /usr/share/nginx/www/wp-content/plugins/nginx-helper
# Activate nginx plugin and set up pretty permalink structure once logged in
cat << ENDL >> /usr/share/nginx/www/wp-config.php
\$plugins = get_option( 'active_plugins' );
if ( count( \$plugins ) === 0 ) {
require_once(ABSPATH .'/wp-admin/includes/plugin.php');
\$wp_rewrite->set_permalink_structure( '/%postname%/' );
\$pluginsToActivate = array( 'nginx-helper/nginx-helper.php' );
foreach ( \$pluginsToActivate as \$plugin ) {
if ( !in_array( \$plugin, \$plugins ) ) {
activate_plugin( '/usr/share/nginx/www/wp-content/plugins/' . \$plugin );
}
}
}
ENDL
chown www-data:www-data /usr/share/nginx/www/wp-config.php
fi
chown -R www-data:www-data /usr/share/nginx/www
sed -i -e "/'DB_HOST'/s/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/${MYSQL_PORT_3306_TCP_ADDR}/" /usr/share/nginx/www/wp-config.php
# start all the services
/usr/local/bin/supervisord -n