maketars revision 1.57
1#!/bin/sh
2#
3# $NetBSD: maketars,v 1.57 2006/01/03 16:40:16 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 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
29
30usage()
31{
32	cat 1>&2 <<USAGE
33Usage: ${prog} [-b] [-x] [-i idir] [-a arch] [-m machine] [-s setsdir] [-S]
34	    [-M metalog] [-N etcdir] [-d dest] [-t targetdir] [setname ...]
35	-b		Make both netbsd and x11 lists
36	-x		Only make x11 lists
37		[Default: make netbsd lists]
38	-i idir		Install sets to idir instead of creating tar files
39	-a arch		Set arch (e.g, m68k, mipseb, mipsel, powerpc) [$MACHINE_ARCH]
40	-m machine	Set machine (e.g, amiga, i386, macppc) [$MACHINE]
41	-s setsdir	Directory to find sets [$setsdir]
42	-S		Exit after creating set files $dest/etc/mtree/set.*
43	-M metalog	metalog file
44	-N etcdir	etc dir for metalog use [$dest/etc]
45	-d dest		\$DESTDIR	[$dest]
46	-t targetdir	\$RELEASEDIR	[$tars]
47	[setname ...]	Sets to build 	[$lists]
48USAGE
49	exit 1
50}
51
52# handle args
53while getopts bxi:a:m:s:SM:N:d:t: ch; do
54	case ${ch} in
55	b)
56		lists="$nlists $xlists"
57		;;
58	x)
59		lists="$xlists"
60		;;
61	i)
62		installdir=${OPTARG}
63		;;
64	a)
65		MACHINE_ARCH=${OPTARG}
66		MACHINE_CPU=$(arch_to_cpu ${OPTARG})
67		;;
68	m)
69		MACHINE=${OPTARG}
70		;;
71	s)
72		setsdir=${OPTARG}
73		;;
74	S)
75		setfilesonly=true
76		;;
77	M)
78		metalog=${OPTARG}
79		;;
80	N)
81		etcdir=${OPTARG}
82		;;
83	d)
84		dest=${OPTARG}
85		;;
86	t)
87		tars=${OPTARG}
88		;;
89	*)
90		usage
91		;;
92	esac
93done
94shift $((${OPTIND} - 1))
95if [ -n "$installdir" ]; then	# if -i, remove etc & xetc from the default list
96	lists=$(echo $lists | ${SED} -e 's/ etc / /;s/ xetc / /')
97fi
98if [ -n "$*" ]; then
99	lists="$*"
100fi
101
102if [ -z "$tars" -a -z "$installdir" ]; then
103	echo 1>&2 \$RELEASEDIR must be set, or -i must be used
104	exit 1
105fi
106
107if [ -z "$dest" ]; then
108	echo 1>&2 \$DESTDIR must be set
109	exit 1
110fi
111: ${etcdir:=${dest}/etc}
112
113SDIR=$(${MKTEMP} -d /tmp/${prog}.XXXXXX)
114
115setlistdir=${dest}/etc/mtree
116
117cleanup()
118{
119	es=$?
120	/bin/rm -rf $SDIR
121	exit $es
122}
123trap cleanup 0 2 3 13		# EXIT INT QUIT PIPE
124
125#
126# build the setfiles
127#
128
129if [ -n "$metalog" ]; then
130	(
131		cat ${etcdir}/mtree/NetBSD.dist
132		echo "/unset all"
133		cat $metalog 2>/dev/null
134	) | ${MTREE} -C -k all -N ${etcdir} > $SDIR/metalog
135	rv=$?
136	if [ $rv -ne 0 ]; then
137		echo 1>&2 "${prog}: mtree parse of ${metalog} failed"
138		exit $rv
139	fi
140fi
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 && echo "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 $SDIR/metalog
152			echo "./etc/mtree/set.${setname} type=file mode=0444"
153		) > ${setlistdir}/set.${setname}
154	elif ! cmp -s ${SDIR}/flist.${setname} \
155			${setlistdir}/set.${setname} >/dev/null 2>&1; then
156		rm -f ${setlistdir}/set.${setname}
157		cp ${SDIR}/flist.${setname} ${setlistdir}/set.${setname}
158	fi
159done
160if $setfilesonly; then		# exit after creating the set lists
161	exit 0
162fi
163
164#
165# now build the tarfiles
166#
167
168GZIP=-9			# for pax -z
169export GZIP
170es=0
171for setname in $lists; do
172	out=$setname.tgz
173	if [ -n "$installdir" ]; then
174		echo "Copying set $setname"
175		( cd $dest ; \
176		    ${PAX} -O -rwpe -d -N${etcdir} ${metalog:+-M} \
177			${installdir} < ${setlistdir}/set.${setname} )
178	else
179		if [ -n "$metalog" -a $tars/$out -nt "$metalog" ]; then
180			echo "$out is up to date"
181			continue
182		fi
183		echo "Creating $out"
184		rm -f ${tars}/$out
185		( cd $dest ; \
186		    ${PAX} -O -w -d -z -N${etcdir} ${metalog:+-M} \
187			< ${setlistdir}/set.${setname} ) > ${tars}/$out.tmp &&
188		mv ${tars}/$out.tmp ${tars}/$out
189	fi
190	es=$(($es + $?))
191done
192if [ $es -gt 255 ] ; then
193	es=255
194fi
195exit $es
196