preinstall.sh 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. DB_ADAPTER="$(grep -m 1 '^[[:space:]]*adapter:' < /opt/zammad/config/database.yml | sed -e 's/.*adapter:[[:space:]]*//g')"
  20. else
  21. # Skip this whole script if we can't find our database file
  22. echo "Warning: Could not find database.yml"
  23. exit 0
  24. fi
  25. if [ "${DB_HOST}x" == "x" ]; then
  26. DB_HOST="localhost"
  27. fi
  28. if [ -n "$(which psql 2> /dev/null)" ] && [ "${DB_ADAPTER}" == 'postgresql' ]; then
  29. if [ "${DB_PORT}x" == "x" ]; then
  30. DB_PORT="5432"
  31. fi
  32. if [ "${DB_SOCKET}x" == "x" ]; then
  33. pg_isready -q -h $DB_HOST -p $DB_PORT
  34. state=$?
  35. else
  36. pg_isready -q
  37. state=$?
  38. fi
  39. elif [ -n "$(which mysql 2> /dev/null)" ] && [ "${DB_ADAPTER}" == 'mysql2' ]; then
  40. if [ "${DB_PORT}x" == "x" ]; then
  41. DB_PORT="3306"
  42. fi
  43. mysqladmin status -h $DB_HOST -P $DB_PORT -u $DB_USER -p$DB_PASS > /dev/null
  44. state=$?
  45. fi
  46. # Check error state to ensure database is online
  47. if [[ $state -gt 0 ]]; then
  48. echo "!!! ERROR !!!"
  49. echo "Your database does not seem to be online!"
  50. echo "Please check your configuration in config/database.yml and ensure the configured database server is online."
  51. echo "Exiting Zammad package installation / upgrade - try again."
  52. exit 1
  53. fi
  54. # remove local files of the packages
  55. if [ -n "$(which zammad 2> /dev/null)" ]; then
  56. PATH=/opt/zammad/bin:/opt/zammad/vendor/bundle/bin:/sbin:/bin:/usr/sbin:/usr/bin:
  57. RAKE_TASKS=$(zammad run rake --tasks | grep "zammad:package:uninstall_all_files")
  58. if [[ x$RAKE_TASKS == 'x' ]]; then
  59. echo "# Code does not yet fit, skipping automatic package uninstall."
  60. echo "... This is not an error and will work during your next upgrade ..."
  61. exit 0
  62. fi
  63. if [ "$(zammad run rails r 'puts Package.count.positive?')" == "true" ] && [ -n "$(which pnpm 2> /dev/null)" ] && [ -n "$(which node 2> /dev/null)" ]; then
  64. echo "# Detected custom packages..."
  65. echo "# Remove custom packages files temporarily..."
  66. zammad run rake zammad:package:uninstall_all_files
  67. fi
  68. fi