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