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