#!/bin/sh # $Id: rsync_slackware_patches.sh,v 1.3 2005/09/11 14:00:32 root Exp root $ #----------------------------------------------------------------------------- # Program name: # rsync_slackware_patches.sh # Purpose: # Keep the /patches tree for a Slackware release in sync with a master # server. See the output of the "rsync_slackware_patches.sh -h" command # for the available command-line switches. # Author: # Eric Hameleers # Date: # 29jul2005 #----------------------------------------------------------------------------- BN=`basename $0` SLACKDEF=10.1 SLACKTREE="/home/ftp/pub/Linux/Slackware" VERBOSE=1 while getopts ":hnr:q" Option do case $Option in h ) echo "Parameters are:" echo " -h This help." echo " -n Rsync dry-run (don't download anything)." echo " -r Act on Slackware version . The default" echo " is to download patches for Slackware ${SLACKDEF}" echo " -q Non-verbose output (for cron jobs)." exit ;; n ) echo "Performing a dry-run!" ; RSYNCOPTS="${RSYNCOPTS} -n" ;; r ) VERSION=${OPTARG} ;; q ) VERBOSE=0 ;; * ) ;; # DEFAULT esac done # End of option parsing. shift $(($OPTIND - 1)) # $1 now references the first non option item supplied on the command line # if one exists. VERSION=${VERSION:-${SLACKDEF}} [ ${VERBOSE} -eq 1 ] && RSYNCVERBOSE="-v" || RSYNCVERBOSE="-q" [ ${VERBOSE} -eq 1 ] && echo "[$BN:] Syncing patches for version '${VERSION}' ..." if [ ! -d ${SLACKTREE}/slackware-${VERSION}/patches ]; then echo "[$BN:] Target directory ${SLACKTREE}/slackware-${VERSION}/patches does not exist!" echo "[$BN:] Please create it first, and then re-run this script." exit 1 fi cd ${SLACKTREE}/slackware-$VERSION/patches # Record time of last modification of ChangeLog.txt (it might not yet be there!) LASTMOD=`stat -c %Y ChangeLog.txt 2>/dev/null` LASTMOD=${LASTMOD:-0} # Keep a copy of ChangeLog.txt for feedback in case of updates: TMPFILE=`mktemp /tmp/ChangeLog.XXXXXX` TMPFILE=${TMPFILE:-/tmp/ChangeLog.txt.$$} cat ChangeLog.txt > $TMPFILE 2>/dev/null [ ${VERBOSE} -eq 1 ] && echo "[$BN:] Here we go..." rsync ${RSYNCOPTS} ${RSYNCVERBOSE} -az --delete slackware.mirrors.tds.net::slackware/slackware-$VERSION/patches/ . [ ${VERBOSE} -eq 1 ] && echo "[$BN:] Exit status: $?" [ ${VERBOSE} -eq 1 ] && echo "[$BN:] Done rsync-ing." # Compare time of last modification of the ChangeLog.txt to what we had: NEWMOD=`stat -c %Y ChangeLog.txt` if [ $LASTMOD -ne $NEWMOD ]; then echo "[$BN:] New patches have arrived for Slackware ${VERSION} !" echo echo "......................................................................." echo diff $TMPFILE ChangeLog.txt elif [ ${VERBOSE} -eq 1 ]; then echo "[$BN:] No change detected in the ChangeLog.txt." fi # Clean up: [ ${VERBOSE} -eq 1 ] && echo "[$BN:] Removing temporary file '$TMPFILE'." rm -f $TMPFILE [ ${VERBOSE} -eq 1 ] && echo "[$BN:] Done!"