start.sh 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. /*
  16. http://cmanios.wordpress.com/2014/04/12/nginx-https-reverse-proxy-to-wordpress-with-apache-http-and-different-port/
  17. http://wordpress.org/support/topic/compatibility-with-wordpress-behind-a-reverse-proxy
  18. https://wordpress.org/support/topic/wp_home-and-wp_siteurl
  19. */
  20. // If WordPress is behind reverse proxy which proxies https to http
  21. if (!empty(\$_SERVER['HTTP_X_FORWARDED_FOR'])) {
  22. \$_SERVER['HTTP_HOST'] = \$_SERVER['HTTP_X_FORWARDED_HOST'];
  23. if (\$_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
  24. \$_SERVER['HTTPS']='on';
  25. }
  26. EOF
  27. readonly admin_email=${MAIL_SMTP_USERNAME}@${MAIL_DOMAIN}
  28. $WP --url="https://$(hostname -f)" core install \
  29. --url="https://$(hostname -f)" \
  30. --title="My blog" \
  31. --admin_user=admin \
  32. --admin_password="${admin_password}" \
  33. --admin_email="${admin_email}"
  34. echo "Installing OAuth plugin"
  35. $WP plugin install --activate --force /app/code/wp-oauth.zip
  36. $WP plugin install --activate --force /app/code/disable-wordpress-updates.zip
  37. $WP plugin install --activate --force /app/code/wp-mail-smtp.zip
  38. $WP option update users_can_register 1 # without this, nothing works
  39. $WP option update wpoa_cloudron_api_enabled 1
  40. $WP option update wpoa_new_user_role administrator # TODO: let the plugin determine this from the oauth profile
  41. # $WP option update wpoa_hide_wordpress_login_form 1 # disabling this will make it impossible for users (commenters) to login
  42. $WP option update wpoa_suppress_welcome_email 1
  43. else
  44. rm -rf /app/code/wp-content # upgrades & updates - starting out with existing data
  45. ln -sf /app/data/wp-content /app/code/wp-content
  46. fi
  47. # Settings to be updated on every run
  48. sed -e "s/define('DB_NAME',.*/define('DB_NAME', '${MYSQL_DATABASE}');/" \
  49. -e "s/define('DB_USER',.*/define('DB_USER', '${MYSQL_USERNAME}');/" \
  50. -e "s/define('DB_PASSWORD',.*/define('DB_PASSWORD', '${MYSQL_PASSWORD}');/" \
  51. -e "s/define('DB_HOST',.*/define('DB_HOST', '${MYSQL_HOST}');/" \
  52. -i /app/data/wp-config.php # sed -i seems to destroy symlink
  53. # reset the admin password
  54. $WP user update $($WP user get admin --field=ID) --user_pass="${admin_password}"
  55. # configure WP mail smtp plugin (smtp_user, smtp_pass can be set when supported)
  56. $WP option update mailer smtp
  57. $WP option update mail_from ${MAIL_SMTP_USERNAME}@${MAIL_DOMAIN}
  58. $WP option update mail_from_name ${MAIL_SMTP_USERNAME}
  59. $WP option update smtp_host ${MAIL_SMTP_SERVER}
  60. $WP option update smtp_port ${MAIL_SMTP_PORT}
  61. $WP option update smtp_auth false
  62. $WP option update wpoa_cloudron_api_id "${OAUTH_CLIENT_ID}"
  63. $WP option update wpoa_cloudron_api_secret "${OAUTH_CLIENT_SECRET}"
  64. chown -R www-data:www-data /app/code /app/data
  65. /usr/bin/supervisord --configuration /etc/supervisor/supervisord.conf --nodaemon -i WordPress