start.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. # cleanup for old apache2-app.conf
  10. rm -f /app/data/apache2-app.conf
  11. if [ ! -f "/app/data/php.ini" ]; then
  12. cp /etc/php/7.0/apache2/php.ini.orig /app/data/php.ini
  13. fi
  14. # SFTP_PORT can be unset to disable SFTP
  15. disable_sftp="false"
  16. if [[ -z "${SFTP_PORT:-}" ]]; then
  17. echo "SSH disabled"
  18. SFTP_PORT=29418 # arbitrary port to keep sshd happy
  19. disable_sftp="true"
  20. else
  21. sed -e "s,##SERVER_NAME,${APP_DOMAIN}," \
  22. -e "s/##SFTP_PORT/${SFTP_PORT}/" \
  23. -e "s,##LDAP_URL,${LDAP_URL},g" \
  24. -e "s/##LDAP_BIND_DN/${LDAP_BIND_DN}/g" \
  25. -e "s/##LDAP_BIND_PASSWORD/${LDAP_BIND_PASSWORD}/g" \
  26. -e "s/##LDAP_USERS_BASE_DN/${LDAP_USERS_BASE_DN}/g" \
  27. -e "s/##LDAP_UID/$(id -u www-data)/g" \
  28. -e "s/##LDAP_GID/$(id -g www-data)/g" \
  29. /app/code/proftpd.conf.template > /run/proftpd/proftpd.conf
  30. if [[ -f /app/data/public/index.php ]]; then
  31. sed -e "s,^sftp -P.*public/$,sftp -P ${SFTP_PORT} ${APP_DOMAIN}:public/," \
  32. -i /app/data/public/index.php
  33. fi
  34. fi
  35. if [[ ! -f "/app/data/sftpd/ssh_host_ed25519_key" ]]; then
  36. echo "Generating ssh host keys"
  37. mkdir -p /app/data/sftpd
  38. ssh-keygen -qt rsa -N '' -f /app/data/sftpd/ssh_host_rsa_key
  39. ssh-keygen -qt dsa -N '' -f /app/data/sftpd/ssh_host_dsa_key
  40. ssh-keygen -qt ecdsa -N '' -f /app/data/sftpd/ssh_host_ecdsa_key
  41. ssh-keygen -qt ed25519 -N '' -f /app/data/sftpd/ssh_host_ed25519_key
  42. else
  43. echo "Reusing existing host keys"
  44. fi
  45. chmod 0600 /app/data/sftpd/*_key
  46. chmod 0644 /app/data/sftpd/*.pub
  47. ## Generate apache config. PMA is disabled based on SFTP config
  48. if [[ "${disable_sftp}" == "true" ]]; then
  49. echo "PMA disabled"
  50. sed '/.*PMA BEGIN/,/.*PMA END/d' /app/code/apache2-app.conf > /run/apache2/app.conf
  51. else
  52. sed -e "s@AuthLDAPURL .*@AuthLDAPURL ${LDAP_URL}/${LDAP_USERS_BASE_DN}?username??(objectclass=user)@" \
  53. -e "s@AuthLDAPBindDN .*@AuthLDAPBindDN ${LDAP_BIND_DN}@" \
  54. -e "s@AuthLDAPBindPassword .*@AuthLDAPBindPassword ${LDAP_BIND_PASSWORD}@" \
  55. /app/code/apache2-app.conf > /run/apache2/app.conf
  56. fi
  57. ## hook for custom start script in /app/data/run.sh
  58. if [ -f "/app/data/run.sh" ]; then
  59. /bin/bash /app/data/run.sh
  60. fi
  61. ## configure in-container Crontab
  62. if [ -f "/app/data/crontab" ]; then
  63. crontab -u www-data /app/data/crontab
  64. fi
  65. chown -R www-data:www-data /app/data /run/apache2 /run/proftpd /run/app
  66. echo "Starting supervisord"
  67. exec /usr/bin/supervisord --configuration /etc/supervisor/supervisord.conf --nodaemon -i Lamp