makesums revision 1.12
11.1Sis#!/bin/sh
21.1Sis#
31.12Sapb# $NetBSD: makesums,v 1.12 2006/01/03 15:42:42 apb 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.12Sapbrundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
241.12Sapb. "${rundir}/sets.subr"
251.7Slukem
261.1Sis# set defaults
271.7Slukemtargetdir=$RELEASEDIR
281.2Stoddpwdash_all=no
291.10Sjmcappend=\>
301.1Sis
311.7Slukemusage()
321.7Slukem{
331.7Slukem	cat 1>&2 <<USAGE
341.10SjmcUsage: ${prog} [-A] [-a] [-t targetdir] [setname [...]]
351.10Sjmc	-A		Append to possible existing checksum files 
361.7Slukem	-a		checksum all plain files instead of [setname [...]]
371.7Slukem	-t targetdir	\$RELEASEDIR		[$targetdir]
381.7Slukem	setname [...]	sets to checksum 	[*.tgz]
391.7SlukemUSAGE
401.7Slukem	exit 1
411.7Slukem}
421.7Slukem
431.1Sis# handle args
441.10Sjmcwhile getopts aAt: ch; do
451.7Slukem	case ${ch} in
461.10Sjmc	A)
471.10Sjmc		append=\>\>
481.10Sjmc		;;
491.7Slukem	a)
501.2Stoddpw		dash_all=yes
511.1Sis		;;
521.7Slukem	t)	
531.7Slukem		targetdir=${OPTARG}
541.1Sis		;;
551.1Sis	*)
561.7Slukem		usage
571.1Sis		;;
581.1Sis	esac
591.1Sisdone
601.7Slukemshift $((${OPTIND} - 1))
611.1Sis
621.7Slukemif [ -z "$targetdir" ]; then
631.7Slukem	echo 1>&2 '$RELEASEDIR must be set or provided with -t'
641.1Sis	exit 1
651.1Sisfi
661.1Sis
671.7Slukemcd $targetdir
681.2Stoddpwpat="$*"
691.2Stoddpwif [ $dash_all = yes ]; then
701.2Stoddpw	pat='*'
711.2Stoddpwelif [ -z "$pat" ]; then
721.2Stoddpw	pat='*.tgz'
731.2Stoddpwfi
741.8Seladlists=$(find $pat -prune \( -type f -o -type l \) \! -name '*SUM' \! -name MD5 \! -name SHA512 2>/dev/null)
751.2Stoddpwif [ -n "$lists" ]; then
761.10Sjmc	eval ${CKSUM} -o1 $lists $append BSDSUM
771.10Sjmc	eval ${CKSUM}     $lists $append CKSUM
781.10Sjmc	eval ${CKSUM} -a md5  $lists $append MD5
791.10Sjmc	eval ${CKSUM} -o2 $lists $append SYSVSUM
801.10Sjmc	eval ${CKSUM} -a sha512  $lists $append SHA512
811.1Sisfi
82