maketars revision 1.70 1 1.2 gwr #!/bin/sh
2 1.2 gwr #
3 1.70 uebayasi # $NetBSD: maketars,v 1.70 2009/11/30 16:13:23 uebayasi 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.62 jmmv # The default sets are "base comp 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.58 apb lists="${nlists}"
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.70 uebayasi lists=$(
68 1.70 uebayasi for _list in $( echo ${OPTARG} | tr , ' ' ); do
69 1.70 uebayasi case $_list in
70 1.70 uebayasi base) echo "${nlists}" ;;
71 1.70 uebayasi x) echo "${xlists}" ;;
72 1.70 uebayasi ext) echo "${extlists}" ;;
73 1.70 uebayasi esac
74 1.70 uebayasi done
75 1.70 uebayasi )
76 1.70 uebayasi ;;
77 1.70 uebayasi # backward compat
78 1.47 lukem b)
79 1.58 apb lists="${nlists} ${xlists}"
80 1.47 lukem ;;
81 1.47 lukem x)
82 1.58 apb lists="${xlists}"
83 1.47 lukem ;;
84 1.70 uebayasi y)
85 1.70 uebayasi lists="${extlists}"
86 1.70 uebayasi ;;
87 1.47 lukem i)
88 1.58 apb installdir="${OPTARG}"
89 1.47 lukem ;;
90 1.47 lukem a)
91 1.58 apb MACHINE_ARCH="${OPTARG}"
92 1.58 apb MACHINE_CPU="$(arch_to_cpu "${OPTARG}")"
93 1.47 lukem ;;
94 1.47 lukem m)
95 1.58 apb MACHINE="${OPTARG}"
96 1.47 lukem ;;
97 1.64 lukem q)
98 1.64 lukem quiet=true
99 1.64 lukem ;;
100 1.47 lukem s)
101 1.58 apb setsdir="${OPTARG}"
102 1.47 lukem ;;
103 1.50 lukem S)
104 1.50 lukem setfilesonly=true
105 1.50 lukem ;;
106 1.47 lukem M)
107 1.58 apb metalog="${OPTARG}"
108 1.47 lukem ;;
109 1.47 lukem N)
110 1.58 apb etcdir="${OPTARG}"
111 1.47 lukem ;;
112 1.47 lukem d)
113 1.58 apb dest="${OPTARG}"
114 1.47 lukem ;;
115 1.47 lukem t)
116 1.58 apb tars="${OPTARG}"
117 1.9 lukem ;;
118 1.9 lukem *)
119 1.47 lukem usage
120 1.9 lukem ;;
121 1.2 gwr esac
122 1.2 gwr done
123 1.47 lukem shift $((${OPTIND} - 1))
124 1.70 uebayasi if [ -n "${installdir}" ]; then # if -i, remove etc + xetc + extetc from the default list
125 1.70 uebayasi lists="$(echo ${lists} | ${SED} -e 's/ etc / /;s/ xetc / /;s/ extetc / /')"
126 1.28 lukem fi
127 1.10 ross if [ -n "$*" ]; then
128 1.10 ross lists="$*"
129 1.9 lukem fi
130 1.1 cgd
131 1.58 apb if [ -z "${tars}" -a -z "${installdir}" ]; then
132 1.60 apb echo >&2 "${prog}: \${RELEASEDIR} must be set, or -i must be used"
133 1.1 cgd exit 1
134 1.9 lukem fi
135 1.1 cgd
136 1.58 apb if [ -z "${dest}" ]; then
137 1.60 apb echo >&2 "${prog}: \${DESTDIR} must be set"
138 1.1 cgd exit 1
139 1.9 lukem fi
140 1.58 apb : ${etcdir:="${dest}/etc"}
141 1.1 cgd
142 1.58 apb SDIR="$(${MKTEMP} -d "/tmp/${prog}.XXXXXX")"
143 1.63 lukem TMPFILES=
144 1.20 bjh21
145 1.58 apb setlistdir="${dest}/etc/mtree"
146 1.50 lukem
147 1.38 erh cleanup()
148 1.38 erh {
149 1.44 dsl es=$?
150 1.63 lukem /bin/rm -rf "${SDIR}" ${TMPFILES}
151 1.63 lukem trap - 0
152 1.58 apb exit ${es}
153 1.38 erh }
154 1.38 erh trap cleanup 0 2 3 13 # EXIT INT QUIT PIPE
155 1.18 lukem
156 1.50 lukem #
157 1.50 lukem # build the setfiles
158 1.50 lukem #
159 1.50 lukem
160 1.58 apb for setname in ${lists}; do
161 1.58 apb ${HOST_SH} "${setsdir}/makeflist" -a "${MACHINE_ARCH}" -m "${MACHINE}" \
162 1.69 apb -s "${setsdir}" "${setname}" > "${SDIR}/flist.${setname}" \
163 1.69 apb || exit 1
164 1.58 apb if [ -n "${metalog}" ]; then
165 1.64 lukem ${setfilesonly} && msg "Creating ${setlistdir}/set.${setname}"
166 1.58 apb ${AWK} -f "${rundir}/getdirs.awk" "${SDIR}/flist.${setname}" \
167 1.69 apb > "${SDIR}/flist.${setname}.full" \
168 1.69 apb || exit 1
169 1.23 lukem (
170 1.23 lukem echo "/set uname=root gname=wheel"
171 1.58 apb ${AWK} -f "${rundir}/join.awk" \
172 1.68 apb "${SDIR}/flist.${setname}.full" "${metalog}"
173 1.50 lukem echo "./etc/mtree/set.${setname} type=file mode=0444"
174 1.68 apb ) | ${MTREE} -CS -k all -R time -N "${etcdir}" \
175 1.69 apb > "${setlistdir}/set.${setname}" \
176 1.69 apb || exit 1
177 1.59 apb # We deliberately do not add set.${setname} to ${metalog},
178 1.59 apb # because we depend on it as an input.
179 1.58 apb elif ! cmp -s "${SDIR}/flist.${setname}" \
180 1.58 apb "${setlistdir}/set.${setname}" >/dev/null 2>&1; then
181 1.58 apb rm -f "${setlistdir}/set.${setname}"
182 1.69 apb cp "${SDIR}/flist.${setname}" "${setlistdir}/set.${setname}" \
183 1.69 apb || exit 1
184 1.18 lukem fi
185 1.50 lukem done
186 1.58 apb if ${setfilesonly}; then # exit after creating the set lists
187 1.50 lukem exit 0
188 1.50 lukem fi
189 1.18 lukem
190 1.50 lukem #
191 1.50 lukem # now build the tarfiles
192 1.50 lukem #
193 1.50 lukem
194 1.67 perry GZIP=-9n # for pax -z
195 1.50 lukem export GZIP
196 1.50 lukem es=0
197 1.58 apb for setname in ${lists}; do
198 1.58 apb out="${setname}.tgz"
199 1.58 apb if [ -n "${installdir}" ]; then
200 1.64 lukem msg "Copying set ${setname}"
201 1.61 apb ( cd "${dest}"; \
202 1.58 apb ${PAX} -O -rwpe -d -N"${etcdir}" ${metalog:+-M} \
203 1.58 apb "${installdir}" < "${setlistdir}/set.${setname}" )
204 1.28 lukem else
205 1.58 apb if [ -n "${metalog}" -a "${tars}/${out}" -nt "${metalog}" ]
206 1.58 apb then
207 1.64 lukem msg "${out} is up to date"
208 1.50 lukem continue
209 1.50 lukem fi
210 1.64 lukem msg "Creating ${out}"
211 1.58 apb rm -f "${tars}/${out}"
212 1.63 lukem TMPFILES="${TMPFILES} ${tars}/${out}.tmp"
213 1.61 apb ( cd "${dest}"; \
214 1.58 apb ${PAX} -O -w -d -z -N"${etcdir}" ${metalog:+-M} \
215 1.58 apb < "${setlistdir}/set.${setname}" ) \
216 1.58 apb > "${tars}/${out}.tmp" &&
217 1.58 apb mv "${tars}/${out}.tmp" "${tars}/${out}"
218 1.28 lukem fi
219 1.58 apb es=$((${es} + $?))
220 1.2 gwr done
221 1.61 apb if [ ${es} -gt 255 ]; then
222 1.38 erh es=255
223 1.38 erh fi
224 1.58 apb exit ${es}
225