regpkg revision 1.2
1#! /bin/sh 2# 3# $NetBSD: regpkg,v 1.2 2003/06/13 02:32:26 jwise 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 72tinyvers=`awk '$1 ~ '/$pkg/' { print substr($0, length($1) + 2) }' versions` 73case "$tinyvers" in 74"") echo "***WARNING ***: no version for \"$pkg\"" 2>&1 75 tinyvers="System package for $pkg" 76 ;; 77esac 78 79# we need the last mtime of the files which make up the package 80osvers=`sh ../../sys/conf/osrelease.sh` 81t=$osvers.$tinyvers 82 83# create the directory and minimal contents 84SYSPKGDIR=${SYSPKGROOT}/$pkg-$t 85if [ -d ${SYSPKGDIR} ]; then 86 echo "There is already a $pkg-$t package installed (${SYSPKGDIR})" 87 exit 1 88fi 89 90mkdir -p ${SYSPKGDIR} 91 92# create the comment 93comment=`awk '$1 ~ '/$pkg/' { print substr($0, length($1) + 2) }' comments` 94case "$comment" in 95"") echo "***WARNING ***: no comment for \"$pkg\"" 2>&1 96 comment="System package for $pkg" 97 ;; 98esac 99echo "$comment" > ${SYSPKGDIR}/+COMMENT 100 101# create the description 102descr=`awk '$1 ~ '/$pkg/' { print substr($0, length($1) + 2) }' descrs` 103case "$descr" in 104"") echo "***WARNING ***: no description for \"$pkg\"" 2>&1 105 descr="System package for $pkg" 106 ;; 107esac 108echo "$descr" > ${SYSPKGDIR}/+DESC 109printf "\nHomepage:\nhttp://www.NetBSD.org/\n" >> ${SYSPKGDIR}/+DESC 110 111# create the pkg tiny version 112tinyvers=`awk '$1 ~ '/$pkg/' { print substr($0, length($1) + 2) }' versions` 113case "$tinyvers" in 114"") echo "***WARNING ***: no version for \"$pkg\"" 2>&1 115 tinyvers="System package for $pkg" 116 ;; 117esac 118 119# create the build information 120echo "OPSYS=`uname -s`" > ${SYSPKGDIR}/+BUILD_INFO 121echo "OS_VERSION=`uname -r`" >> ${SYSPKGDIR}/+BUILD_INFO 122echo "OBJECT_FMT=`printf '.include <bsd.own.mk>\nall:\n\t@echo ${OBJECT_FMT}' | make -f- all`" >> ${SYSPKGDIR}/+BUILD_INFO 123echo "MACHINE_ARCH=`printf '.include <bsd.own.mk>\nall:\n\t@echo ${MACHINE_ARCH}' | make -f- all`" >> ${SYSPKGDIR}/+BUILD_INFO 124echo "MACHINE_GNU_ARCH=`printf '.include <bsd.own.mk>\nall:\n\t@echo ${MACHINE_GNU_ARCH}' | make -f- all`" >> ${SYSPKGDIR}/+BUILD_INFO 125echo "_PKGTOOLS_VER=`pkg_create -V`" >> ${SYSPKGDIR}/+BUILD_INFO 126 127# test for attributes 128args="" 129attrs=`awk '$1 ~ '/$pkg/' { print substr($0, length($1) + 2) }' attrs` 130for a in "$attrs"; do 131 case "$attrs" in 132 "") ;; 133 preserve) echo "$pkg-$t" > ${SYSPKGDIR}/+PRESERVE 134 args="$args -n ${SYSPKGDIR}/+PRESERVE" 135 ;; 136 esac 137done 138 139pkg_create -v -c ${SYSPKGDIR}/+COMMENT \ 140 -d ${SYSPKGDIR}/+DESC \ 141 $args \ 142 -f $PLIST -l -b /dev/null -B ${SYSPKGDIR}/+BUILD_INFO \ 143 -s /dev/null -S /dev/null -O $pkg-$t \ 144 > ${SYSPKGDIR}/+CONTENTS 145 146