NetBSD/distrib/sets/regpkg

156 lines
4.8 KiB
Plaintext
Raw Normal View History

#! /bin/sh
#
# $NetBSD: regpkg,v 1.1 2003/06/12 20:04:00 agc Exp $
#
# Copyright (c) 2003 Alistair G. Crooks. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
# must display the following acknowledgement:
# This product includes software developed by Alistair G. Crooks.
# for the NetBSD project.
# 4. The name of the author may not be used to endorse or promote
# products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Usage: regpkg set pkgname
SYSPKGROOT=${PKG_DBDIR:-/var/db/pkg}
case "${SYSPKG_DBDIR}" in
"") ;;
*) SYSPKGROOT=${SYSPKG_DBDIR} ;;
esac
PLIST=/tmp/.PLIST.$$
verbose=""
while [ $# -gt 2 ]; do
case $1 in
-v) verbose=$1 ;;
*) break ;;
esac
shift
done
if [ $# -ne 2 ]; then
echo "Usage: regpkg set pkgname"
exit 1
fi
pkgset=$1
pkg=$2
case $verbose in
-v) echo "Making PLIST for \"$pkgset\" set and \"$pkg\" package" ;;
esac
# create the skeleton PLIST from the pkgset description
./makeplist $pkgset $pkg > $PLIST
# we need the last mtime of the files which make up the package
args=`awk '
/^@cwd/ { prefix = $2; next }
/^@dirrm/ { next }
{ printf("%s%s\n", prefix, $0) }' $PLIST`
t=`env TZ=UTC LOCALE=C ls -lT $args | awk '
BEGIN { newest = 0 }
{
t = $9 "";
if ($6 == "Jan") t = t "01";
if ($6 == "Feb") t = t "02";
if ($6 == "Mar") t = t "03";
if ($6 == "Apr") t = t "04";
if ($6 == "May") t = t "05";
if ($6 == "Jun") t = t "06";
if ($6 == "Jul") t = t "07";
if ($6 == "Aug") t = t "08";
if ($6 == "Sep") t = t "09";
if ($6 == "Oct") t = t "10";
if ($6 == "Nov") t = t "11";
if ($6 == "Dec") t = t "12";
if ($7 < 10) t = t "0";
t = t $7;
#these next two lines add the 24h clock onto the date
#gsub(":", "", $8);
#t = sprintf("%s.%4.4s", t, $8);
if (t > newest) newest = t;
}
END { print newest }'`
# create the directory and minimal contents
SYSPKGDIR=${SYSPKGROOT}/$pkg-$t
if [ -d ${SYSPKGDIR} ]; then
echo "There is already a $pkg-$t package installed (${SYSPKGDIR})"
exit 1
fi
mkdir -p ${SYSPKGDIR}
# create the comment
comment=`awk '$1 ~ '/$pkg/' { print substr($0, length($1) + 2) }' comments`
case "$comment" in
"") echo "***WARNING ***: no comment for \"$pkg\"" 2>&1
comment="System package for $pkg"
;;
esac
echo "$comment" > ${SYSPKGDIR}/+COMMENT
# create the description
descr=`awk '$1 ~ '/$pkg/' { print substr($0, length($1) + 2) }' descrs`
case "$descr" in
"") echo "***WARNING ***: no description for \"$pkg\"" 2>&1
descr="System package for $pkg"
;;
esac
echo "$descr" > ${SYSPKGDIR}/+DESC
printf "\nHomepage:\nhttp://www.NetBSD.org/\n" >> ${SYSPKGDIR}/+DESC
# create the build information
echo "OPSYS=`uname -s`" > ${SYSPKGDIR}/+BUILD_INFO
echo "OS_VERSION=`uname -r`" >> ${SYSPKGDIR}/+BUILD_INFO
echo "OBJECT_FMT=`printf '.include <bsd.own.mk>\nall:\n\t@echo ${OBJECT_FMT}' | make -f- all`" >> ${SYSPKGDIR}/+BUILD_INFO
echo "MACHINE_ARCH=`printf '.include <bsd.own.mk>\nall:\n\t@echo ${MACHINE_ARCH}' | make -f- all`" >> ${SYSPKGDIR}/+BUILD_INFO
echo "MACHINE_GNU_ARCH=`printf '.include <bsd.own.mk>\nall:\n\t@echo ${MACHINE_GNU_ARCH}' | make -f- all`" >> ${SYSPKGDIR}/+BUILD_INFO
echo "_PKGTOOLS_VER=`pkg_create -V`" >> ${SYSPKGDIR}/+BUILD_INFO
# test for attributes
args=""
attrs=`awk '$1 ~ '/$pkg/' { print substr($0, length($1) + 2) }' attrs`
for a in "$attrs"; do
case "$attrs" in
"") ;;
preserve) echo "$pkg-$t" > ${SYSPKGDIR}/+PRESERVE
args="$args -n ${SYSPKGDIR}/+PRESERVE"
;;
esac
done
pkg_create -v -c ${SYSPKGDIR}/+COMMENT \
-d ${SYSPKGDIR}/+DESC \
$args \
-f $PLIST -l -b /dev/null -B ${SYSPKGDIR}/+BUILD_INFO \
-s /dev/null -S /dev/null -O $pkg-$t \
> ${SYSPKGDIR}/+CONTENTS