#!/bin/bash set -e -o pipefail errhandler() { echo >&2 echo "Installation encountered error on line $1. Aborting. Please contact Groundwork Support for assistance." >&2 echo >&2 } trap 'errhandler $LINENO' ERR GWVER="7.1.1" PATCH="TB$GWVER-2" GWDIR="/usr/local/groundwork" OUTDIR="$GWDIR/common/var/patches" LOGFILE="$OUTDIR/$PATCH.log" OUTFILE="$OUTDIR/$PATCH.installed" echo "===== Groundwork Patch $PATCH installer =====" echo echo "This patch will allow you to have Groundwork use a" echo "custom installed JDK7 instead of the included Oracle JDK7." echo echo "Please note that this script will stop/start Groundwork which" echo "will result in a few minutes of downtime. This script will also" echo "modify various portions of your Groundwork installation." echo echo -n "Ok to proceed? [y/N] " read -r proceed echo case "$proceed" in [yY][eE][sS]|[yY]) ;; *) echo "Installation aborted" exit 0 ;; esac if [[ $EUID -ne 0 ]]; then echo "ERROR: This script must be run as root" >&2 exit 1 fi if [ -f $OUTFILE ]; then echo "ERROR: Patch already installed. Please contact Groundwork Support for assistance." >&2 exit 1 fi if ! grep -Exq "version= 7.1.0|version= $GWVER" $GWDIR/Info.txt; then echo "ERROR: Version 7.1.0 or $GWVER required" >&2 exit 1 fi if ! which java &>/dev/null; then echo "ERROR: java required but not found" >&2 exit 1 fi if ! which javac &>/dev/null; then echo "ERROR: JDK required but not found" >&2 exit 1 fi mkdir -p $OUTDIR exec &> >(tee -a "$LOGFILE") echo "PATCH: $PATCH" echo "USER: $USER" echo "HOST: `hostname -f`" echo "INSTALL START: `date`" echo "==================================================" echo "Determining JDK location..." JDK_PATH=`dirname $(dirname $(readlink -f $(which javac)))` echo "System default JDK is at $JDK_PATH" echo -n "Use this? [Y/n] " read -r response case "$response" in [yY][eE][sS]|[yY]|"") ;; *) echo "Please enter path to JDK (should be parent directory of bin, jre," echo "lib, etc.) example: /usr/lib/jvm/java-7-openjdk-amd64" echo -n "> " read -r JDK_PATH ;; esac echo "Stopping gwservices..." /etc/init.d/groundwork stop gwservices echo "Backing up original JDK..." mv $GWDIR/java $GWDIR/java.original echo "Setting JAVA_HOME to $JDK_PATH in $GWDIR/scripts/setenv.sh...." sed -i.original "s|$GWDIR/java|$JDK_PATH|g" $GWDIR/scripts/setenv.sh echo "Setting JAVA_HOME to $JDK_PATH in $GWDIR/nagios/libexec/check_jvm.pl..." sed -i.original "s|$GWDIR/java|$JDK_PATH|g" $GWDIR/nagios/libexec/check_jvm.pl echo "Setting JAVA_HOME to $JDK_PATH in $GWDIR/foundation/container/rstools/php/bsmCheck/protected/components/ConsoleCommand.php..." sed -i.original "s|/groundwork/java|$JDK_PATH|g" $GWDIR/foundation/container/rstools/php/bsmCheck/protected/components/ConsoleCommand.php echo "Starting gwservices..." /etc/init.d/groundwork start gwservices echo "==================================================" echo "INSTALL COMPLETE: `date`" touch $OUTFILE