xref: /netbsd-src/distrib/sets/makesums (revision e3606ab09ead8e3dc0a34037c78eeada7bc67baa)
1#!/bin/sh
2#
3# $NetBSD: makesums,v 1.19 2023/11/08 13:02:47 christos 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 *.tar.xz'' 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 two
19# output files (MD5 and SHA512) are produced.
20#
21
22prog="${0##*/}"
23rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
24. "${rundir}/sets.subr"
25
26# set defaults
27targetdir="${RELEASEDIR}"
28dash_all=no
29append=\>
30
31usage()
32{
33	cat 1>&2 <<USAGE
34Usage: ${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 *.tar.xz]
39USAGE
40	exit 1
41}
42
43umask 022
44# handle args
45while getopts aAt: ch; do
46	case ${ch} in
47	A)
48		append=\>\>
49		;;
50	a)
51		dash_all=yes
52		;;
53	t)
54		targetdir="${OPTARG}"
55		;;
56	*)
57		usage
58		;;
59	esac
60done
61shift $((${OPTIND} - 1))
62
63if [ -z "${targetdir}" ]; then
64	echo >&2 "${prog}: \${RELEASEDIR} must be set or provided with -t"
65	exit 1
66fi
67
68cd "${targetdir}"
69pat="$*"
70if [ "${dash_all}" = yes ]; then
71	pat='*'
72elif [ -z "${pat}" ]; then
73	pat='*.tgz *.tar.xz'
74fi
75lists="$(${FIND} ${pat} -prune \( -type f -o -type l \) \
76	\! -name '*SUM' \! -name MD5 \! -name SHA512 2>/dev/null)"
77if [ -n "${lists}" ]; then
78	eval ${CKSUM} -a md5  ${lists} ${append} MD5
79	eval ${CKSUM} -a sha512  ${lists} ${append} SHA512
80fi
81