Skip to content

Instantly share code, notes, and snippets.

@meisterheister
Last active October 3, 2021 11:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save meisterheister/e02b1446c2037c5650b0cf0e96221916 to your computer and use it in GitHub Desktop.
Save meisterheister/e02b1446c2037c5650b0cf0e96221916 to your computer and use it in GitHub Desktop.
OTRS Patch Level Update Script for OTRS 6.0
#!/bin/bash
# OTRS Patch Level Update Script for OTRS 6.0
#
# Author: https://github.com/meisterheister
# Last Update: 2020-03-30
#
# NOTE: This script was tested on Ubuntu 16.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 OTRS 6 source code
wget -c -P /opt https://ftp.otrs.org/pub/otrs/otrs-latest-6.0.tar.gz
mkdir /opt/otrs-latest-6.0
tar -xzf /opt/otrs-latest-6.0.tar.gz -C /opt/otrs-latest-6.0 --strip-components=1
rm -f /opt/otrs-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/otrs-latest-6.0/RELEASE' -e '6.0.*'`
downminor=`grep -o -m1 '/opt/otrs-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/otrs-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
# Copy System Config
mv /opt/otrs /opt/otrs-$installed
mv /opt/otrs-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/var/httpd/htdocs/skins/Agent/default/img/banner.png /opt/otrs/var/httpd/htdocs/skins/Agent/default/img/
cp /opt/otrs-$installed/var/httpd/htdocs/skins/Agent/default/img/banner2.png /opt/otrs/var/httpd/htdocs/skins/Agent/default/img/
cp /opt/otrs-$installed/var/httpd/htdocs/skins/Agent/default/img/logo.png /opt/otrs/var/httpd/htdocs/skins/Agent/default/img/
cp /opt/otrs-$installed/var/httpd/htdocs/skins/Customer/default/img/banner3.png /opt/otrs/var/httpd/htdocs/skins/Customer/default/img/
cp /opt/otrs-$installed/var/httpd/htdocs/skins/Agent/default/img/icons/icon.ico /opt/otrs/var/httpd/htdocs/skins/Agent/default/img/icons/
cp /opt/otrs-$installed/var/logo2.png /opt/otrs/var/
cp /opt/otrs-$installed/Kernel/Language/de_Custom.pm /opt/otrs/Kernel/Language/
cp /opt/otrs-$installed/var/httpd/htdocs/js/FillBcc.js /opt/otrs/var/httpd/htdocs/js/
cp /opt/otrs-$installed/Kernel/Config/Files/XML/Prefix* /opt/otrs/Kernel/Config/Files/XML/
cp -r /opt/otrs-$installed/var/httpd/htdocs/AvatarPictures /opt/otrs/var/httpd/htdocs
cp -r /opt/otrs-$installed/var/httpd/htdocs/skins/Agent/dark-slim /opt/otrs/var/httpd/htdocs/skins/Agent
# Remove Ckeditor plugins to re-enable browser Context menu
sed -i 's/list,liststyle/list/g' /opt/otrs/var/httpd/htdocs/js/thirdparty/ckeditor-*/ckeditor.js
sed -i 's/menu,contextmenu/menu/g' /opt/otrs/var/httpd/htdocs/js/thirdparty/ckeditor-*/ckeditor.js
sed -i 's/table,tabletools/table/g' /opt/otrs/var/httpd/htdocs/js/thirdparty/ckeditor-*/ckeditor.js
# Change default hight for popups
sed -i 's/Height: 700/Height: 900/g' /opt/otrs/var/httpd/htdocs/js/Core.UI.Popup.js
# Make richtext editor reziseable, add font and remove plugin for context menu fix
patch -b /opt/otrs/var/httpd/htdocs/js/Core.UI.RichTextEditor.js <<'EOF'
--- Core.UI.RichTextEditor.js.orig 2019-01-30 07:52:43.171471346 +0000
+++ Core.UI.RichTextEditor.js 2019-07-26 11:33:55.421971767 +0000
@@ -153,6 +153,9 @@
// set default editor config, but allow custom config for other types for editors
/*eslint-disable camelcase */
EditorConfig = {
+ resize_enabled: true,
+ resize_dir: 'both',
+ font_names: 'Segoe UI;Arial;Comic Sans MS;Courier New;Georgia;Lucida Sans Unicode;Tahoma;Timnes New Roman;Trebuchet MS;Verdana',
customConfig: '', // avoid loading external config files
disableNativeSpellChecker: false,
defaultLanguage: UserLanguage,
@@ -171,7 +174,7 @@
toolbar: CheckFormID($EditorArea).length ? Core.Config.Get('RichText.Toolbar') : Core.Config.Get('RichText.ToolbarWithoutImage'),
filebrowserBrowseUrl: '',
filebrowserUploadUrl: UploadURL,
- extraPlugins: 'splitquote,preventimagepaste,contextmenu_linkopen',
+ extraPlugins: 'splitquote,preventimagepaste',
entities: false,
skin: 'moono-lisa'
};
EOF
# replace default orange with green
# declare colors to replace
colors=("#f72" "#F72" "#f92" "#F92" "#ff9922" "#FF9922" "#FCB24B" "#F39C19" "#FFA922" "#f4b259" "#F4B259")
# replace all colors with #A7B73E
echo "Now changing default color orange to green ..."
for i in "${colors[@]}"
do
sed -i "s/$i/#A7B73E/g" /opt/otrs/var/httpd/htdocs/js/* 2>/dev/null
sed -i "s/$i/#A7B73E/g" /opt/otrs/var/httpd/htdocs/skins/Agent/default/css/* 2>/dev/null
sed -i "s/$i/#A7B73E/g" /opt/otrs/var/httpd/htdocs/skins/Customer/default/css/* 2>/dev/null
done
#################################################
# 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
chmod 600 /opt/otrs/.mylogin.cnf && chown otrs:nogroup /opt/otrs/.mylogin.cnf
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 OTRS Log
echo "Do you want to see the OTRS 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