regpkg revision 1.4
1#! /bin/sh 2# 3# $NetBSD: regpkg,v 1.4 2003/06/23 09:25:34 dyoung 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 38SYSPKGROOT=${PKG_DBDIR:-/var/db/pkg} 39case "${SYSPKG_DBDIR}" in 40"") ;; 41*) SYSPKGROOT=${SYSPKG_DBDIR} ;; 42esac 43 44PLIST=/tmp/.PLIST.$$ 45 46verbose="" 47while [ $# -gt 2 ]; do 48 case $1 in 49 -v) verbose=$1 ;; 50 *) break ;; 51 esac 52 shift 53done 54 55if [ $# -ne 2 ]; then 56 echo "Usage: regpkg set pkgname" 57 exit 1 58fi 59 60pkgset=$1 61 62pkg=$2 63 64case $verbose in 65-v) echo "Making PLIST for \"$pkgset\" set and \"$pkg\" package" ;; 66esac 67 68# create the skeleton PLIST from the pkgset description 69./makeplist $pkgset $pkg > $PLIST 70 71# create the pkg tiny version 72case "${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=osreleases 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 ;; 133esac 134 135# print version number that we're using 136case "$verbose" in 137-v) echo "$pkg - $t version using $method method" ;; 138esac 139 140# create the directory and minimal contents 141SYSPKGDIR=${SYSPKGROOT}/$pkg-$t 142if [ -d ${SYSPKGDIR} ]; then 143 echo "There is already a $pkg-$t package installed (${SYSPKGDIR})" 144 exit 1 145fi 146 147mkdir -p ${SYSPKGDIR} 148 149# add the dependencies 150awk '$1 ~ '/$pkg/' { print $2 }' deps | sort | \ 151 awk '{ print "@pkgdep " $1 "-[0-9]*" }' >> $PLIST 152 153# create the comment 154comment=`awk '$1 ~ '/$pkg/' { print substr($0, length($1) + 2) }' comments` 155case "$comment" in 156"") echo "***WARNING ***: no comment for \"$pkg\"" 2>&1 157 comment="System package for $pkg" 158 ;; 159esac 160echo "$comment" > ${SYSPKGDIR}/+COMMENT 161 162# create the description 163descr=`awk '$1 ~ '/$pkg/' { print substr($0, length($1) + 2) }' descrs` 164case "$descr" in 165"") echo "***WARNING ***: no description for \"$pkg\"" 2>&1 166 descr="System package for $pkg" 167 ;; 168esac 169echo "$descr" > ${SYSPKGDIR}/+DESC 170printf "\nHomepage:\nhttp://www.NetBSD.org/\n" >> ${SYSPKGDIR}/+DESC 171 172# create the build information 173{ 174echo "OPSYS=`uname -s`" 175echo "OS_VERSION=`uname -r`" 176make -f- all <<EOF 177.include <bsd.own.mk> 178all: 179 @echo OBJECT_FMT=${OBJECT_FMT} 180 @echo MACHINE_ARCH=${MACHINE_ARCH} 181 @echo MACHINE_GNU_ARCH=${MACHINE_GNU_ARCH} 182EOF 183echo "_PKGTOOLS_VER=`pkg_create -V`" 184} > ${SYSPKGDIR}/+BUILD_INFO 185 186# test for attributes 187args="" 188attrs=`awk '$1 ~ '/$pkg/' { print substr($0, length($1) + 2) }' attrs` 189for a in "$attrs"; do 190 case "$attrs" in 191 "") ;; 192 preserve) echo "$pkg-$t" > ${SYSPKGDIR}/+PRESERVE 193 args="$args -n ${SYSPKGDIR}/+PRESERVE" 194 ;; 195 esac 196done 197 198pkg_create -v -c ${SYSPKGDIR}/+COMMENT \ 199 -d ${SYSPKGDIR}/+DESC \ 200 $args \ 201 -f $PLIST -l -b /dev/null -B ${SYSPKGDIR}/+BUILD_INFO \ 202 -s /dev/null -S /dev/null -O $pkg-$t \ 203 > ${SYSPKGDIR}/+CONTENTS 204 205rm $PLIST 206