Home | History | Annotate | Line # | Download | only in sets
regpkgset revision 1.9
      1  1.1     agc #! /bin/sh
      2  1.1     agc #
      3  1.9     apb # $NetBSD: regpkgset,v 1.9 2007/02/05 18:26:01 apb Exp $
      4  1.1     agc #
      5  1.1     agc # Copyright (c) 2003 Alistair G. Crooks.  All rights reserved.
      6  1.1     agc #
      7  1.1     agc # Redistribution and use in source and binary forms, with or without
      8  1.1     agc # modification, are permitted provided that the following conditions
      9  1.1     agc # are met:
     10  1.1     agc # 1. Redistributions of source code must retain the above copyright
     11  1.1     agc #    notice, this list of conditions and the following disclaimer.
     12  1.1     agc # 2. Redistributions in binary form must reproduce the above copyright
     13  1.1     agc #    notice, this list of conditions and the following disclaimer in the
     14  1.1     agc #    documentation and/or other materials provided with the distribution.
     15  1.1     agc # 3. All advertising materials mentioning features or use of this software
     16  1.1     agc #    must display the following acknowledgement:
     17  1.1     agc #	This product includes software developed by Alistair G. Crooks.
     18  1.1     agc #	for the NetBSD project.
     19  1.1     agc # 4. The name of the author may not be used to endorse or promote
     20  1.1     agc #    products derived from this software without specific prior written
     21  1.1     agc #    permission.
     22  1.1     agc #
     23  1.1     agc # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     24  1.1     agc # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     25  1.1     agc # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  1.1     agc # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
     27  1.1     agc # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  1.1     agc # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     29  1.1     agc # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     30  1.1     agc # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     31  1.1     agc # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     32  1.1     agc # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     33  1.1     agc # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     34  1.1     agc #
     35  1.1     agc 
     36  1.6     apb # Usage: regpkgset [options] set
     37  1.6     apb #
     38  1.6     apb # Options:
     39  1.6     apb #   -q		Quiet.
     40  1.6     apb #   -v		Verbose.
     41  1.6     apb #   -f		Force.
     42  1.6     apb #   -m		Ignore errors from missing files.
     43  1.6     apb #   -u		Update.
     44  1.6     apb #   -c		Cache some information in ${BUILD_INFO_CACHE}.
     45  1.6     apb #   -d destdir	Sets DESTDIR.
     46  1.6     apb #   -t binpkgdir Create a binary package (in *.tgz format) in the
     47  1.6     apb #		specified directory.  Without this option, a binary
     48  1.6     apb #		package is not created.
     49  1.6     apb #   -M metalog	Use the specified metalog file to override file
     50  1.6     apb #		or directory attributes when creating a binary package.
     51  1.6     apb #   -N etcdir	Use the specified directory for passwd and group files.
     52  1.1     agc 
     53  1.6     apb prog="${0##*/}"
     54  1.6     apb toppid=$$
     55  1.5     apb rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
     56  1.6     apb . "${rundir}/sets.subr"
     57  1.6     apb 
     58  1.8     apb : ${TARGET_ENDIANNESS:="$(arch_to_endian "${MACHINE_ARCH}")"}
     59  1.7     apb export TARGET_ENDIANNESS
     60  1.7     apb 
     61  1.6     apb bomb()
     62  1.6     apb {
     63  1.6     apb 	kill ${toppid}		# in case we were invoked from a subshell
     64  1.6     apb 	exit 1
     65  1.6     apb }
     66  1.3     erh 
     67  1.6     apb # A literal newline
     68  1.6     apb nl='
     69  1.6     apb '
     70  1.1     agc 
     71  1.6     apb #
     72  1.6     apb # cleanup() deletes temporary files.
     73  1.6     apb #
     74  1.6     apb es=0
     75  1.8     apb cleanup()
     76  1.6     apb {
     77  1.6     apb 	trap - 0
     78  1.6     apb 	[ x"${BUILD_INFO_CACHE}" != x ] && rm -f "${BUILD_INFO_CACHE}"
     79  1.6     apb 	exit ${es}
     80  1.6     apb }
     81  1.6     apb trap 'es=128; cleanup' 1 2 3 13 15	# HUP INT QUIT PIPE TERM
     82  1.6     apb trap 'es=$?; cleanup' 0 		# EXIT
     83  1.6     apb 
     84  1.6     apb #
     85  1.6     apb # Parse command line args.
     86  1.6     apb #
     87  1.6     apb verbose=false
     88  1.6     apb quiet=false
     89  1.6     apb force=false
     90  1.6     apb allowmissing=false
     91  1.6     apb update=false
     92  1.6     apb cache=false
     93  1.6     apb pkgdir=""
     94  1.6     apb metalog=""
     95  1.6     apb etcdir=""
     96  1.6     apb all_options=""
     97  1.1     agc while [ $# -gt 1 ]; do
     98  1.6     apb 	# XXX: ${all_options} doesn't correctly handle args with
     99  1.6     apb 	# embedded shell special characters.
    100  1.5     apb 	case "$1" in
    101  1.8     apb 	-q)	quiet=true; verbose=false ;;
    102  1.8     apb 	-v)	verbose=true; quiet=false ;;
    103  1.6     apb 	-f)	force=true ;;
    104  1.6     apb 	-m)	allowmissing=true ;;
    105  1.6     apb 	-u)	update=true ;;
    106  1.6     apb 	-c)	cache=true ;;
    107  1.8     apb 	-d)	DESTDIR="$2"; all_options="${all_options} $1"; shift ;;
    108  1.6     apb 	-d*)	DESTDIR="${1#-?}" ;;
    109  1.8     apb 	-t)	pkgdir="$2"; all_options="${all_options} $1"; shift ;;
    110  1.6     apb 	-t*)	pkgdir="${1#-?}" ;;
    111  1.8     apb 	-M)	metalog="$2"; all_options="${all_options} $1"; shift ;;
    112  1.6     apb 	-M*)	metalog="${1#-?}" ;;
    113  1.8     apb 	-N)	etcdir="$2"; all_options="${all_options} $1"; shift ;;
    114  1.6     apb 	-N*)	etcdir="${1#-?}" ;;
    115  1.8     apb 	-*)	echo "Usage: regpkgset [options] set ..."; bomb ;;
    116  1.1     agc 	*)	break ;;
    117  1.1     agc 	esac
    118  1.6     apb 	all_options="${all_options} $1"
    119  1.1     agc 	shift
    120  1.1     agc done
    121  1.6     apb export DESTDIR
    122  1.1     agc 
    123  1.1     agc if [ $# -lt 1 ]; then
    124  1.6     apb 	echo "Usage: regpkgset [options] set ..."
    125  1.6     apb 	bomb
    126  1.1     agc fi
    127  1.1     agc 
    128  1.5     apb case "$1" in
    129  1.1     agc all)	list="base comp etc games man misc text" ;;
    130  1.5     apb *)	list="$*" ;;
    131  1.1     agc esac
    132  1.1     agc 
    133  1.8     apb if ${cache}; then
    134  1.6     apb 	BUILD_INFO_CACHE="$(${MKTEMP} "/var/tmp/${prog}-BUILD_INFO.XXXXXX")"
    135  1.2  dyoung 	export BUILD_INFO_CACHE
    136  1.2  dyoung 	{
    137  1.6     apb 	# These variables describe the build
    138  1.6     apb 	# environment, not the target.
    139  1.5     apb 	echo "OPSYS=$(${UNAME} -s)"
    140  1.5     apb 	echo "OS_VERSION=$(${UNAME} -r)"
    141  1.9     apb 	${MAKE} -B -f- all <<EOF
    142  1.2  dyoung .include <bsd.own.mk>
    143  1.2  dyoung all:
    144  1.2  dyoung 	@echo OBJECT_FMT=${OBJECT_FMT}
    145  1.2  dyoung 	@echo MACHINE_ARCH=${MACHINE_ARCH}
    146  1.2  dyoung 	@echo MACHINE_GNU_ARCH=${MACHINE_GNU_ARCH}
    147  1.2  dyoung EOF
    148  1.6     apb 	# XXX: what's the point of reporting _PKGTOOLS_VER
    149  1.6     apb 	# when we roll everything by hand without using
    150  1.6     apb 	# the pkg tools?
    151  1.5     apb 	echo "_PKGTOOLS_VER=$(${PKG_CREATE} -V)"
    152  1.5     apb 	} > "${BUILD_INFO_CACHE}"
    153  1.2  dyoung fi
    154  1.2  dyoung 
    155  1.6     apb #
    156  1.6     apb # For each pkgset mentioned in ${list}, get a list of all pkgs in the pkgset.
    157  1.6     apb #
    158  1.6     apb # Sort all the pkgs into dependency order (with prerequisite pkgs before
    159  1.6     apb # pkgs that depend on them).
    160  1.6     apb #
    161  1.6     apb # Invoke ${rundir}/regpkg for each pkg, taking care to do it in dependency
    162  1.6     apb # order.  If there were any pkgs for which we failed to find dependency
    163  1.6     apb # information, handle them at the end.
    164  1.6     apb #
    165  1.8     apb pkgs="$(for pkgset in ${list}; do
    166  1.6     apb 		${HOST_SH} "${rundir}/listpkgs" "${pkgset}" || bomb
    167  1.8     apb 	 done)"
    168  1.8     apb tsort_input="$(${AWK} '{print $2 " " $1}' <"${rundir}/deps" || bomb)"
    169  1.8     apb tsort_output="$(echo "${tsort_input}" | ${TSORT} || bomb)"
    170  1.8     apb for pkg in ${tsort_output}; do
    171  1.6     apb 	case "${nl}${pkgs}${nl}" in
    172  1.6     apb 	*"${nl}${pkg}${nl}"*)
    173  1.6     apb 		# We want this pkg.
    174  1.6     apb 		pkgset="${pkg%%-*}"
    175  1.6     apb 		${verbose} && echo "${prog}: registering ${pkg}"
    176  1.6     apb 		${HOST_SH} "${rundir}/regpkg" ${all_options} \
    177  1.6     apb 			"${pkgset}" "${pkg}" || bomb
    178  1.6     apb 		;;
    179  1.6     apb 	*)	# pkg is mentioned in ${tsort_output} but not in ${pkgs}.
    180  1.6     apb 		# We do not want this pkg.
    181  1.6     apb 		;;
    182  1.6     apb 	esac
    183  1.6     apb done
    184  1.8     apb for pkg in ${pkgs}; do
    185  1.6     apb 	case "${nl}${tsort_output}${nl}" in
    186  1.6     apb 	*"${nl}${pkg}${nl}"*)
    187  1.6     apb 		# pkg was in the tsort output, so it would have been
    188  1.6     apb 		# handled above.
    189  1.6     apb 		;;
    190  1.6     apb 	*)	# This pkg was not in the tsort output.
    191  1.6     apb 		# This is probably an error, but process the
    192  1.6     apb 		# pkg anyway.
    193  1.6     apb 		echo >&2 "${prog}: WARNING: ${pkg} is not mentioned in deps file"
    194  1.6     apb 		pkgset="${pkg%%-*}"
    195  1.6     apb 		${verbose} && echo "${prog}: registering ${pkg}"
    196  1.6     apb 		${HOST_SH} "${rundir}/regpkg" ${all_options} \
    197  1.6     apb 			"${pkgset}" "${pkg}" || bomb
    198  1.6     apb 		;;
    199  1.6     apb 	esac
    200  1.1     agc done
    201  1.1     agc 
    202  1.1     agc exit 0
    203