19152e1c5SLionel Sambuc#!/bin/sh 29152e1c5SLionel Sambuc# 30a6a1f1dSLionel Sambuc# $NetBSD: maketars,v 1.84 2015/05/27 15:18:29 martin Exp $ 49152e1c5SLionel Sambuc# 59152e1c5SLionel Sambuc# Make release tar files for some or all lists. Usage: 69152e1c5SLionel Sambuc# maketars [-b] [-x] [-i installdir] [-a arch] [-m machine] [-s setsdir] 70a6a1f1dSLionel Sambuc# [-M metalog] [-N etcdir] [-F setlistsdir] [-d destdir] 80a6a1f1dSLionel Sambuc# [-t tardir] [-U] [setname ...] 99152e1c5SLionel Sambuc# 1084d9c625SLionel Sambuc# The default sets are "base comp debug etc games man misc tests text" 1184d9c625SLionel Sambuc# The X sets are "xbase xcomp xdebug xetc xfont xserver" 129152e1c5SLionel Sambuc# The extsrc sets are "extbase extcomp extetc" 139152e1c5SLionel Sambuc# 149152e1c5SLionel Sambuc# If '-i installdir' is given, copy the given sets to installdir 159152e1c5SLionel Sambuc# (using pax -rw ...) instead of creating tar files. 169152e1c5SLionel Sambuc# In this case, remove "etc", "xetc", and "extetc" from the list of default sets. 179152e1c5SLionel Sambuc# 189152e1c5SLionel Sambuc 199152e1c5SLionel Sambucprog="${0##*/}" 209152e1c5SLionel Sambucrundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/" 219152e1c5SLionel Sambuc. "${rundir}/sets.subr" 229152e1c5SLionel Sambuc 239152e1c5SLionel Sambuc# set defaults 249152e1c5SLionel Sambuclists= 259152e1c5SLionel Sambuctars="${RELEASEDIR}" 269152e1c5SLionel Sambucdest="${DESTDIR}" 279152e1c5SLionel Sambucmetalog= 289152e1c5SLionel Sambucinstalldir= 299152e1c5SLionel Sambucetcdir= 300a6a1f1dSLionel Sambucsetlistdir= 319152e1c5SLionel Sambucsetfilesonly=false 329152e1c5SLionel Sambucquiet=false 3384d9c625SLionel Sambucskipkeys=time,md5,sha1,sha384,sha512,rmd160,cksum 340a6a1f1dSLionel Sambucpreserve="-pe" 359152e1c5SLionel Sambuc 369152e1c5SLionel Sambucusage() 379152e1c5SLionel Sambuc{ 389152e1c5SLionel Sambuc cat 1>&2 <<USAGE 390a6a1f1dSLionel SambucUsage: ${prog} [-L base,x,ext] [-b] [-x] [-y] [-i idir] [-a arch] [-m machine] 400a6a1f1dSLionel Sambuc [-s setsdir] [-S] [-M metalog] [-N etcdir] [-F setlistdir] 410a6a1f1dSLionel Sambuc [-d dest] [-t targetdir] [setname ...] 429152e1c5SLionel Sambuc -L base,x,ext Make specified lists 439152e1c5SLionel Sambuc -b Make both netbsd and x11 lists 449152e1c5SLionel Sambuc -x Only make x11 lists 459152e1c5SLionel Sambuc [Default: make netbsd lists] 469152e1c5SLionel Sambuc -y Only make extsrc lists 479152e1c5SLionel Sambuc [Default: make netbsd lists] 489152e1c5SLionel Sambuc -i idir Install sets to idir instead of creating tar files 499152e1c5SLionel Sambuc -a arch Set arch (e.g, m68k, mipseb, mipsel, powerpc) [${MACHINE_ARCH}] 509152e1c5SLionel Sambuc -m machine Set machine (e.g, amiga, i386, macppc) [${MACHINE}] 519152e1c5SLionel Sambuc -q Quiet operation 529152e1c5SLionel Sambuc -s setsdir Directory to find sets [${setsdir}] 530a6a1f1dSLionel Sambuc -F setlistdir output directory for generated set lists [${dest}/etc/mtree/] 549152e1c5SLionel Sambuc -S Exit after creating set files ${dest}/etc/mtree/set.* 559152e1c5SLionel Sambuc -M metalog metalog file 569152e1c5SLionel Sambuc -N etcdir etc dir for metalog use [${dest}/etc] 570a6a1f1dSLionel Sambuc -U do not preserve file permissions (with -i ..) 589152e1c5SLionel Sambuc -d dest \${DESTDIR} [${dest}] 599152e1c5SLionel Sambuc -t targetdir \${RELEASEDIR} [${tars}] 609152e1c5SLionel Sambuc [setname ...] Sets to build [${lists}] 619152e1c5SLionel SambucUSAGE 629152e1c5SLionel Sambuc exit 1 639152e1c5SLionel Sambuc} 649152e1c5SLionel Sambuc 659152e1c5SLionel Sambucmsg() 669152e1c5SLionel Sambuc{ 679152e1c5SLionel Sambuc $quiet || echo $* 689152e1c5SLionel Sambuc} 699152e1c5SLionel Sambuc 709152e1c5SLionel Sambuc# handle args 710a6a1f1dSLionel Sambucwhile getopts L:bxyi:a:m:qs:F:SM:N:Ud:t: ch; do 729152e1c5SLionel Sambuc case ${ch} in 739152e1c5SLionel Sambuc L) 749152e1c5SLionel Sambuc save_IFS="${IFS}" 759152e1c5SLionel Sambuc IFS=, 769152e1c5SLionel Sambuc for _list in ${OPTARG}; do 779152e1c5SLionel Sambuc case $_list in 789152e1c5SLionel Sambuc base) lists="${lists} ${nlists}" ;; 799152e1c5SLionel Sambuc x) lists="${lists} ${xlists}" ;; 809152e1c5SLionel Sambuc ext) lists="${lists} ${extlists}" ;; 819152e1c5SLionel Sambuc esac 829152e1c5SLionel Sambuc done 839152e1c5SLionel Sambuc IFS="${save_IFS}" 849152e1c5SLionel Sambuc ;; 859152e1c5SLionel Sambuc # backward compat 869152e1c5SLionel Sambuc b) 879152e1c5SLionel Sambuc lists="${nlists} ${xlists}" 889152e1c5SLionel Sambuc ;; 899152e1c5SLionel Sambuc x) 909152e1c5SLionel Sambuc lists="${xlists}" 919152e1c5SLionel Sambuc ;; 929152e1c5SLionel Sambuc y) 939152e1c5SLionel Sambuc lists="${extlists}" 949152e1c5SLionel Sambuc ;; 959152e1c5SLionel Sambuc i) 969152e1c5SLionel Sambuc installdir="${OPTARG}" 979152e1c5SLionel Sambuc ;; 989152e1c5SLionel Sambuc a) 999152e1c5SLionel Sambuc MACHINE_ARCH="${OPTARG}" 1009152e1c5SLionel Sambuc MACHINE_CPU="$(arch_to_cpu "${OPTARG}")" 1019152e1c5SLionel Sambuc ;; 1029152e1c5SLionel Sambuc m) 1039152e1c5SLionel Sambuc MACHINE="${OPTARG}" 1049152e1c5SLionel Sambuc ;; 1059152e1c5SLionel Sambuc q) 1069152e1c5SLionel Sambuc quiet=true 1079152e1c5SLionel Sambuc ;; 1089152e1c5SLionel Sambuc s) 1099152e1c5SLionel Sambuc setsdir="${OPTARG}" 1109152e1c5SLionel Sambuc ;; 1110a6a1f1dSLionel Sambuc F) 1120a6a1f1dSLionel Sambuc setlistdir="${OPTARG}" 1130a6a1f1dSLionel Sambuc ;; 1149152e1c5SLionel Sambuc S) 1159152e1c5SLionel Sambuc setfilesonly=true 1169152e1c5SLionel Sambuc ;; 1179152e1c5SLionel Sambuc M) 1189152e1c5SLionel Sambuc metalog="${OPTARG}" 1199152e1c5SLionel Sambuc ;; 1209152e1c5SLionel Sambuc N) 1219152e1c5SLionel Sambuc etcdir="${OPTARG}" 1229152e1c5SLionel Sambuc ;; 1230a6a1f1dSLionel Sambuc U) 1240a6a1f1dSLionel Sambuc preserve= 1250a6a1f1dSLionel Sambuc ;; 1269152e1c5SLionel Sambuc d) 1279152e1c5SLionel Sambuc dest="${OPTARG}" 1289152e1c5SLionel Sambuc ;; 1299152e1c5SLionel Sambuc t) 1309152e1c5SLionel Sambuc tars="${OPTARG}" 1319152e1c5SLionel Sambuc ;; 1329152e1c5SLionel Sambuc *) 1339152e1c5SLionel Sambuc usage 1349152e1c5SLionel Sambuc ;; 1359152e1c5SLionel Sambuc esac 1369152e1c5SLionel Sambucdone 1379152e1c5SLionel Sambucshift $((${OPTIND} - 1)) 1389152e1c5SLionel Sambucif [ -n "${installdir}" ]; then # if -i, remove etc + xetc + extetc from the default list 1399152e1c5SLionel Sambuc lists="$(echo ${lists} | ${SED} -e 's/ etc / /;s/ xetc / /;s/ extetc / /')" 1409152e1c5SLionel Sambucfi 1419152e1c5SLionel Sambucif [ -n "$*" ]; then 1429152e1c5SLionel Sambuc lists="$*" 1439152e1c5SLionel Sambucfi 1449152e1c5SLionel Sambuc 1459152e1c5SLionel Sambucif [ -z "${tars}" -a -z "${installdir}" ]; then 1469152e1c5SLionel Sambuc echo >&2 "${prog}: \${RELEASEDIR} must be set, or -i must be used" 1479152e1c5SLionel Sambuc exit 1 1489152e1c5SLionel Sambucfi 1499152e1c5SLionel Sambuc 1509152e1c5SLionel Sambucif [ -z "${dest}" ]; then 1519152e1c5SLionel Sambuc echo >&2 "${prog}: \${DESTDIR} must be set" 1529152e1c5SLionel Sambuc exit 1 1539152e1c5SLionel Sambucfi 1549152e1c5SLionel Sambuc: ${etcdir:="${dest}/etc"} 1559152e1c5SLionel Sambuc 1569152e1c5SLionel SambucSDIR="$(${MKTEMP} -d "/tmp/${prog}.XXXXXX")" 1579152e1c5SLionel SambucTMPFILES= 1589152e1c5SLionel Sambuc 1590a6a1f1dSLionel Sambuc: ${setlistdir:="${dest}/etc/mtree"} 1609152e1c5SLionel Sambuc 1619152e1c5SLionel Sambuccleanup() 1629152e1c5SLionel Sambuc{ 1639152e1c5SLionel Sambuc es=$? 1649152e1c5SLionel Sambuc /bin/rm -rf "${SDIR}" ${TMPFILES} 1659152e1c5SLionel Sambuc trap - 0 1669152e1c5SLionel Sambuc exit ${es} 1679152e1c5SLionel Sambuc} 1689152e1c5SLionel Sambuctrap cleanup 0 2 3 13 # EXIT INT QUIT PIPE 1699152e1c5SLionel Sambuc 1709152e1c5SLionel Sambuc# 1719152e1c5SLionel Sambuc# build the setfiles 1729152e1c5SLionel Sambuc# 1739152e1c5SLionel Sambuc 1749152e1c5SLionel Sambucfor setname in ${lists}; do 1759152e1c5SLionel Sambuc ${HOST_SH} "${setsdir}/makeflist" -a "${MACHINE_ARCH}" -m "${MACHINE}" \ 1769152e1c5SLionel Sambuc -s "${setsdir}" "${setname}" > "${SDIR}/flist.${setname}" \ 1779152e1c5SLionel Sambuc || exit 1 1789152e1c5SLionel Sambuc if [ ! -s "${SDIR}/flist.${setname}" ]; then 1799152e1c5SLionel Sambuc echo >&2 "makeflist output is empty for ${setname}" 1809152e1c5SLionel Sambuc exit 1 1819152e1c5SLionel Sambuc fi 1829152e1c5SLionel Sambuc ${setfilesonly} && msg "Creating ${setlistdir}/set.${setname}" 18384d9c625SLionel Sambuc if [ -n "${metalog}" ]; then 1849152e1c5SLionel Sambuc ${AWK} -f "${rundir}/getdirs.awk" "${SDIR}/flist.${setname}" \ 1859152e1c5SLionel Sambuc > "${SDIR}/flist.${setname}.full" \ 1869152e1c5SLionel Sambuc || exit 1 1879152e1c5SLionel Sambuc ( 188*77e79d33SDavid van Moolenbroek echo "/set uname=root gname=wheel" 1899152e1c5SLionel Sambuc ${AWK} -f "${rundir}/join.awk" \ 1909152e1c5SLionel Sambuc "${SDIR}/flist.${setname}.full" "${metalog}" 1919152e1c5SLionel Sambuc echo "./etc/mtree/set.${setname} type=file mode=0444" 19284d9c625SLionel Sambuc ) | ${MTREE} -CS -k all -R "${skipkeys}" -N "${etcdir}" \ 1939152e1c5SLionel Sambuc > "${setlistdir}/set.${setname}" \ 1949152e1c5SLionel Sambuc || exit 1 1959152e1c5SLionel Sambuc # We deliberately do not add set.${setname} to ${metalog}, 1969152e1c5SLionel Sambuc # because we depend on it as an input. 19784d9c625SLionel Sambuc else 19884d9c625SLionel Sambuc ${MTREE} -c -p "${dest}" -k all -R "${skipkeys}" \ 19984d9c625SLionel Sambuc -O "${SDIR}/flist.${setname}" | ${MTREE} -C -k all > \ 20084d9c625SLionel Sambuc "${setlistdir}/set.${setname}" 2019152e1c5SLionel Sambuc fi 2029152e1c5SLionel Sambucdone 2039152e1c5SLionel Sambucif ${setfilesonly}; then # exit after creating the set lists 2049152e1c5SLionel Sambuc exit 0 2059152e1c5SLionel Sambucfi 2069152e1c5SLionel Sambuc 20784d9c625SLionel Sambucrunpax() { 20884d9c625SLionel Sambuc local s="$1" 20984d9c625SLionel Sambuc shift 21084d9c625SLionel Sambuc (cd "${dest}" && 21184d9c625SLionel Sambuc ${PAX} -dOw -N"${etcdir}" -M "$@" < "${setlistdir}/set.${s}") 21284d9c625SLionel Sambuc} 21384d9c625SLionel Sambuc 2149152e1c5SLionel Sambuc# 2159152e1c5SLionel Sambuc# now build the tarfiles 2169152e1c5SLionel Sambuc# 2179152e1c5SLionel Sambuc 2189152e1c5SLionel SambucGZIP=-9n # for pax -z 2199152e1c5SLionel Sambucexport GZIP 2209152e1c5SLionel Sambuces=0 2210a6a1f1dSLionel Sambuc 2229152e1c5SLionel Sambucfor setname in ${lists:-${nlists}}; do 2239152e1c5SLionel Sambuc out="${setname}.tgz" 2249152e1c5SLionel Sambuc if [ -n "${installdir}" ]; then 2259152e1c5SLionel Sambuc msg "Copying set ${setname}" 2260a6a1f1dSLionel Sambuc runpax "${setname}" -r ${preserve} "${installdir}" 2279152e1c5SLionel Sambuc else 2289152e1c5SLionel Sambuc if [ -n "${metalog}" -a "${tars}/${out}" -nt "${metalog}" ] 2299152e1c5SLionel Sambuc then 2309152e1c5SLionel Sambuc msg "${out} is up to date" 2319152e1c5SLionel Sambuc continue 2329152e1c5SLionel Sambuc fi 2339152e1c5SLionel Sambuc msg "Creating ${out}" 2349152e1c5SLionel Sambuc rm -f "${tars}/${out}" 2359152e1c5SLionel Sambuc TMPFILES="${TMPFILES} ${tars}/${out}.tmp" 23684d9c625SLionel Sambuc runpax "${setname}" -z --use-compress-program \ 23784d9c625SLionel Sambuc ${COMPRESS_PROGRAM} > "${tars}/${out}.tmp" && 2389152e1c5SLionel Sambuc mv "${tars}/${out}.tmp" "${tars}/${out}" 2399152e1c5SLionel Sambuc fi 2409152e1c5SLionel Sambuc es=$((${es} + $?)) 2419152e1c5SLionel Sambucdone 2429152e1c5SLionel Sambucif [ ${es} -gt 255 ]; then 2439152e1c5SLionel Sambuc es=255 2449152e1c5SLionel Sambucfi 2459152e1c5SLionel Sambucexit ${es} 246