Home | History | Annotate | Line # | Download | only in sets
regpkgset revision 1.6
      1  1.1     agc #! /bin/sh
      2  1.1     agc #
      3  1.6     apb # $NetBSD: regpkgset,v 1.6 2006/01/04 14:18:00 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.6     apb bomb()
     59  1.6     apb {
     60  1.6     apb 	kill ${toppid}		# in case we were invoked from a subshell
     61  1.6     apb 	exit 1
     62  1.6     apb }
     63  1.3     erh 
     64  1.6     apb # A literal newline
     65  1.6     apb nl='
     66  1.6     apb '
     67  1.1     agc 
     68  1.6     apb #
     69  1.6     apb # cleanup() deletes temporary files.
     70  1.6     apb #
     71  1.6     apb es=0
     72  1.6     apb cleanup ()
     73  1.6     apb {
     74  1.6     apb 	trap - 0
     75  1.6     apb 	[ x"${BUILD_INFO_CACHE}" != x ] && rm -f "${BUILD_INFO_CACHE}"
     76  1.6     apb 	exit ${es}
     77  1.6     apb }
     78  1.6     apb trap 'es=128; cleanup' 1 2 3 13 15	# HUP INT QUIT PIPE TERM
     79  1.6     apb trap 'es=$?; cleanup' 0 		# EXIT
     80  1.6     apb 
     81  1.6     apb #
     82  1.6     apb # Parse command line args.
     83  1.6     apb #
     84  1.6     apb verbose=false
     85  1.6     apb quiet=false
     86  1.6     apb force=false
     87  1.6     apb allowmissing=false
     88  1.6     apb update=false
     89  1.6     apb cache=false
     90  1.6     apb pkgdir=""
     91  1.6     apb metalog=""
     92  1.6     apb etcdir=""
     93  1.6     apb all_options=""
     94  1.1     agc while [ $# -gt 1 ]; do
     95  1.6     apb 	# XXX: ${all_options} doesn't correctly handle args with
     96  1.6     apb 	# embedded shell special characters.
     97  1.5     apb 	case "$1" in
     98  1.6     apb 	-q)	quiet=true ; verbose=false ;;
     99  1.6     apb 	-v)	verbose=true ; quiet=false ;;
    100  1.6     apb 	-f)	force=true ;;
    101  1.6     apb 	-m)	allowmissing=true ;;
    102  1.6     apb 	-u)	update=true ;;
    103  1.6     apb 	-c)	cache=true ;;
    104  1.6     apb 	-d)	DESTDIR="$2" ; all_options="${all_options} $1" ; shift ;;
    105  1.6     apb 	-d*)	DESTDIR="${1#-?}" ;;
    106  1.6     apb 	-t)	pkgdir="$2" ; all_options="${all_options} $1" ; shift ;;
    107  1.6     apb 	-t*)	pkgdir="${1#-?}" ;;
    108  1.6     apb 	-M)	metalog="$2" ; all_options="${all_options} $1" ; shift ;;
    109  1.6     apb 	-M*)	metalog="${1#-?}" ;;
    110  1.6     apb 	-N)	etcdir="$2" ; all_options="${all_options} $1" ; shift ;;
    111  1.6     apb 	-N*)	etcdir="${1#-?}" ;;
    112  1.6     apb 	-*)	echo "Usage: regpkgset [options] set ..." ; bomb ;;
    113  1.1     agc 	*)	break ;;
    114  1.1     agc 	esac
    115  1.6     apb 	all_options="${all_options} $1"
    116  1.1     agc 	shift
    117  1.1     agc done
    118  1.6     apb export DESTDIR
    119  1.1     agc 
    120  1.1     agc if [ $# -lt 1 ]; then
    121  1.6     apb 	echo "Usage: regpkgset [options] set ..."
    122  1.6     apb 	bomb
    123  1.1     agc fi
    124  1.1     agc 
    125  1.5     apb case "$1" in
    126  1.1     agc all)	list="base comp etc games man misc text" ;;
    127  1.5     apb *)	list="$*" ;;
    128  1.1     agc esac
    129  1.1     agc 
    130  1.6     apb if ${cache} ; then
    131  1.6     apb 	BUILD_INFO_CACHE="$(${MKTEMP} "/var/tmp/${prog}-BUILD_INFO.XXXXXX")"
    132  1.2  dyoung 	export BUILD_INFO_CACHE
    133  1.2  dyoung 	{
    134  1.6     apb 	# These variables describe the build
    135  1.6     apb 	# environment, not the target.
    136  1.5     apb 	echo "OPSYS=$(${UNAME} -s)"
    137  1.5     apb 	echo "OS_VERSION=$(${UNAME} -r)"
    138  1.4     apb 	${MAKE} -f- all <<EOF
    139  1.2  dyoung .include <bsd.own.mk>
    140  1.2  dyoung all:
    141  1.2  dyoung 	@echo OBJECT_FMT=${OBJECT_FMT}
    142  1.2  dyoung 	@echo MACHINE_ARCH=${MACHINE_ARCH}
    143  1.2  dyoung 	@echo MACHINE_GNU_ARCH=${MACHINE_GNU_ARCH}
    144  1.2  dyoung EOF
    145  1.6     apb 	# XXX: what's the point of reporting _PKGTOOLS_VER
    146  1.6     apb 	# when we roll everything by hand without using
    147  1.6     apb 	# the pkg tools?
    148  1.5     apb 	echo "_PKGTOOLS_VER=$(${PKG_CREATE} -V)"
    149  1.5     apb 	} > "${BUILD_INFO_CACHE}"
    150  1.2  dyoung fi
    151  1.2  dyoung 
    152  1.6     apb #
    153  1.6     apb # For each pkgset mentioned in ${list}, get a list of all pkgs in the pkgset.
    154  1.6     apb #
    155  1.6     apb # Sort all the pkgs into dependency order (with prerequisite pkgs before
    156  1.6     apb # pkgs that depend on them).
    157  1.6     apb #
    158  1.6     apb # Invoke ${rundir}/regpkg for each pkg, taking care to do it in dependency
    159  1.6     apb # order.  If there were any pkgs for which we failed to find dependency
    160  1.6     apb # information, handle them at the end.
    161  1.6     apb #
    162  1.6     apb pkgs="$( for pkgset in ${list}; do
    163  1.6     apb 		${HOST_SH} "${rundir}/listpkgs" "${pkgset}" || bomb
    164  1.6     apb 	 done )"
    165  1.6     apb tsort_input="$( ${AWK} '{print $2 " " $1}' <"${rundir}/deps" || bomb )"
    166  1.6     apb tsort_output="$( echo "${tsort_input}" | ${TSORT} || bomb )"
    167  1.6     apb for pkg in ${tsort_output} ; do
    168  1.6     apb 	case "${nl}${pkgs}${nl}" in
    169  1.6     apb 	*"${nl}${pkg}${nl}"*)
    170  1.6     apb 		# We want this pkg.
    171  1.6     apb 		pkgset="${pkg%%-*}"
    172  1.6     apb 		${verbose} && echo "${prog}: registering ${pkg}"
    173  1.6     apb 		${HOST_SH} "${rundir}/regpkg" ${all_options} \
    174  1.6     apb 			"${pkgset}" "${pkg}" || bomb
    175  1.6     apb 		;;
    176  1.6     apb 	*)	# pkg is mentioned in ${tsort_output} but not in ${pkgs}.
    177  1.6     apb 		# We do not want this pkg.
    178  1.6     apb 		;;
    179  1.6     apb 	esac
    180  1.6     apb done
    181  1.6     apb for pkg in ${pkgs} ; do
    182  1.6     apb 	case "${nl}${tsort_output}${nl}" in
    183  1.6     apb 	*"${nl}${pkg}${nl}"*)
    184  1.6     apb 		# pkg was in the tsort output, so it would have been
    185  1.6     apb 		# handled above.
    186  1.6     apb 		;;
    187  1.6     apb 	*)	# This pkg was not in the tsort output.
    188  1.6     apb 		# This is probably an error, but process the
    189  1.6     apb 		# pkg anyway.
    190  1.6     apb 		echo >&2 "${prog}: WARNING: ${pkg} is not mentioned in deps file"
    191  1.6     apb 		pkgset="${pkg%%-*}"
    192  1.6     apb 		${verbose} && echo "${prog}: registering ${pkg}"
    193  1.6     apb 		${HOST_SH} "${rundir}/regpkg" ${all_options} \
    194  1.6     apb 			"${pkgset}" "${pkg}" || bomb
    195  1.6     apb 		;;
    196  1.6     apb 	esac
    197  1.1     agc done
    198  1.1     agc 
    199  1.1     agc exit 0
    200