regpkgset revision 1.9
11.1Sagc#! /bin/sh
21.1Sagc#
31.9Sapb# $NetBSD: regpkgset,v 1.9 2007/02/05 18:26:01 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.8Sapb: ${TARGET_ENDIANNESS:="$(arch_to_endian "${MACHINE_ARCH}")"}
591.7Sapbexport TARGET_ENDIANNESS
601.7Sapb
611.6Sapbbomb()
621.6Sapb{
631.6Sapb	kill ${toppid}		# in case we were invoked from a subshell
641.6Sapb	exit 1
651.6Sapb}
661.3Serh
671.6Sapb# A literal newline
681.6Sapbnl='
691.6Sapb'
701.1Sagc
711.6Sapb#
721.6Sapb# cleanup() deletes temporary files.
731.6Sapb#
741.6Sapbes=0
751.8Sapbcleanup()
761.6Sapb{
771.6Sapb	trap - 0
781.6Sapb	[ x"${BUILD_INFO_CACHE}" != x ] && rm -f "${BUILD_INFO_CACHE}"
791.6Sapb	exit ${es}
801.6Sapb}
811.6Sapbtrap 'es=128; cleanup' 1 2 3 13 15	# HUP INT QUIT PIPE TERM
821.6Sapbtrap 'es=$?; cleanup' 0 		# EXIT
831.6Sapb
841.6Sapb#
851.6Sapb# Parse command line args.
861.6Sapb#
871.6Sapbverbose=false
881.6Sapbquiet=false
891.6Sapbforce=false
901.6Sapballowmissing=false
911.6Sapbupdate=false
921.6Sapbcache=false
931.6Sapbpkgdir=""
941.6Sapbmetalog=""
951.6Sapbetcdir=""
961.6Sapball_options=""
971.1Sagcwhile [ $# -gt 1 ]; do
981.6Sapb	# XXX: ${all_options} doesn't correctly handle args with
991.6Sapb	# embedded shell special characters.
1001.5Sapb	case "$1" in
1011.8Sapb	-q)	quiet=true; verbose=false ;;
1021.8Sapb	-v)	verbose=true; quiet=false ;;
1031.6Sapb	-f)	force=true ;;
1041.6Sapb	-m)	allowmissing=true ;;
1051.6Sapb	-u)	update=true ;;
1061.6Sapb	-c)	cache=true ;;
1071.8Sapb	-d)	DESTDIR="$2"; all_options="${all_options} $1"; shift ;;
1081.6Sapb	-d*)	DESTDIR="${1#-?}" ;;
1091.8Sapb	-t)	pkgdir="$2"; all_options="${all_options} $1"; shift ;;
1101.6Sapb	-t*)	pkgdir="${1#-?}" ;;
1111.8Sapb	-M)	metalog="$2"; all_options="${all_options} $1"; shift ;;
1121.6Sapb	-M*)	metalog="${1#-?}" ;;
1131.8Sapb	-N)	etcdir="$2"; all_options="${all_options} $1"; shift ;;
1141.6Sapb	-N*)	etcdir="${1#-?}" ;;
1151.8Sapb	-*)	echo "Usage: regpkgset [options] set ..."; bomb ;;
1161.1Sagc	*)	break ;;
1171.1Sagc	esac
1181.6Sapb	all_options="${all_options} $1"
1191.1Sagc	shift
1201.1Sagcdone
1211.6Sapbexport DESTDIR
1221.1Sagc
1231.1Sagcif [ $# -lt 1 ]; then
1241.6Sapb	echo "Usage: regpkgset [options] set ..."
1251.6Sapb	bomb
1261.1Sagcfi
1271.1Sagc
1281.5Sapbcase "$1" in
1291.1Sagcall)	list="base comp etc games man misc text" ;;
1301.5Sapb*)	list="$*" ;;
1311.1Sagcesac
1321.1Sagc
1331.8Sapbif ${cache}; then
1341.6Sapb	BUILD_INFO_CACHE="$(${MKTEMP} "/var/tmp/${prog}-BUILD_INFO.XXXXXX")"
1351.2Sdyoung	export BUILD_INFO_CACHE
1361.2Sdyoung	{
1371.6Sapb	# These variables describe the build
1381.6Sapb	# environment, not the target.
1391.5Sapb	echo "OPSYS=$(${UNAME} -s)"
1401.5Sapb	echo "OS_VERSION=$(${UNAME} -r)"
1411.9Sapb	${MAKE} -B -f- all <<EOF
1421.2Sdyoung.include <bsd.own.mk>
1431.2Sdyoungall:
1441.2Sdyoung	@echo OBJECT_FMT=${OBJECT_FMT}
1451.2Sdyoung	@echo MACHINE_ARCH=${MACHINE_ARCH}
1461.2Sdyoung	@echo MACHINE_GNU_ARCH=${MACHINE_GNU_ARCH}
1471.2SdyoungEOF
1481.6Sapb	# XXX: what's the point of reporting _PKGTOOLS_VER
1491.6Sapb	# when we roll everything by hand without using
1501.6Sapb	# the pkg tools?
1511.5Sapb	echo "_PKGTOOLS_VER=$(${PKG_CREATE} -V)"
1521.5Sapb	} > "${BUILD_INFO_CACHE}"
1531.2Sdyoungfi
1541.2Sdyoung
1551.6Sapb#
1561.6Sapb# For each pkgset mentioned in ${list}, get a list of all pkgs in the pkgset.
1571.6Sapb#
1581.6Sapb# Sort all the pkgs into dependency order (with prerequisite pkgs before
1591.6Sapb# pkgs that depend on them).
1601.6Sapb#
1611.6Sapb# Invoke ${rundir}/regpkg for each pkg, taking care to do it in dependency
1621.6Sapb# order.  If there were any pkgs for which we failed to find dependency
1631.6Sapb# information, handle them at the end.
1641.6Sapb#
1651.8Sapbpkgs="$(for pkgset in ${list}; do
1661.6Sapb		${HOST_SH} "${rundir}/listpkgs" "${pkgset}" || bomb
1671.8Sapb	 done)"
1681.8Sapbtsort_input="$(${AWK} '{print $2 " " $1}' <"${rundir}/deps" || bomb)"
1691.8Sapbtsort_output="$(echo "${tsort_input}" | ${TSORT} || bomb)"
1701.8Sapbfor pkg in ${tsort_output}; do
1711.6Sapb	case "${nl}${pkgs}${nl}" in
1721.6Sapb	*"${nl}${pkg}${nl}"*)
1731.6Sapb		# We want this pkg.
1741.6Sapb		pkgset="${pkg%%-*}"
1751.6Sapb		${verbose} && echo "${prog}: registering ${pkg}"
1761.6Sapb		${HOST_SH} "${rundir}/regpkg" ${all_options} \
1771.6Sapb			"${pkgset}" "${pkg}" || bomb
1781.6Sapb		;;
1791.6Sapb	*)	# pkg is mentioned in ${tsort_output} but not in ${pkgs}.
1801.6Sapb		# We do not want this pkg.
1811.6Sapb		;;
1821.6Sapb	esac
1831.6Sapbdone
1841.8Sapbfor pkg in ${pkgs}; do
1851.6Sapb	case "${nl}${tsort_output}${nl}" in
1861.6Sapb	*"${nl}${pkg}${nl}"*)
1871.6Sapb		# pkg was in the tsort output, so it would have been
1881.6Sapb		# handled above.
1891.6Sapb		;;
1901.6Sapb	*)	# This pkg was not in the tsort output.
1911.6Sapb		# This is probably an error, but process the
1921.6Sapb		# pkg anyway.
1931.6Sapb		echo >&2 "${prog}: WARNING: ${pkg} is not mentioned in deps file"
1941.6Sapb		pkgset="${pkg%%-*}"
1951.6Sapb		${verbose} && echo "${prog}: registering ${pkg}"
1961.6Sapb		${HOST_SH} "${rundir}/regpkg" ${all_options} \
1971.6Sapb			"${pkgset}" "${pkg}" || bomb
1981.6Sapb		;;
1991.6Sapb	esac
2001.1Sagcdone
2011.1Sagc
2021.1Sagcexit 0
203