start.sh 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/bin/bash
  2. set -eu
  3. readonly WP="/app/code/wp --allow-root"
  4. readonly admin_password=$(pwgen -1y 16)
  5. readonly admin_email=${MAIL_SMTP_USERNAME}@${MAIL_DOMAIN}
  6. echo "Admin password is ${admin_password} and email is ${admin_email}"
  7. # Settings to be updated on every run. Regenerating salts means users have to relogin
  8. sed -e "s/##MYSQL_DATABASE/${MYSQL_DATABASE}/" \
  9. -e "s/##MYSQL_USERNAME/${MYSQL_USERNAME}/" \
  10. -e "s/##MYSQL_PASSWORD/${MYSQL_PASSWORD}/" \
  11. -e "s/##MYSQL_HOST/${MYSQL_HOST}:${MYSQL_PORT}/" \
  12. -e "s,##APP_ORIGIN,${APP_ORIGIN}," \
  13. -e "s/##AUTH_KEY/$(pwgen -1cns 64)/" \
  14. -e "s/##SECURE_AUTH_KEY/$(pwgen -1cns 64)/" \
  15. -e "s/##LOGGED_IN_KEY/$(pwgen -1cns 64)/" \
  16. -e "s/##NONCE_KEY/$(pwgen -1cns 64)/" \
  17. -e "s/##AUTH_SALT/$(pwgen -1cns 64)/" \
  18. -e "s/##SECURE_AUTH_SALT/$(pwgen -1cns 64)/" \
  19. -e "s/##LOGGED_IN_SALT/$(pwgen -1cns 64)/" \
  20. -e "s/##NONCE_SALT/$(pwgen -1cns 64)/" \
  21. /app/code/wp-config.php.template > /run/wordpress/wp-config.php # sed -i seems to destroy symlink
  22. if [[ -z "$(ls -A /app/data)" ]]; then
  23. echo "Copying wp-content files on first run"
  24. mkdir -p /app/data/wp-content/mu-plugins
  25. cp -r /app/code/wp-content-vanilla/* /app/data/wp-content/
  26. # create db tables
  27. $WP --url="${APP_ORIGIN}" core install \
  28. --url="${APP_ORIGIN}" \
  29. --title="My blog" \
  30. --admin_user=admin \
  31. --admin_password="${admin_password}" \
  32. --admin_email="${admin_email}"
  33. # install and backup the plugins
  34. $WP plugin install --activate --force /app/code/disable-wordpress-updates.zip
  35. mv /app/data/wp-content/plugins/disable-wordpress-updates /app/data/wp-content/mu-plugins/
  36. $WP plugin install --activate --force /app/code/wp-mail-smtp.zip
  37. mv /app/data/wp-content/plugins/wp-mail-smtp /app/data/wp-content/mu-plugins/
  38. else
  39. # Update wordpress
  40. $WP core update-db
  41. fi
  42. # reset the admin password
  43. $WP user update $($WP user get admin --field=ID) --user_pass="${admin_password}"
  44. $WP user update $($WP user get admin --field=ID) --user_email="${admin_email}"
  45. # configure WP mail smtp plugin (smtp_user, smtp_pass can be set when supported)
  46. $WP option update mailer smtp
  47. $WP option update mail_from ${MAIL_SMTP_USERNAME}@${MAIL_DOMAIN}
  48. $WP option update mail_from_name ${MAIL_SMTP_USERNAME}
  49. $WP option update smtp_host ${MAIL_SMTP_SERVER}
  50. $WP option update smtp_port ${MAIL_SMTP_PORT}
  51. $WP option update smtp_auth false
  52. chown -R www-data:www-data /app/data
  53. echo "Starting apache"
  54. APACHE_CONFDIR="" source /etc/apache2/envvars
  55. rm -f "${APACHE_PID_FILE}"
  56. exec /usr/sbin/apache2 -DFOREGROUND