makesums revision 1.15
11.1Sis#!/bin/sh 21.1Sis# 31.15Sapb# $NetBSD: makesums,v 1.15 2006/01/08 10:10:03 apb Exp $ 41.1Sis# 51.2Stoddpw# Make checksum files for files in ``tardir''. Usage: 61.7Slukem# makesums [-a] [-t tardir] [setname [...]] 71.2Stoddpw# 81.2Stoddpw# If -t is omitted, RELEASEDIR must be set and not empty. 91.2Stoddpw# The ``setname'' arguments comprise a list of files to checksum, 101.2Stoddpw# and may be omitted (in which case ``*.tgz'' is used). 111.10Sjmc# If -A is given, then the checksum are appended to possibly existing files. 121.10Sjmc# NOTE: Don't use this when running parallel jobs 131.7Slukem# If -a is given, then the list of sets is ignored, and ``*'' is used. 141.2Stoddpw# 151.2Stoddpw# After shell glob expansion, the list of sets is filtered to remove known 161.9Sjmc# output file names (of the form *SUM, SHA512 and MD5), non-existent files, and 171.2Stoddpw# subdirectories. If this filtering leaves no files, then no output files are 181.9Sjmc# produced. Otherwise the resulting list of files are checksummed and five 191.9Sjmc# output files (BSDSUM, CKSUM, MD5, SHA512, SYSVSUM) are produced. 201.1Sis# 211.1Sis 221.14Sapbprog="${0##*/}" 231.12Sapbrundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/" 241.12Sapb. "${rundir}/sets.subr" 251.7Slukem 261.1Sis# set defaults 271.14Sapbtargetdir="${RELEASEDIR}" 281.2Stoddpwdash_all=no 291.10Sjmcappend=\> 301.1Sis 311.7Slukemusage() 321.7Slukem{ 331.7Slukem cat 1>&2 <<USAGE 341.10SjmcUsage: ${prog} [-A] [-a] [-t targetdir] [setname [...]] 351.10Sjmc -A Append to possible existing checksum files 361.7Slukem -a checksum all plain files instead of [setname [...]] 371.14Sapb -t targetdir \${RELEASEDIR} [${targetdir}] 381.7Slukem setname [...] sets to checksum [*.tgz] 391.7SlukemUSAGE 401.7Slukem exit 1 411.7Slukem} 421.7Slukem 431.1Sis# handle args 441.10Sjmcwhile getopts aAt: ch; do 451.7Slukem case ${ch} in 461.10Sjmc A) 471.10Sjmc append=\>\> 481.10Sjmc ;; 491.7Slukem a) 501.2Stoddpw dash_all=yes 511.1Sis ;; 521.7Slukem t) 531.14Sapb targetdir="${OPTARG}" 541.1Sis ;; 551.1Sis *) 561.7Slukem usage 571.1Sis ;; 581.1Sis esac 591.1Sisdone 601.7Slukemshift $((${OPTIND} - 1)) 611.1Sis 621.14Sapbif [ -z "${targetdir}" ]; then 631.15Sapb echo >&2 "${prog}: \${RELEASEDIR} must be set or provided with -t" 641.1Sis exit 1 651.1Sisfi 661.1Sis 671.14Sapbcd "${targetdir}" 681.2Stoddpwpat="$*" 691.14Sapbif [ "${dash_all}" = yes ]; then 701.2Stoddpw pat='*' 711.14Sapbelif [ -z "${pat}" ]; then 721.2Stoddpw pat='*.tgz' 731.2Stoddpwfi 741.14Sapblists="$(${FIND} ${pat} -prune \( -type f -o -type l \) \ 751.14Sapb \! -name '*SUM' \! -name MD5 \! -name SHA512 2>/dev/null)" 761.14Sapbif [ -n "${lists}" ]; then 771.14Sapb eval ${CKSUM} -o1 ${lists} ${append} BSDSUM 781.14Sapb eval ${CKSUM} ${lists} ${append} CKSUM 791.14Sapb eval ${CKSUM} -a md5 ${lists} ${append} MD5 801.14Sapb eval ${CKSUM} -o2 ${lists} ${append} SYSVSUM 811.14Sapb eval ${CKSUM} -a sha512 ${lists} ${append} SHA512 821.1Sisfi 83