preinstall.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/bash
  2. #
  3. # packager.io preinstall script
  4. #
  5. #
  6. # Make sure that after installation/update there can be only one sprockets manifest,
  7. # the one coming from the package. The package manager will ignore any duplicate files
  8. # which might come from a backup restore and/or a manual 'assets:precompile' command run.
  9. # These duplicates can cause the application to fail, however.
  10. #
  11. rm -f /opt/zammad/public/assets/.sprockets-manifest-*.json || true
  12. # Ensure database connectivity
  13. if [[ -f /opt/zammad/config/database.yml ]]; then
  14. DB_HOST="$(grep -m 1 '^[[:space:]]*host:' < /opt/zammad/config/database.yml | sed -e 's/.*host:[[:space:]]*//g')"
  15. DB_PORT="$(grep -m 1 '^[[:space:]]*port:' < /opt/zammad/config/database.yml | sed -e 's/.*port:[[:space:]]*//g')"
  16. DB_USER="$(grep -m 1 '^[[:space:]]*username:' < /opt/zammad/config/database.yml | sed -e 's/.*username:[[:space:]]*//g')"
  17. DB_PASS="$(grep -m 1 '^[[:space:]]*password:' < /opt/zammad/config/database.yml | sed -e 's/.*password:[[:space:]]*//g')"
  18. DB_SOCKET="$(grep -m 1 '^[[:space:]]*socket:' < /opt/zammad/config/database.yml | sed -e 's/.*socket:[[:space:]]*//g')"
  19. else
  20. # Skip this whole script if we can't find our database file
  21. echo "Warning: Could not find database.yml"
  22. exit 0
  23. fi
  24. if [ "${DB_HOST}x" == "x" ]; then
  25. DB_HOST="localhost"
  26. fi
  27. if [ -n "$(which psql 2> /dev/null)" ]; then
  28. if [ "${DB_PORT}x" == "x" ]; then
  29. DB_PORT="5432"
  30. fi
  31. if [ "${DB_SOCKET}x" == "x" ]; then
  32. pg_isready -q -h $DB_HOST -p $DB_PORT
  33. state=$?
  34. else
  35. pg_isready -q
  36. state=$?
  37. fi
  38. elif [ -n "$(which mysql 2> /dev/null)" ]; then
  39. if [ "${DB_PORT}x" == "x" ]; then
  40. DB_PORT="3306"
  41. fi
  42. mysqladmin status -h $DB_HOST -P $DB_PORT -u $DB_USER -p$DB_PASS > /dev/null
  43. state=$?
  44. fi
  45. # Check error state to ensure database is online
  46. if [[ $state -gt 0 ]]; then
  47. echo "!!! ERROR !!!"
  48. echo "Your database does not seem to be online!"
  49. echo "Please check your configuration in config/database.yml and ensure the configured database server is online."
  50. echo "Exiting Zammad package installation / upgrade - try again."
  51. exit 1
  52. fi
  53. # remove local files of the packages
  54. if [ -n "$(which zammad 2> /dev/null)" ]; then
  55. PATH=/opt/zammad/bin:/opt/zammad/vendor/bundle/bin:/sbin:/bin:/usr/sbin:/usr/bin:
  56. RAKE_TASKS=$(zammad run rake --tasks | grep "zammad:package:uninstall_all_files")
  57. if [[ x$RAKE_TASKS == 'x' ]]; then
  58. echo "# Code does not yet fit, skipping automatic package uninstall."
  59. echo "... This is not an error and will work during your next upgrade ..."
  60. exit 0
  61. fi
  62. if [ "$(zammad run rails r 'puts Package.count.positive?')" == "true" ] && [ -n "$(which yarn 2> /dev/null)" ] && [ -n "$(which node 2> /dev/null)" ]; then
  63. echo "# Detected custom packages..."
  64. echo "# Remove custom packages files temporarily..."
  65. zammad run rake zammad:package:uninstall_all_files
  66. fi
  67. fi