#!/bin/sh # # $Id$ # # The author disclaims all copyrights and releases this script into the # public domain. # # Script to export from CVS a named module and drop it into a directory. # This directory will be created if it does not exist, and rsync used to # merge the export into the directory, as 'cvs export' does not export # to a populated directory. # Expect to be moving large amounts of data, which could be too large # for /tmp. Set TMPDIR or use -T option to set different directory. if [ -z $TMPDIR ]; then TMPDIR=/var/tmp fi REVISION="-D NOW" STAGING_AREA= OPT= while getopts d:r:T: OPT; do case $OPT in d) CVSROOT=$OPTARG ;; r) # for CVS option to 'cvs export' REVISION="-r $OPTARG" ;; T) TMPDIR=$OPTARG ;; esac done shift $(($OPTIND - 1)) if [ -z "$1" ]; then echo "usage: `basename $0` [-d cvsroot] [-r tag] [-T tmpdir] module target-dir" >&2 exit 1 fi MODULE=$1 TARGET=$2 cleanup () { if [ ! -z "$STAGING_AREA" ]; then if [ -d "$STAGING_AREA" ]; then rm -rf "$STAGING_AREA" fi fi } trap "cleanup" 0 1 2 13 15 STAGING_AREA=`mktemp -d $TMPDIR/stage.XXXXXXXX` || exit $? # KLUGE append / to directory for rsync copy STAGING_AREA="$STAGING_AREA/" cvs -Q -d "$CVSROOT" export $REVISION -d "$STAGING_AREA" "$MODULE" || exit $? if [ ! -e "$TARGET" ]; then echo "notice: creating target directory: dir=$TARGET" >&2 mkdir -p -- "$TARGET" fi if [ ! -d "$TARGET" ]; then echo "error: target directory not a directory: dir=$TARGET" >&2 exit 1 fi # TODO watch output and change exit value if target was or was not # updated? (If updated, then trigger other actions.) rsync -crut --delete --timeout=999 "$STAGING_AREA" "$TARGET" || exit $?