Home | History | Annotate | Line # | Download | only in sets
regpkg revision 1.1
      1  1.1  agc #! /bin/sh
      2  1.1  agc #
      3  1.1  agc # $NetBSD: regpkg,v 1.1 2003/06/12 20:04:00 agc 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.1  agc # Usage: regpkg set pkgname
     37  1.1  agc 
     38  1.1  agc SYSPKGROOT=${PKG_DBDIR:-/var/db/pkg}
     39  1.1  agc case "${SYSPKG_DBDIR}" in
     40  1.1  agc "")	;;
     41  1.1  agc *)	SYSPKGROOT=${SYSPKG_DBDIR} ;;
     42  1.1  agc esac
     43  1.1  agc 
     44  1.1  agc PLIST=/tmp/.PLIST.$$
     45  1.1  agc 
     46  1.1  agc verbose=""
     47  1.1  agc while [ $# -gt 2 ]; do
     48  1.1  agc 	case $1 in
     49  1.1  agc 	-v)	verbose=$1 ;;
     50  1.1  agc 	*)	break ;;
     51  1.1  agc 	esac
     52  1.1  agc 	shift
     53  1.1  agc done
     54  1.1  agc 
     55  1.1  agc if [ $# -ne 2 ]; then
     56  1.1  agc 	echo "Usage: regpkg set pkgname"
     57  1.1  agc 	exit 1
     58  1.1  agc fi
     59  1.1  agc 
     60  1.1  agc pkgset=$1
     61  1.1  agc 
     62  1.1  agc pkg=$2
     63  1.1  agc 
     64  1.1  agc case $verbose in
     65  1.1  agc -v)	echo "Making PLIST for \"$pkgset\" set and \"$pkg\" package" ;;
     66  1.1  agc esac
     67  1.1  agc 
     68  1.1  agc # create the skeleton PLIST from the pkgset description
     69  1.1  agc ./makeplist $pkgset $pkg > $PLIST
     70  1.1  agc 
     71  1.1  agc # we need the last mtime of the files which make up the package
     72  1.1  agc args=`awk '
     73  1.1  agc 	/^@cwd/ { prefix = $2; next }
     74  1.1  agc 	/^@dirrm/ { next }
     75  1.1  agc 	{ printf("%s%s\n", prefix, $0) }' $PLIST`
     76  1.1  agc t=`env TZ=UTC LOCALE=C ls -lT $args | awk '
     77  1.1  agc 	BEGIN { newest = 0 }
     78  1.1  agc 	{
     79  1.1  agc 		t = $9 "";
     80  1.1  agc 		if ($6 == "Jan") t = t "01";
     81  1.1  agc 		if ($6 == "Feb") t = t "02";
     82  1.1  agc 		if ($6 == "Mar") t = t "03";
     83  1.1  agc 		if ($6 == "Apr") t = t "04";
     84  1.1  agc 		if ($6 == "May") t = t "05";
     85  1.1  agc 		if ($6 == "Jun") t = t "06";
     86  1.1  agc 		if ($6 == "Jul") t = t "07";
     87  1.1  agc 		if ($6 == "Aug") t = t "08";
     88  1.1  agc 		if ($6 == "Sep") t = t "09";
     89  1.1  agc 		if ($6 == "Oct") t = t "10";
     90  1.1  agc 		if ($6 == "Nov") t = t "11";
     91  1.1  agc 		if ($6 == "Dec") t = t "12";
     92  1.1  agc 		if ($7 < 10) t = t "0";
     93  1.1  agc 		t = t $7;
     94  1.1  agc 		#these next two lines add the 24h clock onto the date
     95  1.1  agc 		#gsub(":", "", $8);
     96  1.1  agc 		#t = sprintf("%s.%4.4s", t, $8);
     97  1.1  agc 		if (t > newest) newest = t;
     98  1.1  agc 	}
     99  1.1  agc 	END { print newest }'`
    100  1.1  agc 
    101  1.1  agc # create the directory and minimal contents
    102  1.1  agc SYSPKGDIR=${SYSPKGROOT}/$pkg-$t
    103  1.1  agc if [ -d ${SYSPKGDIR} ]; then
    104  1.1  agc 	echo "There is already a $pkg-$t package installed (${SYSPKGDIR})"
    105  1.1  agc 	exit 1
    106  1.1  agc fi
    107  1.1  agc 
    108  1.1  agc mkdir -p ${SYSPKGDIR}
    109  1.1  agc 
    110  1.1  agc # create the comment
    111  1.1  agc comment=`awk '$1 ~ '/$pkg/' { print substr($0, length($1) + 2) }' comments`
    112  1.1  agc case "$comment" in
    113  1.1  agc "")	echo "***WARNING ***: no comment for \"$pkg\"" 2>&1
    114  1.1  agc 	comment="System package for $pkg"
    115  1.1  agc 	;;
    116  1.1  agc esac
    117  1.1  agc echo "$comment" > ${SYSPKGDIR}/+COMMENT
    118  1.1  agc 
    119  1.1  agc # create the description
    120  1.1  agc descr=`awk '$1 ~ '/$pkg/' { print substr($0, length($1) + 2) }' descrs`
    121  1.1  agc case "$descr" in
    122  1.1  agc "")	echo "***WARNING ***: no description for \"$pkg\"" 2>&1
    123  1.1  agc 	descr="System package for $pkg"
    124  1.1  agc 	;;
    125  1.1  agc esac
    126  1.1  agc echo "$descr" > ${SYSPKGDIR}/+DESC
    127  1.1  agc printf "\nHomepage:\nhttp://www.NetBSD.org/\n" >> ${SYSPKGDIR}/+DESC
    128  1.1  agc 
    129  1.1  agc # create the build information
    130  1.1  agc echo "OPSYS=`uname -s`" > ${SYSPKGDIR}/+BUILD_INFO
    131  1.1  agc echo "OS_VERSION=`uname -r`" >> ${SYSPKGDIR}/+BUILD_INFO
    132  1.1  agc echo "OBJECT_FMT=`printf '.include <bsd.own.mk>\nall:\n\t@echo ${OBJECT_FMT}' | make -f- all`" >> ${SYSPKGDIR}/+BUILD_INFO
    133  1.1  agc echo "MACHINE_ARCH=`printf '.include <bsd.own.mk>\nall:\n\t@echo ${MACHINE_ARCH}' | make -f- all`" >> ${SYSPKGDIR}/+BUILD_INFO
    134  1.1  agc echo "MACHINE_GNU_ARCH=`printf '.include <bsd.own.mk>\nall:\n\t@echo ${MACHINE_GNU_ARCH}' | make -f- all`" >> ${SYSPKGDIR}/+BUILD_INFO
    135  1.1  agc echo "_PKGTOOLS_VER=`pkg_create -V`" >> ${SYSPKGDIR}/+BUILD_INFO
    136  1.1  agc 
    137  1.1  agc # test for attributes
    138  1.1  agc args=""
    139  1.1  agc attrs=`awk '$1 ~ '/$pkg/' { print substr($0, length($1) + 2) }' attrs`
    140  1.1  agc for a in "$attrs"; do
    141  1.1  agc 	case "$attrs" in
    142  1.1  agc 	"")		;;
    143  1.1  agc 	preserve)	echo "$pkg-$t" > ${SYSPKGDIR}/+PRESERVE
    144  1.1  agc 			args="$args -n ${SYSPKGDIR}/+PRESERVE"
    145  1.1  agc 			;;
    146  1.1  agc 	esac
    147  1.1  agc done
    148  1.1  agc 
    149  1.1  agc pkg_create -v -c ${SYSPKGDIR}/+COMMENT \
    150  1.1  agc 	-d ${SYSPKGDIR}/+DESC \
    151  1.1  agc 	$args \
    152  1.1  agc 	-f $PLIST -l -b /dev/null -B ${SYSPKGDIR}/+BUILD_INFO \
    153  1.1  agc 	-s /dev/null -S /dev/null -O $pkg-$t \
    154  1.1  agc 		> ${SYSPKGDIR}/+CONTENTS
    155  1.1  agc 
    156