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