Forked from meisterheister/otrs-update-patchlevel.sh
Last active
December 2, 2021 08:17
-
-
Save patrickgrebe/5cf0846b0c5e5a47fd30fca6168c4f53 to your computer and use it in GitHub Desktop.
ZNUNY Patch Level Update Script for ZNUNY 6.0 (LTS)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# ZNUNY Patch Level Update Script for ZNUNY 6.0 | |
# Can also be used to migrate the OTRS Community Edition in version 6 to ZNUNY LTS. | |
# Furthermore, to update the patch level of the migrated version. | |
# | |
# Author: https://github.com/meisterheister | |
# Last Update: 2021-10-28 | |
# Modified by: Patrick Grebe@Hensel | |
# | |
# NOTE: This script was tested on Ubuntu 20.04. LTS. It can be run with 'sudo bash otrs-update-patchlevel.sh' | |
# Check if root | |
if [ "$(whoami)" != "root" ]; then | |
echo "WARNING: you must run this as sudoer! Exiting ..." | |
exit 1 | |
fi | |
# Get the system FQDN for update result check | |
URL=`sudo -u otrs /opt/otrs/bin/otrs.Console.pl Maint::Config::Dump FQDN` | |
# get latest ZNUNY 6 source code | |
wget -c -P /opt https://download.znuny.org/releases/znuny-latest-6.0.tar.gz | |
mkdir /opt/znuny-latest-6.0 | |
tar -xzf /opt/znuny-latest-6.0.tar.gz -C /opt/znuny-latest-6.0 --strip-components=1 | |
rm -f /opt/znuny-latest-6.0.tar.gz | |
installed=`grep -o -m1 '/opt/otrs/RELEASE' -e '6.0.*'` | |
instminor=`grep -o -m1 '/opt/otrs/RELEASE' -e '6.0.*' | sed 's/6.0.//g'` | |
downloaded=`grep -o -m1 '/opt/znuny-latest-6.0/RELEASE' -e '6.0.*'` | |
downminor=`grep -o -m1 '/opt/znuny-latest-6.0/RELEASE' -e '6.0.*' | sed 's/6.0.//g'` | |
# check if downloaded version is greater than installed | |
if [ $instminor -ge $downminor ] | |
then | |
rm -r /opt/znuny-latest-6.0 | |
echo "The current version is the latest! Exiting ..." | |
exit 1 | |
fi | |
# DEBUG on | |
# set -x | |
# Stop services | |
service cron stop | |
service apache2 stop | |
sudo -u otrs /opt/otrs/bin/Cron.sh stop | |
sudo -u otrs /opt/otrs/bin/otrs.Daemon.pl stop | |
# Backup database | |
BACKUPDATE=`date +%Y-%m-%d_%H-%M` | |
/opt/otrs/scripts/backup.pl -d /opt/otrs -t dbonly --no-tablespaces | |
# Copy System Config | |
mv /opt/otrs /opt/otrs-$installed | |
mv /opt/znuny-latest-6.0 /opt/otrs | |
cp /opt/otrs-$installed/Kernel/Config.pm /opt/otrs/Kernel/ | |
mv /opt/otrs-$installed/var/article /opt/otrs/var/ | |
cp /opt/otrs-$installed/var/stats/*.installed /opt/otrs/var/stats | |
cp -r /opt/otrs-$installed/Custom/* /opt/otrs/Custom | |
cp -r /opt/otrs-$installed/var/cron/* /opt/otrs/var/cron | |
# Patch restore.pl in order to restore otrs db automatically on failure | |
patch -b /opt/otrs/scripts/restore.pl <<'EOF' | |
--- /opt/otrs/scripts/restore.pl.bak 2018-04-23 21:59:08.000000000 +0000 | |
+++ /opt/otrs/scripts/restore.pl 2018-07-05 22:23:52.338013192 +0000 | |
@@ -175,7 +175,18 @@ | |
if ($Check) { | |
print STDERR | |
"ERROR: Already existing tables in this database. A empty database is required for restore!\n"; | |
- exit 1; | |
+ | |
+ # drop existing database and create an empty one | |
+ print "DROP exising DB ...\n"; | |
+ $Kernel::OM->Get('Kernel::System::DB')->Prepare( | |
+ SQL => | |
+ "DROP database otrs", | |
+ ); | |
+ print "Create new DB ...\n"; | |
+ $Kernel::OM->Get('Kernel::System::DB')->Prepare( | |
+ SQL => | |
+ "CREATE database otrs", | |
+ ); | |
} | |
} | |
else { | |
EOF | |
################################################# | |
# Copy + Apply CUSTOM Configuration starts here # | |
################################################# | |
cp /opt/otrs-$installed/Kernel/Output/HTML/Templates/Standard/CustomerTicketMessage.tt /opt/otrs/Kernel/Output/HTML/Templates/Standard/ | |
cp /opt/otrs-$installed/Kernel/Output/HTML/Templates/Standard/AgentTicketPhone.tt /opt/otrs/Kernel/Output/HTML/Templates/Standard/ | |
################################################# | |
# Copy + Apply CUSTOM Configuration ends here # | |
################################################# | |
# Set permisions, run DB Update and Re-install as well as upgrade packages | |
cd /opt/otrs | |
/opt/otrs/bin/otrs.SetPermissions.pl | |
sudo -u otrs /opt/otrs/scripts/DBUpdate-to-6.pl | |
sudo -u otrs /opt/otrs/bin/otrs.Console.pl Admin::Package::ReinstallAll | |
sudo -u otrs /opt/otrs/bin/otrs.Console.pl Admin::Package::UpgradeAll | |
# Start webserver | |
service apache2 start | |
# Restore procedure in case the update fails | |
# Check if Website is reachable and roll-back if not | |
echo "Check if website $URL is reachable ..." | |
result=$(curl -sSf --retry 5 $URL 2>&1 >/dev/null) | |
if [ "$result" ]; then | |
echo "Could not reach website! Do you want to roll-back?" | |
select ynn in "Yes" "No"; do | |
case $ynn in | |
Yes ) | |
echo | |
echo "OTRS is not reachable. Rolling back ..." | |
service apache2 stop | |
# save logs | |
sudo -u otrs /opt/otrs/bin/otrs.Console.pl Maint::Log::Print > /opt/failedupdate-otrs-$downloaded.log | |
cp /var/log/apache2/error.log /opt/failedupdate-apache-otrs-$downloaded.log | |
# restore DB | |
/opt/otrs/scripts/restore.pl -b /opt/otrs/$BACKUPDATE -d /opt/otrs | |
# get application files back | |
mv /opt/otrs /opt/otrs-$downloaded | |
mv /opt/otrs-$installed /opt/otrs | |
mv /opt/otrs-$downloaded/var/article /opt/otrs/var/ | |
rm -r /opt/otrs-$downloaded | |
service apache2 start | |
echo "Rollback finished" | |
break;; | |
No ) break;; | |
esac | |
done | |
else | |
echo "Website reachable! Enjoy!" | |
fi | |
# Start all other services | |
service cron start | |
sudo -u otrs /opt/otrs/bin/otrs.Console.pl Maint::Config::Rebuild | |
sudo -u otrs /opt/otrs/bin/otrs.Daemon.pl start >/dev/null | |
sudo -u otrs /opt/otrs/bin/Cron.sh start | |
# Show ZNUNY Log | |
echo "Do you want to see the ZNUNY log?" | |
select yn in "Yes" "No"; do | |
case $yn in | |
Yes ) | |
sudo -u otrs /opt/otrs/bin/otrs.Console.pl Maint::Log::Print | |
break;; | |
No ) break;; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment