Home | History | Annotate | Line # | Download | only in sets
makesums revision 1.17
      1   1.1      is #!/bin/sh
      2   1.1      is #
      3  1.17  martin # $NetBSD: makesums,v 1.17 2018/09/28 15:04:20 martin 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.17  martin # and may be omitted (in which case ``*.tgz *.tar.xz'' 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.16     snj # produced. Otherwise the resulting list of files are checksummed and two
     19  1.16     snj # output files (MD5 and SHA512) are produced.
     20   1.1      is #
     21   1.1      is 
     22  1.14     apb 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.14     apb 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.14     apb 	-t targetdir	\${RELEASEDIR}		[${targetdir}]
     38  1.17  martin 	setname [...]	sets to checksum 	[*.tgz *.tar.xz]
     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.14     apb 		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.14     apb if [ -z "${targetdir}" ]; then
     63  1.15     apb 	echo >&2 "${prog}: \${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.14     apb cd "${targetdir}"
     68   1.2  toddpw pat="$*"
     69  1.14     apb if [ "${dash_all}" = yes ]; then
     70   1.2  toddpw 	pat='*'
     71  1.14     apb elif [ -z "${pat}" ]; then
     72  1.17  martin 	pat='*.tgz *.tar.xz'
     73   1.2  toddpw fi
     74  1.14     apb lists="$(${FIND} ${pat} -prune \( -type f -o -type l \) \
     75  1.14     apb 	\! -name '*SUM' \! -name MD5 \! -name SHA512 2>/dev/null)"
     76  1.14     apb if [ -n "${lists}" ]; then
     77  1.14     apb 	eval ${CKSUM} -a md5  ${lists} ${append} MD5
     78  1.14     apb 	eval ${CKSUM} -a sha512  ${lists} ${append} SHA512
     79   1.1      is fi
     80