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