start.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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
  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
  42. else
  43. rm -rf /app/code/wp-content # upgrades & updates - starting out with existing data
  44. ln -sf /app/data/wp-content /app/code/wp-content
  45. $WP user update $($WP user get admin --field=ID) --user_pass="${admin_password}"
  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. # configure WP mail smtp plugin (smtp_user, smtp_pass can be set when supported)
  54. $WP option update mailer smtp
  55. $WP option update mail_from ${MAIL_SMTP_USERNAME}@${MAIL_DOMAIN}
  56. $WP option update mail_from_name ${MAIL_SMTP_USERNAME}
  57. $WP option update smtp_host ${MAIL_SMTP_SERVER}
  58. $WP option update smtp_port ${MAIL_SMTP_PORT}
  59. $WP option update smtp_auth false
  60. $WP option update wpoa_cloudron_api_id "${OAUTH_CLIENT_ID}"
  61. $WP option update wpoa_cloudron_api_secret "${OAUTH_CLIENT_SECRET}"
  62. chown -R www-data:www-data /app/code /app/data
  63. /usr/bin/supervisord --configuration /etc/supervisor/supervisord.conf --nodaemon -i WordPress