start.sh 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/bin/bash
  2. set -eu
  3. mkdir -p /app/data/public /run/apache2 /run/proftpd /run/app
  4. # check if any index file exists
  5. for f in /app/data/public/index.*; do
  6. [ -e "$f" ] && echo "Do not override existing index file" || cp /app/code/index.php /app/data/public/index.php
  7. break
  8. done
  9. # check for old webdav enabled apache2-app.conf
  10. if grep "### WARNING the following lines will be updated dynamically by start.sh" /app/data/apache2-app.conf; then
  11. echo "=> Removing old apache2-app.conf"
  12. rm -f /app/data/apache2-app.conf
  13. fi
  14. if [ ! -f "/app/data/php.ini" ]; then
  15. cp /etc/php/7.0/apache2/php.ini.orig /app/data/php.ini
  16. fi
  17. if [ ! -f "/app/data/apache2-app.conf" ]; then
  18. cp /app/code/apache2-app.conf /app/data/apache2-app.conf
  19. fi
  20. # SFTP_PORT can be unset to disable SFTP
  21. disable_sftp="false"
  22. if [[ -z "${SFTP_PORT:-}" ]]; then
  23. echo "SSH disabled"
  24. SFTP_PORT=29418 # arbitrary port to keep sshd happy
  25. disable_sftp="true"
  26. else
  27. sed -e "s,##SERVER_NAME,${APP_DOMAIN}," \
  28. -e "s/##SFTP_PORT/${SFTP_PORT}/" \
  29. -e "s,##LDAP_URL,${LDAP_URL},g" \
  30. -e "s/##LDAP_BIND_DN/${LDAP_BIND_DN}/g" \
  31. -e "s/##LDAP_BIND_PASSWORD/${LDAP_BIND_PASSWORD}/g" \
  32. -e "s/##LDAP_USERS_BASE_DN/${LDAP_USERS_BASE_DN}/g" \
  33. -e "s/##LDAP_UID/$(id -u www-data)/g" \
  34. -e "s/##LDAP_GID/$(id -g www-data)/g" \
  35. /app/code/proftpd.conf.template > /run/proftpd/proftpd.conf
  36. if [[ -f /app/data/public/index.php ]]; then
  37. sed -e "s,##SFTP_PORT,${SFTP_PORT}," \
  38. -e "s,##SFTP_DOMAIN,${APP_DOMAIN}," \
  39. -i /app/data/public/index.php
  40. fi
  41. fi
  42. if [[ ! -f "/app/data/sftpd/ssh_host_ed25519_key" ]]; then
  43. echo "Generating ssh host keys"
  44. mkdir -p /app/data/sftpd
  45. ssh-keygen -qt rsa -N '' -f /app/data/sftpd/ssh_host_rsa_key
  46. ssh-keygen -qt dsa -N '' -f /app/data/sftpd/ssh_host_dsa_key
  47. ssh-keygen -qt ecdsa -N '' -f /app/data/sftpd/ssh_host_ecdsa_key
  48. ssh-keygen -qt ed25519 -N '' -f /app/data/sftpd/ssh_host_ed25519_key
  49. else
  50. echo "Reusing existing host keys"
  51. fi
  52. chmod 0600 /app/data/sftpd/*_key
  53. chmod 0644 /app/data/sftpd/*.pub
  54. ## hook for custom start script in /app/data/run.sh
  55. if [ -f "/app/data/run.sh" ]; then
  56. /bin/bash /app/data/run.sh
  57. fi
  58. chown -R www-data:www-data /app/data /run/apache2 /run/proftpd /run/app
  59. echo "Starting supervisord"
  60. exec /usr/bin/supervisord --configuration /etc/supervisor/supervisord.conf --nodaemon -i Lamp