start.sh 3.1 KB

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