Home | History | Annotate | Line # | Download | only in sets
regpkg revision 1.3
      1  1.1    agc #! /bin/sh
      2  1.1    agc #
      3  1.3    agc # $NetBSD: regpkg,v 1.3 2003/06/18 10:53:52 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.2  jwise # create the pkg tiny version
     72  1.3    agc case "${SYSPKG_DATES}" in
     73  1.3    agc "")	tinyvers=`awk '$1 ~ '/$pkg/' { print $2 }' versions`
     74  1.3    agc 	case "$tinyvers" in
     75  1.3    agc 	"")	tinyvers=0
     76  1.3    agc 		;;
     77  1.3    agc 	esac
     78  1.3    agc 	if [ -f ../../sys/conf/osrelease.sh ]; then
     79  1.3    agc 		osvers=`sh ../../sys/conf/osrelease.sh`
     80  1.3    agc 		method=osreleasese
     81  1.3    agc 	else
     82  1.3    agc 		osvers=`uname -r`
     83  1.3    agc 		method=uname
     84  1.3    agc 	fi
     85  1.3    agc 	t=$osvers.$tinyvers
     86  1.3    agc 	;;
     87  1.3    agc *)	args=`awk '
     88  1.3    agc 		/^@cwd/ { prefix = $2; next }
     89  1.3    agc 		/^@dirrm/ { next }
     90  1.3    agc 		{ printf("%s%s\n", prefix, $0) }' $PLIST`
     91  1.3    agc 	# first try for any RCS identifiers in the files
     92  1.3    agc 	t=0
     93  1.3    agc 	case "$args" in
     94  1.3    agc 	"")	;;
     95  1.3    agc 	*)	t=`ident $args 2>/dev/null | awk '
     96  1.3    agc 			BEGIN { last = 0 }
     97  1.3    agc 			$2 == "crt0.c,v" { next }
     98  1.3    agc 			NF == 8 { t = $4; gsub("/", "", t); if (t > last) last = t; }
     99  1.3    agc 			END { print last }'`
    100  1.3    agc 		method=ident
    101  1.3    agc 		;;
    102  1.3    agc 	esac
    103  1.3    agc 	case "$t" in
    104  1.3    agc 	0)	# we need the last mtime of the files which make up the package
    105  1.3    agc 		t=`env TZ=UTC LOCALE=C ls -lT $args | awk '
    106  1.3    agc 			BEGIN { newest = 0 }
    107  1.3    agc 			{
    108  1.3    agc 				t = $9 "";
    109  1.3    agc 				if ($6 == "Jan") t = t "01";
    110  1.3    agc 				if ($6 == "Feb") t = t "02";
    111  1.3    agc 				if ($6 == "Mar") t = t "03";
    112  1.3    agc 				if ($6 == "Apr") t = t "04";
    113  1.3    agc 				if ($6 == "May") t = t "05";
    114  1.3    agc 				if ($6 == "Jun") t = t "06";
    115  1.3    agc 				if ($6 == "Jul") t = t "07";
    116  1.3    agc 				if ($6 == "Aug") t = t "08";
    117  1.3    agc 				if ($6 == "Sep") t = t "09";
    118  1.3    agc 				if ($6 == "Oct") t = t "10";
    119  1.3    agc 				if ($6 == "Nov") t = t "11";
    120  1.3    agc 				if ($6 == "Dec") t = t "12";
    121  1.3    agc 				if ($7 < 10) t = t "0";
    122  1.3    agc 				t = t $7;
    123  1.3    agc 				#these next two lines add the 24h clock onto the date
    124  1.3    agc 				#gsub(":", "", $8);
    125  1.3    agc 				#t = sprintf("%s.%4.4s", t, $8);
    126  1.3    agc 				if (t > newest) newest = t;
    127  1.3    agc 			}
    128  1.3    agc 			END { print newest }'`
    129  1.3    agc 		method=ls
    130  1.3    agc 		;;
    131  1.3    agc 	esac
    132  1.2  jwise 	;;
    133  1.2  jwise esac
    134  1.2  jwise 
    135  1.3    agc # print version number that we're using
    136  1.3    agc case "$verbose" in
    137  1.3    agc -v)	echo "$pkg - $t version using $method method" ;;
    138  1.3    agc esac
    139  1.1    agc 
    140  1.1    agc # create the directory and minimal contents
    141  1.1    agc SYSPKGDIR=${SYSPKGROOT}/$pkg-$t
    142  1.1    agc if [ -d ${SYSPKGDIR} ]; then
    143  1.1    agc 	echo "There is already a $pkg-$t package installed (${SYSPKGDIR})"
    144  1.1    agc 	exit 1
    145  1.1    agc fi
    146  1.1    agc 
    147  1.1    agc mkdir -p ${SYSPKGDIR}
    148  1.1    agc 
    149  1.1    agc # create the comment
    150  1.1    agc comment=`awk '$1 ~ '/$pkg/' { print substr($0, length($1) + 2) }' comments`
    151  1.1    agc case "$comment" in
    152  1.1    agc "")	echo "***WARNING ***: no comment for \"$pkg\"" 2>&1
    153  1.1    agc 	comment="System package for $pkg"
    154  1.1    agc 	;;
    155  1.1    agc esac
    156  1.1    agc echo "$comment" > ${SYSPKGDIR}/+COMMENT
    157  1.1    agc 
    158  1.1    agc # create the description
    159  1.1    agc descr=`awk '$1 ~ '/$pkg/' { print substr($0, length($1) + 2) }' descrs`
    160  1.1    agc case "$descr" in
    161  1.1    agc "")	echo "***WARNING ***: no description for \"$pkg\"" 2>&1
    162  1.1    agc 	descr="System package for $pkg"
    163  1.1    agc 	;;
    164  1.1    agc esac
    165  1.1    agc echo "$descr" > ${SYSPKGDIR}/+DESC
    166  1.1    agc printf "\nHomepage:\nhttp://www.NetBSD.org/\n" >> ${SYSPKGDIR}/+DESC
    167  1.1    agc 
    168  1.1    agc # create the build information
    169  1.1    agc echo "OPSYS=`uname -s`" > ${SYSPKGDIR}/+BUILD_INFO
    170  1.1    agc echo "OS_VERSION=`uname -r`" >> ${SYSPKGDIR}/+BUILD_INFO
    171  1.1    agc echo "OBJECT_FMT=`printf '.include <bsd.own.mk>\nall:\n\t@echo ${OBJECT_FMT}' | make -f- all`" >> ${SYSPKGDIR}/+BUILD_INFO
    172  1.1    agc echo "MACHINE_ARCH=`printf '.include <bsd.own.mk>\nall:\n\t@echo ${MACHINE_ARCH}' | make -f- all`" >> ${SYSPKGDIR}/+BUILD_INFO
    173  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
    174  1.1    agc echo "_PKGTOOLS_VER=`pkg_create -V`" >> ${SYSPKGDIR}/+BUILD_INFO
    175  1.1    agc 
    176  1.1    agc # test for attributes
    177  1.1    agc args=""
    178  1.1    agc attrs=`awk '$1 ~ '/$pkg/' { print substr($0, length($1) + 2) }' attrs`
    179  1.1    agc for a in "$attrs"; do
    180  1.1    agc 	case "$attrs" in
    181  1.1    agc 	"")		;;
    182  1.1    agc 	preserve)	echo "$pkg-$t" > ${SYSPKGDIR}/+PRESERVE
    183  1.1    agc 			args="$args -n ${SYSPKGDIR}/+PRESERVE"
    184  1.1    agc 			;;
    185  1.1    agc 	esac
    186  1.1    agc done
    187  1.1    agc 
    188  1.1    agc pkg_create -v -c ${SYSPKGDIR}/+COMMENT \
    189  1.1    agc 	-d ${SYSPKGDIR}/+DESC \
    190  1.1    agc 	$args \
    191  1.1    agc 	-f $PLIST -l -b /dev/null -B ${SYSPKGDIR}/+BUILD_INFO \
    192  1.1    agc 	-s /dev/null -S /dev/null -O $pkg-$t \
    193  1.1    agc 		> ${SYSPKGDIR}/+CONTENTS
    194  1.1    agc 
    195