Home | History | Annotate | Line # | Download | only in sets
regpkg revision 1.11
      1   1.1     agc #! /bin/sh
      2   1.1     agc #
      3  1.11     apb # $NetBSD: regpkg,v 1.11 2006/01/08 10:24:04 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.9     apb # Usage: regpkg [options] set pkgname
     37   1.9     apb #
     38   1.9     apb # Registers a syspkg in the database directory,
     39   1.9     apb # and optionally creates a binary package.
     40   1.9     apb #
     41   1.9     apb # Options:
     42   1.9     apb #   -q		Quiet.
     43   1.9     apb #   -v		Verbose.
     44   1.9     apb #   -f		Force.
     45   1.9     apb #   -m		Ignore errors from missing files.
     46   1.9     apb #   -u		Update.
     47   1.9     apb #   -c		Use cached information from ${BUILD_INFO_CACHE}.
     48   1.9     apb #   -d destdir	Sets DESTDIR.
     49   1.9     apb #   -t binpkgdir Create a binary package (in *.tgz format) in the
     50   1.9     apb #		specified directory.  Without this option, a binary
     51   1.9     apb #		package is not created.
     52   1.9     apb #   -M metalog	Use the specified metalog file to override file
     53   1.9     apb #		or directory attributes when creating a binary package.
     54   1.9     apb #   -N etcdir	Use the specified directory for passwd and group files.
     55   1.9     apb #
     56   1.9     apb # When -f is set:  If the desired syspkg already exists, it is overwritten.
     57   1.9     apb # When -u is set:  If the desired syspkg already exists, it might be
     58   1.9     apb #		overwritten or left alone, depending on whether it's older
     59   1.9     apb #		or newer than the files that belong to the syspkg.
     60   1.9     apb # When neither -u nor -f are set:  It's an error for the desired syspkg
     61   1.9     apb #		to already exist.
     62   1.1     agc 
     63   1.9     apb prog="${0##*/}"
     64   1.9     apb toppid=$$
     65   1.8     apb rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
     66   1.9     apb . "${rundir}/sets.subr"
     67   1.9     apb 
     68   1.9     apb bomb()
     69   1.9     apb {
     70   1.9     apb 	#echo "${prog}: bomb: start, toppid=${toppid} \$\$=$$"
     71   1.9     apb 	kill ${toppid}		# in case we were invoked from a subshell
     72   1.9     apb 	#echo "${prog}: bomb: killed ${toppid}"
     73   1.9     apb 	exit 1
     74   1.9     apb }
     75   1.6     erh 
     76   1.9     apb # A literal newline
     77   1.9     apb nl='
     78   1.9     apb '
     79   1.9     apb # A literal tab
     80   1.9     apb tab='	'
     81   1.9     apb 
     82   1.9     apb # Prefixes for error messages, warnings, and important informational
     83   1.9     apb # messages.
     84   1.9     apb ERROR="${prog}: ERROR: "
     85   1.9     apb WARNING="${prog}: WARNING: "
     86   1.9     apb NOTE="${prog}: NOTE: "
     87   1.9     apb ERRWARN="${ERROR}"	# may be changed by "-f" (force) command line flag
     88   1.9     apb ERRWARNNOTE="${ERROR}"	# may be changed by "-u" (update) command line flag
     89   1.1     agc 
     90   1.9     apb #
     91   1.9     apb # All temporary files will go in ${SCRATCH}, which will be deleted on
     92   1.9     apb # exit.
     93   1.9     apb #
     94   1.9     apb SCRATCH="$( ${MKTEMP} -d "/var/tmp/${0##*/}.XXXXXX" )"
     95   1.9     apb if [ $? -ne 0 -o \! -d "${SCRATCH}" ]; then
     96  1.10     apb 	echo >&2 "${prog}: Could not create scratch directory."
     97   1.9     apb 	bomb
     98   1.1     agc fi
     99   1.1     agc 
    100   1.9     apb #
    101   1.9     apb # cleanup() always deletes the SCRATCH directory, and might also
    102   1.9     apb # delete other files or directories.
    103   1.9     apb #
    104   1.9     apb es=0
    105   1.9     apb cleanup_must_delete_binpkgfile=false
    106   1.9     apb cleanup_must_delete_dbsubdir=false
    107   1.9     apb cleanup ()
    108   1.9     apb {
    109   1.9     apb 	trap - 0
    110   1.9     apb 	#echo "${prog}: cleanup start"
    111   1.9     apb 	if ${cleanup_must_delete_binpkgfile:-false} && [ -e "${binpkgfile}" ]
    112   1.9     apb 	then
    113   1.9     apb 		echo >&2 "${prog}: deleting partially-created ${binpkgfile}"
    114   1.9     apb 		rm -f "${binpkgfile}"
    115   1.9     apb 	fi
    116   1.9     apb 	if ${cleanup_must_delete_dbsubdir:-false} \
    117   1.9     apb 	   && [ -e "${SYSPKG_DB_SUBDIR}" ]
    118   1.9     apb 	then
    119   1.9     apb 		echo >&2 "${prog}: deleting partially-created ${SYSPKG_DB_SUBDIR}"
    120   1.9     apb 		rm -rf "${SYSPKG_DB_SUBDIR}"
    121   1.9     apb 	fi
    122   1.9     apb 	rm -rf "${SCRATCH}"
    123   1.9     apb 	#echo "${prog}: cleanup done, exit ${es}"
    124   1.9     apb 	exit ${es}
    125   1.9     apb }
    126   1.9     apb trap 'es=128; cleanup' 1 2 3 13 15	# HUP INT QUIT PIPE TERM
    127   1.9     apb trap 'es=$?; cleanup' 0 		# EXIT
    128   1.9     apb 
    129   1.9     apb #
    130   1.9     apb # Parse command line args.
    131   1.9     apb #
    132   1.9     apb verbose=false
    133   1.9     apb verbosity=0
    134   1.9     apb quiet=false
    135   1.9     apb force=false
    136   1.9     apb update=false
    137   1.9     apb allowmissing=false
    138   1.9     apb DESTDIR="${DESTDIR}"
    139   1.9     apb binpkgdir=""
    140   1.9     apb metalog=""
    141   1.9     apb etcdir=""
    142   1.9     apb SYSPKG_DB_TOPDIR=""
    143   1.9     apb pkgset=""
    144   1.9     apb pkg=""
    145   1.9     apb parse_args ()
    146   1.9     apb {
    147   1.9     apb 	while [ $# -gt 2 ]; do
    148   1.9     apb 		case "$1" in
    149   1.9     apb 		-q)	quiet=true ; verbose=false ;;
    150   1.9     apb 		-v)	verbose=true ; quiet=false
    151   1.9     apb 			verbosity=$(( ${verbosity} + 1 ))
    152   1.9     apb 			;;
    153   1.9     apb 		-f)	force=true ;;
    154   1.9     apb 		-u)	update=true ;;
    155   1.9     apb 		-m)	allowmissing=true ;;
    156   1.9     apb 		-c)	# The -c option is ignored.  The BUILD_INFO_CACHE
    157   1.9     apb 			# environment variable is used instead.
    158   1.9     apb 			;;
    159   1.9     apb 		-d)	DESTDIR="$2" ; shift ;;
    160   1.9     apb 		-d*)	DESTDIR="${1#-?}" ;;
    161   1.9     apb 		-t)	binpkgdir="$2" ; shift ;;
    162   1.9     apb 		-t*)	binpkgdir="${1#-?}" ;;
    163   1.9     apb 		-M)	metalog="$2" ; shift ;;
    164   1.9     apb 		-M*)	metalog="${1#-?}" ;;
    165   1.9     apb 		-N)	etcdir="$2" ; shift ;;
    166   1.9     apb 		-N*)	etcdir="${1#-?}" ;;
    167   1.9     apb 		*)	break ;;
    168   1.9     apb 		esac
    169   1.9     apb 		shift
    170   1.9     apb 	done
    171   1.9     apb 	if ${force}; then
    172   1.9     apb 		ERRWARN="${WARNING}"
    173   1.9     apb 	else
    174   1.9     apb 		ERRWARN="${ERROR}"
    175   1.9     apb 	fi
    176   1.9     apb 	if ${update}; then
    177   1.9     apb 		ERRWARNNOTE="${NOTE}"
    178   1.9     apb 	else
    179   1.9     apb 		ERRWARNNOTE="${ERRWARN}"
    180   1.9     apb 	fi
    181   1.9     apb 	DESTDIR="${DESTDIR%/}" # delete trailing "/" if any
    182   1.9     apb 	if [ \! -n "${etcdir}" ]; then
    183   1.9     apb 		etcdir="${DESTDIR}/etc"
    184   1.9     apb 	fi
    185   1.9     apb 	if [ -n "${binpkgdir}" -a \! -d "${binpkgdir}" ]; then
    186   1.9     apb 		echo >&2 "${ERROR}binary pkg directory ${binpkgdir} does not exist"
    187   1.9     apb 		bomb
    188   1.9     apb 	fi
    189   1.9     apb 	#
    190   1.9     apb 	# SYSPKG_DB_TOPDIR is the top level directory for registering
    191   1.9     apb 	# syspkgs.  It defaults to ${DESTDIR}/var/db/syspkg, but can be
    192   1.9     apb 	# overridden by environment variables SYSPKG_DBDIR or PKG_DBDIR.
    193   1.9     apb 	#
    194   1.9     apb 	# Note that this corresponds to the default value of PKG_DBDIR
    195   1.9     apb 	# set in .../distrib/syspkg/mk/bsd.syspkg.mk.
    196   1.9     apb 	# 
    197   1.9     apb 	SYSPKG_DB_TOPDIR="${SYSPKG_DBDIR:-${PKG_DBDIR:-${DESTDIR}/var/db/syspkg}}"
    198   1.9     apb 
    199   1.9     apb 	if [ $# -ne 2 ]; then
    200   1.9     apb 		echo "Usage: regpkg [options] set pkgname"
    201   1.9     apb 		bomb
    202   1.9     apb 	fi
    203   1.9     apb 
    204   1.9     apb 	pkgset="$1"
    205   1.9     apb 	pkg="$2"
    206   1.9     apb }
    207   1.1     agc 
    208   1.9     apb #
    209   1.9     apb # make_PLIST() creates a skeleton PLIST from the pkgset description.
    210   1.9     apb #
    211   1.9     apb # The result is stored in the file ${PLIST}.
    212   1.9     apb #
    213   1.9     apb PLIST="${SCRATCH}/PLIST"
    214   1.9     apb make_PLIST ()
    215   1.9     apb {
    216   1.9     apb 	if ${verbose} ; then
    217   1.9     apb 		echo "Making PLIST for \"${pkg}\" package (part of ${pkgset} set)"
    218   1.9     apb 	fi
    219   1.9     apb 	prefix="${DESTDIR:-/}"
    220   1.9     apb 	realprefix=/
    221   1.9     apb 	${HOST_SH} "${rundir}/makeplist" -p "${prefix}" -I "${realprefix}" \
    222   1.9     apb 		"${pkgset}" "${pkg}" \
    223   1.9     apb 		>"${PLIST}" 2>"${SCRATCH}/makeplist-errors"
    224   1.9     apb 	if ${EGREP} -v '^DEBUG:' "${SCRATCH}/makeplist-errors" ; then
    225   1.9     apb 		# "find" invoked from makeplist sometimes reports
    226   1.9     apb 		# errors about missing files or directories, and
    227   1.9     apb 		# makeplist ignores the errors.  Catch them here.
    228   1.9     apb 		echo >&2 "${ERROR}makeplist reported errors for ${pkg}:"
    229   1.9     apb 		cat >&2 "${SCRATCH}/makeplist-errors"
    230   1.9     apb 		echo >&2 "${ERROR}see above for errors from makeplist"
    231   1.9     apb 		if ${allowmissing}; then
    232   1.9     apb 			echo >&2 "${prog}: ${NOTE}: ignoring above errors, due to '-m' option."
    233   1.9     apb 		else
    234   1.9     apb 			${force} || bomb
    235   1.9     apb 		fi
    236   1.9     apb 	fi
    237   1.9     apb }
    238   1.1     agc 
    239   1.9     apb #
    240   1.9     apb # init_allfiles() converts the PLIST (which contains relative filenames)
    241   1.9     apb # into a list of absolute filenames.  Directories are excluded from the
    242   1.9     apb # result.
    243   1.9     apb # 
    244   1.9     apb # The result is stored in the variable ${allfiles}.
    245   1.9     apb #
    246   1.9     apb allfiles=''
    247   1.9     apb init_allfiles ()
    248   1.9     apb {
    249   1.9     apb 	[ -f "${PLIST}" ] || make_PLIST
    250   1.9     apb 	allfiles="$( ${AWK} '
    251   1.9     apb 		BEGIN { destdir = "'"${DESTDIR%/}"'" }
    252   1.9     apb 		/^@cwd/ { prefix = $2; next }
    253   1.9     apb 		/^@dirrm/ { next }
    254   1.9     apb 		{ printf("%s%s%s\n", destdir, prefix, $0) }' "${PLIST}" )"
    255   1.9     apb }
    256   1.1     agc 
    257   1.9     apb #
    258   1.9     apb # init_newestfile() finds the newest file (most recent mtime).
    259   1.9     apb #
    260   1.9     apb # The result is stored in the variable ${newestfile}.
    261   1.9     apb #
    262   1.9     apb newestfile=''
    263   1.9     apb init_newestfile ()
    264   1.9     apb {
    265   1.9     apb 	[ -s "${allfiles}" ] || init_allfiles
    266   1.9     apb 	# We assume no shell special characters in ${allfiles},
    267   1.9     apb 	# and spaces only between file names, not inside file names.
    268   1.9     apb 	# This should be safe, because it has no no user-specified parts.
    269   1.9     apb 	newestfile="$( ${LS} -1dt ${allfiles} | ${SED} '1q' )"
    270   1.9     apb }
    271   1.1     agc 
    272   1.9     apb #
    273   1.9     apb # Various ways of getting parts of the syspkg version number:
    274   1.9     apb #
    275   1.9     apb # get_osvers() - get the OS version number from osrelease.sh or $(uname -r),
    276   1.9     apb #		return it in ${osvers}, and set ${method}.
    277   1.9     apb # get_tinyvers() - get the tiny version number from the "versions" file,
    278   1.9     apb #		and return it in ${tinyvers}.  Does not set ${method}.
    279   1.9     apb # get_newest_rcsid_date() - get the newest RCS date,
    280   1.9     apb #		and return it in ${newest}.  Does not set ${method}.
    281   1.9     apb # get_newest_mtime_date() - get the newest file modification date,
    282   1.9     apb #		and return it in ${newest}.  Does not set ${method}.
    283   1.9     apb # get_newest_date() - get date from rcsid or mtime, return it in ${newest},
    284   1.9     apb #		and set ${method}.
    285   1.9     apb #
    286   1.9     apb get_osvers ()
    287   1.9     apb {
    288   1.3     agc 	if [ -f ../../sys/conf/osrelease.sh ]; then
    289   1.8     apb 		osvers="$(${HOST_SH} ../../sys/conf/osrelease.sh)"
    290   1.4  dyoung 		method=osreleases
    291   1.3     agc 	else
    292   1.8     apb 		osvers="$(${UNAME} -r)"
    293   1.3     agc 		method=uname
    294   1.3     agc 	fi
    295   1.9     apb 	#echo "${osvers}"
    296   1.9     apb }
    297   1.9     apb get_tinyvers ()
    298   1.9     apb {
    299   1.9     apb 	tinyvers="$( ${AWK} '$1 ~ '/"${pkg}"/' { print $2 }' \
    300   1.9     apb 			"${rundir}/versions" )"
    301   1.9     apb 	case "${tinyvers}" in
    302   1.9     apb 	"")	tinyvers=0
    303   1.9     apb 		;;
    304   1.9     apb 	esac
    305   1.9     apb 	#echo "${tinyvers}"
    306   1.9     apb }
    307   1.9     apb get_newest_rcsid_date()
    308   1.9     apb {
    309   1.9     apb 	[ -s "${allfiles}" ] || init_allfiles
    310   1.9     apb 
    311   1.9     apb 	# Old RCS identifiers might have 2-digit years, so we match both
    312   1.9     apb 	# YY/MM/DD and YYYY/MM/DD.  We also try to deal with the Y10K
    313   1.9     apb 	# problem by allowing >4 digit years.
    314   1.9     apb 	newest=0
    315   1.9     apb 	case "${allfiles}" in
    316   1.3     agc 	"")	;;
    317   1.9     apb 	*)	newest="$( ${IDENT} ${allfiles} 2>/dev/null | ${AWK} '
    318   1.3     agc 			BEGIN { last = 0 }
    319   1.3     agc 			$2 == "crt0.c,v" { next }
    320   1.9     apb 			NF == 8 && \
    321   1.9     apb 			$4 ~ /^[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9]$/ \
    322   1.9     apb 				{ t = "19" $4; gsub("/", "", t);
    323   1.9     apb 				  if (t > last) last = t; }
    324   1.9     apb 			NF == 8 && \
    325   1.9     apb 			$4 ~ /^[0-9][0-9][0-9][0-9][0-9]*\/[0-9][0-9]\/[0-9][0-9]$/ \
    326   1.9     apb 				{ t = $4; gsub("/", "", t);
    327   1.9     apb 				  if (t > last) last = t; }
    328   1.9     apb 			END { print last }' )"
    329   1.3     agc 		method=ident
    330   1.3     agc 		;;
    331   1.3     agc 	esac
    332   1.9     apb 	#echo "${newest}"
    333   1.9     apb }
    334   1.9     apb get_newest_mtime_date ()
    335   1.9     apb {
    336   1.9     apb 	[ -s "${newestfile}" ] || init_newestfile
    337   1.9     apb 
    338   1.9     apb 	# We could simplify the awk program to take advantage of the
    339   1.9     apb 	# fact thet it should have exactly one line of input.
    340   1.9     apb 	newest="$( ${ENV_CMD} TZ=UTC LOCALE=C ${LS} -lT "${newestfile}" \
    341   1.9     apb 		| ${AWK} '
    342   1.9     apb 		BEGIN { newest = 0 }
    343   1.9     apb 		{
    344   1.9     apb 			t = $9 "";
    345   1.9     apb 			if ($6 == "Jan") t = t "01";
    346   1.9     apb 			if ($6 == "Feb") t = t "02";
    347   1.9     apb 			if ($6 == "Mar") t = t "03";
    348   1.9     apb 			if ($6 == "Apr") t = t "04";
    349   1.9     apb 			if ($6 == "May") t = t "05";
    350   1.9     apb 			if ($6 == "Jun") t = t "06";
    351   1.9     apb 			if ($6 == "Jul") t = t "07";
    352   1.9     apb 			if ($6 == "Aug") t = t "08";
    353   1.9     apb 			if ($6 == "Sep") t = t "09";
    354   1.9     apb 			if ($6 == "Oct") t = t "10";
    355   1.9     apb 			if ($6 == "Nov") t = t "11";
    356   1.9     apb 			if ($6 == "Dec") t = t "12";
    357   1.9     apb 			if ($7 < 10) t = t "0";
    358   1.9     apb 			t = t $7;
    359   1.9     apb 			#these next two lines add the 24h clock onto the date
    360   1.9     apb 			#gsub(":", "", $8);
    361   1.9     apb 			#t = sprintf("%s.%4.4s", t, $8);
    362   1.9     apb 			if (t > newest) newest = t;
    363   1.9     apb 		}
    364   1.9     apb 		END { print newest }' )"
    365   1.9     apb 	#echo "${newest}"
    366   1.9     apb }
    367   1.9     apb get_newest_date ()
    368   1.9     apb {
    369   1.9     apb 	get_newest_rcsid_date
    370   1.9     apb 	case "${newest}" in
    371   1.9     apb 	""|0)	get_newest_mtime_date
    372   1.3     agc 		method=ls
    373   1.3     agc 		;;
    374   1.9     apb 	*)	method=rcsid
    375   1.9     apb 		;;
    376   1.3     agc 	esac
    377   1.9     apb 	#echo "${newest}"
    378   1.9     apb }
    379   1.9     apb 
    380   1.9     apb #
    381   1.9     apb # choose_version_number() chooses the syspkg version number,
    382   1.9     apb # by concatenating several components (OS version, syspkg "tiny"
    383   1.9     apb # version and date).  We end up with something like
    384   1.9     apb # osvers="3.99.15", tinyvers="0", newest="20060104",
    385   1.9     apb # and t="3.99.15.0.20060104".
    386   1.9     apb #
    387   1.9     apb # The result is stored in the variables ${t} and ${method}.
    388   1.9     apb #
    389   1.9     apb method=''
    390   1.9     apb t=''
    391   1.9     apb choose_version_number ()
    392   1.9     apb {
    393   1.9     apb 	get_osvers ; m1="${method}"
    394   1.9     apb 	get_tinyvers # does not set ${method}
    395   1.9     apb 	get_newest_date ; m2="${method}"
    396   1.9     apb 	t="${osvers}.${tinyvers}.${newest}"
    397   1.9     apb 	method="${m1}.${m2}"
    398   1.9     apb 
    399   1.9     apb 	# print version number that we're using
    400   1.9     apb 	if ${verbose}; then
    401   1.9     apb 		echo "${pkg} - ${t} version using ${method} method"
    402   1.9     apb 	fi
    403   1.9     apb }
    404   1.9     apb 
    405   1.9     apb #
    406   1.9     apb # print_dir_exec_lines outputs an "@exec install" line for each
    407   1.9     apb # directory in ${PLIST}
    408   1.9     apb #
    409   1.9     apb print_dir_exec_lines ()
    410   1.9     apb {
    411   1.9     apb 	local dir uname gname mode
    412   1.9     apb 	local dot_slash_dir
    413   1.9     apb 	local no_dot_dir
    414   1.9     apb 	local word line
    415   1.9     apb 	${AWK} '/^@dirrm/ { print $2 }' <"${PLIST}" | \
    416   1.9     apb 	${SORT} | \
    417   1.9     apb 	while read dir ; do
    418   1.9     apb 		# Sanitise the name. ${dir} could be an absolute or
    419   1.9     apb 		# relative name, with or without a leading "./".
    420   1.9     apb 		# ${dot_slash_dir} always has a leading "./" (except when
    421   1.9     apb 		# it's exactly equal to "."). ${no_dot_dir} never has a
    422   1.9     apb 		# leading "." or "/" (except when it's exactly equal to
    423   1.9     apb 		# ".").
    424   1.9     apb 		case "${dir}" in
    425   1.9     apb 		.|./|/)	dot_slash_dir=.  ;;
    426   1.9     apb 		./*)	dot_slash_dir="${dir}" ;;
    427   1.9     apb 		/*)	dot_slash_dir=".${dir}" ;;
    428   1.9     apb 		*)	dot_slash_dir="./${dir}" ;;
    429   1.9     apb 		esac
    430   1.9     apb 		no_dot_dir="${dot_slash_dir#./}"
    431   1.9     apb 		# Get the directory's owner, group, and mode
    432   1.9     apb 		# from the live file system, or let it be overridden
    433   1.9     apb 		# by the metalog.
    434   1.9     apb 		eval "$( ${STAT} -f 'uname=%Su gname=%Sg mode=%#OLp' \
    435   1.9     apb 				"${DESTDIR}/${dot_slash_dir}" )"
    436   1.9     apb 		if [ -n "${metalog}" ]; then
    437   1.9     apb 			line="$( echo "${dot_slash_dir}" | \
    438   1.9     apb 				${AWK} -f "${rundir}/join.awk" \
    439   1.9     apb 					/dev/stdin "${metalog}" )"
    440   1.9     apb 			for word in ${line} ; do
    441   1.9     apb 				case "${word}" in
    442   1.9     apb 				uname=*|gname=*|mode=*)	eval "${word}" ;;
    443   1.9     apb 				esac
    444   1.9     apb 			done
    445   1.9     apb 		fi
    446   1.9     apb 		# XXX: Work around yet another pkg_add bug: @cwd lines
    447   1.9     apb 		# do not actually cause the working directory to change,
    448   1.9     apb 		# so file names in @exec lines need to be qualified by
    449   1.9     apb 		# %D, which (in our case, since we know there's an
    450   1.9     apb 		# "@cwd /" line) will be the dir name passed to
    451   1.9     apb 		# "pkg_add -p PREFIX".
    452   1.9     apb 		case "${no_dot_dir}" in
    453   1.9     apb 		.) d="%D" ;;
    454   1.9     apb 		*) d="%D/${no_dot_dir}" ;;
    455   1.9     apb 		esac
    456   1.9     apb 		cat <<EOF
    457   1.9     apb @exec install -d -o ${uname} -g ${gname} -m ${mode} ${d}
    458   1.9     apb EOF
    459   1.9     apb 	done
    460   1.9     apb }
    461   1.2   jwise 
    462   1.9     apb #
    463   1.9     apb # register_syspkg() registers the syspkg in ${SYSPKG_DB_TOPDIR}.
    464   1.9     apb # This involves creating the subdirectory ${SYSPKG_DB_SUBDIR}
    465   1.9     apb # and populating it with several files.
    466   1.9     apb #
    467   1.9     apb register_syspkg ()
    468   1.9     apb {
    469   1.9     apb 	cleanup_must_delete_dbsubdir=true
    470   1.9     apb 	[ -n "${SYSPKG_DB_SUBDIR}" ] || bomb
    471   1.9     apb 	mkdir -p "${SYSPKG_DB_SUBDIR}"
    472   1.9     apb 
    473   1.9     apb 	#
    474   1.9     apb 	# Guess what versions of other packages to depend on.
    475   1.9     apb 	#
    476   1.9     apb 	# If we are using the OS version as part of the pkg
    477   1.9     apb 	# version, then depend on any version ">=${osvers}".  For
    478   1.9     apb 	# example, etc-sys-etc-1.6ZI.0.20040206 might depend on
    479   1.9     apb 	# base-sys-root>=1.6ZI.
    480   1.9     apb 	#
    481   1.9     apb 	# Failing that, depend on any version "-[0-9]*".
    482   1.9     apb 	#
    483   1.9     apb 	# XXX: We could extend the format of the "deps" file to carry
    484   1.9     apb 	# this sort of information, so we wouldn't have to guess.
    485   1.9     apb 	#
    486   1.9     apb 	case "${t}" in
    487   1.9     apb 	${osvers}.*)	depversion=">=${osvers}" ;;
    488   1.9     apb 	*)		depversion="-[0-9]*" ;;
    489   1.9     apb 	esac
    490   1.9     apb 
    491   1.9     apb 	#
    492   1.9     apb 	# Add the dependencies.
    493   1.9     apb 	#
    494   1.9     apb 	# We always add a "@pkgdep" line for each prerequisite package.
    495   1.9     apb 	#
    496   1.9     apb 	# If the prerequisite pkg is already registered (as it should be
    497   1.9     apb 	# if our caller is doing things in the right order), then we put
    498   1.9     apb 	# its exact version number in a "@blddep" line.
    499   1.9     apb 	#
    500   1.9     apb 	${AWK} '$1 ~ '/"${pkg}"/' { print $2 }' "${rundir}/deps" | ${SORT} | \
    501   1.9     apb 	while read depname ; do
    502   1.9     apb 		# ${pkgdepglob} is a shell glob pattern that should match
    503   1.9     apb 		# any version of a pkg.  ${pkgdep} uses the special syntax
    504   1.9     apb 		# for pkg dependencies, and is not usable as a shell
    505   1.9     apb 		# glob pattern.
    506   1.9     apb 		pkgdepglob="${depname}-[0-9]*"
    507   1.9     apb 		pkgdep="${depname}${depversion}"
    508   1.9     apb 		echo "@pkgdep ${pkgdep}"
    509   1.9     apb 		blddep="$( cd "${SYSPKG_DB_TOPDIR}" && echo ${pkgdepglob} \
    510   1.9     apb 			|| bomb )"
    511   1.9     apb 		case "${blddep}" in
    512   1.9     apb 		*\*)	# pkgdepglob did not match anything
    513   1.9     apb 			echo >&2 "${WARNING}${pkg} depends on '${pkgdep}' but there is no matching syspkg in ${SYSPKG_DB_TOPDIR}"
    514   1.9     apb 			;;
    515   1.9     apb 		*\ *)	# pkgdepglob matched more than once.
    516   1.9     apb 			echo >&2 "${ERRWARN}${pkg} depends on '${pkgdep}' but there are multiple matching syspkgs in ${SYSPKG_DB_TOPDIR}"
    517   1.9     apb 			${force} || bomb
    518   1.9     apb 			# If ${force} is set, then assume that the last
    519   1.9     apb 			# match is the most recent.
    520   1.9     apb 			# XXX: This might be wrong, because of
    521   1.9     apb 			# differences between lexical sorting and
    522   1.9     apb 			# numeric sorting.
    523   1.9     apb 			lastmatch="${blddep##* }"
    524   1.9     apb 			echo "@blddep ${lastmatch}"
    525   1.9     apb 			;;
    526   1.9     apb 		*)	# exactly one match.
    527   1.9     apb 			# XXX: We ignore the possibility that the
    528   1.9     apb 			# version we found via ${pkgdepglob} might not
    529   1.9     apb 			# satisfy ${pkgdep}.  We could conceivably use
    530   1.9     apb 			# "pkg_admin pmatch" to check, but that's not a
    531   1.9     apb 			# host tool so we can't assume that it will be
    532   1.9     apb 			# available.
    533   1.9     apb 			echo "@blddep ${blddep}"
    534   1.9     apb 			;;
    535   1.9     apb 		esac
    536   1.9     apb 	done >>"${PLIST}"
    537   1.9     apb 
    538   1.9     apb 	# create the comment (should be one line)
    539   1.9     apb 	comment="$( ${AWK} '$1 ~ '/"${pkg}"/' \
    540   1.9     apb 			{ print substr($0, length($1) + 2) }' \
    541   1.9     apb 			"${rundir}/comments" )"
    542   1.9     apb 	case "${comment}" in
    543   1.9     apb 	"")	echo >&2 "${WARNING}no comment for \"${pkg}\" (using placeholder)"
    544   1.9     apb 		comment="System package for ${pkg}"
    545   1.9     apb 		;;
    546   1.9     apb 	*"${nl}"*)
    547   1.9     apb 		echo >&2 "${ERRWARN}multi-line comment for \"${pkg}\""
    548   1.9     apb 		${force} || bomb
    549   1.9     apb 		;;
    550   1.9     apb 	esac
    551   1.9     apb 	echo "${comment}" > "${SYSPKG_DB_SUBDIR}/+COMMENT"
    552   1.1     agc 
    553   1.9     apb 	# create the description (could be multiple lines)
    554   1.9     apb 	descr="$( ${AWK} '$1 ~ '/"${pkg}"/' {
    555   1.9     apb 			print substr($0, length($1) + 2) }' \
    556   1.9     apb 			"${rundir}/descrs" )"
    557   1.9     apb 	case "${descr}" in
    558   1.9     apb 	"")	echo >&2 "${WARNING}no description for \"${pkg}\" (re-using comment)" 2>&1
    559   1.9     apb 		descr="${comment}"
    560   1.9     apb 		;;
    561   1.9     apb 	esac
    562   1.9     apb 	echo "${descr}" > "${SYSPKG_DB_SUBDIR}/+DESC"
    563   1.9     apb 	${PRINTF} "\nHomepage:\nhttp://www.NetBSD.org/\n" >> "${SYSPKG_DB_SUBDIR}/+DESC"
    564   1.1     agc 
    565   1.9     apb 	# create the build information
    566   1.9     apb 	if [ x"${BUILD_INFO_CACHE}" = x ]; then
    567   1.9     apb 		{
    568   1.9     apb 		# These variables describe the build
    569   1.9     apb 		# environment, not the target.
    570   1.9     apb 		echo "OPSYS=$(${UNAME} -s)"
    571   1.9     apb 		echo "OS_VERSION=$(${UNAME} -r)"
    572   1.9     apb 		${MAKE} -f- all <<EOF
    573   1.4  dyoung .include <bsd.own.mk>
    574   1.4  dyoung all:
    575   1.4  dyoung 	@echo OBJECT_FMT=${OBJECT_FMT}
    576   1.4  dyoung 	@echo MACHINE_ARCH=${MACHINE_ARCH}
    577   1.4  dyoung 	@echo MACHINE_GNU_ARCH=${MACHINE_GNU_ARCH}
    578   1.4  dyoung EOF
    579   1.9     apb 		# XXX: what's the point of reporting _PKGTOOLS_VER
    580   1.9     apb 		# when we roll everything by hand without using
    581   1.9     apb 		# the pkg tools?
    582   1.9     apb 		echo "_PKGTOOLS_VER=$(${PKG_CREATE} -V)"
    583   1.9     apb 		} > "${SYSPKG_DB_SUBDIR}/+BUILD_INFO"
    584   1.9     apb 	else
    585   1.9     apb 		cp "${BUILD_INFO_CACHE}" "${SYSPKG_DB_SUBDIR}/+BUILD_INFO"
    586   1.9     apb 	fi
    587   1.9     apb 
    588   1.9     apb 	# test for attributes
    589   1.9     apb 	args=""
    590   1.9     apb 	attrs="$( ${AWK} '$1 ~ '/"${pkg}"/' { \
    591   1.9     apb 			print substr($0, length($1) + 2) }' \
    592   1.9     apb 		"${rundir}/attrs" )"
    593   1.9     apb 	for a in "${attrs}"; do
    594   1.9     apb 		case "${attrs}" in
    595   1.9     apb 		"")	;;
    596   1.9     apb 		preserve)
    597   1.9     apb 			echo "${pkg}-${t}" >"${SYSPKG_DB_SUBDIR}/+PRESERVE"
    598   1.9     apb 			args="${args} -n ${SYSPKG_DB_SUBDIR}/+PRESERVE"
    599   1.9     apb 			;;
    600   1.9     apb 		esac
    601   1.9     apb 	done
    602   1.9     apb 
    603   1.9     apb 	#
    604   1.9     apb 	# Create ${SYSPKGSIR}/+CONTENTS from ${PLIST}, by adding an
    605   1.9     apb 	# "@name" line and a lot of "@comment MD5:" lines.
    606   1.9     apb 	#
    607   1.9     apb 	{
    608  1.11     apb 		rcsid='$NetBSD: regpkg,v 1.11 2006/01/08 10:24:04 apb Exp $'
    609   1.9     apb 		utcdate="$( ${ENV_CMD} TZ=UTC LOCALE=C \
    610   1.9     apb 			${DATE} '+%Y-%m-%d %H:%M' )"
    611   1.9     apb 		user="${USER:-root}"
    612   1.9     apb 		host="$( ${HOSTNAME} )"
    613   1.9     apb 		echo "@name ${pkg}-${t}"
    614   1.9     apb 		echo "@comment Packaged at ${utcdate} UTC by ${user}@${host}"
    615   1.9     apb 		echo "@comment Packaged using ${prog} ${rcsid}"
    616   1.9     apb 		# XXX: "option extract-in-place" might help to get
    617   1.9     apb 		#	pkg_add to create directories.
    618   1.9     apb 		# XXX: no, it doesn't work.  Yet another pkg_add bug.
    619   1.9     apb 		## echo "@option extract-in-place"
    620   1.9     apb 		# Move the @pkgdep and @blddep lines up, so that
    621   1.9     apb 		# they are easy to see when people do "less
    622   1.9     apb 		# ${DESTDIR}/var/db/syspkg/*/+CONTENTS".
    623   1.9     apb 		${EGREP} '^(@pkgdep|@blddep)' "${PLIST}" || true
    624   1.9     apb 		# Now do the remainder of the file.
    625   1.9     apb 		while read line ; do
    626   1.9     apb 			case "${line}" in
    627   1.9     apb 			@pkgdep*|@blddep*)
    628   1.9     apb 				# already handled by grep above
    629   1.9     apb 				;;
    630   1.9     apb 			@cwd*)
    631   1.9     apb 				# There should be exactly one @cwd line.
    632   1.9     apb 				# Just after it, add an "@exec mkdir"
    633   1.9     apb 				# line for every directory.  This is to
    634   1.9     apb 				# work around a pkg-add bug (see
    635   1.9     apb 				# <http://mail-index.NetBSD.org/tech-pkg/2003/12/11/0018.html>)
    636   1.9     apb 				echo "${line}"
    637   1.9     apb 				print_dir_exec_lines
    638   1.9     apb 				;;
    639   1.9     apb 			@*)	
    640   1.9     apb 				# just pass through all other @foo lines
    641   1.9     apb 				echo "${line}"
    642   1.9     apb 				;;
    643   1.9     apb 			*)	
    644   1.9     apb 				# This should be a file name.  Pass it
    645   1.9     apb 				# through, and append "@comment MD5:".
    646   1.9     apb 				# XXX why not SHA256 ?
    647   1.9     apb 				echo "${line}"
    648   1.9     apb 				file="${DESTDIR}${line}"
    649   1.9     apb 				if [ -f "${file}" -a -r "${file}" ];
    650   1.9     apb 				then
    651   1.9     apb 					md5sum="$( ${CKSUM} -n -m "${file}" \
    652   1.9     apb 						   | ${AWK} '{print $1}'
    653   1.9     apb 						)"
    654   1.9     apb 					echo "@comment MD5:${md5sum}"
    655   1.9     apb 				fi
    656   1.9     apb 				;;
    657   1.9     apb 			esac
    658   1.9     apb 		done <"${PLIST}"
    659   1.9     apb 	} >"${SYSPKG_DB_SUBDIR}/+CONTENTS"
    660   1.9     apb 
    661   1.9     apb 	#
    662   1.9     apb 	#  Update ${SYSPKG_DB_TOPDIR}/pkgdb.byfile.db.
    663   1.9     apb 	#
    664   1.9     apb 	{
    665   1.9     apb 		dbfile="${SYSPKG_DB_TOPDIR}/pkgdb.byfile.db"
    666   1.9     apb 		dbtype="btree"
    667   1.9     apb 		db_opts=''
    668   1.9     apb 		# XXX: cross builds should really add "-E B" or "-E L"
    669   1.9     apb 		# (big-endian or little-endian) to db_opts, but we don't
    670   1.9     apb 		# do that yet.
    671   1.9     apb 		if ${update} || ${force} ; then
    672   1.9     apb 			# overwriting an existing entry is not an error
    673   1.9     apb 			db_opts="${db_opts} -R"
    674   1.9     apb 		fi
    675   1.9     apb 		if [ ${verbosity} -lt 2 ]; then
    676   1.9     apb 			# don't print all the keys added to the database
    677   1.9     apb 			db_opts="${db_opts} -q"
    678   1.9     apb 		fi
    679   1.9     apb 
    680   1.9     apb 		# Transform ${PLIST} into a form to be used as keys in
    681   1.9     apb 		# ${dbfile}.  The results look like absolute paths,
    682   1.9     apb 		# but they are really relative to ${DESTDIR}.
    683   1.9     apb 		#
    684   1.9     apb 		# "@dirrm ."		-> "/"
    685   1.9     apb 		# "@dirrm foo/bar"	-> "/foo/bar"
    686   1.9     apb 		# "@dirrm ./foo/bar"	-> "/foo/bar"
    687   1.9     apb 		# "foo/bar/baz"		-> "/foo/bar/baz"
    688   1.9     apb 		# "./foo/bar/baz"	-> "/foo/bar/baz"
    689   1.9     apb 		#
    690   1.9     apb 		dblist="${SCRATCH}/dblist"
    691   1.9     apb 		${AWK} '/^@dirrm \.\//	{gsub("^.", "", $2); print $2; next}
    692   1.9     apb 			/^@dirrm \.$/	{print "/"; next}
    693   1.9     apb 			/^@dirrm/	{print "/" $2; next}
    694   1.9     apb 			/^@/		{next}
    695   1.9     apb 			/^\.\//		{gsub("^.", "", $0); print $0; next}
    696   1.9     apb 			/./		{print "/" $0; next}' \
    697   1.9     apb 			<"${PLIST}" >"${dblist}"
    698   1.9     apb 		# Add all the path names to the database.
    699   1.9     apb 		${AWK} '{print $1 "\t" "'"${pkg}-${t}"'"}' <"${dblist}" \
    700   1.9     apb 		| ${DB} -w ${db_opts} -F "${tab}" -f - "${dbtype}" "${dbfile}"
    701   1.9     apb 	}
    702   1.9     apb 
    703   1.9     apb 	if ${verbose} ; then
    704   1.9     apb 		echo "Registered ${pkg}-${t} in ${SYSPKG_DB_TOPDIR}"
    705   1.9     apb 	elif ! ${quiet} ; then
    706   1.9     apb 		echo "Registered ${pkg}-${t}"
    707   1.9     apb 	fi
    708   1.9     apb 
    709   1.9     apb 	cleanup_must_delete_dbsubdir=false
    710   1.9     apb }
    711   1.9     apb 
    712   1.9     apb #
    713   1.9     apb # create_syspkg_tgz() creates the *.tgz file for the package.
    714   1.9     apb #
    715   1.9     apb # The output file is ${binpkgdir}/${pkg}-${t}.tgz.
    716   1.9     apb #
    717   1.9     apb create_syspkg_tgz ()
    718   1.9     apb {
    719   1.9     apb 	#
    720   1.9     apb 	# pkg_create does not understand metalog files, so we have to
    721   1.9     apb 	# use pax directly.
    722   1.9     apb 	#
    723   1.9     apb 	# We create two specfiles: specfile_overhead describes the
    724   1.9     apb 	# special files that are part of the package system's metadata
    725   1.9     apb 	# (+CONTENTS, +COMMENT, +DESCR, and more); and specfile_payload
    726   1.9     apb 	# describes the files and directories that we actually want as
    727   1.9     apb 	# part of the package's payload.
    728   1.9     apb 	#
    729   1.9     apb 	# We then use the specfiles to create a compressed tarball that
    730   1.9     apb 	# contains both the overhead files and the payload files.
    731   1.9     apb 	#
    732   1.9     apb 	# There's no trivial way to get a single pax run to do
    733   1.9     apb 	# everything we want, so we run pax twice, with a different
    734   1.9     apb 	# working directory and a different specfile each time.
    735   1.9     apb 	#
    736   1.9     apb 	# We could conceivably make clever use of pax's "-s" option to
    737   1.9     apb 	# get what we want from a single pax run with a single (more
    738   1.9     apb 	# complicated) specfile, but the extra trouble doesn't seem
    739   1.9     apb 	# warranted.
    740   1.9     apb 	#
    741   1.9     apb 	cleanup_must_delete_binpkgfile=true
    742   1.9     apb 	specfile_overhead="${SCRATCH}/spec_overhead"
    743   1.9     apb 	specfile_payload="${SCRATCH}/spec_payload"
    744   1.9     apb 	tarball_uncompressed="${SCRATCH}/tarball_uncompressed"
    745   1.9     apb 
    746   1.9     apb 	# Create a specfile for all the overhead files (+CONTENTS and
    747   1.9     apb 	# friends).
    748   1.9     apb 	{
    749   1.9     apb 		plusnames_first="${SCRATCH}/plusnames_first"
    750   1.9     apb 		plusnames_rest="${SCRATCH}/plusnames_rest"
    751   1.9     apb 
    752   1.9     apb 		# Ensure that the first few files are in the same order
    753   1.9     apb 		# that "pkg_create" would have used, just in case anything
    754   1.9     apb 		# depends on that.  Other files in alphabetical order.
    755   1.9     apb 		SHOULD_BE_FIRST="+CONTENTS +COMMENT +DESC"
    756   1.9     apb 		(
    757   1.9     apb 			cd "${SYSPKG_DB_SUBDIR}" || bomb
    758   1.9     apb 			for file in ${SHOULD_BE_FIRST}; do
    759   1.9     apb 				[ -e "./${file}" ] && echo "${file}"
    760   1.9     apb 			done >"${plusnames_first}"
    761   1.9     apb 			${LS} -1 | ${FGREP} -v -f "${plusnames_first}" \
    762   1.9     apb 				>"${plusnames_rest}" \
    763   1.9     apb 				|| true
    764   1.9     apb 		)
    765   1.9     apb 
    766   1.9     apb 		# Convert the file list to specfile format, and override the
    767   1.9     apb 		# uid/gid/mode.
    768   1.9     apb 		{
    769   1.9     apb 			echo ". optional type=dir"
    770   1.9     apb 			${AWK} '{print "./" $0 " type=file uid=0 gid=0 mode=0444"
    771   1.9     apb 				}' "${plusnames_first}" "${plusnames_rest}"
    772   1.9     apb 		} >"${specfile_overhead}"
    773   1.9     apb 	}
    774   1.9     apb 
    775   1.9     apb 	# Create a specfile for the payload of the package.
    776   1.9     apb 	{
    777   1.9     apb 		spec1="${SCRATCH}/spec1"
    778   1.9     apb 		spec2="${SCRATCH}/spec2"
    779   1.9     apb 
    780   1.9     apb 		# Transform ${PLIST} into simple specfile format:
    781   1.9     apb 		#
    782  1.11     apb 		# "@dirrm ."		-> ". type=dir"
    783  1.11     apb 		# "@dirrm foo/bar"	-> "./foo/bar type=dir"
    784  1.11     apb 		# "@dirrm ./foo/bar"	-> "./foo/bar type=dir"
    785   1.9     apb 		# "foo/bar/baz"		-> "./foo/bar/baz"
    786   1.9     apb 		# "./foo/bar/baz"	-> "./foo/bar/baz"
    787   1.9     apb 		#
    788   1.9     apb 		# Ignores @cwd lines.  This should be safe, given how
    789   1.9     apb 		# makeplist works.
    790  1.11     apb 		${AWK} '/^@dirrm \.\//	{print $2 " type=dir" ; next}
    791  1.11     apb 			/^@dirrm \.$/	{print ". type=dir"; next}
    792  1.11     apb 			/^@dirrm/	{print "./" $2 " type=dir" ; next}
    793   1.9     apb 			/^@/		{next}
    794   1.9     apb 			/^\.\//		{print $0; next}
    795   1.9     apb 			/./		{print "./" $0; next}' \
    796   1.9     apb 			<"${PLIST}" >"${spec1}"
    797   1.9     apb 
    798   1.9     apb 		# If metalog was specified, attributes from metalog override
    799   1.9     apb 		# attributes in the file system.  We also fake up an
    800   1.9     apb 		# entry for the ./etc/mtree/set.${pkgset} file.
    801   1.9     apb 		{
    802   1.9     apb 			if [ -n "${metalog}" ]; then
    803   1.9     apb 				${AWK} -f "${rundir}/join.awk" \
    804   1.9     apb 					"${spec1}" "${metalog}"
    805   1.9     apb 				${AWK} -f "${rundir}/join.awk" \
    806   1.9     apb 					"${spec1}" /dev/stdin <<EOF
    807   1.9     apb ./etc/mtree/set.${pkgset} type=file mode=0444 uname=root gname=wheel
    808   1.9     apb EOF
    809   1.9     apb 			else
    810   1.9     apb 				cat "${spec1}"
    811   1.9     apb 			fi
    812   1.9     apb 		} >"${spec2}"
    813   1.9     apb 
    814   1.9     apb 		#
    815   1.9     apb 		# If a file or directory to was mentioned explicitly
    816   1.9     apb 		# in ${PLIST} but not mentioned in ${metalog}, then the
    817   1.9     apb 		# file or directory will not be mentioned in ${spec2}.
    818   1.9     apb 		# This is an error, and means that the metalog was
    819   1.9     apb 		# not built correctly.
    820   1.9     apb 		#
    821   1.9     apb 		if [ -n "${metalog}" ]; then
    822   1.9     apb 			names1="${SCRATCH}/names1"
    823   1.9     apb 			names2="${SCRATCH}/names2"
    824   1.9     apb 			${AWK} '{print $1}' <"${spec1}" | ${SORT} >"${names1}"
    825   1.9     apb 			${AWK} '{print $1}' <"${spec2}" | ${SORT} >"${names2}"
    826   1.9     apb 			if ${FGREP} -v -f "${names2}" "${spec1}" >/dev/null
    827   1.9     apb 			then
    828   1.9     apb 				cat >&2 <<EOM
    829   1.9     apb ${ERRWARN}The metalog file (${metalog}) does not
    830   1.9     apb 	contain entries for the following files or directories
    831   1.9     apb 	which should be part of the ${pkg} syspkg:
    832   1.9     apb EOM
    833   1.9     apb 				${FGREP} -v -f "${names2}" "${spec1}" >&2
    834   1.9     apb 				${force} || bomb
    835   1.9     apb 			fi
    836   1.9     apb 			if ${FGREP} -v -f "${names1}" "${spec2}" >/dev/null
    837   1.9     apb 			then
    838   1.9     apb 				cat >&2 <<EOM
    839   1.9     apb ${ERRWARN}The following lines are in the metalog file
    840   1.9     apb 	(${metalog}), and the corresponding files or directories
    841   1.9     apb 	should be in the ${pkg} syspkg, but something is wrong:
    842   1.9     apb EOM
    843   1.9     apb 				${FGREP} -v -f "${names1}" "${spec2}" >&2
    844   1.9     apb 				bomb
    845   1.9     apb 			fi
    846   1.9     apb 		fi
    847   1.9     apb 
    848   1.9     apb 		# Add lines (tagged "optional") for any implicit directories.
    849   1.9     apb 		#
    850   1.9     apb 		# For example, if we have a file ./foo/bar/baz, then we add
    851   1.9     apb 		# "./foo/bar optional type=dir", "./foo optional type=dir",
    852   1.9     apb 		# and ". optional type=dir", unless those directories were
    853   1.9     apb 		# already mentioned explicitly.
    854   1.9     apb 		#
    855   1.9     apb 		${AWK} -f "${rundir}/getdirs.awk" "${spec2}" \
    856   1.9     apb 		| ${SORT} -u >"${specfile_payload}"
    857   1.9     apb 	}
    858   1.9     apb 
    859   1.9     apb 	# Use two pax invocations followed by gzip to create
    860   1.9     apb 	# the tgz file.
    861   1.9     apb 	#
    862   1.9     apb 	# Remove any leading "./" from path names, because that
    863   1.9     apb 	# could confuse tools that work with binary packages.
    864   1.9     apb 	(
    865   1.9     apb 		cd "${SYSPKG_DB_SUBDIR}" && \
    866   1.9     apb 		${PAX} -O -w -d -N"${etcdir}" -M '-s,^\./,,' \
    867   1.9     apb 			-f "${tarball_uncompressed}" \
    868   1.9     apb 			<"${specfile_overhead}" \
    869   1.9     apb 		|| bomb
    870   1.9     apb 	)
    871   1.9     apb 	(
    872   1.9     apb 		cd "${DESTDIR:-/}" && \
    873   1.9     apb 		${PAX} -O -w -d -N"${etcdir}" -M '-s,^\./,,' \
    874   1.9     apb 			-a -f "${tarball_uncompressed}" \
    875   1.9     apb 			<"${specfile_payload}" \
    876   1.9     apb 		|| bomb
    877   1.9     apb 	)
    878   1.9     apb 	${GZIP_CMD} -9 <"${tarball_uncompressed}" >"${binpkgfile}" || bomb
    879   1.9     apb 
    880   1.9     apb 	# (Extra space is to make message line up with "Registered" message.)
    881   1.9     apb 	if ${verbose} ; then
    882   1.9     apb 		echo "  Packaged ${binpkgfile}"
    883   1.9     apb 	elif ! ${quiet} ; then
    884   1.9     apb 		echo "  Packaged ${binpkgfile##*/}"
    885   1.9     apb 	fi
    886   1.9     apb 
    887   1.9     apb 	cleanup_must_delete_binpkgfile=false
    888   1.9     apb 
    889   1.9     apb }
    890   1.9     apb 
    891   1.9     apb #
    892   1.9     apb # do_register_syspkg() registers the syspkg if appropriate.
    893   1.9     apb #
    894   1.9     apb # If SYSPKG_DB_SUBDIR already exists, that might be an error, depending
    895   1.9     apb # on ${force} and ${update} flags.
    896   1.9     apb #
    897   1.9     apb do_register_syspkg ()
    898   1.9     apb {
    899   1.9     apb 	# Check that necessary variables are defined
    900   1.9     apb 	[ -n "${SYSPKG_DB_TOPDIR}" ] || bomb
    901   1.9     apb 	[ -n "${SYSPKG_DB_SUBDIR}" ] || bomb
    902   1.9     apb 
    903   1.9     apb 	# Create SYSPKG_DB_TOPDIR if necessary
    904   1.9     apb 	[ -d "${SYSPKG_DB_TOPDIR}" ] || mkdir -p "${SYSPKG_DB_TOPDIR}" || bomb
    905   1.9     apb 
    906   1.9     apb 	# A function to delete and re-register a syspkg
    907   1.9     apb 	delete_and_reregister ()
    908   1.9     apb 	{
    909   1.9     apb 		echo >&2 "${ERRWARNNOTE}deleting and re-registering ${pkg}-${t}"
    910   1.9     apb 		cleanup_must_delete_dbsubdir=true
    911   1.9     apb 		rm -rf "${SYSPKG_DB_SUBDIR}"
    912   1.9     apb 		register_syspkg
    913   1.9     apb 	}
    914   1.9     apb 
    915   1.9     apb 	# Check whether another version of ${pkg} is already registered.
    916   1.9     apb 	pattern="${pkg}-[0-9]*"
    917   1.9     apb 	matches="$( cd "${SYSPKG_DB_TOPDIR}" && echo ${pattern} || bomb )"
    918   1.9     apb 	case "${matches}" in
    919   1.9     apb 	*\*)		;;	# wildcard did not match anything
    920   1.9     apb 	"${pkg}-${t}")	;;	# exact match
    921   1.9     apb 	*)	echo >&2 "${ERRWARN}another version of ${pkg} is already registered in ${SYSPKG_DB_TOPDIR} (while creating ${pkg}-${t})"
    922   1.9     apb 		${force} || bomb
    923   1.9     apb 		;;
    924   1.9     apb 	esac
    925   1.9     apb 
    926   1.9     apb 	# Check whether the desired version of ${pkg} is already registered,
    927   1.9     apb 	# and create it if appropriate.
    928   1.9     apb 	if [ -d "${SYSPKG_DB_SUBDIR}" ]; then
    929   1.9     apb 		echo >&2 "${ERRWARNNOTE}${pkg}-${t} is already registered"
    930   1.9     apb 		${verbose} && echo >&2 "	in ${SYSPKG_DB_TOPDIR}"
    931   1.9     apb 		if ${force}; then
    932   1.9     apb 			delete_and_reregister
    933   1.9     apb 		elif ${update}; then
    934   1.9     apb 			#
    935   1.9     apb 			# If all files in SYSPKG_DB_SUBDIR are newer
    936   1.9     apb 			# than all files in the pkg, then do nothing.
    937   1.9     apb 			# Else delete and re-register the pkg.
    938   1.9     apb 			#
    939   1.9     apb 			[ -n "${newestfile}" ] || init_newestfile
    940   1.9     apb 			if [ -n "${newestfile}" ]; then
    941   1.9     apb 				case "$( ${FIND} "${SYSPKG_DB_SUBDIR}" -type f \
    942   1.9     apb 					! -newer "${newestfile}" -print )" \
    943   1.9     apb 				in
    944   1.9     apb 				"")	;;
    945   1.9     apb 				*)	delete_and_reregister ;;
    946   1.9     apb 				esac
    947   1.9     apb 
    948   1.9     apb 			else
    949   1.9     apb 				# No files in the pkg?  (This could happen
    950   1.9     apb 				# if a pkg contains only directories.)
    951   1.9     apb 				# Do nothing.
    952   1.9     apb 			fi
    953   1.9     apb 		else
    954   1.9     apb 			bomb
    955   1.9     apb 		fi
    956   1.9     apb 	else
    957   1.9     apb 		register_syspkg
    958   1.9     apb 	fi
    959   1.9     apb }
    960   1.9     apb 
    961   1.9     apb #
    962   1.9     apb # do_create_syspkg_tgz() creates the the binary pkg (*.tgz) if
    963   1.9     apb # appropriate.
    964   1.9     apb #
    965   1.9     apb # If binpkgfile already exists, that might be an error, depending on
    966   1.9     apb # ${force} and ${update} flags.
    967   1.9     apb #
    968   1.9     apb do_create_syspkg_tgz ()
    969   1.9     apb {
    970   1.9     apb 	[ -n "${binpkgfile}" ] || bomb
    971   1.9     apb 
    972   1.9     apb 	delete_and_recreate ()
    973   1.9     apb 	{
    974   1.9     apb 		echo >&2 "${ERRWARNNOTE}deleting and re-creating ${pkg}-${t}.tgz"
    975   1.9     apb 		rm -f "${binpkgfile}"
    976   1.9     apb 		create_syspkg_tgz
    977   1.9     apb 	}
    978   1.9     apb 
    979   1.9     apb 	# Check whether another version of ${pkg} already exists.
    980   1.9     apb 	pattern="${pkg}-[0-9]*"
    981   1.9     apb 	matches="$( cd "${binpkgdir}" && echo ${pattern} || bomb )"
    982   1.9     apb 	case "${matches}" in
    983   1.9     apb 	*\*)	;;	# wildcard did not match anything
    984   1.9     apb 	"${pkg}-${t}.tgz") ;;	# exact match
    985   1.9     apb 	*)	echo >&2 "${ERRWARN}another version of ${pkg} already exists in ${binpkgdir} (while creating ${pkg}-${t}.tgz)"
    986   1.9     apb 		${force} || bomb
    987   1.9     apb 		;;
    988   1.9     apb 	esac
    989   1.9     apb 
    990   1.9     apb 	# Check whether the desired version of ${pkg} already exists,
    991   1.9     apb 	# and create it if appropriate.
    992   1.9     apb 	if [ -e "${binpkgfile}" ]; then
    993   1.9     apb 		echo >&2 "${ERRWARNNOTE}${pkg}-${t}.tgz already exists"
    994   1.9     apb 		${verbose} && echo >&2 "	in ${binpkgdir}"
    995   1.9     apb 		if ${force}; then
    996   1.9     apb 			delete_and_recreate
    997   1.9     apb 		elif ${update}; then
    998   1.9     apb 			#
    999   1.9     apb 			# If all files in SYSPKG_DB_SUBDIR are older
   1000   1.9     apb 			# than ${binpkgfile}, then do nothing.
   1001   1.9     apb 			# Else delete and re-create the tgz.
   1002   1.9     apb 			#
   1003   1.9     apb 			case "$( ${FIND} "${SYSPKG_DB_SUBDIR}" -type f \
   1004   1.9     apb 				-newer "${binpkgfile}" -print )" \
   1005   1.9     apb 			in
   1006   1.9     apb 			"")	;;
   1007   1.9     apb 			*)	delete_and_recreate ;;
   1008   1.9     apb 			esac
   1009   1.9     apb 		else
   1010   1.9     apb 			bomb
   1011   1.9     apb 		fi
   1012   1.9     apb 	else
   1013   1.9     apb 		create_syspkg_tgz
   1014   1.9     apb 	fi
   1015   1.9     apb }
   1016   1.9     apb 
   1017   1.9     apb ####################
   1018   1.9     apb # begin main program
   1019   1.9     apb 
   1020   1.9     apb parse_args ${1+"$@"}
   1021   1.9     apb make_PLIST
   1022   1.9     apb choose_version_number
   1023   1.9     apb SYSPKG_DB_SUBDIR="${SYSPKG_DB_TOPDIR}/${pkg}-${t}"
   1024   1.9     apb do_register_syspkg
   1025   1.9     apb if [ -n "${binpkgdir}" ]; then
   1026   1.9     apb 	binpkgfile="${binpkgdir}/${pkg}-${t}.tgz"
   1027   1.9     apb 	do_create_syspkg_tgz
   1028   1.5  dyoung fi
   1029   1.1     agc 
   1030   1.9     apb exit 0
   1031