makesums revision 1.19
11.1Sis#!/bin/sh 21.1Sis# 31.19Schristos# $NetBSD: makesums,v 1.19 2023/11/08 13:02:47 christos 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.17Smartin# and may be omitted (in which case ``*.tgz *.tar.xz'' 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.16Ssnj# produced. Otherwise the resulting list of files are checksummed and two 191.16Ssnj# output files (MD5 and SHA512) 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.17Smartin setname [...] sets to checksum [*.tgz *.tar.xz] 391.7SlukemUSAGE 401.7Slukem exit 1 411.7Slukem} 421.7Slukem 431.19Schristosumask 022 441.1Sis# handle args 451.10Sjmcwhile getopts aAt: ch; do 461.7Slukem case ${ch} in 471.10Sjmc A) 481.10Sjmc append=\>\> 491.10Sjmc ;; 501.7Slukem a) 511.2Stoddpw dash_all=yes 521.1Sis ;; 531.7Slukem t) 541.14Sapb targetdir="${OPTARG}" 551.1Sis ;; 561.1Sis *) 571.7Slukem usage 581.1Sis ;; 591.1Sis esac 601.1Sisdone 611.7Slukemshift $((${OPTIND} - 1)) 621.1Sis 631.14Sapbif [ -z "${targetdir}" ]; then 641.15Sapb echo >&2 "${prog}: \${RELEASEDIR} must be set or provided with -t" 651.1Sis exit 1 661.1Sisfi 671.1Sis 681.14Sapbcd "${targetdir}" 691.2Stoddpwpat="$*" 701.14Sapbif [ "${dash_all}" = yes ]; then 711.2Stoddpw pat='*' 721.14Sapbelif [ -z "${pat}" ]; then 731.17Smartin pat='*.tgz *.tar.xz' 741.2Stoddpwfi 751.14Sapblists="$(${FIND} ${pat} -prune \( -type f -o -type l \) \ 761.14Sapb \! -name '*SUM' \! -name MD5 \! -name SHA512 2>/dev/null)" 771.14Sapbif [ -n "${lists}" ]; then 781.14Sapb eval ${CKSUM} -a md5 ${lists} ${append} MD5 791.14Sapb eval ${CKSUM} -a sha512 ${lists} ${append} SHA512 801.1Sisfi 81