123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- #!/bin/bash
- set -eux
- readonly WP="/app/code/wp --allow-root"
- readonly admin_password=$(pwgen -1)
- echo "Admin password is ${admin_password}"
- if [[ -z "$(ls -A /app/data)" ]]; then
- echo "Copying wp-content files on first run"
- mv /app/code/wp-content /app/data/wp-content/
- rm -rf /app/code/wp-content
- ln -sf /app/data/wp-content /app/code/wp-content
- $WP core config --dbname="${MYSQL_DATABASE}" --dbuser="${MYSQL_USERNAME}" --dbpass="${MYSQL_PASSWORD}" --dbhost="${MYSQL_HOST}" --extra-php <<EOF
- // prevent user from changing the Settings->General, WordPress and Blog address values.
- define('WP_HOME', 'https://$(hostname -f)');
- define('WP_SITEURL', 'https://$(hostname -f)');
- /*
- http://cmanios.wordpress.com/2014/04/12/nginx-https-reverse-proxy-to-wordpress-with-apache-http-and-different-port/
- http://wordpress.org/support/topic/compatibility-with-wordpress-behind-a-reverse-proxy
- https://wordpress.org/support/topic/wp_home-and-wp_siteurl
- */
- // If WordPress is behind reverse proxy which proxies https to http
- if (!empty(\$_SERVER['HTTP_X_FORWARDED_FOR'])) {
- \$_SERVER['HTTP_HOST'] = \$_SERVER['HTTP_X_FORWARDED_HOST'];
- if (\$_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
- \$_SERVER['HTTPS']='on';
- }
- EOF
- readonly admin_email=${MAIL_SMTP_USERNAME}@${MAIL_DOMAIN}
- $WP --url="https://$(hostname -f)" core install \
- --url="https://$(hostname -f)" \
- --title="My blog" \
- --admin_user=admin \
- --admin_password="${admin_password}" \
- --admin_email="${admin_email}"
- echo "Installing OAuth plugin"
- $WP plugin install --activate --force /app/code/wp-oauth.zip
- $WP plugin install --activate --force /app/code/disable-wordpress-updates.zip
- $WP option update users_can_register 1
- $WP option update wpoa_cloudron_api_enabled 1
- $WP option update wpoa_new_user_role administrator
- $WP option update wpoa_hide_wordpress_login_form 1
- else
- rm -rf /app/code/wp-content # upgrades & updates - starting out with existing data
- ln -sf /app/data/wp-content /app/code/wp-content
- $WP user update $($WP user get admin --field=ID) --user_pass="${admin_password}"
- fi
- # Settings to be updated on every run
- sed -e "s/define('DB_NAME',.*/define('DB_NAME', '${MYSQL_DATABASE}');/" \
- -e "s/define('DB_USER',.*/define('DB_USER', '${MYSQL_USERNAME}');/" \
- -e "s/define('DB_PASSWORD',.*/define('DB_PASSWORD', '${MYSQL_PASSWORD}');/" \
- -e "s/define('DB_HOST',.*/define('DB_HOST', '${MYSQL_HOST}');/" \
- -i /app/data/wp-config.php # sed -i seems to destroy symlink
- $WP option update wpoa_cloudron_api_id "${OAUTH_CLIENT_ID}"
- $WP option update wpoa_cloudron_api_secret "${OAUTH_CLIENT_SECRET}"
- chown -R www-data:www-data /app/code /app/data
- /usr/bin/supervisord --configuration /etc/supervisor/supervisord.conf --nodaemon -i WordPress
|