start.sh 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. ## hook for custom start script in /app/data/run.sh
  48. if [ -f "/app/data/run.sh" ]; then
  49. /bin/bash /app/data/run.sh
  50. fi
  51. chown -R www-data:www-data /app/data /run/apache2 /run/proftpd /run/app
  52. echo "Starting supervisord"
  53. exec /usr/bin/supervisord --configuration /etc/supervisor/supervisord.conf --nodaemon -i Lamp