start.sh 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/bash
  2. set -eux
  3. readonly WP=/app/code/wp
  4. if [[ -z "$(ls -A /app/data)" ]]; then
  5. echo "Copying wp-content files on first run"
  6. mv /app/code/wp-content /app/data/wp-content/
  7. rm -rf /app/code/wp-content
  8. ln -sf /app/data/wp-content /app/code/wp-content
  9. $WP core config --allow-root --dbname="${MYSQL_DATABASE}" --dbuser="${MYSQL_USERNAME}" --dbpass="${MYSQL_PASSWORD}" --dbhost="${MYSQL_HOST}" --extra-php <<EOF
  10. // prevent user from changing the Settings->General, WordPress and Blog address values.
  11. define('WP_HOME', 'https://$(hostname -f)');
  12. define('WP_SITEURL', 'https://$(hostname -f)');
  13. /*
  14. http://cmanios.wordpress.com/2014/04/12/nginx-https-reverse-proxy-to-wordpress-with-apache-http-and-different-port/
  15. http://wordpress.org/support/topic/compatibility-with-wordpress-behind-a-reverse-proxy
  16. https://wordpress.org/support/topic/wp_home-and-wp_siteurl
  17. */
  18. // If WordPress is behind reverse proxy which proxies https to http
  19. if (!empty(\$_SERVER['HTTP_X_FORWARDED_FOR'])) {
  20. \$_SERVER['HTTP_HOST'] = \$_SERVER['HTTP_X_FORWARDED_HOST'];
  21. if (\$_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
  22. \$_SERVER['HTTPS']='on';
  23. }
  24. EOF
  25. readonly admin_password=$(pwgen -1)
  26. readonly admin_email=${MAIL_SMTP_USERNAME}@${MAIL_DOMAIN}
  27. echo "Admin password is ${admin_password}"
  28. $WP --url="https://$(hostname -f)" core install \
  29. --allow-root \
  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 --allow-root --activate --force https://github.com//cloudron-io/WP-OAuth/archive/5e77ff326b26f6175fefcd25f46d6c45e0fa14fa.zip
  37. else
  38. rm -rf /app/code/wp-content # upgrades & updates - starting out with existing data
  39. ln -sf /app/data/wp-content /app/code/wp-content
  40. fi
  41. # Settings to be updated on every run
  42. sed -e "s/define('DB_NAME',.*/define('DB_NAME', '${MYSQL_DATABASE}');/" \
  43. -e "s/define('DB_USER',.*/define('DB_USER', '${MYSQL_USERNAME}');/" \
  44. -e "s/define('DB_PASSWORD',.*/define('DB_PASSWORD', '${MYSQL_PASSWORD}');/" \
  45. -e "s/define('DB_HOST',.*/define('DB_HOST', '${MYSQL_HOST}');/" \
  46. -i /app/data/wp-config.php # sed -i seems to destroy symlink
  47. /usr/bin/supervisord --configuration /etc/supervisor/supervisord.conf --nodaemon -i WordPress