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