#!/bin/bash # # $Id: websync,v 1.2 2007/03/20 21:22:09 mmcgrath Exp $ # ## based on script from aja ## modified by tfox for rhl.redhat.com ## commented out qa since we don't have a qa server # # Tunables # MAILTO="mmcgrath@redhat.com" LOCKFILE=/var/tmp/websync.lock RSYNCUSER="rhlweb" RSYNCPASS="haberdashery" CVSHOST="cvs.devel.redhat.com" CVSPATH="rhlweb" DESTDIR="/var/www/" # # Defaults # LINKS="" ACTION="" DRY="" TEST="" VERBOSE="" EXCLUDES="html/test.php \ html/projects/config-tools/template.php \ html/projects/config-tools/redhat-template.todo \ scripts/ \ config/ \ scripts/ \ template-mockup/" EXCLUDES_LIST="" ARGS="$*" usage() { echo "options:" echo " --help This help screen" echo " --dry-run Don't actually rsync any files - test run only" echo " --test Don't actually run rsync, just echo the command line" echo " --verbose Show progress numbers during rsyncs" echo " --live Pull from the LIVE checkout repository" # echo " --qa Pull from the QA checkout repository" echo } # # Process the command line # while [ -n "$1" ] ; do case $1 in --dry*) DRY="--dry-run" shift ;; --test) TEST="yes" MAILTO="`whoami`@redhat.com" LOCKFILE=/tmp/websync.lock shift ;; --verbose) VERBOSE="--progress --verbose" shift ;; --live) shift ;; # --qa) # CVSPATH="webqa/" # shift # ;; --help) usage exit 0 ;; esac done # # Sanity check things before we kick off the rsync # if [ -z ${CVSPATH} ] ; then echo "Environment not specified, bailing out!" exit -1 fi if [ ! -d ${DESTDIR} ] ; then echo "Destination ${DESTDIR} does not exit, bailing out!" exit -1 fi if [ ! -w ${DESTDIR} ] ; then echo "Destination ${DESTDIR} is not writable, bailing out!" exit -1 fi # # Lock the system so that we know not to do multiple websyncs # if [ -f $LOCKFILE ]; then echo "Unable to websync. There appears to be an websync running as:" cat $LOCKFILE exit 3 else echo "WEB sync run on: `date`" > $LOCKFILE if [ $? != 0 ] ; then echo "Unable to create $LOCKFILE, exiting." exit 6 fi echo "tree: $DIR" >> $LOCKFILE fi # make sure not to do links on dry run if [ -n "$DRY" ] ; then LINKS=no fi # # Build the --excludes list for rsync # for excl in $EXCLUDES ; do EXCLUDES_LIST="$EXCLUDES_LIST --exclude $excl" done # # Build the rsync command to run # RSYNC_EXCL="--exclude .snapshot --exclude .nfs* $EXCLUDES_LIST" RSYNC_OPTS="--delete --devices --hard-links --links \ --perms --owner --group --recursive --times" if [ -z "$TEST" ] ; then RSYNC="rsync $RSYNC_OPTS $DRY $VERBOSE $RSYNC_EXCL $RSYNC_DRY" else RSYNC="echo rsync $RSYNC_OPTS $DRY $VERBOSE $RSYNC_EXCL $RSYNC_DRY" fi # # sync in full from arg1 to arg2 # if [ -z "$TEST" ] ; then RSYNC_PASSWORD=${RSYNCPASS} $RSYNC rsync://${RSYNCUSER}@${CVSHOST}/${CVSPATH} ${DESTDIR} else echo $RSYNC rsync://${RSYNCUSER}@${CVSHOST}/${CVSPATH}/ ${DESTDIR} fi if [ -z "$MAILTO" ] ; then # nothing else to do rm -f $LOCKFILE exit 0 fi rm -f $LOCKFILE