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