start.sh 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/bin/bash
  2. set -eu
  3. echo "=========================="
  4. echo " Etherpad start "
  5. echo "=========================="
  6. # make npm behave a bit to improve our log display
  7. export npm_config_progress=false
  8. export npm_config_color=false
  9. export npm_config_spin=false
  10. echo "=> Ensure directories"
  11. mkdir -p /run/etherpad-lite/run /run/etherpad-lite/var /app/data/node_modules /run/etherpad-lite/npm /app/data/custom
  12. # the idea here is make the node_modules dir writable so that ep can install plugins there
  13. # the ep_cloudron has to be symlinked at the top level so that ep can find it
  14. echo "=> Fixing up node_modules"
  15. ln -Tsf /app/code/src /app/data/node_modules/ep_etherpad-lite # this symlink is "require"d by plugins
  16. echo "=> Ensuring cloudron plugin"
  17. npm install ep_cloudron@2.0.4
  18. # Use this instead of the line above during ep_cloudron development
  19. # npm install git+https://git.cloudron.io/cloudron/ep_cloudron.git\#devel --force
  20. # We setup the app with some useful default plugins, the user may or may not uninstall them afterwards
  21. if [[ ! -f "/app/data/.installed" ]]; then
  22. echo "=> First run, installing default plugins"
  23. npm install --no-package-lock ep_page_view ep_headings2 ep_font_color ep_font_family ep_font_size ep_superscript ep_subscript
  24. touch "/app/data/.installed"
  25. fi
  26. echo "=> Ensuring templates"
  27. for f in "index" "pad" "timeslider"; do
  28. if [[ ! -f "/app/data/custom/$f.js" ]]; then
  29. cp "/app/code/src/static/custom_templates/js.template" "/app/data/custom/$f.js"
  30. fi
  31. if [[ ! -f "/app/data/custom/$f.css" ]]; then
  32. cp "/app/code/src/static/custom_templates/css.template" "/app/data/custom/$f.css"
  33. fi
  34. done
  35. echo "=> Generating settings.json"
  36. sed -e "s/##MYSQL_HOST/${MYSQL_HOST}/g" \
  37. -e "s/##MYSQL_PORT/${MYSQL_PORT}/g" \
  38. -e "s/##MYSQL_USERNAME/${MYSQL_USERNAME}/g" \
  39. -e "s/##MYSQL_PASSWORD/${MYSQL_PASSWORD}/g" \
  40. -e "s/##MYSQL_DATABASE/${MYSQL_DATABASE}/g" \
  41. /app/code/settings.json.template > "/run/etherpad-lite/settings.json"
  42. echo "=> Ensure /app/data/settings.json"
  43. if [[ ! -f "/app/data/settings.json" ]]; then
  44. echo -e "{\n\n}" > "/app/data/settings.json"
  45. fi
  46. echo "=> Ensure folder permissions"
  47. chown -R cloudron:cloudron /run/etherpad-lite /app/data
  48. echo "=> Starting etherpad"
  49. export NODE_ENV=production
  50. # etherpad expects APIKEY, SESSIONKEY, node_modules in curdir
  51. cd /app/code
  52. exec /usr/local/bin/gosu cloudron:cloudron node /app/code/src/node/server.js --settings /run/etherpad-lite/settings.json --credentials /app/data/settings.json