setup.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env bash
  2. set -e
  3. apt-get update
  4. apt-get upgrade -y
  5. # Add official PostgreSQL apt repository to not depend on Debian's version.
  6. # https://www.postgresql.org/download/linux/debian/
  7. apt-get install -y postgresql-common
  8. /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y
  9. if [ "$1" = 'builder' ]; then
  10. PACKAGES="build-essential curl git libimlib2-dev libpq-dev shared-mime-info postgresql-17"
  11. elif [ "$1" = 'runner' ]; then
  12. PACKAGES="curl libimlib2 libpq5 nginx gnupg postgresql-client-17"
  13. fi
  14. # shellcheck disable=SC2086
  15. apt-get install -y --no-install-recommends ${PACKAGES}
  16. rm -rf /var/lib/apt/lists/*
  17. if [ "$1" = 'builder' ]; then
  18. # Create an empty DB just so that the Rails stack can run.
  19. /etc/init.d/postgresql start
  20. su - postgres bash -c "createuser zammad -R -S"
  21. su - postgres bash -c "createdb --encoding=utf8 --owner=zammad zammad"
  22. cd "${ZAMMAD_DIR}"
  23. bundle config set --local without 'test development mysql'
  24. # Don't use the 'deployment' switch here as it would require always using 'bundle exec'
  25. # to invoke commands like rails.
  26. bundle config set --local frozen 'true'
  27. bundle install
  28. touch db/schema.rb
  29. ZAMMAD_SAFE_MODE=1 DATABASE_URL=postgresql://zammad:/zammad bundle exec rake assets:precompile # Don't require Redis.
  30. script/build/cleanup.sh
  31. fi
  32. if [ "$1" = 'runner' ]; then
  33. groupadd -g 1000 "${ZAMMAD_USER}"
  34. useradd -M -d "${ZAMMAD_DIR}" -s /bin/bash -u 1000 -g 1000 "${ZAMMAD_USER}"
  35. sed -i -e "s#user www-data;##g" -e 's#/var/log/nginx/\(access\|error\).log#/dev/stdout#g' -e 's#pid /run/nginx.pid;#pid /tmp/nginx.pid;#g' /etc/nginx/nginx.conf
  36. mkdir -p "${ZAMMAD_DIR}" /var/log/nginx
  37. # Pre-create the storage/ and tmp/ folders to avoid mount permission issues (see https://github.com/zammad/zammad/issues/5412).
  38. mkdir -p "${ZAMMAD_DIR}/storage" "${ZAMMAD_DIR}/tmp"
  39. chown -R "${ZAMMAD_USER}":"${ZAMMAD_USER}" /etc/nginx /var/lib/nginx /var/log/nginx "${ZAMMAD_DIR}"
  40. fi