start.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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_PORT,${SFTP_PORT}," \
  32. -e "s,##SFTP_DOMAIN,${APP_DOMAIN}," \
  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. ## hook for custom start script in /app/data/run.sh
  49. if [ -f "/app/data/run.sh" ]; then
  50. /bin/bash /app/data/run.sh
  51. fi
  52. chown -R www-data:www-data /app/data /run/apache2 /run/proftpd /run/app
  53. echo "Starting supervisord"
  54. exec /usr/bin/supervisord --configuration /etc/supervisor/supervisord.conf --nodaemon -i Lamp