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