- some rework on packaer.io postinstall

- added backup restore script
This commit is contained in:
André Bauer 2017-02-12 12:52:10 +01:00
parent 2203830f22
commit 6e5a277efc
5 changed files with 329 additions and 202 deletions

View file

@ -4,55 +4,143 @@
# #
function get_backup_date () { function get_backup_date () {
TIMESTAMP="$(date +'%Y%m%d%H%M%S')" TIMESTAMP="$(date +'%Y%m%d%H%M%S')"
if [ "${DEBUG}" == "yes" ]; then if [ "${DEBUG}" == "yes" ]; then
echo "timestamp is ${TIMESTAMP}" echo "timestamp is ${TIMESTAMP}"
fi fi
} }
function delete_old_backups () { function delete_old_backups () {
test -d ${BACKUP_DIR} && find ${BACKUP_DIR}/*_zammad_*.gz -type f -mtime +${HOLD_DAYS} -exec rm -r \; test -d ${BACKUP_DIR} && find ${BACKUP_DIR}/*_zammad_*.gz -type f -mtime +${HOLD_DAYS} -exec rm -r \;
} }
function get_db_credentials () { function get_db_credentials () {
DB_ADAPTER="$(grep 'adapter:' < ${ZAMMAD_DIR}/${DATABASE_CONFIG} | sed -e 's/.*adapter:\(\| \)//g')" DB_ADAPTER="$(grep 'adapter:' < ${ZAMMAD_DIR}/${DATABASE_CONFIG} | sed -e 's/.*adapter:\(\| \)//g')"
DB_NAME="$(grep 'database:' < ${ZAMMAD_DIR}/${DATABASE_CONFIG} | sed -e 's/.*database:\(\| \) //g')" DB_NAME="$(grep 'database:' < ${ZAMMAD_DIR}/${DATABASE_CONFIG} | sed -e 's/.*database:\(\| \) //g')"
DB_USER="$(grep 'username:' < ${ZAMMAD_DIR}/${DATABASE_CONFIG} | sed -e 's/.*username:\(\| \)//g')" DB_USER="$(grep 'username:' < ${ZAMMAD_DIR}/${DATABASE_CONFIG} | sed -e 's/.*username:\(\| \)//g')"
DB_PASS="$(grep 'password:' < ${ZAMMAD_DIR}/${DATABASE_CONFIG} | sed -e 's/.*password:\(\| \)//g')" DB_PASS="$(grep 'password:' < ${ZAMMAD_DIR}/${DATABASE_CONFIG} | sed -e 's/.*password:\(\| \)//g')"
if [ "${DEBUG}" == "yes" ]; then if [ "${DEBUG}" == "yes" ]; then
echo "adapter=${DB_ADAPTER} dbname=${DB_NAME} dbuser=${DB_USER} dbpass=${DB_PASS}" echo "adapter=${DB_ADAPTER} dbname=${DB_NAME} dbuser=${DB_USER} dbpass=${DB_PASS}"
fi fi
} }
function backup_dir_create () { function backup_dir_create () {
test -d ${BACKUP_DIR} || mkdir -p ${BACKUP_DIR} test -d ${BACKUP_DIR} || mkdir -p ${BACKUP_DIR}
if [ "${DEBUG}" == "yes" ]; then if [ "${DEBUG}" == "yes" ]; then
echo "backup dir is ${BACKUP_DIR}" echo "backup dir is ${BACKUP_DIR}"
fi fi
} }
function backup_files () { function backup_files () {
tar -czf ${BACKUP_DIR}/${TIMESTAMP}_zammad_files.tar.gz ${ZAMMAD_DIR} tar -czf ${BACKUP_DIR}/${TIMESTAMP}_zammad_files.tar.gz ${ZAMMAD_DIR}
} }
function backup_db () { function backup_db () {
if [ "${DB_ADAPTER}" == "mysql2" ]; then if [ "${DB_ADAPTER}" == "mysql2" ]; then
mysqldump --opt --single-transaction -u${DB_USER} -p${DB_PASS} ${DB_NAME} | gzip > ${BACKUP_DIR}/${TIMESTAMP}_zammad_db.mysql.gz mysqldump --opt --single-transaction -u${DB_USER} -p${DB_PASS} ${DB_NAME} | gzip > ${BACKUP_DIR}/${TIMESTAMP}_zammad_db.mysql.gz
elif [ "${DB_ADAPTER}" == "postgresql" ]; then elif [ "${DB_ADAPTER}" == "postgresql" ]; then
su -c "pg_dump ${DB_NAME} | gzip > ${BACKUP_DIR}/${TIMESTAMP}_zammad_db.psql.gz" postgres su -c "pg_dump ${DB_NAME} | gzip > ${BACKUP_DIR}/${TIMESTAMP}_zammad_db.psql.gz" postgres
else else
echo "ADAPTER not found. if its sqlite backup is already saved in filebackup" echo "ADAPTER not found. if its sqlite backup is already saved in filebackup"
fi fi
} }
function check_database_config_exists () { function check_database_config_exists () {
if [ -f ${ZAMMAD_DIR}/${DATABASE_CONFIG} ]; then if [ -f ${ZAMMAD_DIR}/${DATABASE_CONFIG} ]; then
get_db_credentials get_db_credentials
else else
echo "${ZAMMAD_DIR}/${DATABASE_CONFIG} is missing. is zammad configured yet?" echo "${ZAMMAD_DIR}/${DATABASE_CONFIG} is missing. is zammad configured yet?"
exit 1 exit 1
fi fi
}
function restore_warning () {
echo -e "The restore will delete your current config and database!\nBe sure to have a backup available!\n"
echo -e "Enter 'yes' if you want to proceed!"
read -s CHOOSE_RESTORE
if [ "${CHOOSE_RESTORE}" != "yes" ]; then
echo "Restore aborted!"
exit 1
fi
}
function get_restore_dates () {
RESTORE_FILE_DATES="$(find ${BACKUP_DIR} -type f -iname '*_zammad_files.tar.gz' | sed -e "s#${BACKUP_DIR}/##g" -e "s#_zammad_files.tar.gz##g")"
if [ "${ADAPTER}" == "postgresql" ]; then
DB_FILE_EXT="psql"
elif [ "${ADAPTER}" == "mysql2" ]; then
DB_FILE_EXT="mysql"
fi
RESTORE_DB_DATES="$(find ${BACKUP_DIR} -type f -iname "*_zammad_db.${DB_FILE_EXT}.gz" | sed -e "s#${BACKUP_DIR}/##g" -e "s#_zammad_db.${DB_FILE_EXT}.gz##g")"
}
function choose_restore_date () {
echo "Enter file date to restore: ${RESTORE_FILE_DATES}"
read -s RESTORE_FILE_DATE
if [ ! -f "${BACKUP_DIR}/${RESTORE_FILE_DATE}_zammad_files.tar.gz" ];then
echo "File ${BACKUP_DIR}/${RESTORE_FILE_DATE}_zammad_files.tar.gz does not exist!\nRestore aborted!"
exit 1
fi
echo "Enter db date to restore: ${RESTORE_DB_DATES}"
read -s RESTORE_DB_DATE
if [ ! -f "${BACKUP_DIR}/${RESTORE_DB_DATE}_zammad_db.${DB_FILE_EXT}.gz" ];then
echo "File ${BACKUP_DIR}/${RESTORE_DB_DATE}_zammad_files.tar.gz does not exist!\nRestore aborted!"
exit 1
fi
}
function detect_initcmd () {
if [ -n "$(which systemctl 2> /dev/null)" ]; then
INIT_CMD="systemctl"
elif [ -n "$(which initctl 2> /dev/null)" ]; then
INIT_CMD="initctl"
else
function sysvinit () {
service $2 $1
}
INIT_CMD="sysvinit"
fi
if [ "${DOCKER}" == "yes" ]; then
INIT_CMD="initctl"
fi
if [ "${DEBUG}" == "yes" ]; then
echo "INIT CMD = ${INIT_CMD}"
fi
}
function start_zammad () {
echo "# Starting Zammad"
${INIT_CMD} start zammad
}
function stop_zammad () {
echo "# Stopping Zammad"
${INIT_CMD} stop zammad
}
function delete_current_files () {
test -d ${ZAMMAD_DIR} && rm -rf ${ZAMMAD_DIR}
}
function restore_zammad () {
tar -C / -xzf ${BACKUP_DIR}/${RESTORE_FILE_DATE}_zammad_files.tar.gz
if [ "${ADAPTER}" == "postgresql" ]; then
gunzip ${BACKUP_DIR}/${RESTORE_DB_DATE}_zammad_db.${DB_FILE_EXT}.gz | pg_restore -c ${DB_NAME}
elif [ "${ADAPTER}" == "mysql2" ]; then
gunzip ${BACKUP_DIR}/${RESTORE_DB_DATE}_zammad_db.${DB_FILE_EXT}.gz | mysql -u${DB_USER} -p${DB_PASS} ${DB_NAME}
fi
}
function restore_message () {
echo "Zammad restored!"
} }

View file

@ -12,10 +12,10 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin:
. functions . functions
# exec backup # exec backup
delete_old_backups
check_database_config_exists check_database_config_exists
delete_old_backups
get_backup_date get_backup_date
backup_dir_create backup_dir_create

View file

@ -0,0 +1,35 @@
#!/bin/bash
#
# zammad restore script
#
PATH=/sbin:/bin:/usr/sbin:/usr/bin:
# import config
. config
# import functions
. functions
# exec restore
restore_warning
check_database_config_exists
get_db_credentials
get_restore_dates
choose_restore_date
detect_initcmd
stop_zammad
delete_current_files
restore_zammad
start_zammad
restore_message

View file

@ -4,227 +4,247 @@
# #
function debug() { function debug() {
if [ "${DEBUG}" == "yes" ]; then if [ "${DEBUG}" == "yes" ]; then
echo "DEBUG MODE ON" echo "DEBUG MODE ON"
set -ex set -ex
fi fi
} }
function detect_os () { function detect_os () {
. /etc/os-release . /etc/os-release
if [ "${ID}" == "debian" ] || [ "${ID}" == "ubuntu" ]; then if [ "${ID}" == "debian" ] || [ "${ID}" == "ubuntu" ]; then
OS="DEBIAN" OS="DEBIAN"
elif [ "${ID}" == "centos" ] || [ "${ID}" == "fedora" ] || [ "${ID}" == "rhel" ]; then elif [ "${ID}" == "centos" ] || [ "${ID}" == "fedora" ] || [ "${ID}" == "rhel" ]; then
OS="REDHAT" OS="REDHAT"
elif [ "${ID}" == "opensuse" ] || [ "${ID}" == "sles" ] || [ "${ID}" == "suse" ]; then elif [ "${ID}" == "opensuse" ] || [ "${ID}" == "sles" ] || [ "${ID}" == "suse" ]; then
OS="SUSE" OS="SUSE"
else else
OS="UNKNOWN" OS="UNKNOWN"
fi fi
if [ "${DEBUG}" == "yes" ]; then if [ "${DEBUG}" == "yes" ]; then
echo "OS is ${OS} based" echo "OS is ${OS} based"
fi fi
} }
function detect_docker() { function detect_docker() {
if [ -n "$(grep docker < /proc/1/cgroup)" ]; then if [ -n "$(grep docker < /proc/1/cgroup)" ]; then
DOCKER="yes" DOCKER="yes"
else else
DOCKER="no" DOCKER="no"
fi fi
if [ "${DEBUG}" == "yes" ]; then if [ "${DEBUG}" == "yes" ]; then
echo "os runs in docker container = ${DOCKER}" echo "os runs in docker container = ${DOCKER}"
fi fi
} }
function detect_initcmd () { function detect_initcmd () {
if [ -n "$(which systemctl 2> /dev/null)" ]; then if [ -n "$(which systemctl 2> /dev/null)" ]; then
INIT_CMD="systemctl" INIT_CMD="systemctl"
elif [ -n "$(which initctl 2> /dev/null)" ]; then elif [ -n "$(which initctl 2> /dev/null)" ]; then
INIT_CMD="initctl" INIT_CMD="initctl"
else else
function sysvinit () { function sysvinit () {
service $2 $1 service $2 $1
} }
INIT_CMD="sysvinit" INIT_CMD="sysvinit"
fi fi
if [ "${DOCKER}" == "yes" ]; then if [ "${DOCKER}" == "yes" ]; then
INIT_CMD="initctl" INIT_CMD="initctl"
fi fi
if [ "${DEBUG}" == "yes" ]; then if [ "${DEBUG}" == "yes" ]; then
echo "INIT CMD = ${INIT_CMD}" echo "INIT CMD = ${INIT_CMD}"
fi fi
} }
function detect_database () { function detect_database () {
if [ -n "$(which psql 2> /dev/null)" ]; then if [ -n "$(which psql 2> /dev/null)" ]; then
ADAPTER="postgresql" ADAPTER="postgresql"
elif [ -n "$(which mysql 2> /dev/null)" ]; then elif [ -n "$(which mysql 2> /dev/null)" ]; then
ADAPTER="mysql2" ADAPTER="mysql2"
fi fi
if [ "${DEBUG}" == "yes" ]; then if [ "${DEBUG}" == "yes" ]; then
echo "Use ${ADAPTER} adapter in database.yml" echo "Use ${ADAPTER} adapter in database.yml"
fi fi
} }
function detect_webserver () { function detect_webserver () {
if [ -n "$(which nginx 2> /dev/null)" ] ; then if [ -n "$(which nginx 2> /dev/null)" ] ; then
WEBSERVER="nginx" WEBSERVER="nginx"
WEBSERVER_CMD="nginx" WEBSERVER_CMD="nginx"
if [ "${OS}" == "DEBIAN" ]; then if [ "${OS}" == "DEBIAN" ]; then
WEBSERVER_CONF="/etc/nginx/sites-enabled/zammad.conf" WEBSERVER_CONF="/etc/nginx/sites-enabled/zammad.conf"
elif [ "${OS}" == "REDHAT" ]; then elif [ "${OS}" == "REDHAT" ]; then
WEBSERVER_CONF="/etc/nginx/conf.d/zammad.conf" WEBSERVER_CONF="/etc/nginx/conf.d/zammad.conf"
elif [ "${OS}" == "SUSE" ]; then elif [ "${OS}" == "SUSE" ]; then
WEBSERVER_CONF="/etc/nginx/vhosts.d/zammad.conf" WEBSERVER_CONF="/etc/nginx/vhosts.d/zammad.conf"
fi
elif [ -n "$(which apache2 2> /dev/null)" ]; then
WEBSERVER="apache2"
WEBSERVER_CMD="apache2"
if [ "${OS}" == "DEBIAN" ]; then
WEBSERVER_CONF="/etc/apache2/sites-enabled/zammad.conf"
fi
elif [ -n "$(which httpd 2> /dev/null)" ]; then
WEBSERVER="apache2"
WEBSERVER_CMD="httpd"
if [ "${OS}" == "REDHAT" ]; then
WEBSERVER_CONF="/etc/httpd/conf.d/zammad.conf"
elif [ "${OS}" == "SUSE" ]; then
WEBSERVER_CONF="/etc/apache2/vhosts.d/zammad.conf"
fi
fi fi
elif [ -n "$(which apache2 2> /dev/null)" ]; then
WEBSERVER="apache2"
WEBSERVER_CMD="apache2"
if [ "${OS}" == "DEBIAN" ]; then
WEBSERVER_CONF="/etc/apache2/sites-enabled/zammad.conf"
fi
elif [ -n "$(which httpd 2> /dev/null)" ]; then
WEBSERVER="apache2"
WEBSERVER_CMD="httpd"
if [ "${OS}" == "REDHAT" ]; then
WEBSERVER_CONF="/etc/httpd/conf.d/zammad.conf"
elif [ "${OS}" == "SUSE" ]; then
WEBSERVER_CONF="/etc/apache2/vhosts.d/zammad.conf"
fi
fi
if [ "${DEBUG}" == "yes" ]; then if [ "${DEBUG}" == "yes" ]; then
echo "Webserver is ${WEBSERVER_CMD}" echo "Webserver is ${WEBSERVER_CMD}"
fi fi
} }
function create_initscripts () { function create_initscripts () {
echo "# (Re)creating init scripts" echo "# (Re)creating init scripts"
zammad scale web=${ZAMMAD_WEBS} websocket=${ZAMMAD_WEBSOCKETS} worker=${ZAMMAD_WORKERS} zammad scale web=${ZAMMAD_WEBS} websocket=${ZAMMAD_WEBSOCKETS} worker=${ZAMMAD_WORKERS}
echo "# Enabling Zammad on boot" echo "# Enabling Zammad on boot"
${INIT_CMD} enable zammad ${INIT_CMD} enable zammad
} }
function start_zammad () { function start_zammad () {
echo "# Starting Zammad" echo "# Starting Zammad"
${INIT_CMD} start zammad ${INIT_CMD} start zammad
} }
function stop_zammad () { function stop_zammad () {
echo "# Stopping Zammad" echo "# Stopping Zammad"
${INIT_CMD} stop zammad ${INIT_CMD} stop zammad
} }
function create_database_password () { function create_database_password () {
DB_PASS="$(tr -dc A-Za-z0-9 < /dev/urandom | head -c10)" DB_PASS="$(tr -dc A-Za-z0-9 < /dev/urandom | head -c10)"
} }
function create_postgresql_db () { function create_postgresql_db () {
if [ -n "$(which postgresql-setup 2> /dev/null)" ]; then if [ -n "$(which postgresql-setup 2> /dev/null)" ]; then
echo "# Preparing postgresql server" echo "# Preparing postgresql server"
postgresql-setup initdb postgresql-setup initdb
fi fi
echo "# Creating postgresql bootstart" echo "# Creating postgresql bootstart"
${INIT_CMD} enable postgresql.service ${INIT_CMD} enable postgresql.service
echo "# Restarting postgresql server" echo "# Restarting postgresql server"
${INIT_CMD} restart postgresql ${INIT_CMD} restart postgresql
echo "# Creating zammad postgresql db" echo "# Creating zammad postgresql db"
su - postgres -c "createdb -E UTF8 ${DB}" su - postgres -c "createdb -E UTF8 ${DB}"
echo "# Creating zammad postgresql user" echo "# Creating zammad postgresql user"
echo "CREATE USER \"${DB_USER}\" WITH PASSWORD '${DB_PASS}';" | su - postgres -c psql echo "CREATE USER \"${DB_USER}\" WITH PASSWORD '${DB_PASS}';" | su - postgres -c psql
echo "# Grant privileges to new postgresql user" echo "# Grant privileges to new postgresql user"
echo "GRANT ALL PRIVILEGES ON DATABASE \"${DB}\" TO \"${DB_USER}\";" | su - postgres -c psql echo "GRANT ALL PRIVILEGES ON DATABASE \"${DB}\" TO \"${DB_USER}\";" | su - postgres -c psql
} }
function create_mysql_db () { function create_mysql_db () {
if [ -f "${MY_CNF}" ]; then if [ -f "${MY_CNF}" ]; then
MYSQL_CREDENTIALS="--defaults-file=${MY_CNF}" MYSQL_CREDENTIALS="--defaults-file=${MY_CNF}"
else else
echo -n "Please enter your MySQL root password:" echo -n "Please enter your MySQL root password:"
read -s MYSQL_ROOT_PASS read -s MYSQL_ROOT_PASS
MYSQL_CREDENTIALS="-u root -p${MYSQL_ROOT_PASS}" MYSQL_CREDENTIALS="-u root -p${MYSQL_ROOT_PASS}"
fi fi
echo "# Creating zammad mysql db" echo "# Creating zammad mysql db"
mysql ${MYSQL_CREDENTIALS} -e "CREATE DATABASE ${DB} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;" mysql ${MYSQL_CREDENTIALS} -e "CREATE DATABASE ${DB} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;"
echo "# Creating zammad mysql user" echo "# Creating zammad mysql user"
mysql ${MYSQL_CREDENTIALS} -e "CREATE USER \"${DB_USER}\"@\"${DB_HOST}\" IDENTIFIED BY \"${DB_PASS}\";" mysql ${MYSQL_CREDENTIALS} -e "CREATE USER \"${DB_USER}\"@\"${DB_HOST}\" IDENTIFIED BY \"${DB_PASS}\";"
echo "# Grant privileges to new mysql user" echo "# Grant privileges to new mysql user"
mysql ${MYSQL_CREDENTIALS} -e "GRANT ALL PRIVILEGES ON ${DB}.* TO \"${DB_USER}\"@\"${DB_HOST}\"; FLUSH PRIVILEGES;" mysql ${MYSQL_CREDENTIALS} -e "GRANT ALL PRIVILEGES ON ${DB}.* TO \"${DB_USER}\"@\"${DB_HOST}\"; FLUSH PRIVILEGES;"
} }
function update_database_yml () { function update_database_yml () {
if [ "${OS}" == "REDHAT" ] || [ "${OS}" == "SUSE" ]; then if [ "${OS}" == "REDHAT" ] || [ "${OS}" == "SUSE" ]; then
if [ "${ADAPTER}" == "postgresql" ]; then if [ "${ADAPTER}" == "postgresql" ]; then
DB_PASS="" DB_PASS=""
fi
fi fi
fi
echo "# Updating database.yml" echo "# Updating database.yml"
sed -e "s/.*adapter:.*/ adapter: ${ADAPTER}/" \ sed -e "s/.*adapter:.*/ adapter: ${ADAPTER}/" \
-e "s/.*username:.*/ username: ${DB_USER}/" \ -e "s/.*username:.*/ username: ${DB_USER}/" \
-e "s/.*password:.*/ password: ${DB_PASS}/" \ -e "s/.*password:.*/ password: ${DB_PASS}/" \
-e "s/.*database:.*/ database: ${DB}/" < ${ZAMMAD_DIR}/config/database.yml.pkgr > ${ZAMMAD_DIR}/config/database.yml -e "s/.*database:.*/ database: ${DB}/" < ${ZAMMAD_DIR}/config/database.yml.pkgr > ${ZAMMAD_DIR}/config/database.yml
} }
function initialise_database () { function initialise_database () {
zammad run rake db:migrate zammad run rake db:migrate
zammad run rake db:seed zammad run rake db:seed
} }
function update_database () { function update_database () {
echo "# database.yml found. Updating db..." echo "# database.yml found. Updating db..."
zammad run rake db:migrate zammad run rake db:migrate
} }
function create_webserver_config () { function create_webserver_config () {
if [ "${OS}" == "DEBIAN" ]; then if [ "${OS}" == "DEBIAN" ]; then
test -f /etc/${WEBSERVER}/sites-available/zammad.conf || cp ${ZAMMAD_DIR}/contrib/${WEBSERVER}/zammad.conf /etc/${WEBSERVER}/sites-available/zammad.conf test -f /etc/${WEBSERVER}/sites-available/zammad.conf || cp ${ZAMMAD_DIR}/contrib/${WEBSERVER}/zammad.conf /etc/${WEBSERVER}/sites-available/zammad.conf
test -h ${WEBSERVER_CONF} || ln -s /etc/${WEBSERVER}/sites-available/zammad.conf ${WEBSERVER_CONF} test -h ${WEBSERVER_CONF} || ln -s /etc/${WEBSERVER}/sites-available/zammad.conf ${WEBSERVER_CONF}
if [ "${WEBSERVER}" == "apache2" ]; then if [ "${WEBSERVER}" == "apache2" ]; then
a2enmod proxy a2enmod proxy
a2enmod proxy_http a2enmod proxy_http
a2enmod proxy_wstunnel a2enmod proxy_wstunnel
fi fi
else else
test -f ${WEBSERVER_CONF} || cp ${ZAMMAD_DIR}/contrib/${WEBSERVER}/zammad.conf ${WEBSERVER_CONF} test -f ${WEBSERVER_CONF} || cp ${ZAMMAD_DIR}/contrib/${WEBSERVER}/zammad.conf ${WEBSERVER_CONF}
fi
echo "# Creating webserver bootstart"
${INIT_CMD} enable ${WEBSERVER_CMD}
echo "# Restarting webserver ${WEBSERVER_CMD}"
${INIT_CMD} restart ${WEBSERVER_CMD}
}
function update_or_install () {
if [ -f ${ZAMMAD_DIR}/config/database.yml ]; then
update_database
else
create_database_password
if [ "${ADAPTER}" == "postgresql" ]; then
echo "# Installing zammad on postgresql"
create_postgresql_db
elif [ "${ADAPTER}" == "mysql2" ]; then
echo "# Installing zammad on mysql"
create_mysql_db
fi fi
echo "# Creating webserver bootstart" update_database_yml
${INIT_CMD} enable ${WEBSERVER_CMD}
echo "# Restarting webserver ${WEBSERVER_CMD}" initialise_database
${INIT_CMD} restart ${WEBSERVER_CMD} fi
} }
function final_message () { function final_message () {
echo -e "####################################################################################" echo -e "####################################################################################"
echo -e "\nAdd your FQDN to servername directive in ${WEBSERVER_CONF}" echo -e "\nAdd your FQDN to servername directive in ${WEBSERVER_CONF}"
echo -e "and restart your webserver if you're not testing locally" echo -e "and restart your webserver if you're not testing locally"
echo -e "or open http://localhost/ in your browser to start using Zammad.\n" echo -e "or open http://localhost/ in your browser to start using Zammad.\n"
if [ "${OS}" == "REDHAT" ]; then if [ "${OS}" == "REDHAT" ]; then
echo -e "\n Remember to enable selinux and firewall rules!\n" echo -e "\n Remember to enable selinux and firewall rules!\n"
echo -e "Use the follwing commands:" echo -e "Use the follwing commands:"
echo -e " setsebool httpd_can_network_connect on -P" echo -e " setsebool httpd_can_network_connect on -P"
echo -e " firewall-cmd --zone=public --add-service=http --permanent" echo -e " firewall-cmd --zone=public --add-service=http --permanent"
echo -e " firewall-cmd --zone=public --add-service=https --permanent" echo -e " firewall-cmd --zone=public --add-service=https --permanent"
echo -e " firewall-cmd --reload\n" echo -e " firewall-cmd --reload\n"
fi fi
echo -e "####################################################################################" echo -e "####################################################################################"
} }

View file

@ -11,6 +11,7 @@ PATH=/opt/zammad/bin:/opt/zammad/vendor/bundle/bin:/sbin:/bin:/usr/sbin:/usr/bin
# import functions # import functions
. /opt/zammad/contrib/packager.io/functions . /opt/zammad/contrib/packager.io/functions
# exec postinstall
debug debug
detect_os detect_os
@ -27,24 +28,7 @@ create_initscripts
stop_zammad stop_zammad
# check if database.yml exists update_or_install
if [ -f ${ZAMMAD_DIR}/config/database.yml ]; then
update_database
else
create_database_password
if [ "${ADAPTER}" == "postgresql" ]; then
echo "# Installing zammad on postgresql"
create_postgresql_db
elif [ "${ADAPTER}" == "mysql2" ]; then
echo "# Installing zammad on mysql"
create_mysql_db
fi
update_database_yml
initialise_database
fi
start_zammad start_zammad