maketars revision 1.95 1 #!/bin/sh
2 #
3 # $NetBSD: maketars,v 1.95 2023/06/10 14:11:08 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] [-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
18 prog="${0##*/}"
19 rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
20 . "${rundir}/sets.subr"
21
22 # set defaults
23 lists=
24 tars="${RELEASEDIR}"
25 dest="${DESTDIR}"
26 metalog=
27 installdir=
28 etcdir=
29 setlistdir=
30 timestamp=
31 setfilesonly=false
32 quiet=false
33 preserve="-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.
37 skipkeys=cksum,md5,rmd160,sha1,sha384,sha512,time
38
39 usage()
40 {
41 cat 1>&2 <<USAGE
42 Usage: ${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}]
63 USAGE
64 exit 1
65 }
66
67 msg()
68 {
69 $quiet || echo $*
70 }
71
72 # handle args
73 while getopts L:bxi:a:m:qs:F:SM:N:Ud:t:T: ch; do
74 case ${ch} in
75 L)
76 save_IFS="${IFS}"
77 IFS=,
78 for _list in ${OPTARG}; do
79 case $_list in
80 base) lists="${lists} ${nlists}" ;;
81 x) lists="${lists} ${xlists}" ;;
82 esac
83 done
84 IFS="${save_IFS}"
85 ;;
86 # backward compat
87 b)
88 lists="${nlists} ${xlists}"
89 ;;
90 x)
91 lists="${xlists}"
92 ;;
93 i)
94 installdir="${OPTARG}"
95 ;;
96 a)
97 MACHINE_ARCH="${OPTARG}"
98 MACHINE_CPU="$(arch_to_cpu "${OPTARG}")"
99 ;;
100 m)
101 MACHINE="${OPTARG}"
102 ;;
103 q)
104 quiet=true
105 ;;
106 s)
107 setsdir="${OPTARG}"
108 ;;
109 F)
110 setlistdir="${OPTARG}"
111 ;;
112 S)
113 setfilesonly=true
114 ;;
115 M)
116 metalog="${OPTARG}"
117 ;;
118 N)
119 etcdir="${OPTARG}"
120 ;;
121 U)
122 preserve=
123 ;;
124 d)
125 dest="${OPTARG}"
126 ;;
127 t)
128 tars="${OPTARG}"
129 ;;
130 T)
131 timestamp="--timestamp $OPTARG"
132 ;;
133 *)
134 usage
135 ;;
136 esac
137 done
138 shift $((${OPTIND} - 1))
139 if [ -n "${installdir}" ]; then # if -i, remove etc + xetc from the default list
140 lists="$(echo ${lists} | ${SED} -e 's/ etc / /;s/ xetc / /;')"
141 fi
142 if [ -n "$*" ]; then
143 lists="$*"
144 fi
145
146 if [ -z "${tars}" -a -z "${installdir}" ]; then
147 echo >&2 "${prog}: \${RELEASEDIR} must be set, or -i must be used"
148 exit 1
149 fi
150
151 if [ -z "${dest}" ]; then
152 echo >&2 "${prog}: \${DESTDIR} must be set"
153 exit 1
154 fi
155 : ${etcdir:="${dest}/etc"}
156
157 SDIR="$(${MKTEMP} -d "/tmp/${prog}.XXXXXX")"
158 TMPFILES=
159
160 : ${setlistdir:="${dest}/etc/mtree"}
161
162 cleanup()
163 {
164 es=$?
165 rm -rf "${SDIR}" ${TMPFILES}
166 trap - 0
167 exit ${es}
168 }
169 trap cleanup 0 2 3 13 # EXIT INT QUIT PIPE
170
171 #
172 # build the setfiles
173 #
174
175 for setname in ${lists}; do
176 ${HOST_SH} "${setsdir}/makeflist" -a "${MACHINE_ARCH}" -m "${MACHINE}" \
177 -s "${setsdir}" "${setname}" > "${SDIR}/flist.${setname}" \
178 || exit 1
179 if [ ! -s "${SDIR}/flist.${setname}" ]; then
180 echo >&2 "makeflist output is empty for ${setname}"
181 exit 1
182 fi
183 ${setfilesonly} && msg "Creating ${setlistdir}/set.${setname}"
184 if [ -n "${metalog}" ]; then
185 ${AWK} -f "${rundir}/getdirs.awk" "${SDIR}/flist.${setname}" \
186 > "${SDIR}/flist.${setname}.full" \
187 || exit 1
188 (
189 echo "/set uname=root gname=wheel"
190 ${AWK} -f "${rundir}/join.awk" \
191 "${SDIR}/flist.${setname}.full" "${metalog}"
192 echo "./etc/mtree/set.${setname} type=file mode=0444"
193 ) | ${MTREE} -CS -k all -R "${skipkeys}" -N "${etcdir}" \
194 > "${setlistdir}/set.${setname}" \
195 || exit 1
196 # We deliberately do not add set.${setname} to ${metalog},
197 # because we depend on it as an input.
198 else
199 ${MTREE} -c -p "${dest}" -k all -R "${skipkeys}" \
200 -N "${etcdir}" -O "${SDIR}/flist.${setname}" \
201 | ${MTREE} -C -k all -N "${etcdir}" \
202 > "${setlistdir}/set.${setname}"
203 fi
204 done
205 if ${setfilesonly}; then # exit after creating the set lists
206 exit 0
207 fi
208
209 runpax() {
210 local s="$1"
211 shift
212 (cd "${dest}" &&
213 ${PAX} -dOw ${timestamp} -N"${etcdir}" -M "$@" < "${setlistdir}/set.${s}")
214 }
215
216 #
217 # now build the tarfiles
218 #
219
220 GZIP=-9n # for pax -z
221 export GZIP
222 es=0
223
224 for setname in ${lists:-${nlists}}; do
225 out="${setname}.${TAR_SUFF:-tgz}"
226 if [ -n "${installdir}" ]; then
227 msg "Copying set ${setname}"
228 runpax "${setname}" -r ${preserve} "${installdir}"
229 else
230 if [ -n "${metalog}" -a "${tars}/${out}" -nt "${metalog}" ]
231 then
232 msg "${out} is up to date"
233 continue
234 fi
235 msg "Creating ${out}"
236 rm -f "${tars}/${out}"
237 TMPFILES="${TMPFILES} ${tars}/${out}.tmp"
238 runpax "${setname}" -z --use-compress-program \
239 ${COMPRESS_PROGRAM} > "${tars}/${out}.tmp" &&
240 mv "${tars}/${out}.tmp" "${tars}/${out}"
241 fi
242 es=$((${es} + $?))
243 done
244 if [ ${es} -gt 255 ]; then
245 es=255
246 fi
247 exit ${es}
248