regpkg revision 1.6 1 1.1 agc #! /bin/sh
2 1.1 agc #
3 1.6 erh # $NetBSD: regpkg,v 1.6 2004/07/23 15:11:26 erh Exp $
4 1.1 agc #
5 1.1 agc # Copyright (c) 2003 Alistair G. Crooks. All rights reserved.
6 1.1 agc #
7 1.1 agc # Redistribution and use in source and binary forms, with or without
8 1.1 agc # modification, are permitted provided that the following conditions
9 1.1 agc # are met:
10 1.1 agc # 1. Redistributions of source code must retain the above copyright
11 1.1 agc # notice, this list of conditions and the following disclaimer.
12 1.1 agc # 2. Redistributions in binary form must reproduce the above copyright
13 1.1 agc # notice, this list of conditions and the following disclaimer in the
14 1.1 agc # documentation and/or other materials provided with the distribution.
15 1.1 agc # 3. All advertising materials mentioning features or use of this software
16 1.1 agc # must display the following acknowledgement:
17 1.1 agc # This product includes software developed by Alistair G. Crooks.
18 1.1 agc # for the NetBSD project.
19 1.1 agc # 4. The name of the author may not be used to endorse or promote
20 1.1 agc # products derived from this software without specific prior written
21 1.1 agc # permission.
22 1.1 agc #
23 1.1 agc # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
24 1.1 agc # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 1.1 agc # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.1 agc # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
27 1.1 agc # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.1 agc # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29 1.1 agc # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 1.1 agc # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 1.1 agc # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 1.1 agc # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 1.1 agc # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 1.1 agc #
35 1.1 agc
36 1.1 agc # Usage: regpkg set pkgname
37 1.1 agc
38 1.6 erh rundir=${0%/*}
39 1.6 erh
40 1.1 agc SYSPKGROOT=${PKG_DBDIR:-/var/db/pkg}
41 1.1 agc case "${SYSPKG_DBDIR}" in
42 1.1 agc "") ;;
43 1.1 agc *) SYSPKGROOT=${SYSPKG_DBDIR} ;;
44 1.1 agc esac
45 1.1 agc
46 1.1 agc PLIST=/tmp/.PLIST.$$
47 1.1 agc
48 1.1 agc verbose=""
49 1.1 agc while [ $# -gt 2 ]; do
50 1.1 agc case $1 in
51 1.1 agc -v) verbose=$1 ;;
52 1.1 agc *) break ;;
53 1.1 agc esac
54 1.1 agc shift
55 1.1 agc done
56 1.1 agc
57 1.1 agc if [ $# -ne 2 ]; then
58 1.1 agc echo "Usage: regpkg set pkgname"
59 1.1 agc exit 1
60 1.1 agc fi
61 1.1 agc
62 1.1 agc pkgset=$1
63 1.1 agc
64 1.1 agc pkg=$2
65 1.1 agc
66 1.1 agc case $verbose in
67 1.1 agc -v) echo "Making PLIST for \"$pkgset\" set and \"$pkg\" package" ;;
68 1.1 agc esac
69 1.1 agc
70 1.1 agc # create the skeleton PLIST from the pkgset description
71 1.6 erh $rundir/makeplist $pkgset $pkg > $PLIST
72 1.1 agc
73 1.2 jwise # create the pkg tiny version
74 1.3 agc case "${SYSPKG_DATES}" in
75 1.6 erh "") tinyvers=`awk '$1 ~ '/$pkg/' { print $2 }' $rundir/versions`
76 1.3 agc case "$tinyvers" in
77 1.3 agc "") tinyvers=0
78 1.3 agc ;;
79 1.3 agc esac
80 1.3 agc if [ -f ../../sys/conf/osrelease.sh ]; then
81 1.3 agc osvers=`sh ../../sys/conf/osrelease.sh`
82 1.4 dyoung method=osreleases
83 1.3 agc else
84 1.3 agc osvers=`uname -r`
85 1.3 agc method=uname
86 1.3 agc fi
87 1.3 agc t=$osvers.$tinyvers
88 1.3 agc ;;
89 1.3 agc *) args=`awk '
90 1.3 agc /^@cwd/ { prefix = $2; next }
91 1.3 agc /^@dirrm/ { next }
92 1.3 agc { printf("%s%s\n", prefix, $0) }' $PLIST`
93 1.3 agc # first try for any RCS identifiers in the files
94 1.3 agc t=0
95 1.3 agc case "$args" in
96 1.3 agc "") ;;
97 1.3 agc *) t=`ident $args 2>/dev/null | awk '
98 1.3 agc BEGIN { last = 0 }
99 1.3 agc $2 == "crt0.c,v" { next }
100 1.3 agc NF == 8 { t = $4; gsub("/", "", t); if (t > last) last = t; }
101 1.3 agc END { print last }'`
102 1.3 agc method=ident
103 1.3 agc ;;
104 1.3 agc esac
105 1.3 agc case "$t" in
106 1.3 agc 0) # we need the last mtime of the files which make up the package
107 1.3 agc t=`env TZ=UTC LOCALE=C ls -lT $args | awk '
108 1.3 agc BEGIN { newest = 0 }
109 1.3 agc {
110 1.3 agc t = $9 "";
111 1.3 agc if ($6 == "Jan") t = t "01";
112 1.3 agc if ($6 == "Feb") t = t "02";
113 1.3 agc if ($6 == "Mar") t = t "03";
114 1.3 agc if ($6 == "Apr") t = t "04";
115 1.3 agc if ($6 == "May") t = t "05";
116 1.3 agc if ($6 == "Jun") t = t "06";
117 1.3 agc if ($6 == "Jul") t = t "07";
118 1.3 agc if ($6 == "Aug") t = t "08";
119 1.3 agc if ($6 == "Sep") t = t "09";
120 1.3 agc if ($6 == "Oct") t = t "10";
121 1.3 agc if ($6 == "Nov") t = t "11";
122 1.3 agc if ($6 == "Dec") t = t "12";
123 1.3 agc if ($7 < 10) t = t "0";
124 1.3 agc t = t $7;
125 1.3 agc #these next two lines add the 24h clock onto the date
126 1.3 agc #gsub(":", "", $8);
127 1.3 agc #t = sprintf("%s.%4.4s", t, $8);
128 1.3 agc if (t > newest) newest = t;
129 1.3 agc }
130 1.3 agc END { print newest }'`
131 1.3 agc method=ls
132 1.3 agc ;;
133 1.3 agc esac
134 1.2 jwise ;;
135 1.2 jwise esac
136 1.2 jwise
137 1.3 agc # print version number that we're using
138 1.3 agc case "$verbose" in
139 1.3 agc -v) echo "$pkg - $t version using $method method" ;;
140 1.3 agc esac
141 1.1 agc
142 1.1 agc # create the directory and minimal contents
143 1.1 agc SYSPKGDIR=${SYSPKGROOT}/$pkg-$t
144 1.1 agc if [ -d ${SYSPKGDIR} ]; then
145 1.1 agc echo "There is already a $pkg-$t package installed (${SYSPKGDIR})"
146 1.1 agc exit 1
147 1.1 agc fi
148 1.1 agc
149 1.1 agc mkdir -p ${SYSPKGDIR}
150 1.1 agc
151 1.4 dyoung # add the dependencies
152 1.6 erh awk '$1 ~ '/$pkg/' { print $2 }' $rundir/deps | sort | \
153 1.4 dyoung awk '{ print "@pkgdep " $1 "-[0-9]*" }' >> $PLIST
154 1.4 dyoung
155 1.1 agc # create the comment
156 1.6 erh comment=`awk '$1 ~ '/$pkg/' { print substr($0, length($1) + 2) }' $rundir/comments`
157 1.1 agc case "$comment" in
158 1.1 agc "") echo "***WARNING ***: no comment for \"$pkg\"" 2>&1
159 1.1 agc comment="System package for $pkg"
160 1.1 agc ;;
161 1.1 agc esac
162 1.1 agc echo "$comment" > ${SYSPKGDIR}/+COMMENT
163 1.1 agc
164 1.1 agc # create the description
165 1.6 erh descr=`awk '$1 ~ '/$pkg/' { print substr($0, length($1) + 2) }' $rundir/descrs`
166 1.1 agc case "$descr" in
167 1.1 agc "") echo "***WARNING ***: no description for \"$pkg\"" 2>&1
168 1.1 agc descr="System package for $pkg"
169 1.1 agc ;;
170 1.1 agc esac
171 1.1 agc echo "$descr" > ${SYSPKGDIR}/+DESC
172 1.1 agc printf "\nHomepage:\nhttp://www.NetBSD.org/\n" >> ${SYSPKGDIR}/+DESC
173 1.1 agc
174 1.1 agc # create the build information
175 1.5 dyoung if [ x${BUILD_INFO_CACHE} = x ]; then
176 1.5 dyoung {
177 1.5 dyoung echo "OPSYS=`uname -s`"
178 1.5 dyoung echo "OS_VERSION=`uname -r`"
179 1.5 dyoung make -f- all <<EOF
180 1.4 dyoung .include <bsd.own.mk>
181 1.4 dyoung all:
182 1.4 dyoung @echo OBJECT_FMT=${OBJECT_FMT}
183 1.4 dyoung @echo MACHINE_ARCH=${MACHINE_ARCH}
184 1.4 dyoung @echo MACHINE_GNU_ARCH=${MACHINE_GNU_ARCH}
185 1.4 dyoung EOF
186 1.5 dyoung echo "_PKGTOOLS_VER=`pkg_create -V`"
187 1.5 dyoung } > ${SYSPKGDIR}/+BUILD_INFO
188 1.5 dyoung else
189 1.5 dyoung cp ${BUILD_INFO_CACHE} ${SYSPKGDIR}/+BUILD_INFO
190 1.5 dyoung fi
191 1.1 agc
192 1.1 agc # test for attributes
193 1.1 agc args=""
194 1.6 erh attrs=`awk '$1 ~ '/$pkg/' { print substr($0, length($1) + 2) }' $rundir/attrs`
195 1.1 agc for a in "$attrs"; do
196 1.1 agc case "$attrs" in
197 1.1 agc "") ;;
198 1.1 agc preserve) echo "$pkg-$t" > ${SYSPKGDIR}/+PRESERVE
199 1.1 agc args="$args -n ${SYSPKGDIR}/+PRESERVE"
200 1.1 agc ;;
201 1.1 agc esac
202 1.1 agc done
203 1.1 agc
204 1.1 agc pkg_create -v -c ${SYSPKGDIR}/+COMMENT \
205 1.1 agc -d ${SYSPKGDIR}/+DESC \
206 1.1 agc $args \
207 1.1 agc -f $PLIST -l -b /dev/null -B ${SYSPKGDIR}/+BUILD_INFO \
208 1.5 dyoung -s /dev/null -S /dev/null -O $pkg-$t.tgz \
209 1.1 agc > ${SYSPKGDIR}/+CONTENTS
210 1.1 agc
211 1.4 dyoung rm $PLIST
212