Home | History | Annotate | Line # | Download | only in sets
regpkg revision 1.3
      1 #! /bin/sh
      2 #
      3 # $NetBSD: regpkg,v 1.3 2003/06/18 10:53:52 agc Exp $
      4 #
      5 # Copyright (c) 2003 Alistair G. Crooks.  All rights reserved.
      6 #
      7 # Redistribution and use in source and binary forms, with or without
      8 # modification, are permitted provided that the following conditions
      9 # are met:
     10 # 1. Redistributions of source code must retain the above copyright
     11 #    notice, this list of conditions and the following disclaimer.
     12 # 2. Redistributions in binary form must reproduce the above copyright
     13 #    notice, this list of conditions and the following disclaimer in the
     14 #    documentation and/or other materials provided with the distribution.
     15 # 3. All advertising materials mentioning features or use of this software
     16 #    must display the following acknowledgement:
     17 #	This product includes software developed by Alistair G. Crooks.
     18 #	for the NetBSD project.
     19 # 4. The name of the author may not be used to endorse or promote
     20 #    products derived from this software without specific prior written
     21 #    permission.
     22 #
     23 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     24 # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     25 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26 # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
     27 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     29 # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     30 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     31 # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     32 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     33 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     34 #
     35 
     36 # Usage: regpkg set pkgname
     37 
     38 SYSPKGROOT=${PKG_DBDIR:-/var/db/pkg}
     39 case "${SYSPKG_DBDIR}" in
     40 "")	;;
     41 *)	SYSPKGROOT=${SYSPKG_DBDIR} ;;
     42 esac
     43 
     44 PLIST=/tmp/.PLIST.$$
     45 
     46 verbose=""
     47 while [ $# -gt 2 ]; do
     48 	case $1 in
     49 	-v)	verbose=$1 ;;
     50 	*)	break ;;
     51 	esac
     52 	shift
     53 done
     54 
     55 if [ $# -ne 2 ]; then
     56 	echo "Usage: regpkg set pkgname"
     57 	exit 1
     58 fi
     59 
     60 pkgset=$1
     61 
     62 pkg=$2
     63 
     64 case $verbose in
     65 -v)	echo "Making PLIST for \"$pkgset\" set and \"$pkg\" package" ;;
     66 esac
     67 
     68 # create the skeleton PLIST from the pkgset description
     69 ./makeplist $pkgset $pkg > $PLIST
     70 
     71 # create the pkg tiny version
     72 case "${SYSPKG_DATES}" in
     73 "")	tinyvers=`awk '$1 ~ '/$pkg/' { print $2 }' versions`
     74 	case "$tinyvers" in
     75 	"")	tinyvers=0
     76 		;;
     77 	esac
     78 	if [ -f ../../sys/conf/osrelease.sh ]; then
     79 		osvers=`sh ../../sys/conf/osrelease.sh`
     80 		method=osreleasese
     81 	else
     82 		osvers=`uname -r`
     83 		method=uname
     84 	fi
     85 	t=$osvers.$tinyvers
     86 	;;
     87 *)	args=`awk '
     88 		/^@cwd/ { prefix = $2; next }
     89 		/^@dirrm/ { next }
     90 		{ printf("%s%s\n", prefix, $0) }' $PLIST`
     91 	# first try for any RCS identifiers in the files
     92 	t=0
     93 	case "$args" in
     94 	"")	;;
     95 	*)	t=`ident $args 2>/dev/null | awk '
     96 			BEGIN { last = 0 }
     97 			$2 == "crt0.c,v" { next }
     98 			NF == 8 { t = $4; gsub("/", "", t); if (t > last) last = t; }
     99 			END { print last }'`
    100 		method=ident
    101 		;;
    102 	esac
    103 	case "$t" in
    104 	0)	# we need the last mtime of the files which make up the package
    105 		t=`env TZ=UTC LOCALE=C ls -lT $args | awk '
    106 			BEGIN { newest = 0 }
    107 			{
    108 				t = $9 "";
    109 				if ($6 == "Jan") t = t "01";
    110 				if ($6 == "Feb") t = t "02";
    111 				if ($6 == "Mar") t = t "03";
    112 				if ($6 == "Apr") t = t "04";
    113 				if ($6 == "May") t = t "05";
    114 				if ($6 == "Jun") t = t "06";
    115 				if ($6 == "Jul") t = t "07";
    116 				if ($6 == "Aug") t = t "08";
    117 				if ($6 == "Sep") t = t "09";
    118 				if ($6 == "Oct") t = t "10";
    119 				if ($6 == "Nov") t = t "11";
    120 				if ($6 == "Dec") t = t "12";
    121 				if ($7 < 10) t = t "0";
    122 				t = t $7;
    123 				#these next two lines add the 24h clock onto the date
    124 				#gsub(":", "", $8);
    125 				#t = sprintf("%s.%4.4s", t, $8);
    126 				if (t > newest) newest = t;
    127 			}
    128 			END { print newest }'`
    129 		method=ls
    130 		;;
    131 	esac
    132 	;;
    133 esac
    134 
    135 # print version number that we're using
    136 case "$verbose" in
    137 -v)	echo "$pkg - $t version using $method method" ;;
    138 esac
    139 
    140 # create the directory and minimal contents
    141 SYSPKGDIR=${SYSPKGROOT}/$pkg-$t
    142 if [ -d ${SYSPKGDIR} ]; then
    143 	echo "There is already a $pkg-$t package installed (${SYSPKGDIR})"
    144 	exit 1
    145 fi
    146 
    147 mkdir -p ${SYSPKGDIR}
    148 
    149 # create the comment
    150 comment=`awk '$1 ~ '/$pkg/' { print substr($0, length($1) + 2) }' comments`
    151 case "$comment" in
    152 "")	echo "***WARNING ***: no comment for \"$pkg\"" 2>&1
    153 	comment="System package for $pkg"
    154 	;;
    155 esac
    156 echo "$comment" > ${SYSPKGDIR}/+COMMENT
    157 
    158 # create the description
    159 descr=`awk '$1 ~ '/$pkg/' { print substr($0, length($1) + 2) }' descrs`
    160 case "$descr" in
    161 "")	echo "***WARNING ***: no description for \"$pkg\"" 2>&1
    162 	descr="System package for $pkg"
    163 	;;
    164 esac
    165 echo "$descr" > ${SYSPKGDIR}/+DESC
    166 printf "\nHomepage:\nhttp://www.NetBSD.org/\n" >> ${SYSPKGDIR}/+DESC
    167 
    168 # create the build information
    169 echo "OPSYS=`uname -s`" > ${SYSPKGDIR}/+BUILD_INFO
    170 echo "OS_VERSION=`uname -r`" >> ${SYSPKGDIR}/+BUILD_INFO
    171 echo "OBJECT_FMT=`printf '.include <bsd.own.mk>\nall:\n\t@echo ${OBJECT_FMT}' | make -f- all`" >> ${SYSPKGDIR}/+BUILD_INFO
    172 echo "MACHINE_ARCH=`printf '.include <bsd.own.mk>\nall:\n\t@echo ${MACHINE_ARCH}' | make -f- all`" >> ${SYSPKGDIR}/+BUILD_INFO
    173 echo "MACHINE_GNU_ARCH=`printf '.include <bsd.own.mk>\nall:\n\t@echo ${MACHINE_GNU_ARCH}' | make -f- all`" >> ${SYSPKGDIR}/+BUILD_INFO
    174 echo "_PKGTOOLS_VER=`pkg_create -V`" >> ${SYSPKGDIR}/+BUILD_INFO
    175 
    176 # test for attributes
    177 args=""
    178 attrs=`awk '$1 ~ '/$pkg/' { print substr($0, length($1) + 2) }' attrs`
    179 for a in "$attrs"; do
    180 	case "$attrs" in
    181 	"")		;;
    182 	preserve)	echo "$pkg-$t" > ${SYSPKGDIR}/+PRESERVE
    183 			args="$args -n ${SYSPKGDIR}/+PRESERVE"
    184 			;;
    185 	esac
    186 done
    187 
    188 pkg_create -v -c ${SYSPKGDIR}/+COMMENT \
    189 	-d ${SYSPKGDIR}/+DESC \
    190 	$args \
    191 	-f $PLIST -l -b /dev/null -B ${SYSPKGDIR}/+BUILD_INFO \
    192 	-s /dev/null -S /dev/null -O $pkg-$t \
    193 		> ${SYSPKGDIR}/+CONTENTS
    194 
    195