regpkgset revision 1.6
11.1Sagc#! /bin/sh
21.1Sagc#
31.6Sapb# $NetBSD: regpkgset,v 1.6 2006/01/04 14:18:00 apb Exp $
41.1Sagc#
51.1Sagc# Copyright (c) 2003 Alistair G. Crooks.  All rights reserved.
61.1Sagc#
71.1Sagc# Redistribution and use in source and binary forms, with or without
81.1Sagc# modification, are permitted provided that the following conditions
91.1Sagc# are met:
101.1Sagc# 1. Redistributions of source code must retain the above copyright
111.1Sagc#    notice, this list of conditions and the following disclaimer.
121.1Sagc# 2. Redistributions in binary form must reproduce the above copyright
131.1Sagc#    notice, this list of conditions and the following disclaimer in the
141.1Sagc#    documentation and/or other materials provided with the distribution.
151.1Sagc# 3. All advertising materials mentioning features or use of this software
161.1Sagc#    must display the following acknowledgement:
171.1Sagc#	This product includes software developed by Alistair G. Crooks.
181.1Sagc#	for the NetBSD project.
191.1Sagc# 4. The name of the author may not be used to endorse or promote
201.1Sagc#    products derived from this software without specific prior written
211.1Sagc#    permission.
221.1Sagc#
231.1Sagc# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
241.1Sagc# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
251.1Sagc# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
261.1Sagc# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
271.1Sagc# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
281.1Sagc# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
291.1Sagc# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
301.1Sagc# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
311.1Sagc# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
321.1Sagc# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
331.1Sagc# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
341.1Sagc#
351.1Sagc
361.6Sapb# Usage: regpkgset [options] set
371.6Sapb#
381.6Sapb# Options:
391.6Sapb#   -q		Quiet.
401.6Sapb#   -v		Verbose.
411.6Sapb#   -f		Force.
421.6Sapb#   -m		Ignore errors from missing files.
431.6Sapb#   -u		Update.
441.6Sapb#   -c		Cache some information in ${BUILD_INFO_CACHE}.
451.6Sapb#   -d destdir	Sets DESTDIR.
461.6Sapb#   -t binpkgdir Create a binary package (in *.tgz format) in the
471.6Sapb#		specified directory.  Without this option, a binary
481.6Sapb#		package is not created.
491.6Sapb#   -M metalog	Use the specified metalog file to override file
501.6Sapb#		or directory attributes when creating a binary package.
511.6Sapb#   -N etcdir	Use the specified directory for passwd and group files.
521.1Sagc
531.6Sapbprog="${0##*/}"
541.6Sapbtoppid=$$
551.5Sapbrundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
561.6Sapb. "${rundir}/sets.subr"
571.6Sapb
581.6Sapbbomb()
591.6Sapb{
601.6Sapb	kill ${toppid}		# in case we were invoked from a subshell
611.6Sapb	exit 1
621.6Sapb}
631.3Serh
641.6Sapb# A literal newline
651.6Sapbnl='
661.6Sapb'
671.1Sagc
681.6Sapb#
691.6Sapb# cleanup() deletes temporary files.
701.6Sapb#
711.6Sapbes=0
721.6Sapbcleanup ()
731.6Sapb{
741.6Sapb	trap - 0
751.6Sapb	[ x"${BUILD_INFO_CACHE}" != x ] && rm -f "${BUILD_INFO_CACHE}"
761.6Sapb	exit ${es}
771.6Sapb}
781.6Sapbtrap 'es=128; cleanup' 1 2 3 13 15	# HUP INT QUIT PIPE TERM
791.6Sapbtrap 'es=$?; cleanup' 0 		# EXIT
801.6Sapb
811.6Sapb#
821.6Sapb# Parse command line args.
831.6Sapb#
841.6Sapbverbose=false
851.6Sapbquiet=false
861.6Sapbforce=false
871.6Sapballowmissing=false
881.6Sapbupdate=false
891.6Sapbcache=false
901.6Sapbpkgdir=""
911.6Sapbmetalog=""
921.6Sapbetcdir=""
931.6Sapball_options=""
941.1Sagcwhile [ $# -gt 1 ]; do
951.6Sapb	# XXX: ${all_options} doesn't correctly handle args with
961.6Sapb	# embedded shell special characters.
971.5Sapb	case "$1" in
981.6Sapb	-q)	quiet=true ; verbose=false ;;
991.6Sapb	-v)	verbose=true ; quiet=false ;;
1001.6Sapb	-f)	force=true ;;
1011.6Sapb	-m)	allowmissing=true ;;
1021.6Sapb	-u)	update=true ;;
1031.6Sapb	-c)	cache=true ;;
1041.6Sapb	-d)	DESTDIR="$2" ; all_options="${all_options} $1" ; shift ;;
1051.6Sapb	-d*)	DESTDIR="${1#-?}" ;;
1061.6Sapb	-t)	pkgdir="$2" ; all_options="${all_options} $1" ; shift ;;
1071.6Sapb	-t*)	pkgdir="${1#-?}" ;;
1081.6Sapb	-M)	metalog="$2" ; all_options="${all_options} $1" ; shift ;;
1091.6Sapb	-M*)	metalog="${1#-?}" ;;
1101.6Sapb	-N)	etcdir="$2" ; all_options="${all_options} $1" ; shift ;;
1111.6Sapb	-N*)	etcdir="${1#-?}" ;;
1121.6Sapb	-*)	echo "Usage: regpkgset [options] set ..." ; bomb ;;
1131.1Sagc	*)	break ;;
1141.1Sagc	esac
1151.6Sapb	all_options="${all_options} $1"
1161.1Sagc	shift
1171.1Sagcdone
1181.6Sapbexport DESTDIR
1191.1Sagc
1201.1Sagcif [ $# -lt 1 ]; then
1211.6Sapb	echo "Usage: regpkgset [options] set ..."
1221.6Sapb	bomb
1231.1Sagcfi
1241.1Sagc
1251.5Sapbcase "$1" in
1261.1Sagcall)	list="base comp etc games man misc text" ;;
1271.5Sapb*)	list="$*" ;;
1281.1Sagcesac
1291.1Sagc
1301.6Sapbif ${cache} ; then
1311.6Sapb	BUILD_INFO_CACHE="$(${MKTEMP} "/var/tmp/${prog}-BUILD_INFO.XXXXXX")"
1321.2Sdyoung	export BUILD_INFO_CACHE
1331.2Sdyoung	{
1341.6Sapb	# These variables describe the build
1351.6Sapb	# environment, not the target.
1361.5Sapb	echo "OPSYS=$(${UNAME} -s)"
1371.5Sapb	echo "OS_VERSION=$(${UNAME} -r)"
1381.4Sapb	${MAKE} -f- all <<EOF
1391.2Sdyoung.include <bsd.own.mk>
1401.2Sdyoungall:
1411.2Sdyoung	@echo OBJECT_FMT=${OBJECT_FMT}
1421.2Sdyoung	@echo MACHINE_ARCH=${MACHINE_ARCH}
1431.2Sdyoung	@echo MACHINE_GNU_ARCH=${MACHINE_GNU_ARCH}
1441.2SdyoungEOF
1451.6Sapb	# XXX: what's the point of reporting _PKGTOOLS_VER
1461.6Sapb	# when we roll everything by hand without using
1471.6Sapb	# the pkg tools?
1481.5Sapb	echo "_PKGTOOLS_VER=$(${PKG_CREATE} -V)"
1491.5Sapb	} > "${BUILD_INFO_CACHE}"
1501.2Sdyoungfi
1511.2Sdyoung
1521.6Sapb#
1531.6Sapb# For each pkgset mentioned in ${list}, get a list of all pkgs in the pkgset.
1541.6Sapb#
1551.6Sapb# Sort all the pkgs into dependency order (with prerequisite pkgs before
1561.6Sapb# pkgs that depend on them).
1571.6Sapb#
1581.6Sapb# Invoke ${rundir}/regpkg for each pkg, taking care to do it in dependency
1591.6Sapb# order.  If there were any pkgs for which we failed to find dependency
1601.6Sapb# information, handle them at the end.
1611.6Sapb#
1621.6Sapbpkgs="$( for pkgset in ${list}; do
1631.6Sapb		${HOST_SH} "${rundir}/listpkgs" "${pkgset}" || bomb
1641.6Sapb	 done )"
1651.6Sapbtsort_input="$( ${AWK} '{print $2 " " $1}' <"${rundir}/deps" || bomb )"
1661.6Sapbtsort_output="$( echo "${tsort_input}" | ${TSORT} || bomb )"
1671.6Sapbfor pkg in ${tsort_output} ; do
1681.6Sapb	case "${nl}${pkgs}${nl}" in
1691.6Sapb	*"${nl}${pkg}${nl}"*)
1701.6Sapb		# We want this pkg.
1711.6Sapb		pkgset="${pkg%%-*}"
1721.6Sapb		${verbose} && echo "${prog}: registering ${pkg}"
1731.6Sapb		${HOST_SH} "${rundir}/regpkg" ${all_options} \
1741.6Sapb			"${pkgset}" "${pkg}" || bomb
1751.6Sapb		;;
1761.6Sapb	*)	# pkg is mentioned in ${tsort_output} but not in ${pkgs}.
1771.6Sapb		# We do not want this pkg.
1781.6Sapb		;;
1791.6Sapb	esac
1801.6Sapbdone
1811.6Sapbfor pkg in ${pkgs} ; do
1821.6Sapb	case "${nl}${tsort_output}${nl}" in
1831.6Sapb	*"${nl}${pkg}${nl}"*)
1841.6Sapb		# pkg was in the tsort output, so it would have been
1851.6Sapb		# handled above.
1861.6Sapb		;;
1871.6Sapb	*)	# This pkg was not in the tsort output.
1881.6Sapb		# This is probably an error, but process the
1891.6Sapb		# pkg anyway.
1901.6Sapb		echo >&2 "${prog}: WARNING: ${pkg} is not mentioned in deps file"
1911.6Sapb		pkgset="${pkg%%-*}"
1921.6Sapb		${verbose} && echo "${prog}: registering ${pkg}"
1931.6Sapb		${HOST_SH} "${rundir}/regpkg" ${all_options} \
1941.6Sapb			"${pkgset}" "${pkg}" || bomb
1951.6Sapb		;;
1961.6Sapb	esac
1971.1Sagcdone
1981.1Sagc
1991.1Sagcexit 0
200