maketars revision 1.67
1#!/bin/sh
2#
3# $NetBSD: maketars,v 1.67 2009/04/03 22:36:35 perry 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
17prog="${0##*/}"
18rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
19. "${rundir}/sets.subr"
20
21# set defaults
22lists="${nlists}"
23tars="${RELEASEDIR}"
24dest="${DESTDIR}"
25metalog=
26installdir=
27etcdir=
28setfilesonly=false
29quiet=false
30
31usage()
32{
33	cat 1>&2 <<USAGE
34Usage: ${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}]
50USAGE
51	exit 1
52}
53
54msg()
55{
56	$quiet || echo $*
57}
58
59# handle args
60while 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
103done
104shift $((${OPTIND} - 1))
105if [ -n "${installdir}" ]; then	# if -i, remove etc & xetc from the default list
106	lists="$(echo ${lists} | ${SED} -e 's/ etc / /;s/ xetc / /')"
107fi
108if [ -n "$*" ]; then
109	lists="$*"
110fi
111
112if [ -z "${tars}" -a -z "${installdir}" ]; then
113	echo >&2 "${prog}: \${RELEASEDIR} must be set, or -i must be used"
114	exit 1
115fi
116
117if [ -z "${dest}" ]; then
118	echo >&2 "${prog}: \${DESTDIR} must be set"
119	exit 1
120fi
121: ${etcdir:="${dest}/etc"}
122
123SDIR="$(${MKTEMP} -d "/tmp/${prog}.XXXXXX")"
124TMPFILES=
125
126setlistdir="${dest}/etc/mtree"
127
128cleanup()
129{
130	es=$?
131	/bin/rm -rf "${SDIR}" ${TMPFILES}
132	trap - 0
133	exit ${es}
134}
135trap cleanup 0 2 3 13		# EXIT INT QUIT PIPE
136
137#
138# build the setfiles
139#
140
141for setname in ${lists}; do
142	${HOST_SH} "${setsdir}/makeflist" -a "${MACHINE_ARCH}" -m "${MACHINE}" \
143	    -s "${setsdir}" "${setname}" > "${SDIR}/flist.${setname}"
144	if [ -n "${metalog}" ]; then
145		${setfilesonly} && msg "Creating ${setlistdir}/set.${setname}"
146		${AWK} -f "${rundir}/getdirs.awk" "${SDIR}/flist.${setname}" \
147		    | ${SORT} -u > "${SDIR}/flist.${setname}.full"
148		(
149			echo "/set uname=root gname=wheel"
150			${AWK} -f "${rundir}/join.awk" \
151				"${SDIR}/flist.${setname}.full" "${metalog}" \
152				    | ${SORT} -u
153			echo "./etc/mtree/set.${setname} type=file mode=0444"
154		) | ${MTREE} -C -k all -R time -N "${etcdir}" \
155		    > "${setlistdir}/set.${setname}"
156		# We deliberately do not add set.${setname} to ${metalog},
157		# because we depend on it as an input.
158	elif ! cmp -s "${SDIR}/flist.${setname}" \
159			"${setlistdir}/set.${setname}" >/dev/null 2>&1; then
160		rm -f "${setlistdir}/set.${setname}"
161		cp "${SDIR}/flist.${setname}" "${setlistdir}/set.${setname}"
162	fi
163done
164if ${setfilesonly}; then		# exit after creating the set lists
165	exit 0
166fi
167
168#
169# now build the tarfiles
170#
171
172GZIP=-9n		# for pax -z
173export GZIP
174es=0
175for setname in ${lists}; do
176	out="${setname}.tgz"
177	if [ -n "${installdir}" ]; then
178		msg "Copying set ${setname}"
179		( cd "${dest}"; \
180		    ${PAX} -O -rwpe -d -N"${etcdir}" ${metalog:+-M} \
181			"${installdir}" < "${setlistdir}/set.${setname}" )
182	else
183		if [ -n "${metalog}" -a "${tars}/${out}" -nt "${metalog}" ]
184		then
185			msg "${out} is up to date"
186			continue
187		fi
188		msg "Creating ${out}"
189		rm -f "${tars}/${out}"
190		TMPFILES="${TMPFILES} ${tars}/${out}.tmp"
191		( cd "${dest}"; \
192		    ${PAX} -O -w -d -z -N"${etcdir}" ${metalog:+-M} \
193			< "${setlistdir}/set.${setname}" ) \
194			> "${tars}/${out}.tmp" &&
195		mv "${tars}/${out}.tmp" "${tars}/${out}"
196	fi
197	es=$((${es} + $?))
198done
199if [ ${es} -gt 255 ]; then
200	es=255
201fi
202exit ${es}
203