regpkg revision 1.6 1 #! /bin/sh
2 #
3 # $NetBSD: regpkg,v 1.6 2004/07/23 15:11:26 erh 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 rundir=${0%/*}
39
40 SYSPKGROOT=${PKG_DBDIR:-/var/db/pkg}
41 case "${SYSPKG_DBDIR}" in
42 "") ;;
43 *) SYSPKGROOT=${SYSPKG_DBDIR} ;;
44 esac
45
46 PLIST=/tmp/.PLIST.$$
47
48 verbose=""
49 while [ $# -gt 2 ]; do
50 case $1 in
51 -v) verbose=$1 ;;
52 *) break ;;
53 esac
54 shift
55 done
56
57 if [ $# -ne 2 ]; then
58 echo "Usage: regpkg set pkgname"
59 exit 1
60 fi
61
62 pkgset=$1
63
64 pkg=$2
65
66 case $verbose in
67 -v) echo "Making PLIST for \"$pkgset\" set and \"$pkg\" package" ;;
68 esac
69
70 # create the skeleton PLIST from the pkgset description
71 $rundir/makeplist $pkgset $pkg > $PLIST
72
73 # create the pkg tiny version
74 case "${SYSPKG_DATES}" in
75 "") tinyvers=`awk '$1 ~ '/$pkg/' { print $2 }' $rundir/versions`
76 case "$tinyvers" in
77 "") tinyvers=0
78 ;;
79 esac
80 if [ -f ../../sys/conf/osrelease.sh ]; then
81 osvers=`sh ../../sys/conf/osrelease.sh`
82 method=osreleases
83 else
84 osvers=`uname -r`
85 method=uname
86 fi
87 t=$osvers.$tinyvers
88 ;;
89 *) args=`awk '
90 /^@cwd/ { prefix = $2; next }
91 /^@dirrm/ { next }
92 { printf("%s%s\n", prefix, $0) }' $PLIST`
93 # first try for any RCS identifiers in the files
94 t=0
95 case "$args" in
96 "") ;;
97 *) t=`ident $args 2>/dev/null | awk '
98 BEGIN { last = 0 }
99 $2 == "crt0.c,v" { next }
100 NF == 8 { t = $4; gsub("/", "", t); if (t > last) last = t; }
101 END { print last }'`
102 method=ident
103 ;;
104 esac
105 case "$t" in
106 0) # we need the last mtime of the files which make up the package
107 t=`env TZ=UTC LOCALE=C ls -lT $args | awk '
108 BEGIN { newest = 0 }
109 {
110 t = $9 "";
111 if ($6 == "Jan") t = t "01";
112 if ($6 == "Feb") t = t "02";
113 if ($6 == "Mar") t = t "03";
114 if ($6 == "Apr") t = t "04";
115 if ($6 == "May") t = t "05";
116 if ($6 == "Jun") t = t "06";
117 if ($6 == "Jul") t = t "07";
118 if ($6 == "Aug") t = t "08";
119 if ($6 == "Sep") t = t "09";
120 if ($6 == "Oct") t = t "10";
121 if ($6 == "Nov") t = t "11";
122 if ($6 == "Dec") t = t "12";
123 if ($7 < 10) t = t "0";
124 t = t $7;
125 #these next two lines add the 24h clock onto the date
126 #gsub(":", "", $8);
127 #t = sprintf("%s.%4.4s", t, $8);
128 if (t > newest) newest = t;
129 }
130 END { print newest }'`
131 method=ls
132 ;;
133 esac
134 ;;
135 esac
136
137 # print version number that we're using
138 case "$verbose" in
139 -v) echo "$pkg - $t version using $method method" ;;
140 esac
141
142 # create the directory and minimal contents
143 SYSPKGDIR=${SYSPKGROOT}/$pkg-$t
144 if [ -d ${SYSPKGDIR} ]; then
145 echo "There is already a $pkg-$t package installed (${SYSPKGDIR})"
146 exit 1
147 fi
148
149 mkdir -p ${SYSPKGDIR}
150
151 # add the dependencies
152 awk '$1 ~ '/$pkg/' { print $2 }' $rundir/deps | sort | \
153 awk '{ print "@pkgdep " $1 "-[0-9]*" }' >> $PLIST
154
155 # create the comment
156 comment=`awk '$1 ~ '/$pkg/' { print substr($0, length($1) + 2) }' $rundir/comments`
157 case "$comment" in
158 "") echo "***WARNING ***: no comment for \"$pkg\"" 2>&1
159 comment="System package for $pkg"
160 ;;
161 esac
162 echo "$comment" > ${SYSPKGDIR}/+COMMENT
163
164 # create the description
165 descr=`awk '$1 ~ '/$pkg/' { print substr($0, length($1) + 2) }' $rundir/descrs`
166 case "$descr" in
167 "") echo "***WARNING ***: no description for \"$pkg\"" 2>&1
168 descr="System package for $pkg"
169 ;;
170 esac
171 echo "$descr" > ${SYSPKGDIR}/+DESC
172 printf "\nHomepage:\nhttp://www.NetBSD.org/\n" >> ${SYSPKGDIR}/+DESC
173
174 # create the build information
175 if [ x${BUILD_INFO_CACHE} = x ]; then
176 {
177 echo "OPSYS=`uname -s`"
178 echo "OS_VERSION=`uname -r`"
179 make -f- all <<EOF
180 .include <bsd.own.mk>
181 all:
182 @echo OBJECT_FMT=${OBJECT_FMT}
183 @echo MACHINE_ARCH=${MACHINE_ARCH}
184 @echo MACHINE_GNU_ARCH=${MACHINE_GNU_ARCH}
185 EOF
186 echo "_PKGTOOLS_VER=`pkg_create -V`"
187 } > ${SYSPKGDIR}/+BUILD_INFO
188 else
189 cp ${BUILD_INFO_CACHE} ${SYSPKGDIR}/+BUILD_INFO
190 fi
191
192 # test for attributes
193 args=""
194 attrs=`awk '$1 ~ '/$pkg/' { print substr($0, length($1) + 2) }' $rundir/attrs`
195 for a in "$attrs"; do
196 case "$attrs" in
197 "") ;;
198 preserve) echo "$pkg-$t" > ${SYSPKGDIR}/+PRESERVE
199 args="$args -n ${SYSPKGDIR}/+PRESERVE"
200 ;;
201 esac
202 done
203
204 pkg_create -v -c ${SYSPKGDIR}/+COMMENT \
205 -d ${SYSPKGDIR}/+DESC \
206 $args \
207 -f $PLIST -l -b /dev/null -B ${SYSPKGDIR}/+BUILD_INFO \
208 -s /dev/null -S /dev/null -O $pkg-$t.tgz \
209 > ${SYSPKGDIR}/+CONTENTS
210
211 rm $PLIST
212