start.sh 3.0 KB

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