2016-10-25 13:29:10 +00:00
|
|
|
#!/bin/bash
|
2016-10-25 13:51:46 +00:00
|
|
|
#
|
|
|
|
# packager.io postinstall script
|
|
|
|
#
|
2016-10-25 15:59:31 +00:00
|
|
|
|
|
|
|
PATH=/opt/zammad/bin:/opt/zammad/vendor/bundle/bin:/sbin:/bin:/usr/sbin:/usr/bin:
|
|
|
|
|
2016-10-25 16:07:10 +00:00
|
|
|
ZAMMAD_DIR="/opt/zammad"
|
2016-10-25 15:59:31 +00:00
|
|
|
DB="zammad_production"
|
|
|
|
DB_USER="zammad"
|
|
|
|
|
2016-10-26 14:28:59 +00:00
|
|
|
echo "# (Re)creating init scripts"
|
2016-10-26 11:45:14 +00:00
|
|
|
zammad scale web=1 websocket=1 worker=1
|
|
|
|
|
2016-10-26 14:28:59 +00:00
|
|
|
echo "# Stopping Zammad"
|
2016-10-26 11:45:14 +00:00
|
|
|
systemctl stop zammad
|
|
|
|
|
2016-10-26 14:28:59 +00:00
|
|
|
# check if database.yml.bak exists
|
|
|
|
if [ -f ${ZAMMAD_DIR}/config/database.yml.bak ]; then
|
|
|
|
# copy database.yml.bak to database.yml
|
|
|
|
cp ${ZAMMAD_DIR}/config/database.yml.bak ${ZAMMAD_DIR}/config/database.yml
|
2016-10-25 15:59:31 +00:00
|
|
|
|
2016-10-26 11:45:14 +00:00
|
|
|
# db migration
|
2016-10-26 14:28:59 +00:00
|
|
|
echo "# database.yml.bak exists. Updating db..."
|
2016-10-26 11:45:14 +00:00
|
|
|
zammad run rake db:migrate
|
|
|
|
else
|
2016-10-26 14:28:59 +00:00
|
|
|
# create new password
|
2016-10-25 15:59:31 +00:00
|
|
|
DB_PASS="$(tr -dc A-Za-z0-9 < /dev/urandom | head -c10)"
|
|
|
|
|
|
|
|
# create database
|
2016-10-26 14:28:59 +00:00
|
|
|
echo "# database.yml not found. Creating new db..."
|
2016-10-25 15:59:31 +00:00
|
|
|
su - postgres -c "createdb -E UTF8 ${DB}"
|
|
|
|
|
|
|
|
# create postgres user
|
|
|
|
echo "CREATE USER \"${DB_USER}\" WITH PASSWORD '${DB_PASS}';" | su - postgres -c psql
|
|
|
|
|
|
|
|
# grant privileges
|
|
|
|
echo "GRANT ALL PRIVILEGES ON DATABASE \"${DB}\" TO \"${DB_USER}\";" | su - postgres -c psql
|
|
|
|
|
|
|
|
# update configfile
|
2016-10-26 14:28:59 +00:00
|
|
|
sed "s/.*password:.*/ password: ${DB_PASS}/" < ${ZAMMAD_DIR}/config/database.yml.pkgr > ${ZAMMAD_DIR}/config/database.yml
|
|
|
|
|
|
|
|
# save database config for updates
|
|
|
|
cp ${ZAMMAD_DIR}/config/database.yml ${ZAMMAD_DIR}/config/database.yml.bak
|
2016-10-25 15:59:31 +00:00
|
|
|
|
|
|
|
# zammad config set
|
|
|
|
zammad config:set DATABASE_URL=postgres://${DB_USER}:${DB_PASS}@127.0.0.1/${DB}
|
|
|
|
|
|
|
|
# fill database
|
|
|
|
zammad run rake db:migrate
|
|
|
|
zammad run rake db:seed
|
|
|
|
fi
|
2016-10-25 13:29:10 +00:00
|
|
|
|
2016-10-26 14:28:59 +00:00
|
|
|
echo "# Starting Zammad"
|
2016-10-25 15:59:31 +00:00
|
|
|
systemctl start zammad
|
2016-10-25 16:07:10 +00:00
|
|
|
|
|
|
|
# nginx config
|
|
|
|
if [ -d /etc/nginx/sites-enabled ]; then
|
|
|
|
# copy nginx config
|
2016-10-25 16:55:02 +00:00
|
|
|
test -f /etc/nginx/sites-available/zammad.conf || cp ${ZAMMAD_DIR}/contrib/nginx/sites-available/zammad.conf /etc/nginx/sites-available/zammad.conf
|
2016-10-26 09:04:36 +00:00
|
|
|
|
2016-10-26 10:44:37 +00:00
|
|
|
if [ ! -f /etc/nginx/sites-available/zammad.conf ]; then
|
2016-10-26 09:04:36 +00:00
|
|
|
# creating symlink
|
|
|
|
ln -s /etc/nginx/sites-available/zammad.conf /etc/nginx/sites-enabled/zammad.conf
|
|
|
|
|
2016-10-26 10:44:37 +00:00
|
|
|
echo -e "\nAdd your FQDN to servername directive in /etc/nginx/sites/enabled/zammad.conf anmd restart nginx if you're not testing localy!\n"
|
2016-10-26 09:04:36 +00:00
|
|
|
fi
|
|
|
|
|
2016-10-26 14:28:59 +00:00
|
|
|
echo "# Restarting Nginx"
|
2016-10-25 16:07:10 +00:00
|
|
|
systemctl restart nginx
|
2016-10-26 14:28:59 +00:00
|
|
|
|
|
|
|
echo -e "\nOpen http://localhost in your browser to start using Zammad!\n"
|
2016-10-26 09:04:36 +00:00
|
|
|
else
|
2016-10-26 11:45:14 +00:00
|
|
|
echo -e "\nOpen http://localhost:3000 in your browser to start using Zammad!\n"
|
2016-10-25 16:07:10 +00:00
|
|
|
fi
|