#!/bin/sh # @(#) generate md5sum for commited files # # Copyright (c) 2009 Dirk Jagdmann # https://llg.cubic.org/tools/cvsmd5.html # # This software is provided 'as-is', without any express or implied # warranty. In no event will the authors be held liable for any damages # arising from the use of this software. # # Permission is granted to anyone to use this software for any purpose, # including commercial applications, and to alter it and redistribute it # freely, subject to the following restrictions: # # 1. The origin of this software must not be misrepresented; you # must not claim that you wrote the original software. If you use # this software in a product, an acknowledgment in the product # documentation would be appreciated but is not required. # # 2. Altered source versions must be plainly marked as such, and # must not be misrepresented as being the original software. # # 3. This notice may not be removed or altered from any source # distribution. # # Version: 2009-12-30 # # This script works with CVS 1.12.x or newer. # You have to set "UseNewInfoFmtStrings=yes" in CVSROOT/config. # Add this file to your CVSROOT directory and add the following line to # CVSROOT/loginfo as the first directive: # ALL sh $CVSROOT/CVSROOT/md5 %c %r %p %s # Add the following line to CVSROOT/commitinfo: # ALL sh $CVSROOT/CVSROOT/md5 checkmd5 %r %p %s # Add the following line to CVSROOT/posttag: # ALL sh $CVSROOT/CVSROOT/md5 %c %r %p %s # Add the following line to CVSROOT/checkoutlist: # md5 Unable to check out md5sum script # ############################################################################## # set your contact information ADR="Dirk Jagdmann " # enable for debugging and development purposes #DEBUG=1 # enable to write backup version of repository files BACKUP=1 ############################################################################## [ "$DEBUG" ] && echo `date +%Y-%m-%dT%H:%M:%S` "$@" # get command line arguments CMD="$1" REP="$2" DIR="$3" shift 3 ABSDIR="$REP/$DIR" ATTIC="$ABSDIR/Attic" # if a previous run of md5 left work to do, it stored it in the command file #CMDFN="$ABSDIR/md5.run" #if [ -f "$CMDFN" ] ; then # [ "$DEBUG" ] && echo "execute command file $CMDFN" # TMP=`mktemp` # mv -f "$CMDFN" "$TMP" # sh "$TMP" # rm -f "$TMP" #fi if [ "$CMD" = import ] ; then # go into directory if ! cd "$ABSDIR" ; then echo "md5: could not chdir $ABSDIR" exit 1 fi find . -name '*,v' -execdir $0 md5sum {} ';' [ "$DEBUG" ] && echo "md5: exit success" exit 0 # special action invoked by find from import elif [ "$CMD" = md5sum ] ; then # get rid of ./ FN=`echo "$REP" | cut -b 3-` # create md5 sum umask 077 MD5="$FN.md5" BAK="$FN.bak" md5sum "$FN" > "$MD5" if [ "$BACKUP" ] ; then [ "$DEBUG" ] && echo "backup $FN -> $BAK" cp -fp "$FN" "$BAK" fi [ "$DEBUG" ] && echo "md5: exit success" exit 0 fi for fn in "$@" ; do ABSDIR="$REP/$DIR" # this might get modified below, so we have to re-set it for each loop iteration FN="$fn,v" ABSFN="$ABSDIR/$FN" MD5="$FN.md5" BAK="$FN.bak" if [ "$CMD" = commit -o "$CMD" = tag ] ; then # check for file if [ ! -f "$ABSFN" ] ; then # check if the file moved to Attic/ if [ -f "$ATTIC/$FN" ] ; then # remove old MD5 rm -f "$ABSDIR/$MD5" # re-set variables ABSDIR="$ATTIC" ABSFN="$ABSDIR/$FN" [ "$DEBUG" ] && echo "$FN moved to Attic" else echo "md5: did not find file $ABSFN" exit 1 fi fi # go into directory if ! cd "$ABSDIR" ; then echo "md5: could not chdir $ABSDIR" exit 1 fi # generate checksum [ "$DEBUG" ] && echo "md5sum $ABSDIR/$FN > $ABSDIR/$MD5" umask 077 md5sum "$FN" > "$MD5" # check for old checksum in Attic/ if [ ! -f "Attic/$FN" -a -f "Attic/$MD5" ] ; then [ "$DEBUG" ] && echo "remove stale checksum from Attic/" rm -f "Attic/$MD5" fi # generate frozen file if [ "$BACKUP" ] ; then [ "$DEBUG" ] && echo "backup $ABSDIR/$FN -> $ABSDIR/$BAK" cp -fp "$FN" "$BAK" # check for old backup in Attic/ if [ ! -f "Attic/$FN" -a -f "Attic/$BAK" ] ; then [ "$DEBUG" ] && echo "remove stale backup from Attic/" rm -f "Attic/$BAK" fi fi elif [ "$CMD" = checkmd5 -a -f "$ABSFN" ] ; then # go into directory if ! cd "$ABSDIR" ; then echo "md5: could not chdir $ABSDIR" exit 1 fi # check against md5 checksum if [ -f "$MD5" ] ; then TMP=`mktemp` md5sum "$FN" > $TMP cmp "$MD5" $TMP RES=$? rm -f $TMP [ "$DEBUG" ] && echo "cmp $ABSDIR/$MD5 $TMP := $RES" if [ "$RES" != 0 ] ; then echo " MD5 checksum of $ABSFN does not match! Your repository might be corrupted!" echo " Contact your CVS administrator $ADR for help on this problem." exit 1 fi fi fi done [ "$DEBUG" ] && echo "md5: exit success" exit 0