Home | History | Annotate | Line # | Download | only in sets
maketars revision 1.61.10.1
      1        1.2    gwr #!/bin/sh
      2        1.2    gwr #
      3  1.61.10.1   matt # $NetBSD: maketars,v 1.61.10.1 2008/01/09 01:28:13 matt 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.61.10.1   matt # The default sets are "base comp etc games man misc tests 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.60    apb 	echo >&2 "${prog}: \${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.60    apb 	echo >&2 "${prog}: \${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 for setname in ${lists}; do
    130       1.58    apb 	${HOST_SH} "${setsdir}/makeflist" -a "${MACHINE_ARCH}" -m "${MACHINE}" \
    131       1.58    apb 	    -s "${setsdir}" "${setname}" > "${SDIR}/flist.${setname}"
    132       1.58    apb 	if [ -n "${metalog}" ]; then
    133       1.58    apb 		${setfilesonly} && echo "Creating ${setlistdir}/set.${setname}"
    134       1.58    apb 		${AWK} -f "${rundir}/getdirs.awk" "${SDIR}/flist.${setname}" \
    135       1.58    apb 		    | ${SORT} -u > "${SDIR}/flist.${setname}.full"
    136       1.23  lukem 		(
    137       1.23  lukem 			echo "/set uname=root gname=wheel"
    138       1.58    apb 			${AWK} -f "${rundir}/join.awk" \
    139       1.59    apb 				"${SDIR}/flist.${setname}.full" "${metalog}"
    140       1.50  lukem 			echo "./etc/mtree/set.${setname} type=file mode=0444"
    141       1.58    apb 		) > "${setlistdir}/set.${setname}"
    142       1.59    apb 		# We deliberately do not add set.${setname} to ${metalog},
    143       1.59    apb 		# because we depend on it as an input.
    144       1.58    apb 	elif ! cmp -s "${SDIR}/flist.${setname}" \
    145       1.58    apb 			"${setlistdir}/set.${setname}" >/dev/null 2>&1; then
    146       1.58    apb 		rm -f "${setlistdir}/set.${setname}"
    147       1.58    apb 		cp "${SDIR}/flist.${setname}" "${setlistdir}/set.${setname}"
    148       1.18  lukem 	fi
    149       1.50  lukem done
    150       1.58    apb if ${setfilesonly}; then		# exit after creating the set lists
    151       1.50  lukem 	exit 0
    152       1.50  lukem fi
    153       1.18  lukem 
    154       1.50  lukem #
    155       1.50  lukem # now build the tarfiles
    156       1.50  lukem #
    157       1.50  lukem 
    158       1.50  lukem GZIP=-9			# for pax -z
    159       1.50  lukem export GZIP
    160       1.50  lukem es=0
    161       1.58    apb for setname in ${lists}; do
    162       1.58    apb 	out="${setname}.tgz"
    163       1.58    apb 	if [ -n "${installdir}" ]; then
    164       1.58    apb 		echo "Copying set ${setname}"
    165       1.61    apb 		( cd "${dest}"; \
    166       1.58    apb 		    ${PAX} -O -rwpe -d -N"${etcdir}" ${metalog:+-M} \
    167       1.58    apb 			"${installdir}" < "${setlistdir}/set.${setname}" )
    168       1.28  lukem 	else
    169       1.58    apb 		if [ -n "${metalog}" -a "${tars}/${out}" -nt "${metalog}" ]
    170       1.58    apb 		then
    171       1.58    apb 			echo "${out} is up to date"
    172       1.50  lukem 			continue
    173       1.50  lukem 		fi
    174       1.58    apb 		echo "Creating ${out}"
    175       1.58    apb 		rm -f "${tars}/${out}"
    176       1.61    apb 		( cd "${dest}"; \
    177       1.58    apb 		    ${PAX} -O -w -d -z -N"${etcdir}" ${metalog:+-M} \
    178       1.58    apb 			< "${setlistdir}/set.${setname}" ) \
    179       1.58    apb 			> "${tars}/${out}.tmp" &&
    180       1.58    apb 		mv "${tars}/${out}.tmp" "${tars}/${out}"
    181       1.28  lukem 	fi
    182       1.58    apb 	es=$((${es} + $?))
    183        1.2    gwr done
    184       1.61    apb if [ ${es} -gt 255 ]; then
    185       1.38    erh 	es=255
    186       1.38    erh fi
    187       1.58    apb exit ${es}
    188