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