1999-07-23 00:10:16 +04:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2018-09-28 18:04:20 +03:00
|
|
|
# $NetBSD: makesums,v 1.17 2018/09/28 15:04:20 martin Exp $
|
1999-07-23 00:10:16 +04:00
|
|
|
#
|
2000-08-20 12:29:59 +04:00
|
|
|
# Make checksum files for files in ``tardir''. Usage:
|
2004-04-20 09:37:15 +04:00
|
|
|
# makesums [-a] [-t tardir] [setname [...]]
|
2000-08-20 12:29:59 +04:00
|
|
|
#
|
|
|
|
# If -t is omitted, RELEASEDIR must be set and not empty.
|
|
|
|
# The ``setname'' arguments comprise a list of files to checksum,
|
2018-09-28 18:04:20 +03:00
|
|
|
# and may be omitted (in which case ``*.tgz *.tar.xz'' is used).
|
2005-10-07 21:21:36 +04:00
|
|
|
# If -A is given, then the checksum are appended to possibly existing files.
|
|
|
|
# NOTE: Don't use this when running parallel jobs
|
2004-04-20 09:37:15 +04:00
|
|
|
# If -a is given, then the list of sets is ignored, and ``*'' is used.
|
2000-08-20 12:29:59 +04:00
|
|
|
#
|
|
|
|
# After shell glob expansion, the list of sets is filtered to remove known
|
2005-10-06 06:12:49 +04:00
|
|
|
# output file names (of the form *SUM, SHA512 and MD5), non-existent files, and
|
2000-08-20 12:29:59 +04:00
|
|
|
# subdirectories. If this filtering leaves no files, then no output files are
|
2009-09-19 11:09:53 +04:00
|
|
|
# produced. Otherwise the resulting list of files are checksummed and two
|
|
|
|
# output files (MD5 and SHA512) are produced.
|
1999-07-23 00:10:16 +04:00
|
|
|
#
|
|
|
|
|
2006-01-03 21:31:09 +03:00
|
|
|
prog="${0##*/}"
|
2006-01-03 18:42:42 +03:00
|
|
|
rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
|
|
|
|
. "${rundir}/sets.subr"
|
2004-04-20 09:37:15 +04:00
|
|
|
|
1999-07-23 00:10:16 +04:00
|
|
|
# set defaults
|
2006-01-03 21:31:09 +03:00
|
|
|
targetdir="${RELEASEDIR}"
|
2000-08-20 12:29:59 +04:00
|
|
|
dash_all=no
|
2005-10-07 21:21:36 +04:00
|
|
|
append=\>
|
1999-07-23 00:10:16 +04:00
|
|
|
|
2004-04-20 09:37:15 +04:00
|
|
|
usage()
|
|
|
|
{
|
|
|
|
cat 1>&2 <<USAGE
|
2005-10-07 21:21:36 +04:00
|
|
|
Usage: ${prog} [-A] [-a] [-t targetdir] [setname [...]]
|
|
|
|
-A Append to possible existing checksum files
|
2004-04-20 09:37:15 +04:00
|
|
|
-a checksum all plain files instead of [setname [...]]
|
2006-01-03 21:31:09 +03:00
|
|
|
-t targetdir \${RELEASEDIR} [${targetdir}]
|
2018-09-28 18:04:20 +03:00
|
|
|
setname [...] sets to checksum [*.tgz *.tar.xz]
|
2004-04-20 09:37:15 +04:00
|
|
|
USAGE
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
1999-07-23 00:10:16 +04:00
|
|
|
# handle args
|
2005-10-07 21:21:36 +04:00
|
|
|
while getopts aAt: ch; do
|
2004-04-20 09:37:15 +04:00
|
|
|
case ${ch} in
|
2005-10-07 21:21:36 +04:00
|
|
|
A)
|
|
|
|
append=\>\>
|
|
|
|
;;
|
2004-04-20 09:37:15 +04:00
|
|
|
a)
|
2000-08-20 12:29:59 +04:00
|
|
|
dash_all=yes
|
1999-07-23 00:10:16 +04:00
|
|
|
;;
|
2004-04-20 09:37:15 +04:00
|
|
|
t)
|
2006-01-03 21:31:09 +03:00
|
|
|
targetdir="${OPTARG}"
|
1999-07-23 00:10:16 +04:00
|
|
|
;;
|
|
|
|
*)
|
2004-04-20 09:37:15 +04:00
|
|
|
usage
|
1999-07-23 00:10:16 +04:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2004-04-20 09:37:15 +04:00
|
|
|
shift $((${OPTIND} - 1))
|
1999-07-23 00:10:16 +04:00
|
|
|
|
2006-01-03 21:31:09 +03:00
|
|
|
if [ -z "${targetdir}" ]; then
|
2006-01-08 13:10:03 +03:00
|
|
|
echo >&2 "${prog}: \${RELEASEDIR} must be set or provided with -t"
|
1999-07-23 00:10:16 +04:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2006-01-03 21:31:09 +03:00
|
|
|
cd "${targetdir}"
|
2000-08-20 12:29:59 +04:00
|
|
|
pat="$*"
|
2006-01-03 21:31:09 +03:00
|
|
|
if [ "${dash_all}" = yes ]; then
|
2000-08-20 12:29:59 +04:00
|
|
|
pat='*'
|
2006-01-03 21:31:09 +03:00
|
|
|
elif [ -z "${pat}" ]; then
|
2018-09-28 18:04:20 +03:00
|
|
|
pat='*.tgz *.tar.xz'
|
2000-08-20 12:29:59 +04:00
|
|
|
fi
|
2006-01-03 21:31:09 +03:00
|
|
|
lists="$(${FIND} ${pat} -prune \( -type f -o -type l \) \
|
|
|
|
\! -name '*SUM' \! -name MD5 \! -name SHA512 2>/dev/null)"
|
|
|
|
if [ -n "${lists}" ]; then
|
|
|
|
eval ${CKSUM} -a md5 ${lists} ${append} MD5
|
|
|
|
eval ${CKSUM} -a sha512 ${lists} ${append} SHA512
|
1999-07-23 00:10:16 +04:00
|
|
|
fi
|