regpkg revision 1.5
11.1Sagc#! /bin/sh
21.1Sagc#
31.5Sdyoung# $NetBSD: regpkg,v 1.5 2004/01/16 10:05:10 dyoung 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.1Sagc# Usage: regpkg set pkgname
371.1Sagc
381.1SagcSYSPKGROOT=${PKG_DBDIR:-/var/db/pkg}
391.1Sagccase "${SYSPKG_DBDIR}" in
401.1Sagc"")	;;
411.1Sagc*)	SYSPKGROOT=${SYSPKG_DBDIR} ;;
421.1Sagcesac
431.1Sagc
441.1SagcPLIST=/tmp/.PLIST.$$
451.1Sagc
461.1Sagcverbose=""
471.1Sagcwhile [ $# -gt 2 ]; do
481.1Sagc	case $1 in
491.1Sagc	-v)	verbose=$1 ;;
501.1Sagc	*)	break ;;
511.1Sagc	esac
521.1Sagc	shift
531.1Sagcdone
541.1Sagc
551.1Sagcif [ $# -ne 2 ]; then
561.1Sagc	echo "Usage: regpkg set pkgname"
571.1Sagc	exit 1
581.1Sagcfi
591.1Sagc
601.1Sagcpkgset=$1
611.1Sagc
621.1Sagcpkg=$2
631.1Sagc
641.1Sagccase $verbose in
651.1Sagc-v)	echo "Making PLIST for \"$pkgset\" set and \"$pkg\" package" ;;
661.1Sagcesac
671.1Sagc
681.1Sagc# create the skeleton PLIST from the pkgset description
691.1Sagc./makeplist $pkgset $pkg > $PLIST
701.1Sagc
711.2Sjwise# create the pkg tiny version
721.3Sagccase "${SYSPKG_DATES}" in
731.3Sagc"")	tinyvers=`awk '$1 ~ '/$pkg/' { print $2 }' versions`
741.3Sagc	case "$tinyvers" in
751.3Sagc	"")	tinyvers=0
761.3Sagc		;;
771.3Sagc	esac
781.3Sagc	if [ -f ../../sys/conf/osrelease.sh ]; then
791.3Sagc		osvers=`sh ../../sys/conf/osrelease.sh`
801.4Sdyoung		method=osreleases
811.3Sagc	else
821.3Sagc		osvers=`uname -r`
831.3Sagc		method=uname
841.3Sagc	fi
851.3Sagc	t=$osvers.$tinyvers
861.3Sagc	;;
871.3Sagc*)	args=`awk '
881.3Sagc		/^@cwd/ { prefix = $2; next }
891.3Sagc		/^@dirrm/ { next }
901.3Sagc		{ printf("%s%s\n", prefix, $0) }' $PLIST`
911.3Sagc	# first try for any RCS identifiers in the files
921.3Sagc	t=0
931.3Sagc	case "$args" in
941.3Sagc	"")	;;
951.3Sagc	*)	t=`ident $args 2>/dev/null | awk '
961.3Sagc			BEGIN { last = 0 }
971.3Sagc			$2 == "crt0.c,v" { next }
981.3Sagc			NF == 8 { t = $4; gsub("/", "", t); if (t > last) last = t; }
991.3Sagc			END { print last }'`
1001.3Sagc		method=ident
1011.3Sagc		;;
1021.3Sagc	esac
1031.3Sagc	case "$t" in
1041.3Sagc	0)	# we need the last mtime of the files which make up the package
1051.3Sagc		t=`env TZ=UTC LOCALE=C ls -lT $args | awk '
1061.3Sagc			BEGIN { newest = 0 }
1071.3Sagc			{
1081.3Sagc				t = $9 "";
1091.3Sagc				if ($6 == "Jan") t = t "01";
1101.3Sagc				if ($6 == "Feb") t = t "02";
1111.3Sagc				if ($6 == "Mar") t = t "03";
1121.3Sagc				if ($6 == "Apr") t = t "04";
1131.3Sagc				if ($6 == "May") t = t "05";
1141.3Sagc				if ($6 == "Jun") t = t "06";
1151.3Sagc				if ($6 == "Jul") t = t "07";
1161.3Sagc				if ($6 == "Aug") t = t "08";
1171.3Sagc				if ($6 == "Sep") t = t "09";
1181.3Sagc				if ($6 == "Oct") t = t "10";
1191.3Sagc				if ($6 == "Nov") t = t "11";
1201.3Sagc				if ($6 == "Dec") t = t "12";
1211.3Sagc				if ($7 < 10) t = t "0";
1221.3Sagc				t = t $7;
1231.3Sagc				#these next two lines add the 24h clock onto the date
1241.3Sagc				#gsub(":", "", $8);
1251.3Sagc				#t = sprintf("%s.%4.4s", t, $8);
1261.3Sagc				if (t > newest) newest = t;
1271.3Sagc			}
1281.3Sagc			END { print newest }'`
1291.3Sagc		method=ls
1301.3Sagc		;;
1311.3Sagc	esac
1321.2Sjwise	;;
1331.2Sjwiseesac
1341.2Sjwise
1351.3Sagc# print version number that we're using
1361.3Sagccase "$verbose" in
1371.3Sagc-v)	echo "$pkg - $t version using $method method" ;;
1381.3Sagcesac
1391.1Sagc
1401.1Sagc# create the directory and minimal contents
1411.1SagcSYSPKGDIR=${SYSPKGROOT}/$pkg-$t
1421.1Sagcif [ -d ${SYSPKGDIR} ]; then
1431.1Sagc	echo "There is already a $pkg-$t package installed (${SYSPKGDIR})"
1441.1Sagc	exit 1
1451.1Sagcfi
1461.1Sagc
1471.1Sagcmkdir -p ${SYSPKGDIR}
1481.1Sagc
1491.4Sdyoung# add the dependencies
1501.4Sdyoungawk '$1 ~ '/$pkg/' { print $2 }' deps | sort | \
1511.4Sdyoung    awk '{ print "@pkgdep " $1 "-[0-9]*" }' >> $PLIST
1521.4Sdyoung
1531.1Sagc# create the comment
1541.1Sagccomment=`awk '$1 ~ '/$pkg/' { print substr($0, length($1) + 2) }' comments`
1551.1Sagccase "$comment" in
1561.1Sagc"")	echo "***WARNING ***: no comment for \"$pkg\"" 2>&1
1571.1Sagc	comment="System package for $pkg"
1581.1Sagc	;;
1591.1Sagcesac
1601.1Sagcecho "$comment" > ${SYSPKGDIR}/+COMMENT
1611.1Sagc
1621.1Sagc# create the description
1631.1Sagcdescr=`awk '$1 ~ '/$pkg/' { print substr($0, length($1) + 2) }' descrs`
1641.1Sagccase "$descr" in
1651.1Sagc"")	echo "***WARNING ***: no description for \"$pkg\"" 2>&1
1661.1Sagc	descr="System package for $pkg"
1671.1Sagc	;;
1681.1Sagcesac
1691.1Sagcecho "$descr" > ${SYSPKGDIR}/+DESC
1701.1Sagcprintf "\nHomepage:\nhttp://www.NetBSD.org/\n" >> ${SYSPKGDIR}/+DESC
1711.1Sagc
1721.1Sagc# create the build information
1731.5Sdyoungif [ x${BUILD_INFO_CACHE} = x ]; then
1741.5Sdyoung	{
1751.5Sdyoung	echo "OPSYS=`uname -s`"
1761.5Sdyoung	echo "OS_VERSION=`uname -r`"
1771.5Sdyoung	make -f- all <<EOF
1781.4Sdyoung.include <bsd.own.mk>
1791.4Sdyoungall:
1801.4Sdyoung	@echo OBJECT_FMT=${OBJECT_FMT}
1811.4Sdyoung	@echo MACHINE_ARCH=${MACHINE_ARCH}
1821.4Sdyoung	@echo MACHINE_GNU_ARCH=${MACHINE_GNU_ARCH}
1831.4SdyoungEOF
1841.5Sdyoung	echo "_PKGTOOLS_VER=`pkg_create -V`"
1851.5Sdyoung	} > ${SYSPKGDIR}/+BUILD_INFO
1861.5Sdyoungelse
1871.5Sdyoung	cp ${BUILD_INFO_CACHE} ${SYSPKGDIR}/+BUILD_INFO
1881.5Sdyoungfi
1891.1Sagc
1901.1Sagc# test for attributes
1911.1Sagcargs=""
1921.1Sagcattrs=`awk '$1 ~ '/$pkg/' { print substr($0, length($1) + 2) }' attrs`
1931.1Sagcfor a in "$attrs"; do
1941.1Sagc	case "$attrs" in
1951.1Sagc	"")		;;
1961.1Sagc	preserve)	echo "$pkg-$t" > ${SYSPKGDIR}/+PRESERVE
1971.1Sagc			args="$args -n ${SYSPKGDIR}/+PRESERVE"
1981.1Sagc			;;
1991.1Sagc	esac
2001.1Sagcdone
2011.1Sagc
2021.1Sagcpkg_create -v -c ${SYSPKGDIR}/+COMMENT \
2031.1Sagc	-d ${SYSPKGDIR}/+DESC \
2041.1Sagc	$args \
2051.1Sagc	-f $PLIST -l -b /dev/null -B ${SYSPKGDIR}/+BUILD_INFO \
2061.5Sdyoung	-s /dev/null -S /dev/null -O $pkg-$t.tgz \
2071.1Sagc		> ${SYSPKGDIR}/+CONTENTS
2081.1Sagc
2091.4Sdyoungrm $PLIST
210