Home | History | Annotate | Line # | Download | only in sets
maketars revision 1.82
      1   1.2       gwr #!/bin/sh
      2   1.2       gwr #
      3  1.82    martin # $NetBSD: maketars,v 1.82 2015/05/26 15:46:01 martin 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.81    martin #	[-M metalog] [-N etcdir] [-F setlistsdir] [-d destdir]
      8  1.81    martin #	[-t tardir] [setname ...]
      9  1.35     lukem #
     10  1.75  christos # The default sets are "base comp debug etc games man misc tests text"
     11  1.76  christos # The X sets are "xbase xcomp xdebug xetc xfont xserver"
     12  1.70  uebayasi # The extsrc sets are "extbase extcomp extetc"
     13  1.35     lukem #
     14  1.35     lukem # If '-i installdir' is given, copy the given sets to installdir
     15  1.35     lukem # (using pax -rw ...) instead of creating tar files.
     16  1.70  uebayasi # In this case, remove "etc", "xetc", and "extetc" from the list of default sets.
     17   1.2       gwr #
     18   1.2       gwr 
     19  1.58       apb prog="${0##*/}"
     20  1.56       apb rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
     21  1.56       apb . "${rundir}/sets.subr"
     22  1.41     lukem 
     23   1.2       gwr # set defaults
     24  1.72    cegger lists=
     25  1.58       apb tars="${RELEASEDIR}"
     26  1.58       apb dest="${DESTDIR}"
     27  1.18     lukem metalog=
     28  1.28     lukem installdir=
     29  1.30     lukem etcdir=
     30  1.81    martin setlistdir=
     31  1.50     lukem setfilesonly=false
     32  1.64     lukem quiet=false
     33  1.77  christos skipkeys=time,md5,sha1,sha384,sha512,rmd160,cksum
     34   1.2       gwr 
     35  1.47     lukem usage()
     36  1.47     lukem {
     37  1.47     lukem 	cat 1>&2 <<USAGE
     38  1.81    martin Usage: ${prog} [-L base,x,ext] [-b] [-x] [-y] [-i idir] [-a arch] [-m machine]
     39  1.81    martin 	    [-s setsdir] [-S] [-M metalog] [-N etcdir] [-F setlistdir]
     40  1.81    martin 	    [-d dest] [-t targetdir] [setname ...]
     41  1.70  uebayasi 	-L base,x,ext	Make specified lists
     42  1.50     lukem 	-b		Make both netbsd and x11 lists
     43  1.50     lukem 	-x		Only make x11 lists
     44  1.50     lukem 		[Default: make netbsd lists]
     45  1.70  uebayasi 	-y		Only make extsrc lists
     46  1.70  uebayasi 		[Default: make netbsd lists]
     47  1.50     lukem 	-i idir		Install sets to idir instead of creating tar files
     48  1.58       apb 	-a arch		Set arch (e.g, m68k, mipseb, mipsel, powerpc) [${MACHINE_ARCH}]
     49  1.58       apb 	-m machine	Set machine (e.g, amiga, i386, macppc) [${MACHINE}]
     50  1.64     lukem 	-q		Quiet operation
     51  1.58       apb 	-s setsdir	Directory to find sets [${setsdir}]
     52  1.81    martin 	-F setlistdir	output directory for generated set lists [${dest}/etc/mtree/]
     53  1.58       apb 	-S		Exit after creating set files ${dest}/etc/mtree/set.*
     54  1.18     lukem 	-M metalog	metalog file
     55  1.58       apb 	-N etcdir	etc dir for metalog use [${dest}/etc]
     56  1.58       apb 	-d dest		\${DESTDIR}	[${dest}]
     57  1.58       apb 	-t targetdir	\${RELEASEDIR}	[${tars}]
     58  1.58       apb 	[setname ...]	Sets to build 	[${lists}]
     59   1.9     lukem USAGE
     60  1.47     lukem 	exit 1
     61  1.47     lukem }
     62  1.47     lukem 
     63  1.64     lukem msg()
     64  1.64     lukem {
     65  1.64     lukem 	$quiet || echo $*
     66  1.64     lukem }
     67  1.64     lukem 
     68  1.47     lukem # handle args
     69  1.81    martin while getopts L:bxyi:a:m:qs:F:SM:N:d:t: ch; do
     70  1.47     lukem 	case ${ch} in
     71  1.70  uebayasi 	L)
     72  1.72    cegger 		save_IFS="${IFS}"
     73  1.72    cegger 		IFS=,
     74  1.72    cegger 		for _list in ${OPTARG}; do
     75  1.72    cegger 			case $_list in
     76  1.72    cegger 			base)	lists="${lists} ${nlists}" ;;
     77  1.72    cegger 			x)	lists="${lists} ${xlists}" ;;
     78  1.72    cegger 			ext)	lists="${lists} ${extlists}" ;;
     79  1.72    cegger 			esac
     80  1.72    cegger 		done
     81  1.72    cegger 		IFS="${save_IFS}"
     82  1.70  uebayasi 		;;
     83  1.70  uebayasi 	# backward compat
     84  1.47     lukem 	b)
     85  1.58       apb 		lists="${nlists} ${xlists}"
     86  1.47     lukem 		;;
     87  1.47     lukem 	x)
     88  1.58       apb 		lists="${xlists}"
     89  1.47     lukem 		;;
     90  1.70  uebayasi 	y)
     91  1.70  uebayasi 		lists="${extlists}"
     92  1.70  uebayasi 		;;
     93  1.47     lukem 	i)
     94  1.58       apb 		installdir="${OPTARG}"
     95  1.47     lukem 		;;
     96  1.47     lukem 	a)
     97  1.58       apb 		MACHINE_ARCH="${OPTARG}"
     98  1.58       apb 		MACHINE_CPU="$(arch_to_cpu "${OPTARG}")"
     99  1.47     lukem 		;;
    100  1.47     lukem 	m)
    101  1.58       apb 		MACHINE="${OPTARG}"
    102  1.47     lukem 		;;
    103  1.64     lukem 	q)
    104  1.64     lukem 		quiet=true
    105  1.64     lukem 		;;
    106  1.47     lukem 	s)
    107  1.58       apb 		setsdir="${OPTARG}"
    108  1.47     lukem 		;;
    109  1.81    martin 	F)
    110  1.81    martin 		setlistdir="${OPTARG}"
    111  1.81    martin 		;;
    112  1.50     lukem 	S)
    113  1.50     lukem 		setfilesonly=true
    114  1.50     lukem 		;;
    115  1.47     lukem 	M)
    116  1.58       apb 		metalog="${OPTARG}"
    117  1.47     lukem 		;;
    118  1.47     lukem 	N)
    119  1.58       apb 		etcdir="${OPTARG}"
    120  1.47     lukem 		;;
    121  1.47     lukem 	d)
    122  1.58       apb 		dest="${OPTARG}"
    123  1.47     lukem 		;;
    124  1.47     lukem 	t)
    125  1.58       apb 		tars="${OPTARG}"
    126   1.9     lukem 		;;
    127   1.9     lukem 	*)
    128  1.47     lukem 		usage
    129   1.9     lukem 		;;
    130   1.2       gwr 	esac
    131   1.2       gwr done
    132  1.47     lukem shift $((${OPTIND} - 1))
    133  1.70  uebayasi if [ -n "${installdir}" ]; then	# if -i, remove etc + xetc + extetc from the default list
    134  1.70  uebayasi 	lists="$(echo ${lists} | ${SED} -e 's/ etc / /;s/ xetc / /;s/ extetc / /')"
    135  1.28     lukem fi
    136  1.10      ross if [ -n "$*" ]; then
    137  1.10      ross 	lists="$*"
    138   1.9     lukem fi
    139   1.1       cgd 
    140  1.58       apb if [ -z "${tars}" -a -z "${installdir}" ]; then
    141  1.60       apb 	echo >&2 "${prog}: \${RELEASEDIR} must be set, or -i must be used"
    142   1.1       cgd 	exit 1
    143   1.9     lukem fi
    144   1.1       cgd 
    145  1.58       apb if [ -z "${dest}" ]; then
    146  1.60       apb 	echo >&2 "${prog}: \${DESTDIR} must be set"
    147   1.1       cgd 	exit 1
    148   1.9     lukem fi
    149  1.58       apb : ${etcdir:="${dest}/etc"}
    150   1.1       cgd 
    151  1.58       apb SDIR="$(${MKTEMP} -d "/tmp/${prog}.XXXXXX")"
    152  1.63     lukem TMPFILES=
    153  1.20     bjh21 
    154  1.81    martin : ${setlistdir:="${dest}/etc/mtree"}
    155  1.50     lukem 
    156  1.38       erh cleanup()
    157  1.38       erh {
    158  1.44       dsl 	es=$?
    159  1.63     lukem 	/bin/rm -rf "${SDIR}" ${TMPFILES}
    160  1.63     lukem 	trap - 0
    161  1.58       apb 	exit ${es}
    162  1.38       erh }
    163  1.38       erh trap cleanup 0 2 3 13		# EXIT INT QUIT PIPE
    164  1.18     lukem 
    165  1.50     lukem #
    166  1.50     lukem # build the setfiles
    167  1.50     lukem #
    168  1.50     lukem 
    169  1.58       apb for setname in ${lists}; do
    170  1.58       apb 	${HOST_SH} "${setsdir}/makeflist" -a "${MACHINE_ARCH}" -m "${MACHINE}" \
    171  1.69       apb 	    -s "${setsdir}" "${setname}" > "${SDIR}/flist.${setname}" \
    172  1.69       apb 	    || exit 1
    173  1.73  uebayasi 	if [ ! -s "${SDIR}/flist.${setname}" ]; then
    174  1.71       apb 		echo >&2 "makeflist output is empty for ${setname}"
    175  1.71       apb 		exit 1
    176  1.71       apb 	fi
    177  1.77  christos 	${setfilesonly} && msg "Creating ${setlistdir}/set.${setname}"
    178  1.58       apb 	if [ -n "${metalog}" ]; then
    179  1.58       apb 		${AWK} -f "${rundir}/getdirs.awk" "${SDIR}/flist.${setname}" \
    180  1.69       apb 		    > "${SDIR}/flist.${setname}.full" \
    181  1.69       apb 		    || exit 1
    182  1.23     lukem 		(
    183  1.23     lukem 			echo "/set uname=root gname=wheel"
    184  1.58       apb 			${AWK} -f "${rundir}/join.awk" \
    185  1.68       apb 				"${SDIR}/flist.${setname}.full" "${metalog}"
    186  1.50     lukem 			echo "./etc/mtree/set.${setname} type=file mode=0444"
    187  1.77  christos 		) | ${MTREE} -CS -k all -R "${skipkeys}" -N "${etcdir}" \
    188  1.69       apb 		    > "${setlistdir}/set.${setname}" \
    189  1.69       apb 		    || exit 1
    190  1.59       apb 		# We deliberately do not add set.${setname} to ${metalog},
    191  1.59       apb 		# because we depend on it as an input.
    192  1.77  christos 	else
    193  1.78  christos 		${MTREE} -c -p "${dest}" -k all -R "${skipkeys}" \
    194  1.77  christos 		    -O "${SDIR}/flist.${setname}" | ${MTREE} -C -k all > \
    195  1.77  christos 		    "${setlistdir}/set.${setname}"
    196  1.18     lukem 	fi
    197  1.50     lukem done
    198  1.58       apb if ${setfilesonly}; then		# exit after creating the set lists
    199  1.50     lukem 	exit 0
    200  1.50     lukem fi
    201  1.18     lukem 
    202  1.78  christos runpax() {
    203  1.78  christos 	local s="$1"
    204  1.78  christos 	shift
    205  1.80  christos 	(cd "${dest}" && 
    206  1.80  christos 	    ${PAX} -dOw -N"${etcdir}" -M "$@" < "${setlistdir}/set.${s}")
    207  1.78  christos }
    208  1.78  christos 
    209  1.50     lukem #
    210  1.50     lukem # now build the tarfiles
    211  1.50     lukem #
    212  1.50     lukem 
    213  1.67     perry GZIP=-9n		# for pax -z
    214  1.50     lukem export GZIP
    215  1.50     lukem es=0
    216  1.82    martin preserve=
    217  1.82    martin if [ -n "${metalog}" ]; then
    218  1.82    martin 	preserve="-pe"
    219  1.82    martin fi
    220  1.82    martin 
    221  1.72    cegger for setname in ${lists:-${nlists}}; do
    222  1.58       apb 	out="${setname}.tgz"
    223  1.58       apb 	if [ -n "${installdir}" ]; then
    224  1.64     lukem 		msg "Copying set ${setname}"
    225  1.82    martin 		runpax "${setname}" -r ${preserve} "${installdir}"
    226  1.28     lukem 	else
    227  1.58       apb 		if [ -n "${metalog}" -a "${tars}/${out}" -nt "${metalog}" ]
    228  1.58       apb 		then
    229  1.64     lukem 			msg "${out} is up to date"
    230  1.50     lukem 			continue
    231  1.50     lukem 		fi
    232  1.64     lukem 		msg "Creating ${out}"
    233  1.58       apb 		rm -f "${tars}/${out}"
    234  1.63     lukem 		TMPFILES="${TMPFILES} ${tars}/${out}.tmp"
    235  1.79  christos 		runpax "${setname}" -z --use-compress-program \
    236  1.78  christos 		    ${COMPRESS_PROGRAM} > "${tars}/${out}.tmp" &&
    237  1.58       apb 		mv "${tars}/${out}.tmp" "${tars}/${out}"
    238  1.28     lukem 	fi
    239  1.58       apb 	es=$((${es} + $?))
    240   1.2       gwr done
    241  1.61       apb if [ ${es} -gt 255 ]; then
    242  1.38       erh 	es=255
    243  1.38       erh fi
    244  1.58       apb exit ${es}
    245