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