makesums revision 1.9 1 #!/bin/sh
2 #
3 # $NetBSD: makesums,v 1.9 2005/10/06 02:12:49 jmc 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'' is used).
11 # If -a is given, then the list of sets is ignored, and ``*'' is used.
12 #
13 # After shell glob expansion, the list of sets is filtered to remove known
14 # output file names (of the form *SUM, SHA512 and MD5), non-existent files, and
15 # subdirectories. If this filtering leaves no files, then no output files are
16 # produced. Otherwise the resulting list of files are checksummed and five
17 # output files (BSDSUM, CKSUM, MD5, SHA512, SYSVSUM) are produced.
18 #
19
20 prog=${0##*/}
21
22 # set defaults
23 : ${CKSUM=cksum}
24 targetdir=$RELEASEDIR
25 dash_all=no
26
27 usage()
28 {
29 cat 1>&2 <<USAGE
30 Usage: ${prog} [-a] [-t targetdir] [setname [...]]
31 -a checksum all plain files instead of [setname [...]]
32 -t targetdir \$RELEASEDIR [$targetdir]
33 setname [...] sets to checksum [*.tgz]
34 USAGE
35 exit 1
36 }
37
38 # handle args
39 while getopts at: ch; do
40 case ${ch} in
41 a)
42 dash_all=yes
43 ;;
44 t)
45 targetdir=${OPTARG}
46 ;;
47 *)
48 usage
49 ;;
50 esac
51 done
52 shift $((${OPTIND} - 1))
53
54 if [ -z "$targetdir" ]; then
55 echo 1>&2 '$RELEASEDIR must be set or provided with -t'
56 exit 1
57 fi
58
59 cd $targetdir
60 pat="$*"
61 if [ $dash_all = yes ]; then
62 pat='*'
63 elif [ -z "$pat" ]; then
64 pat='*.tgz'
65 fi
66 lists=$(find $pat -prune \( -type f -o -type l \) \! -name '*SUM' \! -name MD5 \! -name SHA512 2>/dev/null)
67 if [ -n "$lists" ]; then
68 ${CKSUM} -o1 $lists > BSDSUM
69 ${CKSUM} $lists > CKSUM
70 ${CKSUM} -a md5 $lists > MD5
71 ${CKSUM} -o2 $lists > SYSVSUM
72 ${CKSUM} -a sha512 $lists > SHA512
73 fi
74