start.sh 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/bash
  2. set -eux
  3. readonly WP="/app/code/wp --allow-root"
  4. readonly admin_password=$(pwgen -1)
  5. echo "Admin password is ${admin_password}"
  6. if [[ -z "$(ls -A /app/data)" ]]; then
  7. echo "Copying wp-content files on first run"
  8. mv /app/code/wp-content /app/data/wp-content/
  9. rm -rf /app/code/wp-content
  10. ln -sf /app/data/wp-content /app/code/wp-content
  11. $WP core config --dbname="${MYSQL_DATABASE}" --dbuser="${MYSQL_USERNAME}" --dbpass="${MYSQL_PASSWORD}" --dbhost="${MYSQL_HOST}" --extra-php <<EOF
  12. // prevent user from changing the Settings->General, WordPress and Blog address values.
  13. define('WP_HOME', 'https://$(hostname -f)');
  14. define('WP_SITEURL', 'https://$(hostname -f)');
  15. define('AUTOMATIC_UPDATER_DISABLED', true);
  16. /*
  17. http://cmanios.wordpress.com/2014/04/12/nginx-https-reverse-proxy-to-wordpress-with-apache-http-and-different-port/
  18. http://wordpress.org/support/topic/compatibility-with-wordpress-behind-a-reverse-proxy
  19. https://wordpress.org/support/topic/wp_home-and-wp_siteurl
  20. */
  21. // If WordPress is behind reverse proxy which proxies https to http
  22. if (!empty(\$_SERVER['HTTP_X_FORWARDED_FOR'])) {
  23. \$_SERVER['HTTP_HOST'] = \$_SERVER['HTTP_X_FORWARDED_HOST'];
  24. if (\$_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
  25. \$_SERVER['HTTPS']='on';
  26. }
  27. EOF
  28. readonly admin_email=${MAIL_SMTP_USERNAME}@${MAIL_DOMAIN}
  29. $WP --url="https://$(hostname -f)" core install \
  30. --url="https://$(hostname -f)" \
  31. --title="My blog" \
  32. --admin_user=admin \
  33. --admin_password="${admin_password}" \
  34. --admin_email="${admin_email}"
  35. echo "Installing OAuth plugin"
  36. $WP plugin install --activate --force /app/code/wp-oauth.zip
  37. $WP option update users_can_register 1
  38. $WP option update wpoa_cloudron_api_enabled 1
  39. $WP option update wpoa_new_user_role administrator
  40. else
  41. rm -rf /app/code/wp-content # upgrades & updates - starting out with existing data
  42. ln -sf /app/data/wp-content /app/code/wp-content
  43. $WP user update "$($WP user get admin --field=ID)" --user_pass="${admin_password}"
  44. fi
  45. # Settings to be updated on every run
  46. sed -e "s/define('DB_NAME',.*/define('DB_NAME', '${MYSQL_DATABASE}');/" \
  47. -e "s/define('DB_USER',.*/define('DB_USER', '${MYSQL_USERNAME}');/" \
  48. -e "s/define('DB_PASSWORD',.*/define('DB_PASSWORD', '${MYSQL_PASSWORD}');/" \
  49. -e "s/define('DB_HOST',.*/define('DB_HOST', '${MYSQL_HOST}');/" \
  50. -i /app/data/wp-config.php # sed -i seems to destroy symlink
  51. $WP option update wpoa_cloudron_api_id "${OAUTH_CLIENT_ID}"
  52. $WP option update wpoa_cloudron_api_secret "${OAUTH_CLIENT_SECRET}"
  53. chown -R www-data:www-data /app/code /app/data
  54. /usr/bin/supervisord --configuration /etc/supervisor/supervisord.conf --nodaemon -i WordPress