maketars revision 1.69 1 #!/bin/sh
2 #
3 # $NetBSD: maketars,v 1.69 2009/09/12 11:01:55 apb 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 #
12 # If '-i installdir' is given, copy the given sets to installdir
13 # (using pax -rw ...) instead of creating tar files.
14 # In this case, remove "etc" and "xetc" from the list of default sets.
15 #
16
17 prog="${0##*/}"
18 rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
19 . "${rundir}/sets.subr"
20
21 # set defaults
22 lists="${nlists}"
23 tars="${RELEASEDIR}"
24 dest="${DESTDIR}"
25 metalog=
26 installdir=
27 etcdir=
28 setfilesonly=false
29 quiet=false
30
31 usage()
32 {
33 cat 1>&2 <<USAGE
34 Usage: ${prog} [-b] [-x] [-i idir] [-a arch] [-m machine] [-s setsdir] [-S]
35 [-M metalog] [-N etcdir] [-d dest] [-t targetdir] [setname ...]
36 -b Make both netbsd and x11 lists
37 -x Only make x11 lists
38 [Default: make netbsd lists]
39 -i idir Install sets to idir instead of creating tar files
40 -a arch Set arch (e.g, m68k, mipseb, mipsel, powerpc) [${MACHINE_ARCH}]
41 -m machine Set machine (e.g, amiga, i386, macppc) [${MACHINE}]
42 -q Quiet operation
43 -s setsdir Directory to find sets [${setsdir}]
44 -S Exit after creating set files ${dest}/etc/mtree/set.*
45 -M metalog metalog file
46 -N etcdir etc dir for metalog use [${dest}/etc]
47 -d dest \${DESTDIR} [${dest}]
48 -t targetdir \${RELEASEDIR} [${tars}]
49 [setname ...] Sets to build [${lists}]
50 USAGE
51 exit 1
52 }
53
54 msg()
55 {
56 $quiet || echo $*
57 }
58
59 # handle args
60 while getopts bxi:a:m:qs:SM:N:d:t: ch; do
61 case ${ch} in
62 b)
63 lists="${nlists} ${xlists}"
64 ;;
65 x)
66 lists="${xlists}"
67 ;;
68 i)
69 installdir="${OPTARG}"
70 ;;
71 a)
72 MACHINE_ARCH="${OPTARG}"
73 MACHINE_CPU="$(arch_to_cpu "${OPTARG}")"
74 ;;
75 m)
76 MACHINE="${OPTARG}"
77 ;;
78 q)
79 quiet=true
80 ;;
81 s)
82 setsdir="${OPTARG}"
83 ;;
84 S)
85 setfilesonly=true
86 ;;
87 M)
88 metalog="${OPTARG}"
89 ;;
90 N)
91 etcdir="${OPTARG}"
92 ;;
93 d)
94 dest="${OPTARG}"
95 ;;
96 t)
97 tars="${OPTARG}"
98 ;;
99 *)
100 usage
101 ;;
102 esac
103 done
104 shift $((${OPTIND} - 1))
105 if [ -n "${installdir}" ]; then # if -i, remove etc & xetc from the default list
106 lists="$(echo ${lists} | ${SED} -e 's/ etc / /;s/ xetc / /')"
107 fi
108 if [ -n "$*" ]; then
109 lists="$*"
110 fi
111
112 if [ -z "${tars}" -a -z "${installdir}" ]; then
113 echo >&2 "${prog}: \${RELEASEDIR} must be set, or -i must be used"
114 exit 1
115 fi
116
117 if [ -z "${dest}" ]; then
118 echo >&2 "${prog}: \${DESTDIR} must be set"
119 exit 1
120 fi
121 : ${etcdir:="${dest}/etc"}
122
123 SDIR="$(${MKTEMP} -d "/tmp/${prog}.XXXXXX")"
124 TMPFILES=
125
126 setlistdir="${dest}/etc/mtree"
127
128 cleanup()
129 {
130 es=$?
131 /bin/rm -rf "${SDIR}" ${TMPFILES}
132 trap - 0
133 exit ${es}
134 }
135 trap cleanup 0 2 3 13 # EXIT INT QUIT PIPE
136
137 #
138 # build the setfiles
139 #
140
141 for setname in ${lists}; do
142 ${HOST_SH} "${setsdir}/makeflist" -a "${MACHINE_ARCH}" -m "${MACHINE}" \
143 -s "${setsdir}" "${setname}" > "${SDIR}/flist.${setname}" \
144 || exit 1
145 if [ -n "${metalog}" ]; then
146 ${setfilesonly} && msg "Creating ${setlistdir}/set.${setname}"
147 ${AWK} -f "${rundir}/getdirs.awk" "${SDIR}/flist.${setname}" \
148 > "${SDIR}/flist.${setname}.full" \
149 || exit 1
150 (
151 echo "/set uname=root gname=wheel"
152 ${AWK} -f "${rundir}/join.awk" \
153 "${SDIR}/flist.${setname}.full" "${metalog}"
154 echo "./etc/mtree/set.${setname} type=file mode=0444"
155 ) | ${MTREE} -CS -k all -R time -N "${etcdir}" \
156 > "${setlistdir}/set.${setname}" \
157 || exit 1
158 # We deliberately do not add set.${setname} to ${metalog},
159 # because we depend on it as an input.
160 elif ! cmp -s "${SDIR}/flist.${setname}" \
161 "${setlistdir}/set.${setname}" >/dev/null 2>&1; then
162 rm -f "${setlistdir}/set.${setname}"
163 cp "${SDIR}/flist.${setname}" "${setlistdir}/set.${setname}" \
164 || exit 1
165 fi
166 done
167 if ${setfilesonly}; then # exit after creating the set lists
168 exit 0
169 fi
170
171 #
172 # now build the tarfiles
173 #
174
175 GZIP=-9n # for pax -z
176 export GZIP
177 es=0
178 for setname in ${lists}; do
179 out="${setname}.tgz"
180 if [ -n "${installdir}" ]; then
181 msg "Copying set ${setname}"
182 ( cd "${dest}"; \
183 ${PAX} -O -rwpe -d -N"${etcdir}" ${metalog:+-M} \
184 "${installdir}" < "${setlistdir}/set.${setname}" )
185 else
186 if [ -n "${metalog}" -a "${tars}/${out}" -nt "${metalog}" ]
187 then
188 msg "${out} is up to date"
189 continue
190 fi
191 msg "Creating ${out}"
192 rm -f "${tars}/${out}"
193 TMPFILES="${TMPFILES} ${tars}/${out}.tmp"
194 ( cd "${dest}"; \
195 ${PAX} -O -w -d -z -N"${etcdir}" ${metalog:+-M} \
196 < "${setlistdir}/set.${setname}" ) \
197 > "${tars}/${out}.tmp" &&
198 mv "${tars}/${out}.tmp" "${tars}/${out}"
199 fi
200 es=$((${es} + $?))
201 done
202 if [ ${es} -gt 255 ]; then
203 es=255
204 fi
205 exit ${es}
206