#!/bin/sh # POST-COMMIT HOOK # # Arguments: # [1] REPOS-PATH (the path to this repository) # [2] REV (the number of the revision just committed) # # Script requires the configuration file quattor-deploy.conf. This # can either be in the same location as this script or in /etc. If # both exist, the one in the same location as this script is used. # # The REQUIRED configuration is sourced directly, so it should be a # list of bourne shell variable definitions. See: # https://trac.lal.in2p3.fr/LCGQWG/wiki/Doc/SCDB/Server # for more information about the parameters. # # Define names for the arguments. REPOS="$1" REV="$2" # By default the debugging flag is off. Set to any non-zero # value to turn debugging on. This can be done in configuration # file. DEBUG=0 # Flag to indicate whether to use sudo instead of ssh for # the post-commit compilation of machine profiles. If # sudo is used, then the QUATTORSERVER variable is optional. # For backwards compatibility, the default is to use ssh. USE_SUDO=0 # Script on Quattor server to deploy new configuration. DEPLOYSCRIPT=/root/quattor/scripts/build-tag.pl # User to run the deployment script. DEPLOYUSER=root # Default commands and options. These should be correct for # a standard linux machine. They can be redefined in the # REQUIRED quattor-deploy.conf file. MAILER="/bin/mail" SVNLOOK="/usr/bin/svnlook" SSH="/usr/bin/ssh" SSH_OPTIONS="-o PasswordAuthentication=no" SUDO="/usr/bin/sudo" SUDO_OPTIONS="-H" # Default prefix for mail subject in case of error ERROR_PREFIX='[Quattor-Deploy]' # The local directory and places to write the log. DIR=`dirname $0` LOG="/tmp/svn-commit-output-$REV.log" # Source the site configuration file. This file is REQUIRED # because some values have no meaningful defaults. # See https://trac.lal.in2p3.fr/LCGQWG/wiki/Doc/SCDB/Server # for more information. ERRORMSG= POST_COMMIT_CONF=quattor-deploy.conf if [ -f ${DIR}/${POST_COMMIT_CONF} ] then . ${DIR}/${POST_COMMIT_CONF} elif [ -f /etc/${POST_COMMIT_CONF} ] then . /etc/${POST_COMMIT_CONF} else ERRORMSG="Error : ${POST_COMMIT_CONF} not found. Aborting deployment" ERRORMSG="${ERRORMSG}\nLook at https://trac.lal.in2p3.fr/LCGQWG/wiki/Doc/SCDB/Server for more information" fi # By default, use ssh to trigger compilation of machine profiles. CMD=$SSH if [ $USE_SUDO -ne 0 ]; then CMD=$SUDO fi # Basic sanity checks if [ -z "$ERRORMSG" ] then if [ ! -x "${MAILER}" ] then ERRORMSG="Configuration error: mailer '${MAILER}' not executable" elif [ ! -x "${CMD}" ] then ERRORMSG="Configuration error: command '${CMD}' not executable" elif [ -z "$NOTIFY" ] then ERRORMSG='Configuration error: $NOTIFY variable undefined' elif [ -z "$USE_SUDO" ] then if [ -z "$QUATTORSRV" ] then ERRORMSG='Configuration error: $QUATTORSRV variable undefined' fi fi fi # Abort the processing if an error message has been set. if [ -n "$ERRORMSG" ] then echo $ERRORMSG echo $ERRORMSG >> $LOG if [ -x "${MAILER}" ] then # Try to send a mail to root on local system if $NOTIFY undefined... if [ -z "$NOTIFY" ] then NOTIFY=root fi echo "$ERRORMSG" | $MAILER -s "$ERROR_PREFIX Error deploying configuration tag $REV" $NOTIFY fi exit 1 fi # Set the command options and parameters. Do this AFTER the # configuration has been checked. The default is for ssh. CMD_OPTIONS=$SSH_OPTIONS ${DEPLOYUSER}@${QUATTORSRV} if [ $USE_SUDO -ne 0 ]; then CMD_OPTIONS=$SUDO_OPTIONS fi # Determine if this is an eligible tag. MATCH=`$SVNLOOK diff --revision $REV $REPOS | grep -E '.*Copied:[[:space:]]+tags/([[:digit:]/\.\-]+)[[:space:]]+.*trunk.*'` DEPLOY=$? echo "MATCH=$MATCH" > $LOG echo "DEPLOY=$DEPLOY" >> $LOG if [ $DEPLOY -eq 0 ]; then TAG=`echo $MATCH | sed 's%.*Copied:[[:space:]]*tags/\([[:digit:]/\.\-]*\).*trunk.*%\1%'` echo "TAG=$TAG" >> $LOG FULL_CMD="$CMD ${CMD_OPTIONS} $DEPLOYSCRIPT $TAG" echo $FULL_CMD >> $LOG $FULL_CMD 2>&1 >> $LOG RC=$? STATUS="SUCCESS" if [ $RC -ne 0 ]; then STATUS="FAILURE" cat $LOG | $MAILER -s "$ERROR_PREFIX $STATUS $RC $REPOS $REV" $NOTIFY fi fi # Clean up the log file unless we're in debug mode. if [ $DEBUG -eq 0 ]; then rm -f $LOG fi