#!/bin/sh # script for updating OTRS on FreeBSD within the same major release, e.g. 6.0.16 -> 6.0.17 DEST_VERSION="$1" OTRS_USER="${2:-otrs}" OTRS_DIR="$3" CURR_VERSION="$4" if [ -z "$DEST_VERSION" -o "$DEST_VERSION" = "-h" -o "$DEST_VERSION" = "--help" ]; then echo "Usage: upgrade_otrs.sh [ [ []]]" exit 1 fi if [ -z "$OTRS_DIR" ]; then OTRS_DIR=`su -m nobody -c "echo ~$OTRS_USER"` || exit 1 fi # try to get current version from RELEASE file inside the installation directory if [ -z "$CURR_VERSION" ]; then while read L; do VERSION="${L#VERSION = }" if [ "$VERSION" != "$L" ]; then CURR_VERSION="$VERSION" fi done < "$OTRS_DIR"/RELEASE || exit 1 fi if [ -z "$CURR_VERSION" ]; then echo "Unable to determine the currently installed OTRS version in $OTRS_DIR" >&2 exit 1 fi CURR_PACKAGE="otrs-$CURR_VERSION" DEST_PACKAGE="otrs-$DEST_VERSION" CURR_TARBALL="${CURR_PACKAGE}.tar.bz2" DEST_TARBALL="${DEST_PACKAGE}.tar.bz2" # fetch tarballs of current and new version if [ ! -f "$CURR_TARBALL" ]; then fetch "http://ftp.otrs.org/pub/otrs/$CURR_TARBALL" || exit 1 fi if [ ! -f "$DEST_TARBALL" ]; then fetch "http://ftp.otrs.org/pub/otrs/$DEST_TARBALL" || exit 1 fi TMP_DIR=`mktemp -d` || exit 1 CURR_DIR="$TMP_DIR"/"$CURR_PACKAGE" DEST_DIR="$TMP_DIR"/"$DEST_PACKAGE" echo "Extracting $CURR_PACKAGE to $CURR_DIR" tar -C "$TMP_DIR" -xjSf "$CURR_TARBALL" || exit 1 rm "$CURR_TARBALL" || exit 1 echo "Extracting $DEST_PACKAGE to $DEST_DIR" tar -C "$TMP_DIR" -xjSf "$DEST_TARBALL" || exit 1 # keep tarball of new version for next upgrade service apache24 onestatus && { service apache24 onestop || exit 1; } crontab -l -u "$OTRS_USER" && { crontab -r -f -u "$OTRS_USER" || exit 1; } su -m "$OTRS_USER" -c "'$OTRS_DIR'/bin/otrs.Daemon.pl stop" || exit 1 su -m "$OTRS_USER" -c "'$OTRS_DIR'/bin/otrs.Console.pl Maint::Cache::Delete" || exit 1 su -m "$OTRS_USER" -c "'$OTRS_DIR'/bin/otrs.Console.pl Maint::Loader::CacheCleanup" || exit 1 su -m "$OTRS_USER" -c "'$OTRS_DIR'/bin/otrs.Console.pl Maint::WebUploadCache::Cleanup" || exit 1 # once again to make sure daemon is not running anymore su -m "$OTRS_USER" -c "'$OTRS_DIR'/bin/otrs.Daemon.pl stop" || exit 1 pkill -f "$OTRS_DIR" cd "$OTRS_DIR" || exit 1 echo "Removing files from $OTRS_DIR that are vanilla $CURR_VERSION ones" find . -type f | while read L; do [ -f "$CURR_DIR"/"$L" ] && cmp -s "$L" "$CURR_DIR"/"$L" && { rm "$L" || exit 1; } done echo "Installing new files from $DEST_VERSION" cp -ai "$DEST_DIR"/ "$OTRS_DIR"/ || exit 1 rm -r "$TMP_DIR" || exit 1 "$OTRS_DIR"/bin/otrs.SetPermissions.pl --admin-group=`id -gn 0` || exit 1 su -m "$OTRS_USER" -c "'$OTRS_DIR'/bin/otrs.Console.pl Maint::Config::Rebuild" || exit 1 su -m "$OTRS_USER" -c "'$OTRS_DIR'/bin/otrs.Console.pl Maint::Config::Sync" || exit 1 "$OTRS_DIR"/bin/Cron.sh start "$OTRS_USER" || exit 1 service apache24 onestart || exit 1 echo "Done."