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