1#!/bin/sh 2# 3# $NetBSD: maketars,v 1.64 2008/03/16 07:02:22 lukem 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] [-d destdir] [-t tardir] [setname ...] 8# 9# The default sets are "base comp etc games man misc tests text" 10# The X sets are "xbase xcomp xetc xfont xserver" 11# 12# If '-i installdir' is given, copy the given sets to installdir 13# (using pax -rw ...) instead of creating tar files. 14# In this case, remove "etc" and "xetc" from the list of default sets. 15# 16 17prog="${0##*/}" 18rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/" 19. "${rundir}/sets.subr" 20 21# set defaults 22lists="${nlists}" 23tars="${RELEASEDIR}" 24dest="${DESTDIR}" 25metalog= 26installdir= 27etcdir= 28setfilesonly=false 29quiet=false 30 31usage() 32{ 33 cat 1>&2 <<USAGE 34Usage: ${prog} [-b] [-x] [-i idir] [-a arch] [-m machine] [-s setsdir] [-S] 35 [-M metalog] [-N etcdir] [-d dest] [-t targetdir] [setname ...] 36 -b Make both netbsd and x11 lists 37 -x Only make x11 lists 38 [Default: make netbsd lists] 39 -i idir Install sets to idir instead of creating tar files 40 -a arch Set arch (e.g, m68k, mipseb, mipsel, powerpc) [${MACHINE_ARCH}] 41 -m machine Set machine (e.g, amiga, i386, macppc) [${MACHINE}] 42 -q Quiet operation 43 -s setsdir Directory to find sets [${setsdir}] 44 -S Exit after creating set files ${dest}/etc/mtree/set.* 45 -M metalog metalog file 46 -N etcdir etc dir for metalog use [${dest}/etc] 47 -d dest \${DESTDIR} [${dest}] 48 -t targetdir \${RELEASEDIR} [${tars}] 49 [setname ...] Sets to build [${lists}] 50USAGE 51 exit 1 52} 53 54msg() 55{ 56 $quiet || echo $* 57} 58 59# handle args 60while getopts bxi:a:m:qs:SM:N:d:t: ch; do 61 case ${ch} in 62 b) 63 lists="${nlists} ${xlists}" 64 ;; 65 x) 66 lists="${xlists}" 67 ;; 68 i) 69 installdir="${OPTARG}" 70 ;; 71 a) 72 MACHINE_ARCH="${OPTARG}" 73 MACHINE_CPU="$(arch_to_cpu "${OPTARG}")" 74 ;; 75 m) 76 MACHINE="${OPTARG}" 77 ;; 78 q) 79 quiet=true 80 ;; 81 s) 82 setsdir="${OPTARG}" 83 ;; 84 S) 85 setfilesonly=true 86 ;; 87 M) 88 metalog="${OPTARG}" 89 ;; 90 N) 91 etcdir="${OPTARG}" 92 ;; 93 d) 94 dest="${OPTARG}" 95 ;; 96 t) 97 tars="${OPTARG}" 98 ;; 99 *) 100 usage 101 ;; 102 esac 103done 104shift $((${OPTIND} - 1)) 105if [ -n "${installdir}" ]; then # if -i, remove etc & xetc from the default list 106 lists="$(echo ${lists} | ${SED} -e 's/ etc / /;s/ xetc / /')" 107fi 108if [ -n "$*" ]; then 109 lists="$*" 110fi 111 112if [ -z "${tars}" -a -z "${installdir}" ]; then 113 echo >&2 "${prog}: \${RELEASEDIR} must be set, or -i must be used" 114 exit 1 115fi 116 117if [ -z "${dest}" ]; then 118 echo >&2 "${prog}: \${DESTDIR} must be set" 119 exit 1 120fi 121: ${etcdir:="${dest}/etc"} 122 123SDIR="$(${MKTEMP} -d "/tmp/${prog}.XXXXXX")" 124TMPFILES= 125 126setlistdir="${dest}/etc/mtree" 127 128cleanup() 129{ 130 es=$? 131 /bin/rm -rf "${SDIR}" ${TMPFILES} 132 trap - 0 133 exit ${es} 134} 135trap cleanup 0 2 3 13 # EXIT INT QUIT PIPE 136 137# 138# build the setfiles 139# 140 141for setname in ${lists}; do 142 ${HOST_SH} "${setsdir}/makeflist" -a "${MACHINE_ARCH}" -m "${MACHINE}" \ 143 -s "${setsdir}" "${setname}" > "${SDIR}/flist.${setname}" 144 if [ -n "${metalog}" ]; then 145 ${setfilesonly} && msg "Creating ${setlistdir}/set.${setname}" 146 ${AWK} -f "${rundir}/getdirs.awk" "${SDIR}/flist.${setname}" \ 147 | ${SORT} -u > "${SDIR}/flist.${setname}.full" 148 ( 149 echo "/set uname=root gname=wheel" 150 ${AWK} -f "${rundir}/join.awk" \ 151 "${SDIR}/flist.${setname}.full" "${metalog}" 152 echo "./etc/mtree/set.${setname} type=file mode=0444" 153 ) > "${setlistdir}/set.${setname}" 154 # We deliberately do not add set.${setname} to ${metalog}, 155 # because we depend on it as an input. 156 elif ! cmp -s "${SDIR}/flist.${setname}" \ 157 "${setlistdir}/set.${setname}" >/dev/null 2>&1; then 158 rm -f "${setlistdir}/set.${setname}" 159 cp "${SDIR}/flist.${setname}" "${setlistdir}/set.${setname}" 160 fi 161done 162if ${setfilesonly}; then # exit after creating the set lists 163 exit 0 164fi 165 166# 167# now build the tarfiles 168# 169 170GZIP=-9 # for pax -z 171export GZIP 172es=0 173for setname in ${lists}; do 174 out="${setname}.tgz" 175 if [ -n "${installdir}" ]; then 176 msg "Copying set ${setname}" 177 ( cd "${dest}"; \ 178 ${PAX} -O -rwpe -d -N"${etcdir}" ${metalog:+-M} \ 179 "${installdir}" < "${setlistdir}/set.${setname}" ) 180 else 181 if [ -n "${metalog}" -a "${tars}/${out}" -nt "${metalog}" ] 182 then 183 msg "${out} is up to date" 184 continue 185 fi 186 msg "Creating ${out}" 187 rm -f "${tars}/${out}" 188 TMPFILES="${TMPFILES} ${tars}/${out}.tmp" 189 ( cd "${dest}"; \ 190 ${PAX} -O -w -d -z -N"${etcdir}" ${metalog:+-M} \ 191 < "${setlistdir}/set.${setname}" ) \ 192 > "${tars}/${out}.tmp" && 193 mv "${tars}/${out}.tmp" "${tars}/${out}" 194 fi 195 es=$((${es} + $?)) 196done 197if [ ${es} -gt 255 ]; then 198 es=255 199fi 200exit ${es} 201