1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
|
#!/bin/ksh -p
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2010 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
#
# usage: acr [root [archivedir]]
#
# examples: acr
# acr /export/home/zone/root
# acr /export/home/zone/root ${CODEMGR_WS}/archives/sparc/nightly
#
if [ $# -gt 2 ] ; then
print -u2 "usage: $0 <root> <archivedir>"
exit 1
fi
root=${1-/}
archivedir=$2
if [ -z "$archivedir" -o "$archivedir" = again ]; then
if [ ! -s $root/etc/motd ]; then
print -u2 "$root/etc/motd not found; this doesn't look like a" \
"valid root."
exit 1
fi
archivedir=$(nawk '/^bfu.ed from / { print $3; exit }' $root/etc/motd)
fi
if [ ! -d "$archivedir" ]; then
print -u2 "Archive directory '$archivedir' not found."
exit 1
fi
#
# temporary file scorecard:
#
# conflictscripts list of scripts we need to run.
#
# installnew list of editable files without class action scripts
#
# processedscript basename of class action script edited to NOP
# installf/removef's and use /tmp/bfubin
#
# allresults log of all class action script output.
#
# thisresult log of most recent class action script
#
tmpdir=$(mktemp -t -d acr.XXXXXX)
if [ -z "$tmpdir" ] ; then
print -u2 "mktemp failed to produce output; aborting."
exit 1
fi
if [ ! -d $tmpdir ] ; then
print -u2 "mktemp failed to create a directory; aborting."
exit 1
fi
conflictscripts=$tmpdir/conflictscripts
installnew=$tmpdir/installnew
allresults=$tmpdir/allresults
thisresult=$tmpdir/thisresult
processedscript=$tmpdir/processedscript
#
# This file is left over (on purpose) by BFU so that in a post-BFU environment
# we know which zones BFU processed.
#
bfu_zone_list=$root/.bfu_zone_list
get_cr_archive() {
compressed_archive=$archivedir/conflict_resolution.gz
if [ ! -s $compressed_archive ] ; then
print -u2 "Failed to find conflict resolution information" \
"at $compressed_archive."
return 1
fi
print -n "Getting ACR information from $archivedir... "
gzip -d -c $compressed_archive | \
(cd $tmpdir; cpio -idmucB > /dev/null 2>&1) || return 1
crdir=$tmpdir/conflict_resolution
if [ ! -d $crdir ] ; then
print -u2 "The conflict resolution archive is missing the" \
"conflict_resolution directory."
return 1
fi
if [ ! -f $crdir/editable_file_db ] ; then
print -u2 "The conflict resolution archive is missing the" \
"editable file list."
return 1
fi
print "ok"
return 0
}
#
# If we're running after a BFU, some behaviors are different.
#
if [ -d /tmp/bfubin ] ; then
bfu_alt_reality="true"
else
bfu_alt_reality="false"
fi
acr_a_root() {
typeset root
typeset zone
root=$1
zone=$2
print "ZONE $2 on $1" >> $allresults
rm -f $conflictscripts
rm -f $installnew
#
# The files that need to be processed are those that were stored by
# bfu in bfu.conflicts. Just process those that changed in the
# distribution since the last bfu (those that are listed in the
# $root/bfu.conflicts/NEW file).
#
if [ ! -d $root/bfu.conflicts ] ; then
print -u2 "No BFU conflict information."
return 1
fi
if [ ! -s $root/bfu.conflicts/NEW ] ; then
print "No conflicts to resolve."
return 0
fi
#
# Some class-action scripts rely on being run in the order defined in
# packages. The $crdir/editable_file_db file contains the classes
# in the correct order, so we preserve that order.
#
cat $crdir/editable_file_db | \
while read filename script pkg pkginst isa mach unique pkgdef
do
grep "^$filename\$" $root/bfu.conflicts/NEW >> /dev/null || \
continue
if [ "$mach" != "-" -a $(uname -m) != "$mach" ] ; then
continue
fi
print $filename $script $pkg $pkginst $isa $mach $unique \
$pkgdef >> $conflictscripts
done
if [ ! -s $conflictscripts ] ; then
print "\nNo upgrade scripts were found for any of the" \
"conflicting files."
return 1
fi
#
# Look for files that are in the conflict list, but don't have
# entries in the $conflictscripts file. These have no
# install scripts, so should just be copied. (The fact that such
# files exist indicates a bug in bfu or possibly in the Solaris
# packaging. If these are really editable files, they should have
# class action scripts. If not, bfu shouldn't special-case them.)
#
cat $root/bfu.conflicts/NEW | while read filename ; do
grep "$filename " $conflictscripts >> /dev/null
if [ $? != 0 ] ; then
print $filename >> $installnew
fi
done
if [ -s $installnew ] ; then
print "\n The following files did not have conflict" \
"resolution scripts; this may"
print " indicate a bug in BFU. The new versions will be" \
"installed. The previous"
print " versions of these files can be found in" \
"$root/bfu.child:\n"
cat $installnew | sed 's/^/ /'
print
fi
UPDATE=yes
BASEDIR=$root
PKGSAV=/tmp
PKG_INSTALL_ROOT=$root
export UPDATE BASEDIR PKGSAV PKG_INSTALL_ROOT
column_fmt=' %-35s %-20s '
printf "\n$column_fmt %s\n" "FILE" "ACTION" "STATUS"
cat $conflictscripts | while read filename script pkg pkginst isa mach \
unique pkgdef ; do
if [ "$script" = "upgrade_default" ] ; then
msg=`printf "$column_fmt" \
$filename "upgrade_default_copy"`
cp $root/bfu.conflicts/$filename $root/$filename
if [ $? = 0 ]; then
printf "$msg ok\n"
continue
else
printf "$msg FAIL\n" 1>&2
return 1
fi
fi
if [ "$unique" = "c" ] ; then
scriptloc=$crdir/$pkgdef/$script
elif [ "$unique" = "s" ] ; then
scriptloc=$crdir/$pkgdef/$pkginst/$script
else
scriptloc=$root/usr/sadm/install/scripts/$script
fi
msg=`printf "$column_fmt" $filename $script`
#
# If we are running in the post-BFU alternate reality, we need
# to modify the class action script to work in that alternate
# reality. Otherwise, we merely need to "neuter" installf
# and removef. In any event, skip this one and go to the next
# if the sed fails.
#
if [ $bfu_alt_reality = "true" ] ; then
sed -e 's,^#! */bin/sh,#!/tmp/bfubin/sh,' \
-e 's,/usr/bin/,/tmp/bfubin/,g' \
-e 's,/usr/bin:,/tmp/bfubin:,' \
-e 's,/usr/sbin/,/tmp/bfubin/,g' \
-e 's,/usr/sbin:,/tmp/bfubin:,' \
-e 's,/lib/svc/bin/,/tmp/bfubin/,g' \
-e 's,/bin/,/tmp/bfubin/,g' \
-e 's,/sbin/,/tmp/bfubin/,g' \
-e 's,installf,/tmp/bfubin/true,' \
-e 's,removef,/tmp/bfubin/true,' \
$scriptloc > $processedscript.$script
error=$?
else
sed -e 's,installf,/usr/bin/true,' \
-e 's,removef,/usr/bin/true,' \
$scriptloc > $processedscript.$script
error=$?
fi
if [ $error != 0 ] ; then
printf "$msg FAIL (sed surgery->$error)\n" 1>&2
continue
fi
chmod +x $processedscript.$script
error=$?
if [ $error != 0 ] ; then
printf "$msg FAIL (chmod->$error)\n" 1>&2
continue
fi
PKG=$pkg
PKGINST=$pkg
if [ $mach = "-" ] ; then
ARCH=$isa
else
ARCH=$isa.$mach
fi
export PKG PKGINST ARCH
print "PROCESSING $filename with $script" >> $allresults
if [ "$script" = "i.build" ] ; then
print $crdir/$pkgdef/$pkginst/$filename $root/$filename |
$processedscript.$script > $thisresult 2>&1
else
print $root/bfu.conflicts/$filename $root/$filename |
$processedscript.$script > $thisresult 2>&1
fi
error=$?
if [ $error != 0 ] ; then
printf "$msg FAIL (exit $error)\n" 1>&2
print -u2 " Output of upgrade script:"
sed 's/^/ /' < $thisresult >&2
else
printf "$msg ok\n"
fi
cat $thisresult >> $allresults
print "RETURN CODE: $error" >> $allresults
done
if [ -s $installnew ] ; then
cat $installnew | while read filename ; do
msg=`printf "$column_fmt" $filename \
"cp from new version"`
cp $root/bfu.conflicts/$filename $root/$filename
error=$?
if [ $error != 0 ] ; then
printf "$msg FAIL (exit $error)\n" 1>&2
else
printf "$msg ok\n"
fi
done
fi
}
#
# If we're post-BFU, then BFU should have left us a file listing which zones it
# processed. If we're not post-BFU, just process all installed native and
# Sn-1 zones.
#
if [ $bfu_alt_reality = "false" ]; then
zoneadm list -pi | nawk -F: '{
if ($3 == "installed" &&
($6 == "native" || $6 == "" || $6 == "sn1")) {
printf "%s %s\n", $2, $4
}
}' > $bfu_zone_list
fi
#
# To be terse, check whether there is any work to do at all; if not,
# just print one line and exit.
#
need_resolve=false
if [ -s $root/bfu.conflicts/NEW ]; then
need_resolve=true
else
if [ -s $bfu_zone_list ]; then
cat $bfu_zone_list | while read zone zonepath; do
if [ -s $zonepath/root/bfu.conflicts/NEW ] ; then
need_resolve=true
fi
done
fi
fi
if [ "$need_resolve" = "false" ]; then
print "No conflicts to resolve."
exit 0
fi
get_cr_archive || exit 1
printf "\nProcessing global zone:\t"
acr_a_root $root "global"
if [ $root != "/" ]; then
printf "\nSkipping non-global zones (root is not /)"
else
if [ -s $bfu_zone_list ]; then
cat $bfu_zone_list | while read zone zonepath; do
printf "\nProcessing zone $zone:\t"
acr_a_root $zonepath/root $zone
done
fi
fi
echo
# workaround for 6644920
cr_args=${root:+ -R $root}
if [ -x /tmp/bfubin/create_ramdisk ] ; then
LD_LIBRARY_PATH=/tmp/bfulib PATH=/tmp/bfubin \
/tmp/bfubin/ksh /tmp/bfubin/create_ramdisk $cr_args
else
LD_LIBRARY_PATH=/tmp/bfulib PATH=/tmp/bfubin \
/tmp/bfubin/ksh $root/boot/solaris/bin/create_ramdisk $cr_args
fi
print "Finished. See $allresults for complete log."
|