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