makesums revision 1.12 1 1.1 is #!/bin/sh
2 1.1 is #
3 1.12 apb # $NetBSD: makesums,v 1.12 2006/01/03 15:42:42 apb 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.2 toddpw # and may be omitted (in which case ``*.tgz'' 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.9 jmc # produced. Otherwise the resulting list of files are checksummed and five
19 1.9 jmc # output files (BSDSUM, CKSUM, MD5, SHA512, SYSVSUM) are produced.
20 1.1 is #
21 1.1 is
22 1.7 lukem 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.7 lukem 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.7 lukem -t targetdir \$RELEASEDIR [$targetdir]
38 1.7 lukem setname [...] sets to checksum [*.tgz]
39 1.7 lukem USAGE
40 1.7 lukem exit 1
41 1.7 lukem }
42 1.7 lukem
43 1.1 is # handle args
44 1.10 jmc while getopts aAt: ch; do
45 1.7 lukem case ${ch} in
46 1.10 jmc A)
47 1.10 jmc append=\>\>
48 1.10 jmc ;;
49 1.7 lukem a)
50 1.2 toddpw dash_all=yes
51 1.1 is ;;
52 1.7 lukem t)
53 1.7 lukem targetdir=${OPTARG}
54 1.1 is ;;
55 1.1 is *)
56 1.7 lukem usage
57 1.1 is ;;
58 1.1 is esac
59 1.1 is done
60 1.7 lukem shift $((${OPTIND} - 1))
61 1.1 is
62 1.7 lukem if [ -z "$targetdir" ]; then
63 1.7 lukem echo 1>&2 '$RELEASEDIR must be set or provided with -t'
64 1.1 is exit 1
65 1.1 is fi
66 1.1 is
67 1.7 lukem cd $targetdir
68 1.2 toddpw pat="$*"
69 1.2 toddpw if [ $dash_all = yes ]; then
70 1.2 toddpw pat='*'
71 1.2 toddpw elif [ -z "$pat" ]; then
72 1.2 toddpw pat='*.tgz'
73 1.2 toddpw fi
74 1.8 elad lists=$(find $pat -prune \( -type f -o -type l \) \! -name '*SUM' \! -name MD5 \! -name SHA512 2>/dev/null)
75 1.2 toddpw if [ -n "$lists" ]; then
76 1.10 jmc eval ${CKSUM} -o1 $lists $append BSDSUM
77 1.10 jmc eval ${CKSUM} $lists $append CKSUM
78 1.10 jmc eval ${CKSUM} -a md5 $lists $append MD5
79 1.10 jmc eval ${CKSUM} -o2 $lists $append SYSVSUM
80 1.10 jmc eval ${CKSUM} -a sha512 $lists $append SHA512
81 1.1 is fi
82