start.sh 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. if [ ! -f "/app/data/php.ini" ]; then
  10. cp /etc/php/7.0/apache2/php.ini.orig /app/data/php.ini
  11. fi
  12. if [ ! -f "/app/data/apache2-app.conf" ]; then
  13. cp /app/code/apache2-app.conf /app/data/apache2-app.conf
  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_PORT,${SFTP_PORT}," \
  33. -e "s,##SFTP_DOMAIN,${APP_DOMAIN}," \
  34. -i /app/data/public/index.php
  35. fi
  36. fi
  37. if [[ ! -f "/app/data/sftpd/ssh_host_ed25519_key" ]]; then
  38. echo "Generating ssh host keys"
  39. mkdir -p /app/data/sftpd
  40. ssh-keygen -qt rsa -N '' -f /app/data/sftpd/ssh_host_rsa_key
  41. ssh-keygen -qt dsa -N '' -f /app/data/sftpd/ssh_host_dsa_key
  42. ssh-keygen -qt ecdsa -N '' -f /app/data/sftpd/ssh_host_ecdsa_key
  43. ssh-keygen -qt ed25519 -N '' -f /app/data/sftpd/ssh_host_ed25519_key
  44. else
  45. echo "Reusing existing host keys"
  46. fi
  47. chmod 0600 /app/data/sftpd/*_key
  48. chmod 0644 /app/data/sftpd/*.pub
  49. ## hook for custom start script in /app/data/run.sh
  50. if [ -f "/app/data/run.sh" ]; then
  51. /bin/bash /app/data/run.sh
  52. fi
  53. chown -R www-data:www-data /app/data /run/apache2 /run/proftpd /run/app
  54. echo "Starting supervisord"
  55. exec /usr/bin/supervisord --configuration /etc/supervisor/supervisord.conf --nodaemon -i Lamp