makesums revision 1.10
11.1Sis#!/bin/sh
21.1Sis#
31.10Sjmc# $NetBSD: makesums,v 1.10 2005/10/07 17:21:36 jmc Exp $
41.1Sis#
51.2Stoddpw# Make checksum files for files in ``tardir''.  Usage:
61.7Slukem# makesums [-a] [-t tardir] [setname [...]]
71.2Stoddpw#
81.2Stoddpw# If -t is omitted, RELEASEDIR must be set and not empty.
91.2Stoddpw# The ``setname'' arguments comprise a list of files to checksum,
101.2Stoddpw# and may be omitted (in which case ``*.tgz'' is used).
111.10Sjmc# If -A is given, then the checksum are appended to possibly existing files.
121.10Sjmc# NOTE: Don't use this when running parallel jobs
131.7Slukem# If -a is given, then the list of sets is ignored, and ``*'' is used.
141.2Stoddpw#
151.2Stoddpw# After shell glob expansion, the list of sets is filtered to remove known
161.9Sjmc# output file names (of the form *SUM, SHA512 and MD5), non-existent files, and
171.2Stoddpw# subdirectories. If this filtering leaves no files, then no output files are
181.9Sjmc# produced. Otherwise the resulting list of files are checksummed and five
191.9Sjmc# output files (BSDSUM, CKSUM, MD5, SHA512, SYSVSUM) are produced.
201.1Sis#
211.1Sis
221.7Slukemprog=${0##*/}
231.7Slukem
241.1Sis# set defaults
251.3Sbjh21: ${CKSUM=cksum}
261.7Slukemtargetdir=$RELEASEDIR
271.2Stoddpwdash_all=no
281.10Sjmcappend=\>
291.1Sis
301.7Slukemusage()
311.7Slukem{
321.7Slukem	cat 1>&2 <<USAGE
331.10SjmcUsage: ${prog} [-A] [-a] [-t targetdir] [setname [...]]
341.10Sjmc	-A		Append to possible existing checksum files 
351.7Slukem	-a		checksum all plain files instead of [setname [...]]
361.7Slukem	-t targetdir	\$RELEASEDIR		[$targetdir]
371.7Slukem	setname [...]	sets to checksum 	[*.tgz]
381.7SlukemUSAGE
391.7Slukem	exit 1
401.7Slukem}
411.7Slukem
421.1Sis# handle args
431.10Sjmcwhile getopts aAt: ch; do
441.7Slukem	case ${ch} in
451.10Sjmc	A)
461.10Sjmc		append=\>\>
471.10Sjmc		;;
481.7Slukem	a)
491.2Stoddpw		dash_all=yes
501.1Sis		;;
511.7Slukem	t)	
521.7Slukem		targetdir=${OPTARG}
531.1Sis		;;
541.1Sis	*)
551.7Slukem		usage
561.1Sis		;;
571.1Sis	esac
581.1Sisdone
591.7Slukemshift $((${OPTIND} - 1))
601.1Sis
611.7Slukemif [ -z "$targetdir" ]; then
621.7Slukem	echo 1>&2 '$RELEASEDIR must be set or provided with -t'
631.1Sis	exit 1
641.1Sisfi
651.1Sis
661.7Slukemcd $targetdir
671.2Stoddpwpat="$*"
681.2Stoddpwif [ $dash_all = yes ]; then
691.2Stoddpw	pat='*'
701.2Stoddpwelif [ -z "$pat" ]; then
711.2Stoddpw	pat='*.tgz'
721.2Stoddpwfi
731.8Seladlists=$(find $pat -prune \( -type f -o -type l \) \! -name '*SUM' \! -name MD5 \! -name SHA512 2>/dev/null)
741.2Stoddpwif [ -n "$lists" ]; then
751.10Sjmc	eval ${CKSUM} -o1 $lists $append BSDSUM
761.10Sjmc	eval ${CKSUM}     $lists $append CKSUM
771.10Sjmc	eval ${CKSUM} -a md5  $lists $append MD5
781.10Sjmc	eval ${CKSUM} -o2 $lists $append SYSVSUM
791.10Sjmc	eval ${CKSUM} -a sha512  $lists $append SHA512
801.1Sisfi
81