maketars revision 1.94
11.2Sgwr#!/bin/sh 21.2Sgwr# 31.94Slukem# $NetBSD: maketars,v 1.94 2022/08/21 07:10:03 lukem 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.93Smaya# The default sets are "base comp debug dtb etc games gpufw man misc rescue tests text" 111.76Schristos# The X sets are "xbase xcomp xdebug xetc xfont xserver" 121.35Slukem# 131.35Slukem# If '-i installdir' is given, copy the given sets to installdir 141.35Slukem# (using pax -rw ...) instead of creating tar files. 151.94Slukem# In this case, remove "etc", and "xetc" from the list of default sets. 161.2Sgwr# 171.2Sgwr 181.58Sapbprog="${0##*/}" 191.56Sapbrundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/" 201.56Sapb. "${rundir}/sets.subr" 211.41Slukem 221.2Sgwr# set defaults 231.72Sceggerlists= 241.58Sapbtars="${RELEASEDIR}" 251.58Sapbdest="${DESTDIR}" 261.18Slukemmetalog= 271.28Slukeminstalldir= 281.30Slukemetcdir= 291.81Smartinsetlistdir= 301.85Schristostimestamp= 311.50Slukemsetfilesonly=false 321.64Slukemquiet=false 331.77Schristosskipkeys=time,md5,sha1,sha384,sha512,rmd160,cksum 341.83Smartinpreserve="-pe" 351.2Sgwr 361.47Slukemusage() 371.47Slukem{ 381.47Slukem cat 1>&2 <<USAGE 391.94SlukemUsage: ${prog} [-L base,x] [-b] [-x] [-i idir] [-a arch] [-m machine] 401.81Smartin [-s setsdir] [-S] [-M metalog] [-N etcdir] [-F setlistdir] 411.81Smartin [-d dest] [-t targetdir] [setname ...] 421.94Slukem -L base,x Make specified lists 431.50Slukem -b Make both netbsd and x11 lists 441.50Slukem -x Only make x11 lists 451.50Slukem [Default: make netbsd lists] 461.50Slukem -i idir Install sets to idir instead of creating tar files 471.58Sapb -a arch Set arch (e.g, m68k, mipseb, mipsel, powerpc) [${MACHINE_ARCH}] 481.58Sapb -m machine Set machine (e.g, amiga, i386, macppc) [${MACHINE}] 491.64Slukem -q Quiet operation 501.58Sapb -s setsdir Directory to find sets [${setsdir}] 511.81Smartin -F setlistdir output directory for generated set lists [${dest}/etc/mtree/] 521.58Sapb -S Exit after creating set files ${dest}/etc/mtree/set.* 531.18Slukem -M metalog metalog file 541.58Sapb -N etcdir etc dir for metalog use [${dest}/etc] 551.83Smartin -U do not preserve file permissions (with -i ..) 561.58Sapb -d dest \${DESTDIR} [${dest}] 571.58Sapb -t targetdir \${RELEASEDIR} [${tars}] 581.85Schristos -T timestamp Timestamp to set for all the files in the tar. 591.58Sapb [setname ...] Sets to build [${lists}] 601.9SlukemUSAGE 611.47Slukem exit 1 621.47Slukem} 631.47Slukem 641.64Slukemmsg() 651.64Slukem{ 661.64Slukem $quiet || echo $* 671.64Slukem} 681.64Slukem 691.47Slukem# handle args 701.94Slukemwhile getopts L:bxi:a:m:qs:F:SM:N:Ud:t:T: ch; do 711.47Slukem case ${ch} in 721.70Suebayasi L) 731.72Scegger save_IFS="${IFS}" 741.72Scegger IFS=, 751.72Scegger for _list in ${OPTARG}; do 761.72Scegger case $_list in 771.72Scegger base) lists="${lists} ${nlists}" ;; 781.72Scegger x) lists="${lists} ${xlists}" ;; 791.72Scegger esac 801.72Scegger done 811.72Scegger IFS="${save_IFS}" 821.70Suebayasi ;; 831.70Suebayasi # backward compat 841.47Slukem b) 851.58Sapb lists="${nlists} ${xlists}" 861.47Slukem ;; 871.47Slukem x) 881.58Sapb lists="${xlists}" 891.47Slukem ;; 901.47Slukem i) 911.58Sapb installdir="${OPTARG}" 921.47Slukem ;; 931.47Slukem a) 941.58Sapb MACHINE_ARCH="${OPTARG}" 951.58Sapb MACHINE_CPU="$(arch_to_cpu "${OPTARG}")" 961.47Slukem ;; 971.47Slukem m) 981.58Sapb MACHINE="${OPTARG}" 991.47Slukem ;; 1001.64Slukem q) 1011.64Slukem quiet=true 1021.64Slukem ;; 1031.47Slukem s) 1041.58Sapb setsdir="${OPTARG}" 1051.47Slukem ;; 1061.81Smartin F) 1071.81Smartin setlistdir="${OPTARG}" 1081.81Smartin ;; 1091.50Slukem S) 1101.50Slukem setfilesonly=true 1111.50Slukem ;; 1121.47Slukem M) 1131.58Sapb metalog="${OPTARG}" 1141.47Slukem ;; 1151.47Slukem N) 1161.58Sapb etcdir="${OPTARG}" 1171.47Slukem ;; 1181.83Smartin U) 1191.84Smartin preserve= 1201.83Smartin ;; 1211.47Slukem d) 1221.58Sapb dest="${OPTARG}" 1231.47Slukem ;; 1241.47Slukem t) 1251.58Sapb tars="${OPTARG}" 1261.9Slukem ;; 1271.85Schristos T) 1281.85Schristos timestamp="--timestamp $OPTARG" 1291.85Schristos ;; 1301.9Slukem *) 1311.47Slukem usage 1321.9Slukem ;; 1331.2Sgwr esac 1341.2Sgwrdone 1351.47Slukemshift $((${OPTIND} - 1)) 1361.94Slukemif [ -n "${installdir}" ]; then # if -i, remove etc + xetc from the default list 1371.94Slukem lists="$(echo ${lists} | ${SED} -e 's/ etc / /;s/ xetc / /;')" 1381.28Slukemfi 1391.10Srossif [ -n "$*" ]; then 1401.10Sross lists="$*" 1411.9Slukemfi 1421.1Scgd 1431.58Sapbif [ -z "${tars}" -a -z "${installdir}" ]; then 1441.60Sapb echo >&2 "${prog}: \${RELEASEDIR} must be set, or -i must be used" 1451.1Scgd exit 1 1461.9Slukemfi 1471.1Scgd 1481.58Sapbif [ -z "${dest}" ]; then 1491.60Sapb echo >&2 "${prog}: \${DESTDIR} must be set" 1501.1Scgd exit 1 1511.9Slukemfi 1521.58Sapb: ${etcdir:="${dest}/etc"} 1531.1Scgd 1541.58SapbSDIR="$(${MKTEMP} -d "/tmp/${prog}.XXXXXX")" 1551.63SlukemTMPFILES= 1561.20Sbjh21 1571.81Smartin: ${setlistdir:="${dest}/etc/mtree"} 1581.50Slukem 1591.38Serhcleanup() 1601.38Serh{ 1611.44Sdsl es=$? 1621.92Schristos rm -rf "${SDIR}" ${TMPFILES} 1631.63Slukem trap - 0 1641.58Sapb exit ${es} 1651.38Serh} 1661.38Serhtrap cleanup 0 2 3 13 # EXIT INT QUIT PIPE 1671.18Slukem 1681.50Slukem# 1691.50Slukem# build the setfiles 1701.50Slukem# 1711.50Slukem 1721.58Sapbfor setname in ${lists}; do 1731.58Sapb ${HOST_SH} "${setsdir}/makeflist" -a "${MACHINE_ARCH}" -m "${MACHINE}" \ 1741.69Sapb -s "${setsdir}" "${setname}" > "${SDIR}/flist.${setname}" \ 1751.69Sapb || exit 1 1761.73Suebayasi if [ ! -s "${SDIR}/flist.${setname}" ]; then 1771.71Sapb echo >&2 "makeflist output is empty for ${setname}" 1781.71Sapb exit 1 1791.71Sapb fi 1801.77Schristos ${setfilesonly} && msg "Creating ${setlistdir}/set.${setname}" 1811.58Sapb if [ -n "${metalog}" ]; then 1821.58Sapb ${AWK} -f "${rundir}/getdirs.awk" "${SDIR}/flist.${setname}" \ 1831.69Sapb > "${SDIR}/flist.${setname}.full" \ 1841.69Sapb || exit 1 1851.23Slukem ( 1861.23Slukem echo "/set uname=root gname=wheel" 1871.58Sapb ${AWK} -f "${rundir}/join.awk" \ 1881.68Sapb "${SDIR}/flist.${setname}.full" "${metalog}" 1891.50Slukem echo "./etc/mtree/set.${setname} type=file mode=0444" 1901.77Schristos ) | ${MTREE} -CS -k all -R "${skipkeys}" -N "${etcdir}" \ 1911.69Sapb > "${setlistdir}/set.${setname}" \ 1921.69Sapb || exit 1 1931.59Sapb # We deliberately do not add set.${setname} to ${metalog}, 1941.59Sapb # because we depend on it as an input. 1951.77Schristos else 1961.78Schristos ${MTREE} -c -p "${dest}" -k all -R "${skipkeys}" \ 1971.86Sjklos -N "${etcdir}" -O "${SDIR}/flist.${setname}" \ 1981.86Sjklos | ${MTREE} -C -k all -N "${etcdir}" \ 1991.86Sjklos > "${setlistdir}/set.${setname}" 2001.18Slukem fi 2011.50Slukemdone 2021.58Sapbif ${setfilesonly}; then # exit after creating the set lists 2031.50Slukem exit 0 2041.50Slukemfi 2051.18Slukem 2061.78Schristosrunpax() { 2071.78Schristos local s="$1" 2081.78Schristos shift 2091.80Schristos (cd "${dest}" && 2101.85Schristos ${PAX} -dOw ${timestamp} -N"${etcdir}" -M "$@" < "${setlistdir}/set.${s}") 2111.78Schristos} 2121.78Schristos 2131.50Slukem# 2141.50Slukem# now build the tarfiles 2151.50Slukem# 2161.50Slukem 2171.67SperryGZIP=-9n # for pax -z 2181.50Slukemexport GZIP 2191.50Slukemes=0 2201.82Smartin 2211.72Sceggerfor setname in ${lists:-${nlists}}; do 2221.89Smartin out="${setname}.${TAR_SUFF:-tgz}" 2231.58Sapb if [ -n "${installdir}" ]; then 2241.64Slukem msg "Copying set ${setname}" 2251.82Smartin runpax "${setname}" -r ${preserve} "${installdir}" 2261.28Slukem else 2271.58Sapb if [ -n "${metalog}" -a "${tars}/${out}" -nt "${metalog}" ] 2281.58Sapb then 2291.64Slukem msg "${out} is up to date" 2301.50Slukem continue 2311.50Slukem fi 2321.64Slukem msg "Creating ${out}" 2331.58Sapb rm -f "${tars}/${out}" 2341.63Slukem TMPFILES="${TMPFILES} ${tars}/${out}.tmp" 2351.88Smartin runpax "${setname}" -z --use-compress-program \ 2361.88Smartin ${COMPRESS_PROGRAM} > "${tars}/${out}.tmp" && 2371.58Sapb mv "${tars}/${out}.tmp" "${tars}/${out}" 2381.28Slukem fi 2391.58Sapb es=$((${es} + $?)) 2401.2Sgwrdone 2411.61Sapbif [ ${es} -gt 255 ]; then 2421.38Serh es=255 2431.38Serhfi 2441.58Sapbexit ${es} 245