Drop main() prototype. Syncs with NetBSD-8
[minix.git] / distrib / sets / maketars
blob1aa4de76191adebfbd6c0a0825095017849d34fb
1 #!/bin/sh
3 # $NetBSD: maketars,v 1.84 2015/05/27 15:18:29 martin Exp $
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 ...]
10 # The default sets are "base comp debug etc games man misc tests text"
11 # The X sets are "xbase xcomp xdebug xetc xfont xserver"
12 # The extsrc sets are "extbase extcomp extetc"
14 # If '-i installdir' is given, copy the given sets to installdir
15 # (using pax -rw ...) instead of creating tar files.
16 # In this case, remove "etc", "xetc", and "extetc" from the list of default sets.
19 prog="${0##*/}"
20 rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
21 . "${rundir}/sets.subr"
23 # set defaults
24 lists=
25 tars="${RELEASEDIR}"
26 dest="${DESTDIR}"
27 metalog=
28 installdir=
29 etcdir=
30 setlistdir=
31 setfilesonly=false
32 quiet=false
33 skipkeys=time,md5,sha1,sha384,sha512,rmd160,cksum
34 preserve="-pe"
36 usage()
38 cat 1>&2 <<USAGE
39 Usage: ${prog} [-L base,x,ext] [-b] [-x] [-y] [-i idir] [-a arch] [-m machine]
40 [-s setsdir] [-S] [-M metalog] [-N etcdir] [-F setlistdir]
41 [-d dest] [-t targetdir] [setname ...]
42 -L base,x,ext Make specified lists
43 -b Make both netbsd and x11 lists
44 -x Only make x11 lists
45 [Default: make netbsd lists]
46 -y Only make extsrc lists
47 [Default: make netbsd lists]
48 -i idir Install sets to idir instead of creating tar files
49 -a arch Set arch (e.g, m68k, mipseb, mipsel, powerpc) [${MACHINE_ARCH}]
50 -m machine Set machine (e.g, amiga, i386, macppc) [${MACHINE}]
51 -q Quiet operation
52 -s setsdir Directory to find sets [${setsdir}]
53 -F setlistdir output directory for generated set lists [${dest}/etc/mtree/]
54 -S Exit after creating set files ${dest}/etc/mtree/set.*
55 -M metalog metalog file
56 -N etcdir etc dir for metalog use [${dest}/etc]
57 -U do not preserve file permissions (with -i ..)
58 -d dest \${DESTDIR} [${dest}]
59 -t targetdir \${RELEASEDIR} [${tars}]
60 [setname ...] Sets to build [${lists}]
61 USAGE
62 exit 1
65 msg()
67 $quiet || echo $*
70 # handle args
71 while getopts L:bxyi:a:m:qs:F:SM:N:Ud:t: ch; do
72 case ${ch} in
74 save_IFS="${IFS}"
75 IFS=,
76 for _list in ${OPTARG}; do
77 case $_list in
78 base) lists="${lists} ${nlists}" ;;
79 x) lists="${lists} ${xlists}" ;;
80 ext) lists="${lists} ${extlists}" ;;
81 esac
82 done
83 IFS="${save_IFS}"
85 # backward compat
87 lists="${nlists} ${xlists}"
90 lists="${xlists}"
93 lists="${extlists}"
96 installdir="${OPTARG}"
99 MACHINE_ARCH="${OPTARG}"
100 MACHINE_CPU="$(arch_to_cpu "${OPTARG}")"
103 MACHINE="${OPTARG}"
106 quiet=true
109 setsdir="${OPTARG}"
112 setlistdir="${OPTARG}"
115 setfilesonly=true
118 metalog="${OPTARG}"
121 etcdir="${OPTARG}"
124 preserve=
127 dest="${OPTARG}"
130 tars="${OPTARG}"
133 usage
135 esac
136 done
137 shift $((${OPTIND} - 1))
138 if [ -n "${installdir}" ]; then # if -i, remove etc + xetc + extetc from the default list
139 lists="$(echo ${lists} | ${SED} -e 's/ etc / /;s/ xetc / /;s/ extetc / /')"
141 if [ -n "$*" ]; then
142 lists="$*"
145 if [ -z "${tars}" -a -z "${installdir}" ]; then
146 echo >&2 "${prog}: \${RELEASEDIR} must be set, or -i must be used"
147 exit 1
150 if [ -z "${dest}" ]; then
151 echo >&2 "${prog}: \${DESTDIR} must be set"
152 exit 1
154 : ${etcdir:="${dest}/etc"}
156 SDIR="$(${MKTEMP} -d "/tmp/${prog}.XXXXXX")"
157 TMPFILES=
159 : ${setlistdir:="${dest}/etc/mtree"}
161 cleanup()
163 es=$?
164 /bin/rm -rf "${SDIR}" ${TMPFILES}
165 trap - 0
166 exit ${es}
168 trap cleanup 0 2 3 13 # EXIT INT QUIT PIPE
171 # build the setfiles
174 for setname in ${lists}; do
175 ${HOST_SH} "${setsdir}/makeflist" -a "${MACHINE_ARCH}" -m "${MACHINE}" \
176 -s "${setsdir}" "${setname}" > "${SDIR}/flist.${setname}" \
177 || exit 1
178 if [ ! -s "${SDIR}/flist.${setname}" ]; then
179 echo >&2 "makeflist output is empty for ${setname}"
180 exit 1
182 ${setfilesonly} && msg "Creating ${setlistdir}/set.${setname}"
183 if [ -n "${metalog}" ]; then
184 ${AWK} -f "${rundir}/getdirs.awk" "${SDIR}/flist.${setname}" \
185 > "${SDIR}/flist.${setname}.full" \
186 || exit 1
188 echo "/set uname=root gname=wheel"
189 ${AWK} -f "${rundir}/join.awk" \
190 "${SDIR}/flist.${setname}.full" "${metalog}"
191 echo "./etc/mtree/set.${setname} type=file mode=0444"
192 ) | ${MTREE} -CS -k all -R "${skipkeys}" -N "${etcdir}" \
193 > "${setlistdir}/set.${setname}" \
194 || exit 1
195 # We deliberately do not add set.${setname} to ${metalog},
196 # because we depend on it as an input.
197 else
198 ${MTREE} -c -p "${dest}" -k all -R "${skipkeys}" \
199 -O "${SDIR}/flist.${setname}" | ${MTREE} -C -k all > \
200 "${setlistdir}/set.${setname}"
202 done
203 if ${setfilesonly}; then # exit after creating the set lists
204 exit 0
207 runpax() {
208 local s="$1"
209 shift
210 (cd "${dest}" &&
211 ${PAX} -dOw -N"${etcdir}" -M "$@" < "${setlistdir}/set.${s}")
215 # now build the tarfiles
218 GZIP=-9n # for pax -z
219 export GZIP
220 es=0
222 for setname in ${lists:-${nlists}}; do
223 out="${setname}.tgz"
224 if [ -n "${installdir}" ]; then
225 msg "Copying set ${setname}"
226 runpax "${setname}" -r ${preserve} "${installdir}"
227 else
228 if [ -n "${metalog}" -a "${tars}/${out}" -nt "${metalog}" ]
229 then
230 msg "${out} is up to date"
231 continue
233 msg "Creating ${out}"
234 rm -f "${tars}/${out}"
235 TMPFILES="${TMPFILES} ${tars}/${out}.tmp"
236 runpax "${setname}" -z --use-compress-program \
237 ${COMPRESS_PROGRAM} > "${tars}/${out}.tmp" &&
238 mv "${tars}/${out}.tmp" "${tars}/${out}"
240 es=$((${es} + $?))
241 done
242 if [ ${es} -gt 255 ]; then
243 es=255
245 exit ${es}