Home | History | Annotate | Line # | Download | only in sets
makesums revision 1.12
      1 #!/bin/sh
      2 #
      3 # $NetBSD: makesums,v 1.12 2006/01/03 15:42:42 apb Exp $
      4 #
      5 # Make checksum files for files in ``tardir''.  Usage:
      6 # makesums [-a] [-t tardir] [setname [...]]
      7 #
      8 # If -t is omitted, RELEASEDIR must be set and not empty.
      9 # The ``setname'' arguments comprise a list of files to checksum,
     10 # and may be omitted (in which case ``*.tgz'' is used).
     11 # If -A is given, then the checksum are appended to possibly existing files.
     12 # NOTE: Don't use this when running parallel jobs
     13 # If -a is given, then the list of sets is ignored, and ``*'' is used.
     14 #
     15 # After shell glob expansion, the list of sets is filtered to remove known
     16 # output file names (of the form *SUM, SHA512 and MD5), non-existent files, and
     17 # subdirectories. If this filtering leaves no files, then no output files are
     18 # produced. Otherwise the resulting list of files are checksummed and five
     19 # output files (BSDSUM, CKSUM, MD5, SHA512, SYSVSUM) are produced.
     20 #
     21 
     22 prog=${0##*/}
     23 rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
     24 . "${rundir}/sets.subr"
     25 
     26 # set defaults
     27 targetdir=$RELEASEDIR
     28 dash_all=no
     29 append=\>
     30 
     31 usage()
     32 {
     33 	cat 1>&2 <<USAGE
     34 Usage: ${prog} [-A] [-a] [-t targetdir] [setname [...]]
     35 	-A		Append to possible existing checksum files 
     36 	-a		checksum all plain files instead of [setname [...]]
     37 	-t targetdir	\$RELEASEDIR		[$targetdir]
     38 	setname [...]	sets to checksum 	[*.tgz]
     39 USAGE
     40 	exit 1
     41 }
     42 
     43 # handle args
     44 while getopts aAt: ch; do
     45 	case ${ch} in
     46 	A)
     47 		append=\>\>
     48 		;;
     49 	a)
     50 		dash_all=yes
     51 		;;
     52 	t)	
     53 		targetdir=${OPTARG}
     54 		;;
     55 	*)
     56 		usage
     57 		;;
     58 	esac
     59 done
     60 shift $((${OPTIND} - 1))
     61 
     62 if [ -z "$targetdir" ]; then
     63 	echo 1>&2 '$RELEASEDIR must be set or provided with -t'
     64 	exit 1
     65 fi
     66 
     67 cd $targetdir
     68 pat="$*"
     69 if [ $dash_all = yes ]; then
     70 	pat='*'
     71 elif [ -z "$pat" ]; then
     72 	pat='*.tgz'
     73 fi
     74 lists=$(find $pat -prune \( -type f -o -type l \) \! -name '*SUM' \! -name MD5 \! -name SHA512 2>/dev/null)
     75 if [ -n "$lists" ]; then
     76 	eval ${CKSUM} -o1 $lists $append BSDSUM
     77 	eval ${CKSUM}     $lists $append CKSUM
     78 	eval ${CKSUM} -a md5  $lists $append MD5
     79 	eval ${CKSUM} -o2 $lists $append SYSVSUM
     80 	eval ${CKSUM} -a sha512  $lists $append SHA512
     81 fi
     82