maketars revision 1.97
1#!/bin/sh 2# 3# $NetBSD: maketars,v 1.97 2023/11/08 12:58:04 christos Exp $ 4# 5# Make release tar files for some or all lists. Usage: 6# maketars [-b] [-x] [-i installdir] [-a arch] [-m machine] [-s setsdir] 7# [-M metalog] [-N etcdir] [-F setlistsdir] [-d destdir] 8# [-t tardir] [-U] [setname ...] 9# 10# The default sets are "base comp debug dtb etc games gpufw man misc rescue tests text" 11# The X sets are "xbase xcomp xdebug xetc xfont xserver" 12# 13# If '-i installdir' is given, copy the given sets to installdir 14# (using pax -rw ...) instead of creating tar files. 15# In this case, remove "etc", and "xetc" from the list of default sets. 16# 17 18prog="${0##*/}" 19rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/" 20. "${rundir}/sets.subr" 21 22# set defaults 23lists= 24tars="${RELEASEDIR}" 25dest="${DESTDIR}" 26metalog= 27installdir= 28etcdir= 29setlistdir= 30timestamp= 31setfilesonly=false 32quiet=false 33preserve="-pe" 34 35# mtree(8) keys to skip (exclude) in the generated /etc/mtree/sets.* files. 36# Note: sets contain sha256 so that keyword is not listed here. 37skipkeys=cksum,md5,rmd160,sha1,sha384,sha512,time 38 39usage() 40{ 41 cat 1>&2 <<USAGE 42Usage: ${prog} [-L base,x] [-b] [-x] [-i idir] [-a arch] [-m machine] 43 [-s setsdir] [-S] [-M metalog] [-N etcdir] [-F setlistdir] 44 [-d dest] [-t targetdir] [setname ...] 45 -L base,x Make specified lists 46 -b Make both netbsd and x11 lists 47 -x Only make x11 lists 48 [Default: make netbsd lists] 49 -i idir Install sets to idir instead of creating tar files 50 -a arch Set arch (e.g, m68k, mipseb, mipsel, powerpc) [${MACHINE_ARCH}] 51 -m machine Set machine (e.g, amiga, i386, macppc) [${MACHINE}] 52 -q Quiet operation 53 -s setsdir Directory to find sets [${setsdir}] 54 -F setlistdir output directory for generated set lists [${dest}/etc/mtree/] 55 -S Exit after creating set files ${dest}/etc/mtree/set.* 56 -M metalog metalog file 57 -N etcdir etc dir for metalog use [${dest}/etc] 58 -U do not preserve file permissions (with -i ..) 59 -d dest \${DESTDIR} [${dest}] 60 -t targetdir \${RELEASEDIR} [${tars}] 61 -T timestamp Timestamp to set for all the files in the tar. 62 [setname ...] Sets to build [${lists}] 63USAGE 64 exit 1 65} 66 67msg() 68{ 69 $quiet || echo $* 70} 71 72umask 002 73# handle args 74while getopts L:bxi:a:m:qs:F:SM:N:Ud:t:T: ch; do 75 case ${ch} in 76 L) 77 save_IFS="${IFS}" 78 IFS=, 79 for _list in ${OPTARG}; do 80 case $_list in 81 base) lists="${lists} ${nlists}" ;; 82 x) lists="${lists} ${xlists}" ;; 83 esac 84 done 85 IFS="${save_IFS}" 86 ;; 87 # backward compat 88 b) 89 lists="${nlists} ${xlists}" 90 ;; 91 x) 92 lists="${xlists}" 93 ;; 94 i) 95 installdir="${OPTARG}" 96 ;; 97 a) 98 MACHINE_ARCH="${OPTARG}" 99 MACHINE_CPU="$(arch_to_cpu "${OPTARG}")" 100 ;; 101 m) 102 MACHINE="${OPTARG}" 103 ;; 104 q) 105 quiet=true 106 ;; 107 s) 108 setsdir="${OPTARG}" 109 ;; 110 F) 111 setlistdir="${OPTARG}" 112 ;; 113 S) 114 setfilesonly=true 115 ;; 116 M) 117 metalog="${OPTARG}" 118 ;; 119 N) 120 etcdir="${OPTARG}" 121 ;; 122 U) 123 preserve= 124 ;; 125 d) 126 dest="${OPTARG}" 127 ;; 128 t) 129 tars="${OPTARG}" 130 ;; 131 T) 132 timestamp="--timestamp $OPTARG" 133 ;; 134 *) 135 usage 136 ;; 137 esac 138done 139shift $((${OPTIND} - 1)) 140if [ -n "${installdir}" ]; then # if -i, remove etc + xetc from the default list 141 lists="$(echo ${lists} | ${SED} -e 's/ etc / /;s/ xetc / /;')" 142fi 143if [ -n "$*" ]; then 144 lists="$*" 145fi 146 147if [ -z "${tars}" -a -z "${installdir}" ]; then 148 echo >&2 "${prog}: \${RELEASEDIR} must be set, or -i must be used" 149 exit 1 150fi 151 152if [ -z "${dest}" ]; then 153 echo >&2 "${prog}: \${DESTDIR} must be set" 154 exit 1 155fi 156: ${etcdir:="${dest}/etc"} 157 158SDIR="$(${MKTEMP} -d "/tmp/${prog}.XXXXXX")" 159TMPFILES= 160 161: ${setlistdir:="${dest}/etc/mtree"} 162 163cleanup() 164{ 165 es=$? 166 rm -rf "${SDIR}" ${TMPFILES} 167 trap - 0 168 exit ${es} 169} 170trap cleanup 0 2 3 13 # EXIT INT QUIT PIPE 171 172# 173# build the setfiles 174# 175 176for setname in ${lists}; do 177 msg "Creating flist.${setname}" 178 ${HOST_SH} "${setsdir}/makeflist" -a "${MACHINE_ARCH}" -m "${MACHINE}" \ 179 -s "${setsdir}" "${setname}" > "${SDIR}/flist.${setname}" \ 180 || exit 1 181 if [ ! -s "${SDIR}/flist.${setname}" ]; then 182 echo >&2 "makeflist output is empty for ${setname}" 183 exit 1 184 fi 185 msg "Creating set.${setname}" 186 if [ -n "${metalog}" ]; then 187 ${AWK} -f "${rundir}/getdirs.awk" "${SDIR}/flist.${setname}" \ 188 > "${SDIR}/flist.${setname}.full" \ 189 || exit 1 190 ( 191 echo "/set uname=root gname=wheel" 192 ${AWK} -f "${rundir}/join.awk" \ 193 "${SDIR}/flist.${setname}.full" "${metalog}" 194 echo "./etc/mtree/set.${setname} type=file mode=0444" 195 ) | ${MTREE} -CS -k all -R "${skipkeys}" -N "${etcdir}" \ 196 > "${setlistdir}/set.${setname}" \ 197 || exit 1 198 # We deliberately do not add set.${setname} to ${metalog}, 199 # because we depend on it as an input. 200 else 201 ${MTREE} -c -p "${dest}" -k all -R "${skipkeys}" \ 202 -N "${etcdir}" -O "${SDIR}/flist.${setname}" \ 203 | ${MTREE} -C -k all -N "${etcdir}" \ 204 > "${setlistdir}/set.${setname}" 205 fi 206done 207if ${setfilesonly}; then # exit after creating the set lists 208 exit 0 209fi 210 211runpax() { 212 local s="$1" 213 shift 214 (cd "${dest}" && 215 ${PAX} -dOw ${timestamp} -N"${etcdir}" -M "$@" < "${setlistdir}/set.${s}") 216} 217 218# 219# now build the tarfiles 220# 221 222GZIP=-9n # for pax -z 223export GZIP 224es=0 225 226for setname in ${lists:-${nlists}}; do 227 out="${setname}.${TAR_SUFF:-tgz}" 228 if [ -n "${installdir}" ]; then 229 msg "Copying set ${setname}" 230 runpax "${setname}" -r ${preserve} "${installdir}" 231 else 232 if [ -n "${metalog}" -a "${tars}/${out}" -nt "${metalog}" ] 233 then 234 msg "${out} is up to date" 235 continue 236 fi 237 msg "Creating ${out}" 238 rm -f "${tars}/${out}" 239 TMPFILES="${TMPFILES} ${tars}/${out}.tmp" 240 runpax "${setname}" -z --use-compress-program \ 241 ${COMPRESS_PROGRAM} > "${tars}/${out}.tmp" && 242 mv "${tars}/${out}.tmp" "${tars}/${out}" 243 fi 244 es=$((${es} + $?)) 245done 246if [ ${es} -gt 255 ]; then 247 es=255 248fi 249exit ${es} 250