start.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. #!/bin/bash
  2. set -eux
  3. if [[ -z "$(ls -A /app/data)" ]]; then
  4. echo "Copying wp-content files on first run"
  5. mv /app/code/wp-content /app/data/wp-content/
  6. fi
  7. [[ ! -L "/app/code/wp-content" ]] && rm -rf /app/code/wp-content # upgrades & updates - starting out with existing data
  8. ln -sf /app/data/wp-content /app/code/wp-content
  9. : ${MYSQL_URL:=}
  10. if [[ -z "${MYSQL_URL}" ]]; then
  11. echo "MYSQL_URL is empty"
  12. exit 1
  13. fi
  14. proto="$(echo "${MYSQL_URL}" | sed -e's,^\(.*://\).*,\1,g')"
  15. url="$(echo ${MYSQL_URL/$proto/})"
  16. username="$(echo ${url} | cut -d: -f1)"
  17. password=$(echo ${url/$username:/} | cut -d@ -f1)
  18. host="$(echo ${url/$username:$password@/} | cut -d/ -f1)"
  19. db="$(echo ${url} | grep / | cut -d/ -f2-)"
  20. sed -e "s/define('DB_NAME',.*/define('DB_NAME', '${db}');/" \
  21. -e "s/define('DB_USER',.*/define('DB_USER', '${username}');/" \
  22. -e "s/define('DB_PASSWORD',.*/define('DB_PASSWORD', '${password}');/" \
  23. -e "s/define('DB_HOST',.*/define('DB_HOST', '${host}');/" \
  24. /app/configs/wp-config.php.template > /app/code/wp-config.php
  25. /usr/bin/supervisord --configuration /etc/supervisor/supervisord.conf --nodaemon -i WordPress