maketars revision 1.75 1 1.2 gwr #!/bin/sh
2 1.2 gwr #
3 1.75 christos # $NetBSD: maketars,v 1.75 2013/01/16 16:01:05 christos 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.34 lukem # [-M metalog] [-N etcdir] [-d destdir] [-t tardir] [setname ...]
8 1.35 lukem #
9 1.75 christos # The default sets are "base comp debug etc games man misc tests text"
10 1.50 lukem # The X sets are "xbase xcomp xetc xfont xserver"
11 1.70 uebayasi # The extsrc sets are "extbase extcomp extetc"
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.70 uebayasi # In this case, remove "etc", "xetc", and "extetc" 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.50 lukem setfilesonly=false
30 1.64 lukem quiet=false
31 1.2 gwr
32 1.47 lukem usage()
33 1.47 lukem {
34 1.47 lukem cat 1>&2 <<USAGE
35 1.70 uebayasi Usage: ${prog} [-L base,x,ext] [-b] [-x] [-y] [-i idir] [-a arch] [-m machine] [-s setsdir] [-S]
36 1.36 lukem [-M metalog] [-N etcdir] [-d dest] [-t targetdir] [setname ...]
37 1.70 uebayasi -L base,x,ext Make specified lists
38 1.50 lukem -b Make both netbsd and x11 lists
39 1.50 lukem -x Only make x11 lists
40 1.50 lukem [Default: make netbsd lists]
41 1.70 uebayasi -y Only make extsrc lists
42 1.70 uebayasi [Default: make netbsd lists]
43 1.50 lukem -i idir Install sets to idir instead of creating tar files
44 1.58 apb -a arch Set arch (e.g, m68k, mipseb, mipsel, powerpc) [${MACHINE_ARCH}]
45 1.58 apb -m machine Set machine (e.g, amiga, i386, macppc) [${MACHINE}]
46 1.64 lukem -q Quiet operation
47 1.58 apb -s setsdir Directory to find sets [${setsdir}]
48 1.58 apb -S Exit after creating set files ${dest}/etc/mtree/set.*
49 1.18 lukem -M metalog metalog file
50 1.58 apb -N etcdir etc dir for metalog use [${dest}/etc]
51 1.58 apb -d dest \${DESTDIR} [${dest}]
52 1.58 apb -t targetdir \${RELEASEDIR} [${tars}]
53 1.58 apb [setname ...] Sets to build [${lists}]
54 1.9 lukem USAGE
55 1.47 lukem exit 1
56 1.47 lukem }
57 1.47 lukem
58 1.64 lukem msg()
59 1.64 lukem {
60 1.64 lukem $quiet || echo $*
61 1.64 lukem }
62 1.64 lukem
63 1.47 lukem # handle args
64 1.70 uebayasi while getopts L:bxyi:a:m:qs:SM:N:d:t: ch; do
65 1.47 lukem case ${ch} in
66 1.70 uebayasi L)
67 1.72 cegger save_IFS="${IFS}"
68 1.72 cegger IFS=,
69 1.72 cegger for _list in ${OPTARG}; do
70 1.72 cegger case $_list in
71 1.72 cegger base) lists="${lists} ${nlists}" ;;
72 1.72 cegger x) lists="${lists} ${xlists}" ;;
73 1.72 cegger ext) lists="${lists} ${extlists}" ;;
74 1.72 cegger esac
75 1.72 cegger done
76 1.72 cegger IFS="${save_IFS}"
77 1.70 uebayasi ;;
78 1.70 uebayasi # backward compat
79 1.47 lukem b)
80 1.58 apb lists="${nlists} ${xlists}"
81 1.47 lukem ;;
82 1.47 lukem x)
83 1.58 apb lists="${xlists}"
84 1.47 lukem ;;
85 1.70 uebayasi y)
86 1.70 uebayasi lists="${extlists}"
87 1.70 uebayasi ;;
88 1.47 lukem i)
89 1.58 apb installdir="${OPTARG}"
90 1.47 lukem ;;
91 1.47 lukem a)
92 1.58 apb MACHINE_ARCH="${OPTARG}"
93 1.58 apb MACHINE_CPU="$(arch_to_cpu "${OPTARG}")"
94 1.47 lukem ;;
95 1.47 lukem m)
96 1.58 apb MACHINE="${OPTARG}"
97 1.47 lukem ;;
98 1.64 lukem q)
99 1.64 lukem quiet=true
100 1.64 lukem ;;
101 1.47 lukem s)
102 1.58 apb setsdir="${OPTARG}"
103 1.47 lukem ;;
104 1.50 lukem S)
105 1.50 lukem setfilesonly=true
106 1.50 lukem ;;
107 1.47 lukem M)
108 1.58 apb metalog="${OPTARG}"
109 1.47 lukem ;;
110 1.47 lukem N)
111 1.58 apb etcdir="${OPTARG}"
112 1.47 lukem ;;
113 1.47 lukem d)
114 1.58 apb dest="${OPTARG}"
115 1.47 lukem ;;
116 1.47 lukem t)
117 1.58 apb tars="${OPTARG}"
118 1.9 lukem ;;
119 1.9 lukem *)
120 1.47 lukem usage
121 1.9 lukem ;;
122 1.2 gwr esac
123 1.2 gwr done
124 1.47 lukem shift $((${OPTIND} - 1))
125 1.70 uebayasi if [ -n "${installdir}" ]; then # if -i, remove etc + xetc + extetc from the default list
126 1.70 uebayasi lists="$(echo ${lists} | ${SED} -e 's/ etc / /;s/ xetc / /;s/ extetc / /')"
127 1.28 lukem fi
128 1.10 ross if [ -n "$*" ]; then
129 1.10 ross lists="$*"
130 1.9 lukem fi
131 1.1 cgd
132 1.58 apb if [ -z "${tars}" -a -z "${installdir}" ]; then
133 1.60 apb echo >&2 "${prog}: \${RELEASEDIR} must be set, or -i must be used"
134 1.1 cgd exit 1
135 1.9 lukem fi
136 1.1 cgd
137 1.58 apb if [ -z "${dest}" ]; then
138 1.60 apb echo >&2 "${prog}: \${DESTDIR} must be set"
139 1.1 cgd exit 1
140 1.9 lukem fi
141 1.58 apb : ${etcdir:="${dest}/etc"}
142 1.1 cgd
143 1.58 apb SDIR="$(${MKTEMP} -d "/tmp/${prog}.XXXXXX")"
144 1.63 lukem TMPFILES=
145 1.20 bjh21
146 1.58 apb setlistdir="${dest}/etc/mtree"
147 1.50 lukem
148 1.38 erh cleanup()
149 1.38 erh {
150 1.44 dsl es=$?
151 1.63 lukem /bin/rm -rf "${SDIR}" ${TMPFILES}
152 1.63 lukem trap - 0
153 1.58 apb exit ${es}
154 1.38 erh }
155 1.38 erh trap cleanup 0 2 3 13 # EXIT INT QUIT PIPE
156 1.18 lukem
157 1.50 lukem #
158 1.50 lukem # build the setfiles
159 1.50 lukem #
160 1.50 lukem
161 1.58 apb for setname in ${lists}; do
162 1.58 apb ${HOST_SH} "${setsdir}/makeflist" -a "${MACHINE_ARCH}" -m "${MACHINE}" \
163 1.69 apb -s "${setsdir}" "${setname}" > "${SDIR}/flist.${setname}" \
164 1.69 apb || exit 1
165 1.73 uebayasi if [ ! -s "${SDIR}/flist.${setname}" ]; then
166 1.71 apb echo >&2 "makeflist output is empty for ${setname}"
167 1.71 apb exit 1
168 1.71 apb fi
169 1.58 apb if [ -n "${metalog}" ]; then
170 1.64 lukem ${setfilesonly} && msg "Creating ${setlistdir}/set.${setname}"
171 1.58 apb ${AWK} -f "${rundir}/getdirs.awk" "${SDIR}/flist.${setname}" \
172 1.69 apb > "${SDIR}/flist.${setname}.full" \
173 1.69 apb || exit 1
174 1.23 lukem (
175 1.23 lukem echo "/set uname=root gname=wheel"
176 1.58 apb ${AWK} -f "${rundir}/join.awk" \
177 1.68 apb "${SDIR}/flist.${setname}.full" "${metalog}"
178 1.50 lukem echo "./etc/mtree/set.${setname} type=file mode=0444"
179 1.68 apb ) | ${MTREE} -CS -k all -R time -N "${etcdir}" \
180 1.69 apb > "${setlistdir}/set.${setname}" \
181 1.69 apb || exit 1
182 1.59 apb # We deliberately do not add set.${setname} to ${metalog},
183 1.59 apb # because we depend on it as an input.
184 1.58 apb elif ! cmp -s "${SDIR}/flist.${setname}" \
185 1.58 apb "${setlistdir}/set.${setname}" >/dev/null 2>&1; then
186 1.58 apb rm -f "${setlistdir}/set.${setname}"
187 1.69 apb cp "${SDIR}/flist.${setname}" "${setlistdir}/set.${setname}" \
188 1.69 apb || exit 1
189 1.18 lukem fi
190 1.50 lukem done
191 1.58 apb if ${setfilesonly}; then # exit after creating the set lists
192 1.50 lukem exit 0
193 1.50 lukem fi
194 1.18 lukem
195 1.50 lukem #
196 1.50 lukem # now build the tarfiles
197 1.50 lukem #
198 1.50 lukem
199 1.67 perry GZIP=-9n # for pax -z
200 1.50 lukem export GZIP
201 1.50 lukem es=0
202 1.72 cegger for setname in ${lists:-${nlists}}; do
203 1.58 apb out="${setname}.tgz"
204 1.58 apb if [ -n "${installdir}" ]; then
205 1.64 lukem msg "Copying set ${setname}"
206 1.61 apb ( cd "${dest}"; \
207 1.58 apb ${PAX} -O -rwpe -d -N"${etcdir}" ${metalog:+-M} \
208 1.58 apb "${installdir}" < "${setlistdir}/set.${setname}" )
209 1.28 lukem else
210 1.58 apb if [ -n "${metalog}" -a "${tars}/${out}" -nt "${metalog}" ]
211 1.58 apb then
212 1.64 lukem msg "${out} is up to date"
213 1.50 lukem continue
214 1.50 lukem fi
215 1.64 lukem msg "Creating ${out}"
216 1.58 apb rm -f "${tars}/${out}"
217 1.63 lukem TMPFILES="${TMPFILES} ${tars}/${out}.tmp"
218 1.61 apb ( cd "${dest}"; \
219 1.58 apb ${PAX} -O -w -d -z -N"${etcdir}" ${metalog:+-M} \
220 1.74 mrg --use-compress-program ${COMPRESS_PROGRAM} \
221 1.58 apb < "${setlistdir}/set.${setname}" ) \
222 1.58 apb > "${tars}/${out}.tmp" &&
223 1.58 apb mv "${tars}/${out}.tmp" "${tars}/${out}"
224 1.28 lukem fi
225 1.58 apb es=$((${es} + $?))
226 1.2 gwr done
227 1.61 apb if [ ${es} -gt 255 ]; then
228 1.38 erh es=255
229 1.38 erh fi
230 1.58 apb exit ${es}
231