trabajo-afectivo/contrib/packager.io/postinstall.sh

99 lines
3 KiB
Bash
Raw Normal View History

#!/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"
# check which init system is used
2016-10-31 12:00:59 +00:00
if [ -n "$(which initctl)" ]; then
INIT_CMD="initctl"
2016-10-31 12:00:59 +00:00
elif [ -n "$(which systemctl)" ]; then
INIT_CMD="systemctl"
else
function sysvinit () {
service $2 $1
}
INIT_CMD="sysvinit"
fi
echo "# (Re)creating init scripts"
zammad scale web=1 websocket=1 worker=1
echo "# Stopping Zammad"
${INIT_CMD} stop zammad
2016-10-25 15:59:31 +00:00
# check if database.yml exists
if [ -f ${ZAMMAD_DIR}/config/database.yml ]; then
# db migration
echo "# database.yml exists. Updating db..."
zammad run rake db:migrate
else
# create new password
2016-10-25 15:59:31 +00:00
DB_PASS="$(tr -dc A-Za-z0-9 < /dev/urandom | head -c10)"
2016-10-31 12:00:59 +00:00
if [ -n "$(which postgresql-setup)" ]; then
echo "preparing postgresql server"
postgresql-setup initdb
echo "backuping postgres config"
test -f /var/lib/pgsql/data/pg_hba.conf.bak || cp /var/lib/pgsql/data/pg_hba.conf /var/lib/pgsql/data/pg_hba.conf.bak
echo "allow login via username and password in postgresql"
2016-10-31 15:32:53 +00:00
egrep -v "^#.*$" < /var/lib/pgsql/data/pg_hba.conf.bak | sed 's/ident/trust/g' > /var/lib/pgsql/data/pg_hba.conf
2016-10-31 12:00:59 +00:00
echo "restarting postgresql server"
${INIT_CMD} restart postgresql
echo "create postgresql bootstart"
${INIT_CMD} enable postgresql.service
2016-10-31 12:00:59 +00:00
fi
2016-10-25 15:59:31 +00:00
# create database
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
sed "s/.*password:.*/ password: ${DB_PASS}/" < ${ZAMMAD_DIR}/config/database.yml.pkgr > ${ZAMMAD_DIR}/config/database.yml
2016-10-25 15:59:31 +00:00
# fill database
zammad run rake db:migrate
zammad run rake db:seed
fi
echo "# Starting Zammad"
${INIT_CMD} start zammad
2016-10-25 16:07:10 +00:00
# nginx config
2016-10-31 12:00:59 +00:00
if [ -n "$(which nginx)" ]; then
2016-10-28 08:06:33 +00:00
# copy nginx config
# debian / ubuntu
if [ -d /etc/nginx/sites-enabled ]; then
NGINX_CONF="/etc/nginx/sites-enabled/zammad.conf"
test -f /etc/nginx/sites-available/zammad.conf || cp ${ZAMMAD_DIR}/contrib/nginx/zammad.conf /etc/nginx/sites-available/zammad.conf
test -h ${NGINX_CONF} || ln -s /etc/nginx/sites-available/zammad.conf ${NGINX_CONF}
# centos / sles
elif [ -d /etc/nginx/conf.d ]; then
NGINX_CONF="/etc/nginx/conf.d/zammad.conf"
test -f ${NGINX_CONF} || cp ${ZAMMAD_DIR}/contrib/nginx/zammad.conf ${NGINX_CONF}
fi
echo "# Restarting Nginx"
${INIT_CMD} restart nginx
echo -e "\nAdd your FQDN to servername directive in ${NGINX_CONF} and restart nginx if you're not testing localy"
echo -e "or open http://localhost in your browser to start using Zammad.\n"
else
echo -e "\nOpen http://localhost:3000 in your browser to start using Zammad.\n"
2016-10-25 16:07:10 +00:00
fi