No empty .Rs/.Re
[netbsd-mini2440.git] / distrib / sets / maketars
blobde65fffb7bb60fa6769d7eb36ff529fc6719e746
1 #!/bin/sh
3 # $NetBSD$
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] [-d destdir] [-t tardir] [setname ...]
9 # The default sets are "base comp etc games man misc tests text"
10 # The X sets are "xbase xcomp xetc xfont xserver"
11 # The extsrc sets are "extbase extcomp extetc"
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", "xetc", and "extetc" from the list of default sets.
18 prog="${0##*/}"
19 rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
20 . "${rundir}/sets.subr"
22 # set defaults
23 lists=
24 tars="${RELEASEDIR}"
25 dest="${DESTDIR}"
26 metalog=
27 installdir=
28 etcdir=
29 setfilesonly=false
30 quiet=false
32 usage()
34 cat 1>&2 <<USAGE
35 Usage: ${prog} [-L base,x,ext] [-b] [-x] [-y] [-i idir] [-a arch] [-m machine] [-s setsdir] [-S]
36 [-M metalog] [-N etcdir] [-d dest] [-t targetdir] [setname ...]
37 -L base,x,ext Make specified lists
38 -b Make both netbsd and x11 lists
39 -x Only make x11 lists
40 [Default: make netbsd lists]
41 -y Only make extsrc lists
42 [Default: make netbsd lists]
43 -i idir Install sets to idir instead of creating tar files
44 -a arch Set arch (e.g, m68k, mipseb, mipsel, powerpc) [${MACHINE_ARCH}]
45 -m machine Set machine (e.g, amiga, i386, macppc) [${MACHINE}]
46 -q Quiet operation
47 -s setsdir Directory to find sets [${setsdir}]
48 -S Exit after creating set files ${dest}/etc/mtree/set.*
49 -M metalog metalog file
50 -N etcdir etc dir for metalog use [${dest}/etc]
51 -d dest \${DESTDIR} [${dest}]
52 -t targetdir \${RELEASEDIR} [${tars}]
53 [setname ...] Sets to build [${lists}]
54 USAGE
55 exit 1
58 msg()
60 $quiet || echo $*
63 # handle args
64 while getopts L:bxyi:a:m:qs:SM:N:d:t: ch; do
65 case ${ch} in
67 save_IFS="${IFS}"
68 IFS=,
69 for _list in ${OPTARG}; do
70 case $_list in
71 base) lists="${lists} ${nlists}" ;;
72 x) lists="${lists} ${xlists}" ;;
73 ext) lists="${lists} ${extlists}" ;;
74 esac
75 done
76 IFS="${save_IFS}"
78 # backward compat
80 lists="${nlists} ${xlists}"
83 lists="${xlists}"
86 lists="${extlists}"
89 installdir="${OPTARG}"
92 MACHINE_ARCH="${OPTARG}"
93 MACHINE_CPU="$(arch_to_cpu "${OPTARG}")"
96 MACHINE="${OPTARG}"
99 quiet=true
102 setsdir="${OPTARG}"
105 setfilesonly=true
108 metalog="${OPTARG}"
111 etcdir="${OPTARG}"
114 dest="${OPTARG}"
117 tars="${OPTARG}"
120 usage
122 esac
123 done
124 shift $((${OPTIND} - 1))
125 if [ -n "${installdir}" ]; then # if -i, remove etc + xetc + extetc from the default list
126 lists="$(echo ${lists} | ${SED} -e 's/ etc / /;s/ xetc / /;s/ extetc / /')"
128 if [ -n "$*" ]; then
129 lists="$*"
132 if [ -z "${tars}" -a -z "${installdir}" ]; then
133 echo >&2 "${prog}: \${RELEASEDIR} must be set, or -i must be used"
134 exit 1
137 if [ -z "${dest}" ]; then
138 echo >&2 "${prog}: \${DESTDIR} must be set"
139 exit 1
141 : ${etcdir:="${dest}/etc"}
143 SDIR="$(${MKTEMP} -d "/tmp/${prog}.XXXXXX")"
144 TMPFILES=
146 setlistdir="${dest}/etc/mtree"
148 cleanup()
150 es=$?
151 /bin/rm -rf "${SDIR}" ${TMPFILES}
152 trap - 0
153 exit ${es}
155 trap cleanup 0 2 3 13 # EXIT INT QUIT PIPE
158 # build the setfiles
161 for setname in ${lists}; do
162 ${HOST_SH} "${setsdir}/makeflist" -a "${MACHINE_ARCH}" -m "${MACHINE}" \
163 -s "${setsdir}" "${setname}" > "${SDIR}/flist.${setname}" \
164 || exit 1
165 if [ ! -s "${SDIR}/flist.${setname}" ]; then
166 echo >&2 "makeflist output is empty for ${setname}"
167 exit 1
169 if [ -n "${metalog}" ]; then
170 ${setfilesonly} && msg "Creating ${setlistdir}/set.${setname}"
171 ${AWK} -f "${rundir}/getdirs.awk" "${SDIR}/flist.${setname}" \
172 > "${SDIR}/flist.${setname}.full" \
173 || exit 1
175 echo "/set uname=root gname=wheel"
176 ${AWK} -f "${rundir}/join.awk" \
177 "${SDIR}/flist.${setname}.full" "${metalog}"
178 echo "./etc/mtree/set.${setname} type=file mode=0444"
179 ) | ${MTREE} -CS -k all -R time -N "${etcdir}" \
180 > "${setlistdir}/set.${setname}" \
181 || exit 1
182 # We deliberately do not add set.${setname} to ${metalog},
183 # because we depend on it as an input.
184 elif ! cmp -s "${SDIR}/flist.${setname}" \
185 "${setlistdir}/set.${setname}" >/dev/null 2>&1; then
186 rm -f "${setlistdir}/set.${setname}"
187 cp "${SDIR}/flist.${setname}" "${setlistdir}/set.${setname}" \
188 || exit 1
190 done
191 if ${setfilesonly}; then # exit after creating the set lists
192 exit 0
196 # now build the tarfiles
199 GZIP=-9n # for pax -z
200 export GZIP
201 es=0
202 for setname in ${lists:-${nlists}}; do
203 out="${setname}.tgz"
204 if [ -n "${installdir}" ]; then
205 msg "Copying set ${setname}"
206 ( cd "${dest}"; \
207 ${PAX} -O -rwpe -d -N"${etcdir}" ${metalog:+-M} \
208 "${installdir}" < "${setlistdir}/set.${setname}" )
209 else
210 if [ -n "${metalog}" -a "${tars}/${out}" -nt "${metalog}" ]
211 then
212 msg "${out} is up to date"
213 continue
215 msg "Creating ${out}"
216 rm -f "${tars}/${out}"
217 TMPFILES="${TMPFILES} ${tars}/${out}.tmp"
218 ( cd "${dest}"; \
219 ${PAX} -O -w -d -z -N"${etcdir}" ${metalog:+-M} \
220 < "${setlistdir}/set.${setname}" ) \
221 > "${tars}/${out}.tmp" &&
222 mv "${tars}/${out}.tmp" "${tars}/${out}"
224 es=$((${es} + $?))
225 done
226 if [ ${es} -gt 255 ]; then
227 es=255
229 exit ${es}