Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 119 lines (104 sloc) 2.488 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
#!/bin/bash

die() {
echo $*
exit 1
}

try() {
"$@"
[ $? -ne 0 ] && exit 1
}

if [ ! -d "$ZENHOME" ]; then
die "\$ZENHOME not set or does not exist. Please make sure you execute this script as the zenoss user."
fi

if [ "$USER" != "zenoss" ]; then
die "Current user is $USER. Please execute as the zenoss user."
fi

if [ "$(which patch 2>/dev/null)" = "" ]; then
die "Cannot find patch command. Please use 'yum install patch' as root to fix this and try again."
fi

TARGET_VERSION=4.2.0
SP=4.2.0-SP1
BACKUPDIR=$ZENHOME/ServicePacks/$SP
install -d $BACKUPDIR || die "Could not create backup directory $BACKUPDIR. Aborting."
export SIMPLE_BACKUP_SUFFIX=""

real_apply=""
skip_apply=""
patch_apply() {
local errval=$1
shift
local fail=""
local optional
local extra_args=""
if [ "$1" = "dry-run" ]; then
extra_args="--dry-run"
my_apply="$(cat patches/series)"
else
my_apply="$real_apply"
fi
for x in $my_apply; do
optional=no
# patches with "opt-" prefix are optional -- someone may not have core ZenPacks installed, for example.
# we attempt to apply them but don't fail
if [ "${x##-*}" = "opt" ]; then
optional=yes
fi
cat patches/$x | ( cd $ZENHOME; try patch -p3 -b -B $BACKUPDIR/ $extra_args )
if [ $? -gt $errval ]; then
if [ "$1" = "dry-run" ]; then
skip_apply="$skip_apply $x"
continue
else
fail=$x
break
fi
fi
# add to our list to apply later.
if [ "$1" = "dry-run" ]; then
real_apply="$real_apply $x"
fi
done

if [ -n "$fail" ]; then
echo
echo "Patch $x failed to apply."
return 1
fi
return 0
}

revert() {
echo
echo "There was a problem applying patches. Reverting..."
echo
cd $BACKUPDIR || die "Couldn't change directories to $BACKUPDIR to revert patches."
rsync -av $BACKUPDIR/ $ZENHOME/ || die "Revert failed."
rm -rf "$BACKUPDIR"
echo
echo "Revert successful."
exit 1
}

dry_run_patch_apply() {
echo
echo "Doing a dry-run patch application..."
echo
patch_apply 2 dry-run || die "Dry-run failed. Maybe you are not running Zenoss ${TARGET_VERSION}?"
}

real_patch_apply() {
echo
echo "Applying $SP..."
echo
patch_apply 1
if [ $? -ne 0 ]; then
revert
else
echo "$SP" > $ZENHOME/ServicePacks/INSTALLED
fi
}

echo "Stopping Zenoss..."
echo
try zenoss stop
dry_run_patch_apply
real_patch_apply
scripts/buildjs.sh || echo "Warning: Couldn't rebuild JavaScript."
cat << EOF

Service pack $SP applied successfully. Please type 'zenoss start' to restart Zenoss.

EOF
exit 0
Something went wrong with that request. Please try again.