summaryrefslogtreecommitdiff
path: root/distrib/sets/makesums
blob: b41537b71323800beee1e50f055f10b835d61c77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/sh
#
# $NetBSD: makesums,v 1.16 2009/09/19 07:09:54 snj Exp $
#
# Make checksum files for files in ``tardir''.  Usage:
# makesums [-a] [-t tardir] [setname [...]]
#
# If -t is omitted, RELEASEDIR must be set and not empty.
# The ``setname'' arguments comprise a list of files to checksum,
# and may be omitted (in which case ``*.tgz'' is used).
# If -A is given, then the checksum are appended to possibly existing files.
# NOTE: Don't use this when running parallel jobs
# If -a is given, then the list of sets is ignored, and ``*'' is used.
#
# After shell glob expansion, the list of sets is filtered to remove known
# output file names (of the form *SUM, SHA512 and MD5), non-existent files, and
# subdirectories. If this filtering leaves no files, then no output files are
# produced. Otherwise the resulting list of files are checksummed and two
# output files (MD5 and SHA512) are produced.
#

prog="${0##*/}"
rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
. "${rundir}/sets.subr"

# set defaults
targetdir="${RELEASEDIR}"
dash_all=no
append=\>

usage()
{
	cat 1>&2 <<USAGE
Usage: ${prog} [-A] [-a] [-t targetdir] [setname [...]]
	-A		Append to possible existing checksum files 
	-a		checksum all plain files instead of [setname [...]]
	-t targetdir	\${RELEASEDIR}		[${targetdir}]
	setname [...]	sets to checksum 	[*.tgz]
USAGE
	exit 1
}

# handle args
while getopts aAt: ch; do
	case ${ch} in
	A)
		append=\>\>
		;;
	a)
		dash_all=yes
		;;
	t)	
		targetdir="${OPTARG}"
		;;
	*)
		usage
		;;
	esac
done
shift $((${OPTIND} - 1))

if [ -z "${targetdir}" ]; then
	echo >&2 "${prog}: \${RELEASEDIR} must be set or provided with -t"
	exit 1
fi

cd "${targetdir}"
pat="$*"
if [ "${dash_all}" = yes ]; then
	pat='*'
elif [ -z "${pat}" ]; then
	pat='*.tgz'
fi
lists="$(${FIND} ${pat} -prune \( -type f -o -type l \) \
	\! -name '*SUM' \! -name MD5 \! -name SHA512 2>/dev/null)"
if [ -n "${lists}" ]; then
	eval ${CKSUM} -a md5  ${lists} ${append} MD5
	eval ${CKSUM} -a sha512  ${lists} ${append} SHA512
fi