regpkg revision 1.7 1 #! /bin/sh
2 #
3 # $NetBSD: regpkg,v 1.7 2006/01/03 16:40:16 apb 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=`${HOST_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_CMD} 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) }' \
157 $rundir/comments`
158 case "$comment" in
159 "") echo "***WARNING ***: no comment for \"$pkg\"" 2>&1
160 comment="System package for $pkg"
161 ;;
162 esac
163 echo "$comment" > ${SYSPKGDIR}/+COMMENT
164
165 # create the description
166 descr=`${AWK} '$1 ~ '/$pkg/' { print substr($0, length($1) + 2) }' \
167 $rundir/descrs`
168 case "$descr" in
169 "") echo "***WARNING ***: no description for \"$pkg\"" 2>&1
170 descr="System package for $pkg"
171 ;;
172 esac
173 echo "$descr" > ${SYSPKGDIR}/+DESC
174 ${PRINTF} "\nHomepage:\nhttp://www.NetBSD.org/\n" >> ${SYSPKGDIR}/+DESC
175
176 # create the build information
177 if [ x${BUILD_INFO_CACHE} = x ]; then
178 {
179 echo "OPSYS=`${UNAME} -s`"
180 echo "OS_VERSION=`${UNAME} -r`"
181 ${MAKE} -f- all <<EOF
182 .include <bsd.own.mk>
183 all:
184 @echo OBJECT_FMT=${OBJECT_FMT}
185 @echo MACHINE_ARCH=${MACHINE_ARCH}
186 @echo MACHINE_GNU_ARCH=${MACHINE_GNU_ARCH}
187 EOF
188 echo "_PKGTOOLS_VER=`${PKG_CREATE} -V`"
189 } > ${SYSPKGDIR}/+BUILD_INFO
190 else
191 cp ${BUILD_INFO_CACHE} ${SYSPKGDIR}/+BUILD_INFO
192 fi
193
194 # test for attributes
195 args=""
196 attrs=`${AWK} '$1 ~ '/$pkg/' { print substr($0, length($1) + 2) }' \
197 $rundir/attrs`
198 for a in "$attrs"; do
199 case "$attrs" in
200 "") ;;
201 preserve) echo "$pkg-$t" > ${SYSPKGDIR}/+PRESERVE
202 args="$args -n ${SYSPKGDIR}/+PRESERVE"
203 ;;
204 esac
205 done
206
207 ${PKG_CREATE} -v -c ${SYSPKGDIR}/+COMMENT \
208 -d ${SYSPKGDIR}/+DESC \
209 $args \
210 -f $PLIST -l -b /dev/null -B ${SYSPKGDIR}/+BUILD_INFO \
211 -s /dev/null -S /dev/null -O $pkg-$t.tgz \
212 > ${SYSPKGDIR}/+CONTENTS
213
214 rm $PLIST
215