start.sh 3.3 KB

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