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