makesums revision 1.10 1 1.1 is #!/bin/sh
2 1.1 is #
3 1.10 jmc # $NetBSD: makesums,v 1.10 2005/10/07 17:21:36 jmc 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.7 lukem
24 1.1 is # set defaults
25 1.3 bjh21 : ${CKSUM=cksum}
26 1.7 lukem targetdir=$RELEASEDIR
27 1.2 toddpw dash_all=no
28 1.10 jmc append=\>
29 1.1 is
30 1.7 lukem usage()
31 1.7 lukem {
32 1.7 lukem cat 1>&2 <<USAGE
33 1.10 jmc Usage: ${prog} [-A] [-a] [-t targetdir] [setname [...]]
34 1.10 jmc -A Append to possible existing checksum files
35 1.7 lukem -a checksum all plain files instead of [setname [...]]
36 1.7 lukem -t targetdir \$RELEASEDIR [$targetdir]
37 1.7 lukem setname [...] sets to checksum [*.tgz]
38 1.7 lukem USAGE
39 1.7 lukem exit 1
40 1.7 lukem }
41 1.7 lukem
42 1.1 is # handle args
43 1.10 jmc while getopts aAt: ch; do
44 1.7 lukem case ${ch} in
45 1.10 jmc A)
46 1.10 jmc append=\>\>
47 1.10 jmc ;;
48 1.7 lukem a)
49 1.2 toddpw dash_all=yes
50 1.1 is ;;
51 1.7 lukem t)
52 1.7 lukem targetdir=${OPTARG}
53 1.1 is ;;
54 1.1 is *)
55 1.7 lukem usage
56 1.1 is ;;
57 1.1 is esac
58 1.1 is done
59 1.7 lukem shift $((${OPTIND} - 1))
60 1.1 is
61 1.7 lukem if [ -z "$targetdir" ]; then
62 1.7 lukem echo 1>&2 '$RELEASEDIR must be set or provided with -t'
63 1.1 is exit 1
64 1.1 is fi
65 1.1 is
66 1.7 lukem cd $targetdir
67 1.2 toddpw pat="$*"
68 1.2 toddpw if [ $dash_all = yes ]; then
69 1.2 toddpw pat='*'
70 1.2 toddpw elif [ -z "$pat" ]; then
71 1.2 toddpw pat='*.tgz'
72 1.2 toddpw fi
73 1.8 elad lists=$(find $pat -prune \( -type f -o -type l \) \! -name '*SUM' \! -name MD5 \! -name SHA512 2>/dev/null)
74 1.2 toddpw if [ -n "$lists" ]; then
75 1.10 jmc eval ${CKSUM} -o1 $lists $append BSDSUM
76 1.10 jmc eval ${CKSUM} $lists $append CKSUM
77 1.10 jmc eval ${CKSUM} -a md5 $lists $append MD5
78 1.10 jmc eval ${CKSUM} -o2 $lists $append SYSVSUM
79 1.10 jmc eval ${CKSUM} -a sha512 $lists $append SHA512
80 1.1 is fi
81