setup.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env bash
  2. set -e
  3. if [ "$1" = 'builder' ]; then
  4. PACKAGES="build-essential curl git libimlib2-dev libpq-dev shared-mime-info postgresql"
  5. elif [ "$1" = 'runner' ]; then
  6. PACKAGES="curl libimlib2 libpq5 nginx gnupg postgresql-client"
  7. fi
  8. apt-get update
  9. apt-get upgrade -y
  10. # shellcheck disable=SC2086
  11. apt-get install -y --no-install-recommends ${PACKAGES}
  12. rm -rf /var/lib/apt/lists/*
  13. if [ "$1" = 'builder' ]; then
  14. # Create an empty DB just so that the Rails stack can run.
  15. /etc/init.d/postgresql start
  16. su - postgres bash -c "createuser zammad -R -S"
  17. su - postgres bash -c "createdb --encoding=utf8 --owner=zammad zammad"
  18. cd "${ZAMMAD_DIR}"
  19. bundle config set --local without 'test development mysql'
  20. # Don't use the 'deployment' switch here as it would require always using 'bundle exec'
  21. # to invoke commands like rails.
  22. bundle config set --local frozen 'true'
  23. bundle install
  24. touch db/schema.rb
  25. ZAMMAD_SAFE_MODE=1 DATABASE_URL=postgresql://zammad:/zammad bundle exec rake assets:precompile # Don't require Redis.
  26. script/build/cleanup.sh
  27. fi
  28. if [ "$1" = 'runner' ]; then
  29. groupadd -g 1000 "${ZAMMAD_USER}"
  30. useradd -M -d "${ZAMMAD_DIR}" -s /bin/bash -u 1000 -g 1000 "${ZAMMAD_USER}"
  31. 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
  32. mkdir -p "${ZAMMAD_DIR}" /var/log/nginx
  33. chown -R "${ZAMMAD_USER}":"${ZAMMAD_USER}" /etc/nginx /var/lib/nginx /var/log/nginx "${ZAMMAD_DIR}"
  34. fi