regpkgset revision 1.6 1 #! /bin/sh
2 #
3 # $NetBSD: regpkgset,v 1.6 2006/01/04 14:18:00 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: regpkgset [options] set
37 #
38 # Options:
39 # -q Quiet.
40 # -v Verbose.
41 # -f Force.
42 # -m Ignore errors from missing files.
43 # -u Update.
44 # -c Cache some information in ${BUILD_INFO_CACHE}.
45 # -d destdir Sets DESTDIR.
46 # -t binpkgdir Create a binary package (in *.tgz format) in the
47 # specified directory. Without this option, a binary
48 # package is not created.
49 # -M metalog Use the specified metalog file to override file
50 # or directory attributes when creating a binary package.
51 # -N etcdir Use the specified directory for passwd and group files.
52
53 prog="${0##*/}"
54 toppid=$$
55 rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
56 . "${rundir}/sets.subr"
57
58 bomb()
59 {
60 kill ${toppid} # in case we were invoked from a subshell
61 exit 1
62 }
63
64 # A literal newline
65 nl='
66 '
67
68 #
69 # cleanup() deletes temporary files.
70 #
71 es=0
72 cleanup ()
73 {
74 trap - 0
75 [ x"${BUILD_INFO_CACHE}" != x ] && rm -f "${BUILD_INFO_CACHE}"
76 exit ${es}
77 }
78 trap 'es=128; cleanup' 1 2 3 13 15 # HUP INT QUIT PIPE TERM
79 trap 'es=$?; cleanup' 0 # EXIT
80
81 #
82 # Parse command line args.
83 #
84 verbose=false
85 quiet=false
86 force=false
87 allowmissing=false
88 update=false
89 cache=false
90 pkgdir=""
91 metalog=""
92 etcdir=""
93 all_options=""
94 while [ $# -gt 1 ]; do
95 # XXX: ${all_options} doesn't correctly handle args with
96 # embedded shell special characters.
97 case "$1" in
98 -q) quiet=true ; verbose=false ;;
99 -v) verbose=true ; quiet=false ;;
100 -f) force=true ;;
101 -m) allowmissing=true ;;
102 -u) update=true ;;
103 -c) cache=true ;;
104 -d) DESTDIR="$2" ; all_options="${all_options} $1" ; shift ;;
105 -d*) DESTDIR="${1#-?}" ;;
106 -t) pkgdir="$2" ; all_options="${all_options} $1" ; shift ;;
107 -t*) pkgdir="${1#-?}" ;;
108 -M) metalog="$2" ; all_options="${all_options} $1" ; shift ;;
109 -M*) metalog="${1#-?}" ;;
110 -N) etcdir="$2" ; all_options="${all_options} $1" ; shift ;;
111 -N*) etcdir="${1#-?}" ;;
112 -*) echo "Usage: regpkgset [options] set ..." ; bomb ;;
113 *) break ;;
114 esac
115 all_options="${all_options} $1"
116 shift
117 done
118 export DESTDIR
119
120 if [ $# -lt 1 ]; then
121 echo "Usage: regpkgset [options] set ..."
122 bomb
123 fi
124
125 case "$1" in
126 all) list="base comp etc games man misc text" ;;
127 *) list="$*" ;;
128 esac
129
130 if ${cache} ; then
131 BUILD_INFO_CACHE="$(${MKTEMP} "/var/tmp/${prog}-BUILD_INFO.XXXXXX")"
132 export BUILD_INFO_CACHE
133 {
134 # These variables describe the build
135 # environment, not the target.
136 echo "OPSYS=$(${UNAME} -s)"
137 echo "OS_VERSION=$(${UNAME} -r)"
138 ${MAKE} -f- all <<EOF
139 .include <bsd.own.mk>
140 all:
141 @echo OBJECT_FMT=${OBJECT_FMT}
142 @echo MACHINE_ARCH=${MACHINE_ARCH}
143 @echo MACHINE_GNU_ARCH=${MACHINE_GNU_ARCH}
144 EOF
145 # XXX: what's the point of reporting _PKGTOOLS_VER
146 # when we roll everything by hand without using
147 # the pkg tools?
148 echo "_PKGTOOLS_VER=$(${PKG_CREATE} -V)"
149 } > "${BUILD_INFO_CACHE}"
150 fi
151
152 #
153 # For each pkgset mentioned in ${list}, get a list of all pkgs in the pkgset.
154 #
155 # Sort all the pkgs into dependency order (with prerequisite pkgs before
156 # pkgs that depend on them).
157 #
158 # Invoke ${rundir}/regpkg for each pkg, taking care to do it in dependency
159 # order. If there were any pkgs for which we failed to find dependency
160 # information, handle them at the end.
161 #
162 pkgs="$( for pkgset in ${list}; do
163 ${HOST_SH} "${rundir}/listpkgs" "${pkgset}" || bomb
164 done )"
165 tsort_input="$( ${AWK} '{print $2 " " $1}' <"${rundir}/deps" || bomb )"
166 tsort_output="$( echo "${tsort_input}" | ${TSORT} || bomb )"
167 for pkg in ${tsort_output} ; do
168 case "${nl}${pkgs}${nl}" in
169 *"${nl}${pkg}${nl}"*)
170 # We want this pkg.
171 pkgset="${pkg%%-*}"
172 ${verbose} && echo "${prog}: registering ${pkg}"
173 ${HOST_SH} "${rundir}/regpkg" ${all_options} \
174 "${pkgset}" "${pkg}" || bomb
175 ;;
176 *) # pkg is mentioned in ${tsort_output} but not in ${pkgs}.
177 # We do not want this pkg.
178 ;;
179 esac
180 done
181 for pkg in ${pkgs} ; do
182 case "${nl}${tsort_output}${nl}" in
183 *"${nl}${pkg}${nl}"*)
184 # pkg was in the tsort output, so it would have been
185 # handled above.
186 ;;
187 *) # This pkg was not in the tsort output.
188 # This is probably an error, but process the
189 # pkg anyway.
190 echo >&2 "${prog}: WARNING: ${pkg} is not mentioned in deps file"
191 pkgset="${pkg%%-*}"
192 ${verbose} && echo "${prog}: registering ${pkg}"
193 ${HOST_SH} "${rundir}/regpkg" ${all_options} \
194 "${pkgset}" "${pkg}" || bomb
195 ;;
196 esac
197 done
198
199 exit 0
200