11.2Sgwr#!/bin/sh 21.2Sgwr# 31.102Snia# $NetBSD: maketars,v 1.102 2024/04/22 14:41:25 nia Exp $ 41.2Sgwr# 51.2Sgwr# Make release tar files for some or all lists. Usage: 61.34Slukem# maketars [-b] [-x] [-i installdir] [-a arch] [-m machine] [-s setsdir] 71.81Smartin# [-M metalog] [-N etcdir] [-F setlistsdir] [-d destdir] 81.83Smartin# [-t tardir] [-U] [setname ...] 91.35Slukem# 101.102Snia# The default sets are "base base32 base64 comp debug debug32 debug64 dtb 111.102Snia# etc games gpufw man manhtml misc rescue tests text" 121.76Schristos# The X sets are "xbase xcomp xdebug xetc xfont xserver" 131.35Slukem# 141.35Slukem# If '-i installdir' is given, copy the given sets to installdir 151.35Slukem# (using pax -rw ...) instead of creating tar files. 161.94Slukem# In this case, remove "etc", and "xetc" from the list of default sets. 171.2Sgwr# 181.2Sgwr 191.58Sapbprog="${0##*/}" 201.56Sapbrundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/" 211.56Sapb. "${rundir}/sets.subr" 221.41Slukem 231.2Sgwr# set defaults 241.72Sceggerlists= 251.58Sapbtars="${RELEASEDIR}" 261.58Sapbdest="${DESTDIR}" 271.18Slukemmetalog= 281.28Slukeminstalldir= 291.30Slukemetcdir= 301.81Smartinsetlistdir= 311.85Schristostimestamp= 321.50Slukemsetfilesonly=false 331.64Slukemquiet=false 341.83Smartinpreserve="-pe" 351.2Sgwr 361.95Slukem# mtree(8) keys to skip (exclude) in the generated /etc/mtree/sets.* files. 371.95Slukem# Note: sets contain sha256 so that keyword is not listed here. 381.95Slukemskipkeys=cksum,md5,rmd160,sha1,sha384,sha512,time 391.95Slukem 401.47Slukemusage() 411.47Slukem{ 421.47Slukem cat 1>&2 <<USAGE 431.94SlukemUsage: ${prog} [-L base,x] [-b] [-x] [-i idir] [-a arch] [-m machine] 441.81Smartin [-s setsdir] [-S] [-M metalog] [-N etcdir] [-F setlistdir] 451.81Smartin [-d dest] [-t targetdir] [setname ...] 461.94Slukem -L base,x Make specified lists 471.50Slukem -b Make both netbsd and x11 lists 481.50Slukem -x Only make x11 lists 491.50Slukem [Default: make netbsd lists] 501.50Slukem -i idir Install sets to idir instead of creating tar files 511.58Sapb -a arch Set arch (e.g, m68k, mipseb, mipsel, powerpc) [${MACHINE_ARCH}] 521.58Sapb -m machine Set machine (e.g, amiga, i386, macppc) [${MACHINE}] 531.64Slukem -q Quiet operation 541.58Sapb -s setsdir Directory to find sets [${setsdir}] 551.81Smartin -F setlistdir output directory for generated set lists [${dest}/etc/mtree/] 561.58Sapb -S Exit after creating set files ${dest}/etc/mtree/set.* 571.18Slukem -M metalog metalog file 581.58Sapb -N etcdir etc dir for metalog use [${dest}/etc] 591.83Smartin -U do not preserve file permissions (with -i ..) 601.58Sapb -d dest \${DESTDIR} [${dest}] 611.58Sapb -t targetdir \${RELEASEDIR} [${tars}] 621.85Schristos -T timestamp Timestamp to set for all the files in the tar. 631.58Sapb [setname ...] Sets to build [${lists}] 641.9SlukemUSAGE 651.47Slukem exit 1 661.47Slukem} 671.47Slukem 681.64Slukemmsg() 691.64Slukem{ 701.64Slukem $quiet || echo $* 711.64Slukem} 721.64Slukem 731.98Schristosumask 022 741.47Slukem# handle args 751.94Slukemwhile getopts L:bxi:a:m:qs:F:SM:N:Ud:t:T: ch; do 761.47Slukem case ${ch} in 771.70Suebayasi L) 781.72Scegger save_IFS="${IFS}" 791.72Scegger IFS=, 801.72Scegger for _list in ${OPTARG}; do 811.72Scegger case $_list in 821.72Scegger base) lists="${lists} ${nlists}" ;; 831.72Scegger x) lists="${lists} ${xlists}" ;; 841.72Scegger esac 851.72Scegger done 861.72Scegger IFS="${save_IFS}" 871.70Suebayasi ;; 881.70Suebayasi # backward compat 891.47Slukem b) 901.58Sapb lists="${nlists} ${xlists}" 911.47Slukem ;; 921.47Slukem x) 931.58Sapb lists="${xlists}" 941.47Slukem ;; 951.47Slukem i) 961.58Sapb installdir="${OPTARG}" 971.47Slukem ;; 981.47Slukem a) 991.58Sapb MACHINE_ARCH="${OPTARG}" 1001.58Sapb MACHINE_CPU="$(arch_to_cpu "${OPTARG}")" 1011.47Slukem ;; 1021.47Slukem m) 1031.58Sapb MACHINE="${OPTARG}" 1041.47Slukem ;; 1051.64Slukem q) 1061.64Slukem quiet=true 1071.64Slukem ;; 1081.47Slukem s) 1091.58Sapb setsdir="${OPTARG}" 1101.47Slukem ;; 1111.81Smartin F) 1121.81Smartin setlistdir="${OPTARG}" 1131.81Smartin ;; 1141.50Slukem S) 1151.50Slukem setfilesonly=true 1161.50Slukem ;; 1171.47Slukem M) 1181.58Sapb metalog="${OPTARG}" 1191.47Slukem ;; 1201.47Slukem N) 1211.58Sapb etcdir="${OPTARG}" 1221.47Slukem ;; 1231.83Smartin U) 1241.84Smartin preserve= 1251.83Smartin ;; 1261.47Slukem d) 1271.58Sapb dest="${OPTARG}" 1281.47Slukem ;; 1291.47Slukem t) 1301.58Sapb tars="${OPTARG}" 1311.9Slukem ;; 1321.85Schristos T) 1331.85Schristos timestamp="--timestamp $OPTARG" 1341.85Schristos ;; 1351.9Slukem *) 1361.47Slukem usage 1371.9Slukem ;; 1381.2Sgwr esac 1391.2Sgwrdone 1401.47Slukemshift $((${OPTIND} - 1)) 1411.94Slukemif [ -n "${installdir}" ]; then # if -i, remove etc + xetc from the default list 1421.94Slukem lists="$(echo ${lists} | ${SED} -e 's/ etc / /;s/ xetc / /;')" 1431.28Slukemfi 1441.10Srossif [ -n "$*" ]; then 1451.10Sross lists="$*" 1461.9Slukemfi 1471.1Scgd 1481.58Sapbif [ -z "${tars}" -a -z "${installdir}" ]; then 1491.60Sapb echo >&2 "${prog}: \${RELEASEDIR} must be set, or -i must be used" 1501.1Scgd exit 1 1511.9Slukemfi 1521.1Scgd 1531.58Sapbif [ -z "${dest}" ]; then 1541.60Sapb echo >&2 "${prog}: \${DESTDIR} must be set" 1551.1Scgd exit 1 1561.9Slukemfi 1571.58Sapb: ${etcdir:="${dest}/etc"} 1581.1Scgd 1591.58SapbSDIR="$(${MKTEMP} -d "/tmp/${prog}.XXXXXX")" 1601.63SlukemTMPFILES= 1611.20Sbjh21 1621.81Smartin: ${setlistdir:="${dest}/etc/mtree"} 1631.50Slukem 1641.38Serhcleanup() 1651.38Serh{ 1661.44Sdsl es=$? 1671.92Schristos rm -rf "${SDIR}" ${TMPFILES} 1681.63Slukem trap - 0 1691.58Sapb exit ${es} 1701.38Serh} 1711.38Serhtrap cleanup 0 2 3 13 # EXIT INT QUIT PIPE 1721.18Slukem 1731.50Slukem# 1741.50Slukem# build the setfiles 1751.50Slukem# 1761.50Slukem 1771.58Sapbfor setname in ${lists}; do 1781.96Slukem msg "Creating flist.${setname}" 1791.58Sapb ${HOST_SH} "${setsdir}/makeflist" -a "${MACHINE_ARCH}" -m "${MACHINE}" \ 1801.69Sapb -s "${setsdir}" "${setname}" > "${SDIR}/flist.${setname}" \ 1811.69Sapb || exit 1 1821.73Suebayasi if [ ! -s "${SDIR}/flist.${setname}" ]; then 1831.71Sapb echo >&2 "makeflist output is empty for ${setname}" 1841.71Sapb exit 1 1851.71Sapb fi 1861.96Slukem msg "Creating set.${setname}" 1871.58Sapb if [ -n "${metalog}" ]; then 1881.58Sapb ${AWK} -f "${rundir}/getdirs.awk" "${SDIR}/flist.${setname}" \ 1891.69Sapb > "${SDIR}/flist.${setname}.full" \ 1901.69Sapb || exit 1 1911.23Slukem ( 1921.23Slukem echo "/set uname=root gname=wheel" 1931.58Sapb ${AWK} -f "${rundir}/join.awk" \ 1941.68Sapb "${SDIR}/flist.${setname}.full" "${metalog}" 1951.50Slukem echo "./etc/mtree/set.${setname} type=file mode=0444" 1961.77Schristos ) | ${MTREE} -CS -k all -R "${skipkeys}" -N "${etcdir}" \ 1971.69Sapb > "${setlistdir}/set.${setname}" \ 1981.69Sapb || exit 1 1991.59Sapb # We deliberately do not add set.${setname} to ${metalog}, 2001.59Sapb # because we depend on it as an input. 2011.77Schristos else 2021.99Smartin ${MTREE} -c -p "${dest}" -k all \ 2031.100Smartin -R "${skipkeys}" \ 2041.86Sjklos -N "${etcdir}" -O "${SDIR}/flist.${setname}" \ 2051.86Sjklos | ${MTREE} -C -k all -N "${etcdir}" \ 2061.100Smartin | ${SED} -e "s:^./etc/mtree/set.${setname}.*\$:./etc/mtree/set.${setname} type=file mode=0444:" \ 2071.86Sjklos > "${setlistdir}/set.${setname}" 2081.18Slukem fi 2091.50Slukemdone 2101.58Sapbif ${setfilesonly}; then # exit after creating the set lists 2111.50Slukem exit 0 2121.50Slukemfi 2131.18Slukem 2141.78Schristosrunpax() { 2151.78Schristos local s="$1" 2161.78Schristos shift 2171.80Schristos (cd "${dest}" && 2181.85Schristos ${PAX} -dOw ${timestamp} -N"${etcdir}" -M "$@" < "${setlistdir}/set.${s}") 2191.78Schristos} 2201.78Schristos 2211.50Slukem# 2221.50Slukem# now build the tarfiles 2231.50Slukem# 2241.50Slukem 2251.67SperryGZIP=-9n # for pax -z 2261.50Slukemexport GZIP 2271.50Slukemes=0 2281.82Smartin 2291.72Sceggerfor setname in ${lists:-${nlists}}; do 2301.89Smartin out="${setname}.${TAR_SUFF:-tgz}" 2311.58Sapb if [ -n "${installdir}" ]; then 2321.64Slukem msg "Copying set ${setname}" 2331.82Smartin runpax "${setname}" -r ${preserve} "${installdir}" 2341.28Slukem else 2351.58Sapb if [ -n "${metalog}" -a "${tars}/${out}" -nt "${metalog}" ] 2361.58Sapb then 2371.64Slukem msg "${out} is up to date" 2381.50Slukem continue 2391.50Slukem fi 2401.64Slukem msg "Creating ${out}" 2411.58Sapb rm -f "${tars}/${out}" 2421.63Slukem TMPFILES="${TMPFILES} ${tars}/${out}.tmp" 2431.88Smartin runpax "${setname}" -z --use-compress-program \ 2441.88Smartin ${COMPRESS_PROGRAM} > "${tars}/${out}.tmp" && 2451.58Sapb mv "${tars}/${out}.tmp" "${tars}/${out}" 2461.28Slukem fi 2471.58Sapb es=$((${es} + $?)) 2481.2Sgwrdone 2491.61Sapbif [ ${es} -gt 255 ]; then 2501.38Serh es=255 2511.38Serhfi 2521.58Sapbexit ${es} 253