New bfu.sh
  1 #!/bin/ksh
  2 #
  3 # CDDL HEADER START
  4 #
  5 # The contents of this file are subject to the terms of the
  6 # Common Development and Distribution License (the "License").
  7 # You may not use this file except in compliance with the License.
  8 #
  9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 10 # or http://www.opensolaris.org/os/licensing.
 11 # See the License for the specific language governing permissions
 12 # and limitations under the License.
 13 #
 14 # When distributing Covered Code, include this CDDL HEADER in each
 15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 16 # If applicable, add the following below this CDDL HEADER, with the
 17 # fields enclosed by brackets "[]" replaced with your own identifying
 18 # information: Portions Copyright [yyyy] [name of copyright owner]
 19 #
 20 # CDDL HEADER END
 21 #
 22 
 23 #
 24 # Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
 25 # Use is subject to license terms.
 26 #
 27 # ident "@(#)bfu.sh     1.347   06/03/13 SMI"
 28 #
 29 # Upgrade a machine from a cpio archive area in about 5 minutes.
 30 # By Roger Faulkner and Jeff Bonwick, April 1993.
 31 # (bfu == Bonwick/Faulkner Upgrade, a.k.a. Blindingly Fast Upgrade)
 32 #
 33 # Usage: bfu    [-f] <archive_dir> [root-dir]     # for normal machines
 34 #        bfu -c [-f] <archive_dir> <exec-dir>       # for diskless clients
 35 #
 36 # The -f flag is to override the built-in safety check which requires
 37 # that the starting-point OS be a least a certain revision.
 38 #
 39 # You have to be super-user.  It's safest to run this from the
 40 # system console, although I've run it under OW and even via
 41 # remote login with no problems.
 42 #
 43 # You will have to reboot the system when the upgrade is complete.
 44 #
 45 # You should add any administrative files you care about to this list.
 46 # Warning: there had better be no leading '/' on any of these filenames.
 47 
 48 #
 49 # The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout
 50 # under certain circumstances, which can really screw things up; unset it.
 51 #
 52 unset CDPATH
 53 
 54 export LC_ALL="C"
 55 
 56 if [ -z "$GATEPATH" ]; then
 57         GATEPATH=/ws/onnv-gate
 58         test -d $GATEPATH || GATEPATH=/net/onnv.eng/export/gate
 59 fi
 60 if [ -z "$ARCHIVEPATH" ]; then
 61         ARCHIVEPATH=/ws/onnv-gate
 62         test -d $ARCHIVEPATH || ARCHIVEPATH=/net/onnv.eng/export
 63 fi
 64 export GATE=${GATEPATH}
 65 export ARCHIVE=${ARCHIVEPATH}
 66 
 67 #
 68 # NOTE: Entries in *_files must expand to either the exact files required,
 69 #       or to directories that will be scoured for files.  Any directories
 70 #       (and subdirectories) resulting from a wildcard expansion will be
 71 #       fully recursed by BFU's searching for files.  (E.g. /etc/inet/* will
 72 #       include all files in any of its directories, as well as any files in
 73 #       /etc/inet/ itself.
 74 #
 75 # First list: files to be saved in global and non-global zones.
 76 #
 77 all_zones_files="
 78         etc/.login
 79         etc/acct/holidays
 80         etc/acctadm.conf
 81         etc/aggregation.conf
 82         etc/auto_*
 83         etc/cron.d/at.deny
 84         etc/cron.d/cron.deny
 85         etc/crypto/pkcs11.conf
 86         etc/datalink.conf
 87         etc/default/*
 88         etc/dfs/dfstab
 89         etc/dumpdates
 90         etc/ftpd/*
 91         etc/ftpusers
 92         etc/group
 93         etc/gss/gsscred.conf
 94         etc/gss/mech
 95         etc/gss/qop
 96         etc/inet/*
 97         etc/init.d/*
 98         etc/inittab
 99         etc/krb5/kadm5.acl
100         etc/krb5/kdc.conf
101         etc/krb5/kpropd.acl
102         etc/krb5/krb5.conf
103         etc/krb5/warn.conf
104         etc/logadm.conf
105         etc/logindevperm
106         etc/lp/Systems
107         etc/mail/*.cf
108         etc/mail/*.hf
109         etc/mail/*.rc
110         etc/mail/aliases
111         etc/mail/helpfile
112         etc/mail/local-host-names
113         etc/mail/trusted-users
114         etc/net/*/services
115         etc/netconfig
116         etc/nfs/nfslog.conf
117         etc/nfssec.conf
118         etc/nscd.conf
119         etc/nsswitch.*
120         etc/pam.conf
121         etc/passwd
122         etc/policy.conf
123         etc/printers.conf
124         etc/profile
125         etc/project
126         etc/publickey
127         etc/remote
128         etc/named.conf
129         etc/resolv.conf
130         etc/rmmount.conf
131         etc/rpc
132         etc/rpld.conf
133         etc/saf/_sactab
134         etc/saf/_sysconfig
135         etc/saf/zsmon/_pmtab
136         etc/security/*_attr
137         etc/security/audit_*
138         etc/security/crypt.conf
139         etc/security/policy.conf
140         etc/sfw/openssl/openssl.cnf
141         etc/shadow
142         etc/skel/.profile
143         etc/skel/local.*
144         etc/smartcard/.keys
145         etc/smartcard/desktop.properties
146         etc/smartcard/ocf.classpath
147         etc/smartcard/opencard.properties
148         etc/ssh/ssh_config
149         etc/ssh/sshd_config
150         etc/syslog.conf
151         etc/ttydefs
152         etc/ttysrch
153         etc/user_attr
154         etc/uucp/[A-Z]*
155         etc/vfstab
156         etc/vold.conf
157         var/spool/cron/crontabs/*
158         var/yp/Makefile
159         var/yp/aliases
160         var/yp/nicknames
161 "
162 
163 #
164 # Second list: files to be saved in the global zone only.
165 #
166 global_zone_only_files="
167         boot/grub/menu.lst
168         boot/solaris/bootenv.rc
169         boot/solaris/devicedb/master
170         boot/solaris/filelist.ramdisk
171         etc/bootrc
172         etc/crypto/kcf.conf
173         etc/devlink.tab
174         etc/driver_aliases
175         etc/driver_classes
176         etc/ipf/ipf.conf
177         etc/ipf/pfil.ap
178         etc/iu.ap
179         etc/lvm/devpath
180         etc/lvm/lock
181         etc/lvm/md.cf
182         etc/lvm/md.ctlrmap
183         etc/lvm/md.tab
184         etc/lvm/mddb.cf
185         etc/lvm/runtime.cf
186         etc/mach
187         etc/minor_perm
188         etc/name_to_major
189         etc/name_to_sysnum
190         etc/nca/*
191         etc/openwin/server/etc/OWconfig
192         etc/path_to_inst
193         etc/power.conf
194         etc/ppp/chap-secrets
195         etc/ppp/options
196         etc/ppp/pap-secrets
197         etc/security/device_policy
198         etc/security/extra_privs
199         etc/system
200         etc/zones/index
201         kernel/drv/elxl.conf
202         kernel/drv/md.conf
203         kernel/drv/options.conf
204         kernel/drv/ra.conf
205         kernel/drv/scsa2usb.conf
206         kernel/drv/scsi_vhci.conf
207         kernel/drv/sd.conf
208         platform/*/kernel/drv/*ppm.conf
209         platform/i86pc/kernel/drv/aha.conf
210         platform/i86pc/kernel/drv/asy.conf
211         platform/sun4u/boot.conf
212 "
213 
214 #
215 # Third list: files extracted from generic.root but which belong in the global
216 # zone only: they are superfluous (and some even harmful) in local zones.
217 #
218 # (note: as /etc/init.d scripts are converted to smf(5) "Greenline" services,
219 # they (and their /etc/rc?.d hardlinks) should be removed from this list when
220 # they are added to smf_obsolete_rc_files, below)
221 #
222 superfluous_local_zone_files="
223         dev/dsk
224         dev/fd
225         dev/pts
226         dev/rdsk
227         dev/rmt
228         dev/sad
229         dev/stderr
230         dev/stdin
231         dev/stdout
232         dev/swap
233         dev/term
234         devices
235         etc/dacf.conf
236         etc/dat
237         etc/default/dhcpagent
238         etc/default/inetinit
239         etc/default/ipsec
240         etc/default/metassist.xml
241         etc/default/mpathd
242         etc/default/power
243         etc/flash/postdeployment/svm.cleanup
244         etc/flash/predeployment/svm.save
245         etc/fm
246         etc/inet/datemsk.ndpd
247         etc/inet/ike
248         etc/inet/ipqosconf.1.sample
249         etc/inet/ipqosconf.2.sample
250         etc/inet/ipqosconf.3.sample
251         etc/inet/ipsecalgs
252         etc/inet/ipsecinit.sample
253         etc/inet/mipagent.conf-sample
254         etc/inet/mipagent.conf.fa-sample
255         etc/inet/mipagent.conf.ha-sample
256         etc/inet/secret
257         etc/inet/sock2path
258         etc/init.d/audit
259         etc/init.d/devlinks
260         etc/init.d/dodatadm.udaplt
261         etc/init.d/drvconfig
262         etc/init.d/flashprom
263         etc/init.d/llc2
264         etc/init.d/mipagent
265         etc/init.d/ncakmod
266         etc/init.d/ncalogd
267         etc/init.d/pcmcia
268         etc/init.d/pppd
269         etc/init.d/sckm
270         etc/init.d/wrsmcfg
271         etc/ipf
272         etc/llc2
273         etc/lvm
274         etc/nca
275         etc/openwin
276         etc/ppp
277         etc/rc0.d/K06mipagent
278         etc/rc0.d/K33audit
279         etc/rc0.d/K34ncalogd
280         etc/rc0.d/K42sckm
281         etc/rc0.d/K50pppd
282         etc/rc0.d/K52llc2
283         etc/rc1.d/K06mipagent
284         etc/rc1.d/K33audit
285         etc/rc1.d/K34ncalogd
286         etc/rc1.d/K40sf880dr
287         etc/rc1.d/K42sckm
288         etc/rc1.d/K50pppd
289         etc/rc1.d/K52llc2
290         etc/rc2.d/K06mipagent
291         etc/rc2.d/S40llc2
292         etc/rc2.d/S42ncakmod
293         etc/rc2.d/S47pppd
294         etc/rc2.d/S70sckm
295         etc/rc2.d/S75flashprom
296         etc/rc2.d/S81dodatadm.udaplt
297         etc/rc2.d/S94ncalogd
298         etc/rc2.d/S98efcode
299         etc/rc2.d/S99audit
300         etc/rc3.d/S80mipagent
301         etc/rcS.d/K06mipagent
302         etc/rcS.d/K34ncalogd
303         etc/rcS.d/K42sckm
304         etc/rcS.d/K44wrsmcfg
305         etc/rcS.d/K50pppd
306         etc/rcS.d/K52llc2
307         etc/rcS.d/S29wrsmcfg
308         etc/rcm
309         etc/snmp/conf/mipagent.acl
310         etc/snmp/conf/mipagent.reg
311         etc/sock2path
312         etc/usb
313         etc/wrsm
314         etc/zones
315         kernel
316         lib/svc/method/svc-intrd
317         lib/svc/method/svc-poold
318         lib/svc/method/svc-pools
319         lib/svc/method/svc-scheduler
320         var/adm/pool
321         var/fm
322         var/log/pool
323         var/svc/manifest/network/aggregation.xml
324         var/svc/manifest/network/datalink-init.xml
325         var/svc/manifest/network/datalink.xml
326         var/svc/manifest/network/ipfilter.xml
327         var/svc/manifest/network/pfil.xml
328         var/svc/manifest/platform
329         var/svc/manifest/system/cvc.xml
330         var/svc/manifest/system/dumpadm.xml
331         var/svc/manifest/system/fmd.xml
332         var/svc/manifest/system/intrd.xml
333         var/svc/manifest/system/mdmonitor.xml
334         var/svc/manifest/system/metainit.xml
335         var/svc/manifest/system/picl.xml
336         var/svc/manifest/system/poold.xml
337         var/svc/manifest/system/pools.xml
338         var/svc/manifest/system/power.xml
339         var/svc/manifest/system/scheduler.xml
340         var/svc/manifest/system/sysevent.xml
341         var/svc/manifest/system/zones.xml
342 "
343 
344 #
345 # files to be preserved, ie unconditionally restored to "child" versions
346 #
347 preserve_files="
348         kernel/misc/amd64/sysinit
349         kernel/misc/sysinit
350         kernel/misc/usbs49_fw
351         kernel/misc/amd64/usbs49_fw
352         kernel/misc/sparcv9/usbs49_fw
353         var/adm/aculog
354         var/adm/spellhist
355         var/adm/utmpx
356         var/adm/wtmpx
357         var/log/authlog
358         var/log/syslog
359         var/saf/zsmon/log
360 "
361 
362 
363 realmode_files="
364         boot/solaris/bootenv.rc
365         boot/solaris/devicedb/master
366 "
367 
368 local_zone_info_file=/tmp/local_zone_info.$$
369 rm -f $local_zone_info_file
370 
371 fail() {
372         print "$*" >& 2
373         print "bfu aborting" >& 2
374         rm -f $local_zone_info_file
375         prun 1
376         exit 1
377 }
378 
379 filelist() {
380         files="$all_zones_files $preserve_files"
381         if [ $1 = "global" ]; then
382                 files="$global_zone_only_files $files"
383         fi
384         find $files -depth -type f ! -name core -print 2>/dev/null | sort -u || {
385                 #
386                 # Force cpio to return non-zero by printing an error message
387                 # to stdout that it won't be able to lstat().
388                 #
389                 echo 'filelist: sort failed'
390                 fail "sort failed"
391         }
392 }
393 
394 realmode_filelist() {
395         find $realmode_files -depth -type f ! -name core -print 2>/dev/null | sort
396 }
397 
398 smf_inetd_conversions="
399         100134
400         100150
401         100155
402         100229
403         100230
404         100234
405         100242
406         100422
407         chargen
408         comsat
409         daytime
410         discard
411         echo
412         eklogin
413         exec
414         finger
415         ftp
416         gssd
417         klogin
418         krb5_prop
419         kshell
420         ktkt_warnd
421         login
422         metad
423         metamedd
424         metamhd
425         name
426         ocfserv
427         printer
428         rexd
429         rquotad
430         rstatd
431         rusersd
432         shell
433         smserverd
434         sprayd
435         sun-dr
436         talk
437         telnet
438         time
439         uucp
440         walld
441 "
442 
443 enable_next_boot () {
444         if [ -x /tmp/bfubin/svccfg ]; then
445             svcadm disable -t $1
446             [ $? = 0 ] || echo "warning: unable to temporarily disable $1"
447             svccfg -s $1 setprop general/enabled = true
448             [ $? = 0 ] || echo "warning: unable to enable $1 for next boot"
449         fi
450 }
451 
452 smf_inetd_disable() {
453         inetconf=$rootprefix/etc/inet/inetd.conf
454         inettmp=/tmp/inetd.tmp.$$
455 
456         sed "$(for i in $smf_inetd_conversions; do 
457                 echo "s:^[      ]*$i[   /]:#SMFbfu# &:"
458         done)" $inetconf > $inettmp && ! cmp -s $inettmp $inetconf &&
459             cp $inettmp $inetconf
460 
461         rm -f -- $inettmp
462 }
463 
464 smf_inetd_reenable() {
465         inetconf=$rootprefix/etc/inet/inetd.conf
466         inettmp=/tmp/inetd.tmp.$$
467 
468         sed 's/^#SMFbfu# //' $inetconf > $inettmp && cp $inettmp $inetconf
469 
470         rm -f -- $inettmp
471 }
472 
473 smf_tftp_reinstall() {
474         inetconf=$rootprefix/etc/inet/inetd.conf
475         inettmp=/tmp/inetd.tmp.$$
476 
477         if grep '^#SMFbfu# tftp' $inetconf >/dev/null ; then
478                 # BFU previously commented out, put it back in place
479                 sed 's/^#SMFbfu# tftp/tftp/' $inetconf > $inettmp &&
480                     cp $inettmp $inetconf
481         elif ! grep '^[#         ]*tftp' $inetconf >/dev/null; then
482                 # No entry, append to end
483                 cat >>$inetconf <<EOF
484 # TFTPD - tftp server (primarily used for booting)
485 #tftp   dgram   udp6    wait    root    /usr/sbin/in.tftpd      in.tftpd -s /tftpboot
486 EOF
487         fi
488 
489         rm -f -- $inettmp
490 }
491 
492 inetd_conf_svm_hack() {
493         # Since inetd.conf is updated by SUNWmdr's postinstall script,
494         # we will update the actual inetd.conf here to reflect the postinstall
495         # changes.
496 
497         inetconf=$rootprefix/etc/inet/inetd.conf
498         inettmp=/tmp/inetd.tmp.$$
499         inetnew=/tmp/inetd.new.$$
500 
501         #
502         # only change inetd.conf if the rpc.metad entry is out of date
503         #
504 
505         if ! grep "^[#  ]*100229/1-2" $inetconf > /dev/null ; then
506 
507                 # Grab existing rpc entries for rpc.metad
508                 # and convert spaces to tabs within the rpc entry, as well as
509                 # the transport method; 
510                 # or add a new entry in case there was none.
511                 if grep "^[#    ]*100229/1" $inetconf > /dev/null ; then
512                         grep "^# METAD - SLVM metadb" $inetconf > $inettmp
513                         grep "^[#       ]*100229/1" $inetconf | \
514                             sed -e 's/[         ][      ]*/     /g' \
515                                 -e 's?100229/1?100229/1-2?' >> $inettmp
516                 else
517                         echo '# METAD - SVM metadb Daemon' > $inettmp
518                         echo "100229/1-2\ttli\trpc/tcp\twait\troot\t/usr/sbin/rpc.metad\trpc.metad" >> $inettmp
519                 fi
520 
521                 grep -v '^# METAD - SLVM metadb' $inetconf | \
522                     grep -v '^[#        ]*100229/1' > $inetnew
523                 cat $inettmp >> $inetnew
524 
525                 if ! diff $inetnew $inetconf > /dev/null ; then
526                         print "Updating inet.conf metad entry ... \c"
527                         if cp $inetnew $inetconf ; then
528                                 print "done."
529                         else
530                                 print "failed."
531                         fi
532                 fi
533                 rm -f $inettmp $inetnew
534         fi
535 
536         #
537         # only change inetd.conf if the rpc.mdcommd entry is out of date
538         #
539 
540         if ! grep "^[#  ]*100422/1" $inetconf > /dev/null ; then
541 
542                 # Grab existing rpc entries for rpc.mdcommd
543                 # and convert spaces to tabs within the rpc entry,
544                 # or add a new entry in case there was none.
545                 if grep "^[#    ]*100422/1" $inetconf > /dev/null ; then
546                         grep "^# MDMN_COMMD - SVM Multi node" $inetconf > $inettmp
547                         grep "^[#       ]*100422/1" $inetconf | \
548                                 sed -e 's/[         ][      ]*/     /g' >> $inettmp 
549                 else
550                         echo '# MDMN_COMMD - SVM Multi node communication daemon' >$inettmp
551                         echo '100422/1\ttli\trpc/tcp\twait\troot\t/usr/sbin/rpc.mdcommd\trpc.mdcommd' >> $inettmp
552                 fi
553 
554                 grep -v '^# MDMN_COMMD - SVM Multi node' $inetconf | \
555                 grep -v '^[#        ]*100422/1' > $inetnew
556                 cat $inettmp >> $inetnew
557 
558                 if ! diff $inetnew $inetconf > /dev/null ; then
559                         print "Updating inetd.conf rpc.mdcommd entry ... \c"
560                         if cp $inetnew $inetconf; then
561                                 print "done."
562                         else
563                                 print "failed."
564                         fi
565                 fi
566 
567                 rm -f $inettmp $inetnew
568         fi
569 }
570 
571 update_policy_conf() {
572         # update /etc/security/policy.conf with the default
573         # Solaris crypt(3c) policy.
574         
575         dest=$rootprefix/etc/security/policy.conf
576 
577         grep 'CRYPT_' $dest > /dev/null 2>&1
578         if [ $? = 1 ] ; then
579                 print "Updating entries for crypt(3c), see policy.conf(4)"
580         cat >> $dest <<EOM
581 
582 # crypt(3c) Algorithms Configuration
583 #
584 # CRYPT_ALGORITHMS_ALLOW specifies the algorithms that are allowed to
585 # be used for new passwords.  This is enforced only in crypt_gensalt(3c).
586 #
587 CRYPT_ALGORITHMS_ALLOW=1,2a,md5
588 
589 # To deprecate use of the traditional unix algorithm, uncomment below
590 # and change CRYPT_DEFAULT= to another algorithm.  For example,
591 # CRYPT_DEFAULT=1 for BSD/Linux MD5.
592 #
593 #CRYPT_ALGORITHMS_DEPRECATE=__unix__
594 
595 # The Solaris default is the traditional UNIX algorithm.  This is not
596 # listed in crypt.conf(4) since it is internal to libc.  The reserved
597 # name __unix__ is used to refer to it.
598 #
599 CRYPT_DEFAULT=__unix__
600 EOM
601         fi
602         grep PRIV_ $dest >/dev/null 2>&1
603         if [ $? = 1 ]; then
604                 echo "Updating entries for privileges(5)," \
605                      "see policy.conf(4) for details."
606 cat >> $dest <<EOM
607 #
608 # These settings determine the default privileges users have.  If not set,
609 # the default privileges are taken from the inherited set.
610 # There are two different settings; PRIV_DEFAULT determines the default
611 # set on login; PRIV_LIMIT defines the Limit set on login.
612 # Individual users can have privileges assigned or taken away through
613 # user_attr.  Privileges can also be assigned to profiles in which case
614 # the users with those profiles can use those privileges through pfexec(1m).
615 # For maximum future compatibility, the specifications should
616 # always include "basic" or "all"; privileges should then be removed using
617 # the negation.  E.g., PRIV_LIMIT=all,!sys_linkdir takes away only the
618 # sys_linkdir privilege, regardless of future additional privileges.
619 # Similarly, PRIV_DEFAULT=basic,!file_link_any takes away only the
620 # file_link_any privilege from the basic privilege set; only that notation
621 # is immune from a future addition of currently unprivileged operations to
622 # the basic privilege set.
623 # NOTE: removing privileges from the the Limit set requires EXTREME care
624 # as any set-uid root program may suddenly fail because it lacks certain
625 # privilege(s).
626 #
627 #PRIV_DEFAULT=basic
628 #PRIV_LIMIT=all
629 EOM
630         fi
631 
632 }
633 
634 #
635 # Cleanup nfsmapid configuration before extracting
636 # root bits.  Remove if they exist:
637 #       nfsmapid entry in inetd.conf
638 #       nfsmapid entry in /etc/net/ti*/services
639 #
640 # Going forward neither should exist, but no harm if services entry exists
641 # Going way backwards (pre-04/28/2004), inetd.conf must exist but will
642 # be a conflict that should be merged in
643 #
644 nfsmapid_cfg() {
645         inetdconf=$rootprefix/etc/inet/inetd.conf
646         tmpinetcf=/tmp/inetd.conf.$$
647         cp -pf ${inetdconf} ${tmpinetcf}
648         cat /dev/null > ${inetdconf} 2>&1
649         sed -e "/^#[#    ]*NFSv4/d"             \
650             -e "/^[#     ]*100166\/1/d"         \
651             ${tmpinetcf} > ${inetdconf} 2>&1
652         rm -f ${tmpinetcf}
653 
654         tmpservices=/tmp/services.$$
655 
656         services=$rootprefix/etc/net/ticotsord/services
657         cp -pf ${services} ${tmpservices}
658         cat /dev/null > ${services} 2>&1
659         sed -e "/^[#     ]*nfsmapid/d"          \
660             ${tmpservices} > ${services} 2>&1
661         rm -f ${tmpservices}
662 
663         services=$rootprefix/etc/net/ticots/services
664         cp -pf ${services} ${tmpservices}
665         cat /dev/null > ${services} 2>&1
666         sed -e "/^[#     ]*nfsmapid/d"          \
667             ${tmpservices} > ${services} 2>&1
668         rm -f ${tmpservices}
669 
670         services=$rootprefix/etc/net/ticlts/services
671         cp -pf ${services} ${tmpservices}
672         cat /dev/null > ${services} 2>&1
673         sed -e "/^[#     ]*nfsmapid/d"          \
674             ${tmpservices} > ${services} 2>&1
675         rm -f ${tmpservices}
676 }
677 
678 # Define global variables
679 #
680 CALL_DEVID_DESTROY=""
681 #
682 # List of SDS commands that must be deleted.
683 #
684 SDSCMDLIST="
685 growfs
686 metaclear
687 metadb
688 metadetach
689 metahs
690 metainit
691 metaoffline
692 metaonline
693 metaparam
694 metarename
695 metareplace
696 metaroot
697 metaset
698 metastat
699 metasync
700 metattach
701 rpc.metad
702 rpc.metamhd
703 "
704 #
705 # List of SDS configuration files that must be deleted.
706 #
707 SDSCONFIGLIST="
708 lock
709 md.cf
710 mddb.cf
711 md.tab
712 devpath
713 md.ctlrmap
714 "
715 #
716 # List of rc scripts that must be deleted.
717 #
718 RCLIST="
719 etc/init.d/SUNWmd.init
720 etc/init.d/SUNWmd.sync
721 etc/init.d/lvm.init
722 etc/init.d/lvm.sync
723 etc/rcS.d/S35SUNWmd.init
724 etc/rcS.d/S35lvm.init
725 etc/rc2.d/S95SUNWmd.sync
726 etc/rc2.d/S95lvm.sync
727 etc/rcS.d/S35slvm.init
728 etc/rc2.d/S95slvm.sync
729 etc/init.d/slvm.init
730 etc/init.d/slvm.sync
731 etc/init.d/init.mdlogd
732 etc/rc3.d/S25mdlogd
733 "
734 #
735 # List of flashprom-related files that must be deleted.
736 #
737 FLASHPROMLIST="
738 etc/rc2.d/S75flashprom
739 etc/init.d/flashprom
740 usr/platform/SUNW,Ultra-1/lib/flash-update.sh
741 usr/platform/SUNW,Ultra-2/lib/flash-update.sh
742 usr/platform/SUNW,Ultra-4/lib/flash-update.sh
743 usr/platform/SUNW,Ultra-Enterprise/lib/flash-update.sh
744 usr/platform/sun4u/doc/flashupdate.txt
745 usr/platform/sun4u/lib/flash-update.sh
746 usr/platform/sun4u/lib/prom/SUNW,Ultra-1
747 usr/platform/sun4u/lib/prom/SUNW,Ultra-2
748 usr/platform/sun4u/lib/prom/SUNW,Ultra-4
749 usr/platform/sun4u/lib/prom/SUNW,Ultra-Enterprise
750 "
751 
752 #
753 # delete the entries associated with bootlist from /etc/system
754 #
755 
756 delete_system_bootlist() {
757         sed -e /"Begin MDD database info"/,/"End MDD database info"/d \
758             < ${SYSTEM_FILE} > /tmp/system.$$
759         cp /tmp/system.$$ ${SYSTEM_FILE} || \
760             echo "copy error: /tmp/system.$$ to ${SYSTEM_FILE}"
761 }
762 
763 #
764 # Add entries in md.conf for bootlist
765 #
766 
767 fix_mdconf() {
768         cp ${mdconf} /tmp/md.conf.$$
769         echo >> /tmp/md.conf.$$
770         echo "# Begin MDD database info (do not edit)" >> /tmp/md.conf.$$
771         sed -e 's/^set md://' -e 's/$/;/' ${SYSTEM_FILE} | \
772             grep mddb_bootlist >> /tmp/md.conf.$$
773         echo "# End MDD database info (do not edit)" >> /tmp/md.conf.$$
774         cp /tmp/md.conf.$$ ${mdconf} || \
775             echo "copy error: /tmp/md.conf.$$ to ${mdconf}"
776 }
777 
778 #
779 # add_devid_destroy(filename)
780 # returns contents in filename
781 # md_devid_destroy property is required when upgrading
782 # from pre SVM to SVM releases or when the device ID returned from
783 # the driver changes.
784 # It is specifically placed between
785 # # Begin MDD database info and # End MDD database info because
786 # on the subsequent reboot, this line will be removed automatically when
787 # metadevadm is run in rc2.d.
788 #
789 add_devid_destroy() {
790         cat $1 | awk '{
791                 if ( $2 == "End" && $4 == "database") {
792                         print "md_devid_destroy=1;"
793                 }
794                 print $0
795         }' >> /tmp/t$$
796         mv /tmp/t$$ $1
797 }
798 
799 #
800 # smf(5) "Greenline" doesn't install the init.d or rc*.d scripts for
801 # converted services.  Clean up previous scripts for such services.
802 #
803 smf_obsolete_rc_files="
804         etc/init.d/ANNOUNCE
805         etc/init.d/MOUNTFSYS
806         etc/init.d/RMTMPFILES
807         etc/init.d/audit
808         etc/init.d/autofs
809         etc/init.d/coreadm
810         etc/init.d/cron
811         etc/init.d/cryptosvc
812         etc/init.d/cvc
813         etc/init.d/devfsadm
814         etc/init.d/dhcp
815         etc/init.d/dhcpagent
816         etc/init.d/domainname
817         etc/init.d/efcode
818         etc/init.d/inetd
819         etc/init.d/inetinit
820         etc/init.d/inetsvc
821         etc/init.d/initboot
822         etc/init.d/ipfboot
823         etc/init.d/kdc
824         etc/init.d/kdc.master
825         etc/init.d/keymap
826         etc/init.d/ldap.client
827         etc/init.d/libc.mount
828         etc/init.d/network
829         etc/init.d/nfs.client
830         etc/init.d/nodename
831         etc/init.d/nscd
832         etc/init.d/perf
833         etc/init.d/pfil
834         etc/init.d/picld
835         etc/init.d/power
836         etc/init.d/rcapd
837         etc/init.d/rootusr
838         etc/init.d/rpc
839         etc/init.d/savecore
840         etc/init.d/sf880dr
841         etc/init.d/slpd
842         etc/init.d/sshd
843         etc/init.d/standardmounts
844         etc/init.d/svm.init
845         etc/init.d/svm.sync
846         etc/init.d/sysid.net
847         etc/init.d/sysid.sys
848         etc/init.d/syslog
849         etc/init.d/utmpd
850         etc/init.d/xntpd
851         etc/init.d/zones
852         etc/rc0.d/K00ANNOUNCE
853         etc/rc0.d/K01zones
854         etc/rc0.d/K03sshd
855         etc/rc0.d/K05volmgt
856         etc/rc0.d/K10rcapd
857         etc/rc0.d/K21dhcp
858         etc/rc0.d/K28kdc
859         etc/rc0.d/K28kdc.master
860         etc/rc0.d/K28nfs.server
861         etc/rc0.d/K32cryptosvc
862         etc/rc0.d/K33audit
863         etc/rc0.d/K33efcode
864         etc/rc0.d/K34svm.sync
865         etc/rc0.d/K36sendmail
866         etc/rc0.d/K36utmpd
867         etc/rc0.d/K37power
868         etc/rc0.d/K40cron
869         etc/rc0.d/K40inetd
870         etc/rc0.d/K40nscd
871         etc/rc0.d/K40sf880dr
872         etc/rc0.d/K40slpd
873         etc/rc0.d/K40syslog
874         etc/rc0.d/K40xntpd
875         etc/rc0.d/K41autofs
876         etc/rc0.d/K41ldap.client
877         etc/rc0.d/K41nfs.client
878         etc/rc0.d/K41rpc
879         etc/rc0.d/K43inet
880         etc/rc0.d/K68picld
881         etc/rc0.d/K83devfsadm
882         etc/rc0.d/K90dhcpagent
883         etc/rc1.d/K00ANNOUNCE
884         etc/rc1.d/K01zones
885         etc/rc1.d/K03sshd
886         etc/rc1.d/K05volmgt
887         etc/rc1.d/K10rcapd
888         etc/rc1.d/K21dhcp
889         etc/rc1.d/K28kdc
890         etc/rc1.d/K28kdc.master
891         etc/rc1.d/K28nfs.server
892         etc/rc1.d/K33audit
893         etc/rc1.d/K33efcode
894         etc/rc1.d/K34svm.sync
895         etc/rc1.d/K36sendmail
896         etc/rc1.d/K36utmpd
897         etc/rc1.d/K37power
898         etc/rc1.d/K40cron
899         etc/rc1.d/K40inetd
900         etc/rc1.d/K40nscd
901         etc/rc1.d/K40sf880dr
902         etc/rc1.d/K40slpd
903         etc/rc1.d/K40syslog
904         etc/rc1.d/K40xntpd
905         etc/rc1.d/K41autofs
906         etc/rc1.d/K41ldap.client
907         etc/rc1.d/K41rpc
908         etc/rc1.d/K43inet
909         etc/rc1.d/K99libc.mount
910         etc/rc1.d/S01MOUNTFSYS
911         etc/rc2.d/K01zones
912         etc/rc2.d/K03sshd
913         etc/rc2.d/K05volmgt
914         etc/rc2.d/K21dhcp
915         etc/rc2.d/K28kdc
916         etc/rc2.d/K28kdc.master
917         etc/rc2.d/K28nfs.server
918         etc/rc2.d/S01MOUNTFSYS
919         etc/rc2.d/S05RMTMPFILES
920         etc/rc2.d/S21perf
921         etc/rc2.d/S30sysid.net
922         etc/rc2.d/S65ipfboot
923         etc/rc2.d/S69domainname
924         etc/rc2.d/S69inet
925         etc/rc2.d/S71ldap.client
926         etc/rc2.d/S71rpc
927         etc/rc2.d/S71sysid.sys
928         etc/rc2.d/S72inetsvc
929         etc/rc2.d/S72slpd
930         etc/rc2.d/S73nfs.client
931         etc/rc2.d/S74autofs
932         etc/rc2.d/S74syslog
933         etc/rc2.d/S74xntpd
934         etc/rc2.d/S75cron
935         etc/rc2.d/S75savecore
936         etc/rc2.d/S76nscd
937         etc/rc2.d/S77inetd
938         etc/rc2.d/S77sf880dr
939         etc/rc2.d/S85power
940         etc/rc2.d/S88sendmail
941         etc/rc2.d/S88utmpd
942         etc/rc2.d/S95svm.sync
943         etc/rc2.d/S98efcode
944         etc/rc2.d/S98libc.mount
945         etc/rc2.d/S99audit
946         etc/rc2.d/S99rcapd
947         etc/rc3.d/S13kdc.master
948         etc/rc3.d/S14kdc
949         etc/rc3.d/S15nfs.server
950         etc/rc3.d/S34dhcp
951         etc/rc3.d/S81volmgt
952         etc/rc3.d/S89sshd
953         etc/rc3.d/S99zones
954         etc/rcS.d/K01zones
955         etc/rcS.d/K03sshd
956         etc/rcS.d/K05volmgt
957         etc/rcS.d/K10rcapd
958         etc/rcS.d/K21dhcp
959         etc/rcS.d/K28kdc
960         etc/rcS.d/K28kdc.master
961         etc/rcS.d/K28nfs.server
962         etc/rcS.d/K33audit
963         etc/rcS.d/K33efcode
964         etc/rcS.d/K34svm.sync
965         etc/rcS.d/K36sendmail
966         etc/rcS.d/K36utmpd
967         etc/rcS.d/K37power
968         etc/rcS.d/K40cron
969         etc/rcS.d/K40inetd
970         etc/rcS.d/K40nscd
971         etc/rcS.d/K40sf880dr
972         etc/rcS.d/K40slpd
973         etc/rcS.d/K40syslog
974         etc/rcS.d/K40xntpd
975         etc/rcS.d/K41autofs
976         etc/rcS.d/K41ldap.client
977         etc/rcS.d/K41rpc
978         etc/rcS.d/K43inet
979         etc/rcS.d/K99libc.mount
980         etc/rcS.d/S10cvc
981         etc/rcS.d/S10pfil
982         etc/rcS.d/S28network.sh
983         etc/rcS.d/S29nodename.sh
984         etc/rcS.d/S30rootusr.sh
985         etc/rcS.d/S33keymap.sh
986         etc/rcS.d/S35svm.init
987         etc/rcS.d/S40standardmounts.sh
988         etc/rcS.d/S42coreadm
989         etc/rcS.d/S45initboot
990         etc/rcS.d/S50devfsadm
991         etc/rcS.d/S72cryptosvc
992         etc/rcS.d/S95picld
993 "
994 
995 # Obsolete smf manifests
996 smf_obsolete_manifests="
997         var/svc/manifest/network/tftp.xml
998         var/svc/manifest/network/lp.xml
999 "
1000 
1001 # smf services whose manifests have been renamed
1002 smf_renamed_manifests="
1003         var/svc/manifest/milestone/name-service.xml
1004         var/svc/manifest/system/filesystem/boot-archive.xml
1005 "
1006 
1007 # Obsolete smf methods
1008 smf_obsolete_methods="
1009         lib/svc/method/print-server
1010 "
1011 
1012 smf_cleanup () {
1013         (
1014                 cd $root;
1015                 print "Removing obsolete rc.d scripts ... \c"
1016                 rm -f $smf_obsolete_rc_files
1017                 print "done."
1018         )
1019 }
1020 
1021 smf_new_profiles () {
1022         [[ "$bfu_isa" = "sparc" ]] || return 0
1023 
1024         [[ -x /tmp/bfubin/svccfg ]] || return 0
1025 
1026         print "Clearing platform profile hash ..."
1027 
1028         # platform_SUNW,Sun-Fire.xml (and other new and
1029         # corrected platforms) were delivered in Build 68.
1030         if [ ! -f \
1031                 $rootprefix/var/svc/profile/platform_SUNW,Sun-Fire.xml \
1032                 ]; then
1033                 for pfx in " " "v"; do
1034                         for plname in \
1035                             none \
1036                             SUNW_Sun_Fire_880 \
1037                             SUNW_Sun_Fire_V890 \
1038                             SUNW_Sun_Fire_15000 \
1039                             SUNW_UltraEnterprise_10000; do
1040                                 svccfg -f - <<EOF
1041 select smf/manifest
1042 delpg ${pfx}ar_svc_profile_platform_${plname}_xml
1043 exit
1044 EOF
1045                         done
1046                 done
1047         fi
1048 }
1049 
1050 smf_handle_new_services () {
1051         #
1052         # Detect, prior to extraction the arrival of new,
1053         # default-enabled-in-profile services.  If so, add a command
1054         # such that they are enabled.
1055         #
1056         if [ ! -f $rootprefix/var/svc/profile/system/sac.xml ]; then
1057                 echo /usr/sbin/svcadm enable system/sac >> \
1058                     $rootprefix/var/svc/profile/upgrade
1059         fi
1060         if [[ $zone = global &&
1061             ! -f $rootprefix/var/svc/manifest/system/intrd.xml ]]; then
1062                 echo /usr/sbin/svcadm enable system/intrd >> \
1063                     $rootprefix/var/svc/profile/upgrade
1064         fi
1065         if [[ $zone = global &&
1066             ! -f $rootprefix/var/svc/profile/system/filesystem/volfs.xml ]]; then
1067                 echo /usr/sbin/svcadm enable system/filesystem/volfs >> \
1068                     $rootprefix/var/svc/profile/upgrade
1069         fi
1070         if [[ $zone = global &&
1071             ! -f $rootprefix/var/svc/manifest/system/scheduler.xml ]]; then
1072                 echo /usr/sbin/svcadm enable system/scheduler >> \
1073                     $rootprefix/var/svc/profile/upgrade
1074         fi
1075 }
1076 
1077 smf_copy_manifest() {
1078         mfstbase=`basename $1`
1079         mymfs=$rootprefix/var/svc/manifest/$2/$mfstbase
1080         if [[ ! -f $mymfs ]] || ! cmp -s $manifest_src/$1 $mymfs ; then
1081                 cp $manifest_src/$1 $mymfs ||
1082                     echo "bfu: could not copy $manifest_src/$1"
1083         fi
1084 }
1085 
1086 smf_copy_method() {
1087         cp $manifest_src/$1 $rootprefix/lib/svc/method ||
1088             echo "bfu: could not copy $manifest_src/$1"
1089 }
1090 
1091 smf_cleanup_initd() {
1092         rm -f $rootprefix/etc/rc?.d/[SK]??$1
1093 }
1094 
1095 smf_delete_manifest() {
1096         (
1097                 mfst=$1
1098                 cd $root
1099                 [ -f $mfst ] || return;
1100                 if [ -r /etc/svc/volatile/repository_door ]; then
1101                         ENTITIES=`/tmp/bfubin/svccfg inventory $mfst`
1102                         for fmri in $ENTITIES; do
1103                                 /tmp/bfubin/svccfg delete -f $fmri
1104                         done
1105                 fi
1106                 rm $mfst
1107         )
1108 }
1109 
1110 smf_delete_methods() {
1111         (
1112                 cd $root;
1113                 rm -f $smf_obsolete_methods
1114         )
1115 }       
1116 
1117 smf_delete_renamed_manifests() {
1118         (
1119                 cd $root;
1120                 rm -f $smf_renamed_manifests
1121         )
1122 }
1123 
1124 smf_gldv3_manifests="
1125         var/svc/manifest/network/aggregation.xml
1126         var/svc/manifest/network/datalink.xml
1127         var/svc/manifest/network/datalink-init.xml
1128 "
1129 smf_gldv3_methods="
1130         lib/svc/method/aggregation
1131         lib/svc/method/datalink
1132         lib/svc/method/datalink-init
1133 "
1134 smf_cleanup_gldv3() {
1135         (
1136                 for f in $smf_gldv3_manifests; do
1137                         smf_delete_manifest $f
1138                 done
1139                 cd $root;
1140                 rm -f $smf_gldv3_methods
1141         )
1142 }
1143 
1144 old_mfst_dir="var/svc/manifest.orig"
1145 new_mfst_dir="var/svc/manifest"
1146 
1147 smf_enable() {
1148         echo "svcadm enable $*" >> $rootprefix/var/svc/profile/upgrade
1149 }
1150 
1151 smf_check_repository() {
1152         repository=etc/svc/repository.db
1153         [[ -f $rootprefix/$repository ]] || return
1154 
1155         print -n "$rootprefix/$repository: " >&2
1156 
1157         sqlite="${SQLITEBIN-$GATE/public/bin/$bfu_isa/sqlite}"
1158         [[ -x $sqlite ]] || sqlite=/lib/svc/bin/sqlite
1159         if [[ ! -x $sqlite ]]; then
1160                 echo "no sqlite binary: skipped integrity check" >&2
1161                 return
1162         fi
1163 
1164         rm -f /tmp/bfurepo.db;
1165         cp $rootprefix/$repository /tmp/bfurepo.db
1166         bad_errors=`echo "PRAGMA integrity_check;" |
1167             $sqlite /tmp/bfurepo.db 2>&1 | grep -v '^ok$'`
1168         if [[ $? -eq 0 ]]; then
1169                 echo "integrity check failed:" >&2
1170                 echo "$bad_errors" >&2
1171                 echo >&2
1172                 if [[ $force_override = no ]]; then
1173                         cat >&2 <<EOF
1174 Reseed the repository (see http://greenline.eng/quickstart.shtml#newrep)
1175 before BFUing (or use the -f flag to force BFU to continue).  Re-seeding
1176 will lose all smf(5) customizations.
1177 EOF
1178                         echo >&2
1179                         exit 2;
1180                 else
1181                         echo "driving on anyway" >&2
1182                 fi
1183         else
1184                 echo "passed integrity check" >&2;
1185         fi
1186 }
1187 
1188 smf_bkbfu_warning() {
1189         print ""
1190         print "*************************************************************"
1191         print " WARNING: BFU'ing $1 backwards across 5090532."
1192         print " Fixes have been made but the services cannot be refreshed"
1193         print " on the $1's inactive repository. Next boot for the"
1194         print " $1 will probably result in maintenance mode due to"
1195         print " dependency cycles. If so, at the $1's console, run:"
1196         print ""
1197         print " /usr/sbin/svcadm refresh system/sysidtool:system"
1198         print " /usr/sbin/svcadm refresh system/sysidtool:net"
1199         print " /usr/sbin/svcadm clear milestone/single-user"
1200         print " /usr/sbin/svcadm clear system/sysidtool:system"
1201         print " /usr/sbin/svcadm clear system/sysidtool:net"
1202         print ""
1203         print " to resolve."
1204         print " To avoid these problems, reseed the zone's repository."
1205         print " See http://greenline.eng/quickstart.shtml#newrep ."
1206         print " Note: Re-seeding will lose all smf(5) customization."
1207         print "*************************************************************"
1208         print ""
1209 }
1210 
1211 smf_is_sysconfig() {
1212         #
1213         # Return success if going to post-5090532, i.e. post-sysconfig bits
1214         #
1215         # By now, we're going to post-smf bits - so multi-user.xml must
1216         # exist (since it was introduced by first SMF putback).
1217         # 
1218         # Function return status is return status of last command executed.
1219         # So, no need to check return status from grep below.
1220 
1221         grep sysconfig $rootprefix/var/svc/manifest/milestone/multi-user.xml \
1222                 >/dev/null 2>&1
1223 }
1224 
1225 smf_bkbfu_past_sysconfig() {
1226         #
1227         # Check if bfu'ing back from post-5090532 to pre-5090532 bits.
1228         #
1229         if [[ -f $rootprefix/var/svc/manifest/milestone/sysconfig.xml ]] &&
1230             ! smf_is_sysconfig ; then
1231                 return 0
1232         fi
1233         return 1
1234 }
1235 
1236 smf_bkbfu_repair_sysconfig() {
1237         #
1238         # Perform the necessary corrections when bfu'ing backwards
1239         # from post-5090532 to pre-5090532 bits.
1240         #
1241         # Get the pre-5090532 non-ON manifests, and issue minimal fixes
1242         # to the repository, to enable re-boot.
1243         #
1244         smf_copy_manifest pre-5090532/sysidtool.xml system
1245         if [[ $zone = global && $karch = i86pc ]]; then
1246                 smf_copy_manifest pre-5090532/kdmconfig.xml platform/i86pc
1247         fi
1248         #
1249         # Now, remove sysidtool:{system, net}'s dependency on
1250         # single-user and filesystem-local.
1251         #
1252         # If $rootprefix is not empty, this could be the global zone,
1253         # with an alternate root BFU, or a non-global zone. For either
1254         # case, the repository to be updated is not the live one: use
1255         # SVCCFG_REPOSITORY to point to the repository to be updated.
1256         #
1257         # Note that in the alternate-root case, doing this seems better
1258         # than forcing the user to re-seed, or to dis-allow it. The
1259         # issue of svccfg and the repository not matching seems remote,
1260         # given that from initial SMF integration (on10_64) to on10_74,
1261         # there was no mismatch. In the remote possibility that there is a
1262         # mis-match (in the future) causing these calls to be suspect,
1263         # the user is already being advised, via the warning message, to
1264         # reseed the repository in case of trouble. If a mis-match is ever
1265         # introduced, code such as this would have to be fixed, so this
1266         # aspect of the warning is useful only during the interim period.
1267         #
1268         # NOTE that this is not an issue for non-global zones'
1269         # repositories - they couldn't be out-of-sync with
1270         # /tmp/bfubin/svccfg.
1271         #
1272         if [[ -n $rootprefix ]]; then
1273                 export SVCCFG_REPOSITORY=$rootprefix/etc/svc/repository.db
1274                 if [[ $zone = global ]]; then
1275                         smf_bkbfu_warning "alternate root"
1276                 else
1277                         smf_bkbfu_warning "zone"
1278                 fi
1279         fi
1280         #
1281         # Using the newer "-s" option to svccfg in the following is OK
1282         # since its introduction preceded 5090532 (and this routine wouldn't
1283         # be called unless the machine is running post-5090532 bits).
1284         #
1285         /tmp/bfubin/svccfg -s system/sysidtool:net delpg single-user
1286         /tmp/bfubin/svccfg -s system/sysidtool:system delpg single-user
1287         /tmp/bfubin/svccfg -s system/sysidtool:net delpg filesystem_local
1288         /tmp/bfubin/svccfg -s system/sysidtool:system delpg filesystem_local
1289 
1290         #
1291         # On a live system, issue the refresh; For alternate root or non-global
1292         # zone, the user was asked to issue the refreshes and "clear"s in the
1293         # message above after a post-bfu reboot.
1294         #
1295         if [[ -z $rootprefix ]]; then
1296                 /tmp/bfubin/svcadm refresh system/sysidtool:system \
1297                     system/sysidtool:net
1298         fi
1299 
1300         #
1301         # Now, reset SVCCFG_REPOSITORY, if it was set
1302         #
1303         [[ -n $rootprefix ]] && unset SVCCFG_REPOSITORY
1304 
1305         #
1306         # Remove the sysconfig.xml manifest when going back.  So backward
1307         # bfu check continues to work, and all manifests are correct.
1308         #
1309         cat >> $rootprefix/var/svc/profile/upgrade <<-EOF
1310         rm -f /var/svc/manifest/milestone/sysconfig.xml
1311         EOF
1312 }
1313 
1314 smf_apply_conf () {
1315         #
1316         # Go thru the original manifests and move any that were unchanged
1317         # (or are not system-provided) back to their proper location.  This
1318         # will avoid superfluous re-import on reboot, as the inode and mtime
1319         # are both part of the hash.
1320         #
1321         if [ -d $rootprefix/$old_mfst_dir ]; then
1322                 for f in `cd $rootprefix/$old_mfst_dir ; find . -type f`
1323                 do
1324                         old=$rootprefix/$old_mfst_dir/$f
1325                         new=$rootprefix/$new_mfst_dir/$f
1326                         if [ ! -f $new ]; then
1327                                 mkdir -m 0755 -p `dirname $new`
1328                                 mv $old $new
1329                                 continue
1330                         fi
1331                         cmp -s $old $new && mv $old $new
1332                 done
1333                 rm -rf $rootprefix/$old_mfst_dir
1334         fi
1335 
1336         if [ -f $rootprefix/etc/init.d/inetd ]; then
1337                 #
1338                 # BFUing to non-SMF system -- undo our previous changes,
1339                 # run an old hack, and skip the remainder of this function.
1340                 #
1341                 smf_inetd_reenable
1342                 smf_tftp_reinstall
1343 
1344                 # Update inetd.conf only if we find rpc.metad file.
1345                 [ -f $usr/sbin/rpc.metad ] &&
1346                     inetd_conf_svm_hack
1347 
1348                 return
1349         fi
1350 
1351         #
1352         # At this point, the archive in question is a SMF version.  If
1353         # the smf(5) repository does not yet exist, create it by copying
1354         # the appropriate seed repository.  Since updating of non-global
1355         # zones only occurs when the live system is bfu'ed, the
1356         # appropriate seed is guaranteed to exist under the /lib
1357         # directory.
1358         #
1359         repository=$rootprefix/etc/svc/repository.db
1360         if [ ! -f $repository ]; then
1361                 print "Initializing service configuration repository ..."
1362                 if [ $zone = global ]; then
1363                         cp $rootprefix/lib/svc/seed/global.db $repository
1364                 else
1365                         cp /lib/svc/seed/nonglobal.db $repository
1366                 fi
1367                 chmod 0600 $repository
1368                 chown root:sys $repository
1369         fi
1370 
1371         print "Removing obsolete smf services ..."
1372         for f in $smf_obsolete_manifests; do
1373                 smf_delete_manifest $f
1374         done
1375         smf_delete_methods
1376         smf_delete_renamed_manifests
1377         if [ $need_datalink = no ]; then
1378                 smf_cleanup_gldv3
1379         fi
1380 
1381         print "Disabling unneeded inetd.conf entries ..."
1382         smf_inetd_disable
1383         smf_tftp_reinstall
1384 
1385         print "Connecting platform and name service profiles ..."
1386 
1387         rm -f $rootprefix/var/svc/profile/name_service.xml
1388 
1389         grep ldap $rootprefix/etc/nsswitch.conf >/dev/null 2>&1
1390         is_ldap=$?
1391         grep nisplus $rootprefix/etc/nsswitch.conf >/dev/null 2>&1
1392         is_nisplus=$?
1393         grep nis $rootprefix/etc/nsswitch.conf >/dev/null 2>&1
1394         is_nis=$?
1395 
1396         if [ $is_ldap  = 0 ]; then
1397                 ns_profile=ns_ldap.xml
1398         elif [ $is_nisplus = 0  ]; then
1399                 ns_profile=ns_nisplus.xml
1400         elif [ $is_nis = 0 ]; then
1401                 ns_profile=ns_nis.xml
1402         else
1403                 ns_profile=ns_files.xml
1404         fi
1405 
1406         ln -s $ns_profile $rootprefix/var/svc/profile/name_service.xml
1407 
1408         rm -f $rootprefix/var/svc/profile/inetd_services.xml
1409         ln -s inetd_upgrade.xml $rootprefix/var/svc/profile/inetd_services.xml
1410 
1411         print "Marking converted services as enabled ..."
1412 
1413         [ -f $rootprefix/etc/resolv.conf ] && smf_enable network/dns/client
1414         [ -f $rootprefix/etc/rcap.conf ] && smf_enable system/rcap
1415         [ -f $rootprefix/etc/inet/dhcpsvc.conf ] && \
1416             smf_enable network/dhcp-server
1417 
1418         if [ $zone = global ]; then
1419                 if [ -f $rootprefix/etc/dfs/dfstab ] &&
1420                     grep '^[    ]*[^#   ]' $rootprefix/etc/dfs/dfstab \
1421                     > /dev/null; then
1422                         smf_enable network/nfs/server
1423                 fi
1424         else
1425                 echo "/usr/sbin/svcadm disable network/nfs/server" >> \
1426                     $rootprefix/var/svc/profile/upgrade
1427         fi
1428 
1429         [ -f $rootprefix/etc/inet/ntp.conf ] && smf_enable network/ntp
1430 
1431 
1432         domainname=`cat $rootprefix/etc/defaultdomain 2>/dev/null`
1433         if [ ! -z "$domainname" -a -d $rootprefix/var/yp/$domainname ]; then
1434                 smf_enable network/nis/server
1435 
1436                 # Determining whether we're a NIS master requires
1437                 # looking through the maps.
1438                 cat >>$rootprefix/var/svc/profile/upgrade <<\_EOF
1439 # Determine whether we are a YP master.
1440 domain=`/usr/bin/domainname`
1441 hostname=`uname -n | cut -d. -f1 | tr '[A-Z]' '[a-z]'`
1442 
1443 if [ -x /usr/sbin/makedbm ]; then
1444         if [ -f /var/yp/NISLDAPmapping ]; then
1445                 master=`/usr/sbin/makedbm -u /var/yp/\$domain/LDAP_passwd.byname | grep YP_MASTER_NAME | nawk '{ print $2 }'`
1446         else
1447                 master=`/usr/sbin/makedbm -u /var/yp/\$domain/passwd.byname | grep YP_MASTER_NAME | nawk '{ print $2 }'`
1448         fi
1449 fi
1450 
1451 # If we are the master server, enable appropriate services.
1452 if [ "$master" = "$hostname" -a "$YP_SERVER" = "TRUE" ]; then
1453         /usr/sbin/svcadm enable network/nis/xfr
1454         /usr/sbin/svcadm enable network/nis/passwd
1455 
1456         if [ ! -f /var/yp/NISLDAPmapping ]; then
1457                 [ -f /var/yp/updaters ] && \
1458                     /usr/svc/svcadm enable network/nis/update
1459         fi
1460 fi
1461 _EOF
1462         fi
1463 
1464         # Check if mddbs don't exist on the image.  If so, disable SVM services.
1465         MDDB_STATUS=1
1466         if [ -f $rootprefix/kernel/drv/md.conf ]; then
1467                 sed -e 's/#.*$//' $rootprefix/kernel/drv/md.conf | \
1468                     egrep '^[        ]*mddb_bootlist' >/dev/null 2>&1
1469                 MDDB_STATUS=$?
1470         fi
1471 
1472         if [ $MDDB_STATUS -ne 0 ]; then
1473                 for svc in metainit mdmonitor; do
1474                     echo "/usr/sbin/svcadm disable system/$svc:default" >> \
1475                         $rootprefix/var/svc/profile/upgrade
1476                 done
1477 
1478                 for svc in meta mdcomm metamed metamh; do
1479                     echo "/usr/sbin/svcadm disable network/rpc/$svc:default" \
1480                         >> $rootprefix/var/svc/profile/upgrade
1481                 done
1482         fi
1483 
1484         # Workaround inetd's handling of "tcp6/udp6" when no IPv6 interfaces
1485         # are configured.
1486         for svc in meta mdcomm metamed metamh; do
1487             echo "/usr/sbin/inetadm -m network/rpc/$svc:default proto=tcp" \
1488                 ">/dev/null 2>&1" >> $rootprefix/var/svc/profile/upgrade
1489         done
1490 
1491         manifest_src=${MANIFEST_SRC-$GATE/public/smf}
1492         [[ -d $manifest_src ]] ||
1493             manifest_src=/net/onnv.eng/export/gate/public/smf
1494         [[ -d $manifest_src ]] || manifest_src=/net/greenline.eng/meta0/smf
1495 
1496         if smf_bkbfu_past_sysconfig ; then
1497                 echo "BFU'ing backwards across 5090532! Now repairing..."
1498                 smf_bkbfu_repair_sysconfig
1499         fi
1500 
1501         #
1502         # If bfu'ing milestone/sysconfig bits or onwards, update the
1503         # corresponding non-ON manifests - sysidtool and kdmconfig.
1504         #
1505         sysidmfst=$rootprefix/var/svc/manifest/system/sysidtool.xml
1506         kdmmfst=$rootprefix/var/svc/manifest/platform/i86pc/kdmconfig.xml
1507         if smf_is_sysconfig ; then
1508                 if [[ ! -f $sysidmfst ]]; then
1509                         #
1510                         # if WOS build on machine is pre-greenline, and
1511                         # we're bfu'ing to the sysconfig bits.
1512                         #
1513                         smf_copy_manifest post-5090532/sysidtool.xml system
1514                         if [[ $zone = global ]]; then
1515                                 smf_copy_method sysidtool-net
1516                                 smf_copy_method sysidtool-system
1517                         fi
1518                         echo "Converted system/sysidtool (post-5090532)"
1519                 else
1520                         #
1521                         # If sysidtool.xml already exists, update it
1522                         # if necessary. Future updates of sysidtool.xml
1523                         # must occur in the dir: $manifest_src/post-5090532
1524                         #
1525                         smf_copy_manifest post-5090532/sysidtool.xml system
1526                 fi
1527                 if [[ $zone = global && $karch = i86pc ]]; then
1528                         if [[ ! -f $kdmmfst ]]; then
1529                                 #
1530                                 # if WOS build on machine is pre-greenline, and
1531                                 # we're bfu'ing to the sysconfig bits.
1532                                 #
1533                                 smf_copy_manifest post-5090532/kdmconfig.xml \
1534                                     platform/i86pc
1535                                 smf_copy_method   svc-kdmconfig
1536                                 smf_cleanup_initd kdmconfig
1537                                 echo "Converted platform/i86pc/kdmconfig"
1538                                 echo "(post-5090532)"
1539                         else
1540                                 #
1541                                 # If kdmconfig.xml already exists, update
1542                                 # it if necessary. Future updates of
1543                                 # kdmconfig.xml must occur in the dir:
1544                                 # $manifest_src/post-5090532
1545                                 #
1546                                 smf_copy_manifest post-5090532/kdmconfig.xml \
1547                                     platform/i86pc
1548                         fi
1549                 fi
1550         else
1551                 if [[ ! -f $sysidmfst ]]; then
1552                         smf_copy_manifest pre-5090532/sysidtool.xml system
1553                         if [[ $zone = global ]]; then
1554                                 smf_copy_method sysidtool-net
1555                                 smf_copy_method sysidtool-system
1556                         fi
1557                         echo "Converted system/sysidtool"
1558                 fi
1559                 if [[ $zone = global && $karch = i86pc && ! -f $kdmmfst ]];
1560                 then
1561                         smf_copy_manifest pre-5090532/kdmconfig.xml \
1562                             platform/i86pc
1563                         smf_copy_method   svc-kdmconfig
1564                         smf_cleanup_initd kdmconfig
1565                         echo "Converted platform/i86pc/kdmconfig"
1566                 fi
1567         fi
1568 
1569         # If we've still got the old dtlogin manifest delivered by earlier
1570         # versions of bfu, delete it, as it was broken and should have
1571         # never been delivered.  A new version delivered by the CDE
1572         # consolidation should be left alone.
1573         if [[ -f $rootprefix/var/svc/manifest/application/dtlogin.xml &&
1574             `grep -c GLXXX \
1575             $rootprefix/var/svc/manifest/application/dtlogin.xml` -gt 0 &&
1576             -x /tmp/bfubin/svccfg ]]; then
1577 
1578                 # Delete the obsolete manifest.
1579                 rm -f $rootprefix/var/svc/manifest/application/dtlogin.xml
1580 
1581                 # Delete the service from repository, then use dtconfig -e to
1582                 # revert to whatever the WOS bits are using if dtlogin was
1583                 # enabled.
1584                 cat >> $rootprefix/var/svc/profile/upgrade <<-EOFA
1585 if /usr/bin/svcprop -q application/cde-login; then
1586         if [ \`/usr/bin/svcprop -p general/enabled \
1587                 application/cde-login:default\` = "true" ]; then
1588                 do_dtconfig=1;
1589         else
1590                 do_dtconfig=0;
1591         fi
1592 
1593         /usr/sbin/svccfg delete -f application/cde-login
1594         type instance_refresh 2>&1 > /dev/null
1595         if [ \$? = 0 ]; then
1596                 instance_refresh system/console-login
1597         else
1598                 /usr/sbin/svcadm refresh system/console-login
1599         fi
1600 
1601         if [ \$do_dtconfig -eq 1 -a -x /usr/dt/bin/dtconfig ]; then
1602                 /usr/dt/bin/dtconfig -e
1603         fi
1604 fi
1605 EOFA
1606         fi
1607 
1608 
1609         # Enable the inetd-upgrade service to convert any changes to inetd.conf
1610         smf_enable network/inetd-upgrade
1611 
1612         # If global zone, and bfu'ing from smf, and the inetd-upgrade
1613         # service has an obsolete dependency, then add a clear of inetd
1614         # and inetd-upgrade to the upgrade file as either may drop into
1615         # maintenance due to a dependency loop resulting from the new
1616         # inetd manifest
1617         if [[ $zone = global && -x /tmp/bfubin/svccfg ]]; then
1618                 /tmp/bfubin/svcprop -q -p network/entities network/inetd-upgrade
1619                 if [[ $? = 0 ]]; then
1620                         echo "/usr/sbin/svcadm clear network/inetd" >> \
1621                             $rootprefix/var/svc/profile/upgrade
1622                         echo "/usr/sbin/svcadm clear network/inetd-upgrade" >> \
1623                             $rootprefix/var/svc/profile/upgrade
1624                 fi
1625         fi
1626 
1627         # If we're in the global zone, and using an alternate root, see if
1628         # we are in an smf root.  If so, import pfil and name-service-cache.
1629         # If we're not bfu'ing an alternate root, and we're post-smf,
1630         # import pfil and name-service-cache.  This is to get pfil and
1631         # name-service-cache(with correct dependencies) in the repository
1632         # before reboot.  If we're bfu'ing from pre-smf, this isn't an
1633         # issue, as pfil is in the seed repository, and name-service-cache
1634         # will be installed with correct dependencies.
1635         if [[ $zone = global &&
1636             -f $rootprefix/var/svc/manifest/network/pfil.xml ]]; then
1637                 if [[ -n $rootprefix ]]; then
1638                         if [ -x /usr/sbin/svccfg ]; then
1639                         SVCCFG_REPOSITORY=$rootprefix/etc/svc/repository.db
1640                         /usr/sbin/svccfg import \
1641                             $rootprefix/var/svc/manifest/network/pfil.xml
1642                         /usr/sbin/svccfg import \
1643                     $rootprefix/var/svc/manifest/system/name-service-cache.xml
1644                         else
1645                         echo "Warning: This system does not have SMF, so I"
1646                         echo "cannot ensure the pre-import of pfil and"
1647                         echo "name-service-cache.  If ipfilter or name-service-"
1648                         echo "cache do not work, reboot your alternate root to"
1649                         echo "fix it."
1650                         fi
1651                 elif [ -x /tmp/bfubin/svccfg ]; then
1652                         /tmp/bfubin/svccfg import \
1653                             /var/svc/manifest/network/pfil.xml
1654                         /tmp/bfubin/svccfg import \
1655                             /var/svc/manifest/system/name-service-cache.xml
1656                 fi
1657         fi
1658 
1659         # Remove pfil from the non-global repository.
1660         if [[ $zone != global ]]; then
1661                 cat >> $rootprefix/var/svc/profile/upgrade << EOF
1662                 svcprop -q -p start/exec network/pfil
1663                 if [[ \$? = 0 ]]; then
1664                         /usr/sbin/svccfg delete -f network/pfil
1665                 fi
1666 EOF
1667         fi
1668 
1669         # If we're in the global zone, and using an alternate root, see if
1670         # we are in an smf root.  If so, import datalink and aggregation svcs.
1671         # If we're not bfu'ing an alternate root, and we're post-smf,
1672         # import datalink and aggregation.  This is to get them 
1673         # in the repository before reboot.  If we're bfu'ing from pre-smf,
1674         # this isn't an issue, as they are in the seed repository.
1675         if [[ $zone = global &&
1676             -f $rootprefix/var/svc/manifest/network/datalink.xml ]]; then
1677                 if [[ -n $rootprefix ]]; then
1678                         if [ -x /usr/sbin/svccfg ]; then
1679                         SVCCFG_REPOSITORY=$rootprefix/etc/svc/repository.db
1680                         sed -e "s/enabled='true'/enabled='false'/" \
1681                          $rootprefix/var/svc/manifest/network/aggregation.xml \
1682                             | svccfg import -
1683                         sed -e "s/enabled='true'/enabled='false'/" \
1684                             $rootprefix/var/svc/manifest/network/datalink.xml \
1685                             | svccfg import -
1686                         sed -e "s/enabled='true'/enabled='false'/" \
1687                        $rootprefix/var/svc/manifest/network/datalink-init.xml \
1688                             | svccfg import -
1689                         else
1690                         echo "Warning: This system does not have SMF, so I"
1691                         echo "cannot ensure the pre-import of datalink and"
1692                         echo "network aggregation.  If they do not work"
1693                         echo "reboot your alternate root to fix it."
1694                         fi
1695                 elif [ -x /tmp/bfubin/svccfg ]; then
1696                         sed -e "s/enabled='true'/enabled='false'/" \
1697                             /var/svc/manifest/network/aggregation.xml | \
1698                             svccfg import -
1699                         sed -e "s/enabled='true'/enabled='false'/" \
1700                             /var/svc/manifest/network/datalink.xml | \
1701                             svccfg import -
1702                         sed -e "s/enabled='true'/enabled='false'/" \
1703                             /var/svc/manifest/network/datalink-init.xml | \
1704                             svccfg import -
1705                 fi
1706 
1707                 #
1708                 # Make sure the services are enabled after reboot.
1709                 #
1710                 enable_next_boot svc:/network/aggregation:default
1711                 enable_next_boot svc:/network/datalink:default
1712                 enable_next_boot svc:/network/datalink-init:default
1713         fi
1714 
1715         # Enable new NFS status and nlockmgr services if client is enabled
1716         cat >> $rootprefix/var/svc/profile/upgrade <<-EOF
1717             cl="svc:/network/nfs/client:default"
1718             if [ \`/usr/bin/svcprop -p general/enabled \$cl\` = "true" ]; then
1719                 /usr/sbin/svcadm enable svc:/network/nfs/status:default
1720                 /usr/sbin/svcadm enable svc:/network/nfs/nlockmgr:default
1721             fi
1722 
1723 EOF
1724 
1725         kpmani="$rootprefix/var/svc/manifest/network/security/krb5_prop.xml"
1726         if grep svc-kdc.slave $kpmani > /dev/null 2>&1; then
1727                 cat >> $rootprefix/var/svc/profile/upgrade <<EOF
1728                 # We are deleting and reimporting kpropd's manifest, because we
1729                 # need to change the restarter.
1730                 kpfmri="svc:/network/security/krb5_prop"
1731                 kkfmri="svc:/network/security/krb5kdc:default"
1732                 lkpmani="/var/svc/manifest/network/security/krb5_prop.xml"
1733                 restarter=\`svcprop -c -p general/restarter \$kpfmri 2>&1\`
1734                 case \$restarter in
1735                         *network/inetd:default)
1736                                 kken=\`svcprop -c -p general/enabled \$kkfmri\`
1737                                 svccfg delete -f \$kpfmri
1738                                 svccfg import \$lkpmani 
1739                                 # Enable kpropd if krb5kdc is enabled, since
1740                                 # krb5kdc would have run kpropd
1741                                 if [ \$kken = "true" ]; then
1742                                         svcadm enable \$kpfmri
1743                                 fi
1744                                 ;;
1745                 esac
1746 EOF
1747         fi
1748 
1749         # Enable print server if there are local queues
1750         queues=`echo $rootprefix/etc/lp/printers/*/configuration`
1751         if [ "$queues" != "$rootprefix/etc/lp/printers/*/configuration" ]; then
1752                 smf_enable application/print/server
1753         fi
1754 
1755         # Enable rarpd and bootparamd if they would have been running pre-SMF
1756         if [ -d $rootprefix/tftpboot ] || [ -d $rootprefix/rplboot ]; then
1757                 smf_enable network/rarp
1758                 smf_enable network/rpc/bootparams
1759         fi
1760 
1761         # To handle the transition from pre-smf ipfilter to smf-aware ipfilter,
1762         # check if ipfilter had been enabled with at least one rule, and if so
1763         # enable the smf instance.
1764         if grep '^[ \t]*[^# \t]' $rootprefix/etc/ipf/ipf.conf >/dev/null 2>&1 &&
1765             [[ $zone = global ]]; then
1766                 smf_enable network/ipfilter
1767         fi
1768 
1769         touch $rootprefix/var/svc/profile/.upgrade_prophist
1770 
1771         cat >> $rootprefix/var/svc/profile/upgrade <<EOF
1772         # We are deleting and reimporting dcs's manifest, because we
1773         # need to change the restarter.
1774         dcsfmri="svc:/platform/sun4u/dcs:default"
1775         dcsmani="/var/svc/manifest/platform/sun4u/dcs.xml"
1776         restarter=\`svcprop -c -p general/restarter \$dcsfmri 2>&1\`
1777         case \$restarter in
1778                 *network/inetd:default)
1779                         en=\`svcprop -c -p general/enabled \$dcsfmri\`
1780                         svccfg delete -f \$dcsfmri
1781                         svccfg import \$dcsmani
1782                         if [ \$en = "true" ]; then
1783                                 svcadm enable \$dcsfmri
1784                         fi
1785                         ;;
1786         esac
1787 EOF
1788 
1789 }
1790 
1791 EXTRACT_LOG=/tmp/bfu-extract-log.$$
1792 
1793 rm -f $EXTRACT_LOG
1794 
1795 extraction_error() {
1796         echo error $* >> $EXTRACT_LOG
1797 }
1798 
1799 #
1800 # Make a local copy of bfu in /tmp and execute that instead.
1801 # This makes us immune to loss of networking and/or changes
1802 # to the original copy that might occur during execution.
1803 #
1804 cd .
1805 abspath=`[[ $0 = /* ]] && print $0 || print $PWD/$0`
1806 if [[ $abspath != /tmp/* ]]; then
1807         localpath=/tmp/bfu.$$
1808         print "Copying $abspath to $localpath"
1809         cp $abspath $localpath
1810         chmod +x $localpath
1811         print "Executing $localpath $*\n"
1812         exec $localpath $*
1813 fi
1814 
1815 export PATH=/usr/bin:/usr/sbin:/sbin
1816 
1817 usage() {
1818         echo "Usage:"
1819         echo "    bfu    [-fh] <archive_dir> [root-dir]"
1820         echo "\tUpdate a single machine by loading archives on root-dir."
1821         echo "\troot-dir defaults to / (a live bfu).\n"
1822         echo "    bfu -c [-fh] <archive_dir> <exec-dir>"
1823         echo "\tUpdate all diskless clients by loading archives on each client"
1824         echo "\tthat mounts exec-dir as /usr.  <exec-dir> must start with"
1825         echo "\t/export/exec and each client's root must be in /export/root.\n"
1826         echo "\t-f        force bfu to continue even if it doesn't seem safe"
1827         fail "\t-h|-help  print this usage message and exit\n"
1828 }
1829 
1830 diskless=no
1831 force_override=no
1832 while [ $# -gt 0 ]; do
1833         case $1 in
1834                 -c)             diskless=yes;;
1835                 -f)             force_override=yes;;
1836                 -h|-help)       usage;;
1837                 *)              break;;
1838         esac
1839         shift
1840 done
1841 
1842 boot_is_pcfs=no
1843 have_realmode=no
1844 multiboot_archives=no
1845 dca_to_multi=no
1846 is_pcfs_boot=no
1847 need_datalink=no
1848 
1849 test $# -ge 1 || usage
1850 
1851 if [ -x /usr/bin/ppriv ]; then
1852         # We prefer to use ppriv, as it is a more accurate test, and also
1853         # has the benefit of preventing use from within a local zone.
1854         ppriv $$ | grep -w "E: all" > /dev/null 2>&1 || \
1855             fail "bfu requires all privileges"
1856 else
1857         # Fall back to old id check if system does not yet have ppriv.
1858         uid=`id | nawk '{print $1}'`
1859         [ "$uid" = "uid=0(root)" ] || \
1860             fail "You must be super-user to run this script."
1861 fi
1862 
1863 bfu_isa=`uname -p`
1864 target_isa=$bfu_isa
1865 karch=`uname -m`
1866 plat=`uname -i`
1867 
1868 cpiodir=$1
1869 
1870 local_zone_info_file=/tmp/local_zone_info.$$
1871 
1872 if [ "$cpiodir" = again ]; then
1873         cpiodir=`nawk '/^bfu.ed from / { print $3; exit }' /etc/motd`
1874 fi
1875 
1876 [[ "$cpiodir" = */* ]] || cpiodir=$ARCHIVE/archives/$target_isa/$1
1877 
1878 [[ "$cpiodir" = /* ]] || fail "archive-dir must be an absolute path"
1879 
1880 cd $cpiodir
1881 case `echo generic.root*` in
1882         generic.root)           ZFIX="";        ZCAT="cat";;
1883         generic.root.gz)        ZFIX=".gz";     ZCAT="gzip -d -c";;
1884         generic.root.Z)         ZFIX=".Z";      ZCAT="zcat";;
1885         *) fail "generic.root missing or in unknown compression format";;
1886 esac
1887 
1888 if [ $diskless = no ]; then
1889         root=${2:-/}
1890         [[ "$root" = /* ]] || fail "root-dir must be an absolute path"
1891         usrroot=$root
1892         usr=${usrroot%/}/usr
1893         rootlist=$root
1894 
1895         [[ -f $root/etc/system ]] || \
1896             fail "$root/etc/system not found; local zone target not allowed"
1897 
1898         # Make sure we extract the sun4u-us3 libc_psr.so.1
1899         if [ -d $root/platform/sun4u -a \
1900            ! -d $root/platform/sun4u-us3 ]
1901         then
1902                 mkdir $root/platform/sun4u-us3
1903                 chmod 755 $root/platform/sun4u-us3
1904                 chown root $root/platform/sun4u-us3
1905                 chgrp sys $root/platform/sun4u-us3
1906         fi
1907 
1908         if [ $karch != $plat -a -f ${cpiodir}/${plat}.usr$ZFIX ]; then
1909                 usrarchs="$karch $plat"
1910         else
1911                 usrarchs="$karch"
1912         fi
1913         if [ $karch != $plat -a -f ${cpiodir}/${plat}.root$ZFIX ]; then
1914                 rootarchs="$karch $plat"
1915         else
1916                 rootarchs="$karch"
1917         fi
1918 
1919         if [ -h ${root}/platform/${plat} ]; then
1920                 rm -f ${root}/platform/${plat}
1921         fi
1922         if [ -h ${usr}/platform/${plat} ]; then
1923                 rm -f ${usr}/platform/${plat}
1924         fi
1925 
1926         if [ $plat != $karch -a -f ${cpiodir}/${plat}.root$ZFIX \
1927             -a -f ${cpiodir}/${plat}.usr$ZFIX ]
1928         then
1929                 cd $cpiodir
1930                 #
1931                 #  Look through all the archives we build and match
1932                 #  the names of built archives with the names of
1933                 #  directories installed on this machine.  We assume
1934                 #  here that we can get the names of all architectures
1935                 #  by pattern matching the names of .root archives - so
1936                 #  if we ever had a case where we had only a .usr archive
1937                 #  we wouldn't find that archive.
1938                 #
1939                 for i in *.root*
1940                 do
1941                         platname=${i%.root*}
1942                         if [ -z "${platname}" -o ${platname} = $karch -o \
1943                             $platname = generic -o ${platname} = $plat ]; then
1944                                 continue;
1945                         fi
1946                         if [ -d ${root}/platform/${platname} -o \
1947                             -h ${root}/platform/${platname} ]; then
1948                                 rootarchs="${rootarchs} ${platname}"
1949                         fi
1950                         if [ -d ${usr}/platform/${platname} -o \
1951                             -h ${usr}/platform/${platname} ]; then
1952                                 usrarchs="${usrarchs} ${platname}"
1953                         fi
1954                         if [ -h ${root}/platform/${platname} ]; then
1955                                 rm -f ${root}/platform/${platname}
1956                         fi
1957                         if [ -h ${usr}/platform/${platname} ]; then
1958                                 rm -f ${usr}/platform/${platname}
1959                         fi
1960                 done
1961         fi
1962         rootslice=`df -k $root | nawk 'NR > 1 { print $1 }' | sed s/dsk/rdsk/`
1963         print "Loading $cpiodir on $root"
1964 else
1965         usrroot=$2
1966         usr=$2/usr
1967         [[ "$usr" = /export/exec/* ]] || fail "exec-dir $usrroot sounds bogus"
1968         case $2 in
1969             *sparc*)
1970                 target_isa=sparc ;;
1971             *i386*)
1972                 target_isa=i386 ;;
1973         esac
1974         cd $cpiodir
1975         test -f generic.root$ZFIX || fail "$cpiodir/generic.root$ZFIX missing"
1976         allarchs=$(echo $(ls *.root$ZFIX | grep -v generic.root$ZFIX | \
1977                 sed -e 's/.root.*//'))
1978         # XXX Pick karch as last available root arch
1979         karch=${allarchs##* }
1980         # XXX Pick plat as first available root arch
1981         plat=${allarchs%% *}
1982         rootlist=""
1983         for root in /export/root/*
1984         do
1985                 test -f $root/etc/vfstab &&
1986                         egrep -s $usrroot $root/etc/vfstab &&
1987                         rootlist="$rootlist $root"
1988         done
1989         test -n "$rootlist" || fail "no clients to upgrade"
1990         print "Loading $cpiodir usr archives on:\n\t$usr\n"
1991         print "Loading $cpiodir root archives on:"
1992         for root in $rootlist
1993         do
1994                 print "\t$root"
1995         done
1996 fi
1997 
1998 nss_lib="$usr/lib/mps/libnss3.so"
1999 nss_lib64="$usr/lib/mps/64/libnss3.so"
2000 valid_rpath="\$ORIGIN:/usr/lib/mps/secv1:/usr/lib/mps"
2001 rpath_msg="(RPATH from file ${nss_lib})"
2002 if [ ! -x /usr/bin/ldd ]; then
2003         if [ "$force_override" = yes ]; then
2004                 echo "/usr/bin/ldd is missing but -f is set; continuing."
2005         else
2006                 echo "/usr/bin/ldd is missing."
2007                 fail "Install the SUNWtoo package."
2008         fi
2009 fi
2010 nss_rpath=`ldd -s $nss_lib | grep "$rpath_msg" | head -1 | cut -d'=' -f2 | \
2011                 awk '{print $1}'`
2012 update_script="/ws/onnv-gate/public/bin/update_nsspkgs"
2013 if [ $valid_rpath != "$nss_rpath" ]; then
2014         if [ "$force_override" = yes ]; then
2015                 echo "$nss_lib is not valid but -f is set; continuing."
2016         else
2017                 echo "$nss_lib is not valid."
2018                 fail "Run $update_script to update the SUNWtls package."
2019         fi
2020 fi
2021 if [ $target_isa = i386 -a ! -f $nss_lib64 ]; then
2022         echo "$nss_lib64 does not exist."
2023         fail "Run $update_script to update the NSS packages."
2024 fi
2025 
2026 update_script="/ws/onnv-gate/public/bin/migrate_bind9"
2027 if [[ ! -f $usr/lib/dns/libdns.so ]] && ! $ZCAT $cpiodir/generic.usr$ZFIX | \
2028             cpio -it 2>/dev/null |  egrep -s '^usr/sbin/ndc' ; then
2029         if [ "$force_override" = yes ]; then
2030                 echo "BIND 9 has not been installed, but -f is set; continuing."
2031         else
2032                 echo "BIND 8 has been removed from ON; BIND 9 is available from SFW."
2033                 fail "Run $update_script to migrate to BIND 9."
2034         fi
2035 fi
2036 
2037 update_script="/ws/onnv-gate/public/bin/update_ce"
2038 if ifconfig -a | egrep '^ce' >/dev/null 2>/dev/null; then
2039         # CE version 1.148 or later is required
2040         cever=`modinfo | grep 'CE Ethernet' | sed 's/.*v1\.//' | tr -d ')' | \
2041             nawk '{ if ($1 < 148) print "BAD"; else print $1 }'`
2042         if [ "$cever" = "BAD" ]; then
2043                 fail "You must run $update_script to upgrade your ce driver."
2044         fi
2045 fi
2046 
2047 if [[ $target_isa = i386 && -f $cpiodir/i86pc.root$ZFIX ]] && \
2048     $ZCAT $cpiodir/i86pc.root$ZFIX | cpio -it 2>/dev/null | \
2049     grep multiboot >/dev/null 2>&1 ; then
2050         multiboot_archives=yes
2051         prtconf -v | grep biosdev >/dev/null 2>&1
2052         if [ $? -ne 0 ]; then
2053                 echo "biosdev cannot be run on this machine."
2054                 echo "Transitioning from classic to multiboot requires a"
2055                 echo "bootconf which is compatible with biosdev."
2056                 echo "bfu to onnv_12 first, then to a build with multiboot."
2057                 fail ""
2058         fi
2059 fi
2060 
2061 if $ZCAT $cpiodir/generic.root$ZFIX | cpio -it 2>/dev/null | \
2062     grep datalink.conf > /dev/null 2>&1 ; then
2063         need_datalink=yes
2064 fi
2065 
2066 time_ref=/tmp/bfu.time_ref.$$
2067 rm -f $time_ref
2068 touch $time_ref || fail "$time_ref: Unable to create time reference."
2069 time_ref_seconds=$SECONDS
2070 
2071 print "\nCreating bfu execution environment ..."
2072 
2073 #
2074 # Save off a few critical libraries and commands, so that bfu will
2075 # continue to function properly even in the face of major
2076 # kernel/library/command incompatibilities during a live upgrade.
2077 #
2078 bfucmd="
2079         /usr/sbin/add_drv
2080         /usr/bin/awk
2081         /usr/bin/cat
2082         /usr/bin/chgrp
2083         /usr/bin/chmod
2084         /usr/bin/chown
2085         /usr/bin/cmp
2086         /usr/bin/cp
2087         /usr/bin/cpio
2088         /usr/bin/csh
2089         /usr/bin/cut
2090         /usr/bin/date
2091         /usr/bin/dd
2092         /usr/bin/df
2093         /usr/bin/diff
2094         /usr/bin/du
2095         /usr/bin/echo
2096         /usr/bin/ed
2097         /usr/bin/egrep
2098         /usr/bin/env
2099         /usr/bin/ex
2100         /usr/bin/expr
2101         /usr/bin/false
2102         /usr/bin/fgrep
2103         /usr/bin/file
2104         /usr/bin/find
2105         /usr/bin/gettext
2106         /usr/bin/grep
2107         /usr/bin/head
2108         /usr/bin/id
2109         /usr/bin/ksh
2110         /usr/bin/line
2111         /usr/bin/ln
2112         /usr/sbin/lofiadm
2113         /usr/bin/ls
2114         /usr/bin/mkdir
2115         /usr/sbin/mkfile
2116         /usr/sbin/mkfs
2117         /usr/sbin/mknod
2118         /usr/bin/mktemp
2119         /usr/bin/more
2120         /usr/sbin/mount
2121         /usr/bin/mv
2122         /usr/bin/nawk
2123         /usr/bin/pgrep
2124         /usr/sbin/newfs
2125         /usr/bin/pkginfo
2126         /usr/bin/pkill
2127         /usr/bin/printf
2128         /usr/sbin/prtconf
2129         /usr/bin/prun
2130         /usr/bin/ps
2131         /usr/bin/pstop
2132         /usr/bin/ptree
2133         /usr/bin/rm
2134         /usr/bin/rmdir
2135         /usr/bin/sed
2136         /usr/bin/sh
2137         /usr/bin/sleep
2138         /usr/bin/sort
2139         /usr/bin/strings
2140         /usr/bin/stty
2141         /usr/bin/su
2142         /usr/bin/sum
2143         /usr/bin/tail
2144         /usr/bin/tee
2145         /usr/bin/touch
2146         /usr/bin/tr
2147         /usr/bin/true
2148         /usr/bin/truss
2149         /usr/bin/tty
2150         /usr/sbin/uadmin
2151         /usr/sbin/umount
2152         /usr/bin/uname
2153         /usr/bin/uniq
2154         /usr/bin/uptime
2155         /usr/bin/vi
2156         /usr/bin/w
2157         /usr/bin/wc
2158         /usr/bin/xargs
2159         /usr/bin/zcat
2160         /usr/sbin/chroot
2161         /usr/sbin/halt
2162         /usr/sbin/lockfs
2163         /usr/sbin/mknod
2164         /usr/sbin/pkgrm
2165         /usr/sbin/reboot
2166         /usr/sbin/sync
2167         /usr/sbin/tar
2168         /usr/sbin/uadmin
2169         /usr/sbin/wall
2170         ${FASTFS-$GATE/public/bin/$bfu_isa/fastfs}
2171         ${GZIPBIN-$GATE/public/bin/$bfu_isa/gzip}
2172 "
2173 
2174 #
2175 # Scripts needed by BFU. These must be modified to use the interpreters in
2176 # /tmp/bfubin. The interpreters in /usr/bin may not be compatible with the
2177 # libraries in the archives being extracted.
2178 #
2179 bfuscr="
2180         ${ACR-${GATE}/public/bin/acr}
2181 "
2182 
2183 #
2184 # basename and dirname may be ELF executables, not shell scripts;
2185 # make sure they go into the right list.
2186 #
2187 if `file /usr/bin/basename | grep ELF >/dev/null`
2188 then    bfucmd="$bfucmd /usr/bin/basename"
2189 else    bfuscr="$bfuscr /usr/bin/basename"
2190 fi
2191 
2192 if `file /usr/bin/dirname | grep ELF >/dev/null`
2193 then    bfucmd="$bfucmd /usr/bin/dirname"
2194 else    bfuscr="$bfuscr /usr/bin/dirname"
2195 fi
2196 
2197 rm -rf /tmp/bfubin
2198 mkdir /tmp/bfubin
2199 set $bfucmd
2200 isalist=`isalist`
2201 while [ $# -gt 0 ]
2202 do
2203         dir=${1%/*}
2204         cmd=${1##*/}
2205         cd $dir
2206         isacmd=`(find $isalist -name $cmd 2>/dev/null; echo $cmd) | head -1`
2207         cp $dir/$isacmd /tmp/bfubin || fail "cannot copy $dir/$isacmd"
2208         shift
2209 done
2210 
2211 #
2212 # Optional commands.  We warn, but do not abort, if we are crossing a
2213 # feature boundary (where a command is not present in the parent).
2214 # Clauses requiring these commands must explicitly test for their
2215 # presence in /tmp/bfubin.
2216 #
2217 bfuoptcmd="
2218         /sbin/biosdev
2219         /sbin/bootadm
2220         /sbin/installgrub
2221         /usr/sbin/fdisk
2222         /usr/sbin/metastat
2223         /usr/bin/mkisofs
2224         /usr/sbin/svcadm
2225         /usr/sbin/svccfg
2226         /usr/bin/svcprop
2227 "
2228 
2229 set $bfuoptcmd
2230 isalist=`isalist`
2231 while [ $# -gt 0 ]
2232 do
2233         dir=${1%/*}
2234         cmd=${1##*/}
2235         cd $dir
2236         isacmd=`(find $isalist -name $cmd 2>/dev/null; echo $cmd) | head -1`
2237         cp $dir/$isacmd /tmp/bfubin 2>/dev/null
2238         shift
2239 done
2240 
2241 #
2242 # set up installgrub and friends if transitioning to multiboot
2243 # do this now so ldd can determine library dependencies
2244 #
2245 MULTIBOOT_BIN_DIR=${MULTIBOOT_BIN_DIR:=${GATE}/public/multiboot}
2246 
2247 multiboot_cmds="
2248         /sbin/biosdev
2249         /sbin/installgrub
2250         /sbin/bootadm
2251 "
2252 copying_mboot_cmds=no
2253 if [ $multiboot_archives = yes ]; then
2254         for cmd in $multiboot_cmds
2255         do
2256                 if [ -f $cmd ]; then
2257                         cp $cmd /tmp/bfubin
2258                 else
2259                         file=`basename $cmd`
2260                         if [ ! -d $MULTIBOOT_BIN_DIR ]; then
2261                                 echo "$MULTIBOOT_BIN_DIR: not found"
2262                         elif [ ! -f $MULTIBOOT_BIN_DIR/$file ]; then
2263                                 echo "$MULTIBOOT_BIN_DIR/$file: not found"
2264                         fi
2265                         if [ $copying_mboot_cmds = no ]; then
2266                                 echo "installing files from $MULTIBOOT_BIN_DIR"
2267                                 copying_mboot_cmds=yes
2268                         fi
2269                         cp $MULTIBOOT_BIN_DIR/$file /tmp/bfubin
2270                 fi
2271 
2272         done
2273 fi
2274 
2275 #
2276 # If available, use ldd to determine which libraries bfu depends on.
2277 # Otherwise, just make an educated guess.
2278 #
2279 if [ -x /usr/bin/ldd ]; then
2280         bfulib="`ldd /tmp/bfubin/* | nawk '$3 ~ /lib/ { print $3 }' | sort -u`"
2281 else
2282         bfulib="
2283                 /lib/libc.so.1
2284                 /lib/libm.so.2
2285                 /lib/libdoor.so.1
2286                 /lib/libm.so.2
2287                 /lib/libmd5.so.1
2288                 /lib/libnvpair.so.1
2289                 /lib/libscf.so.1
2290                 /lib/libuutil.so.1
2291                 /usr/lib/libbsm.so.1
2292                 /usr/lib/libc2.so
2293                 /usr/lib/libdl.so.1
2294                 /usr/lib/libelf.so.1
2295                 /usr/lib/libkstat.so.1
2296                 /usr/lib/libmapmalloc.so.1
2297                 /usr/lib/libmp.so.1
2298                 /usr/lib/libnsl.so.1
2299                 /usr/lib/libpam.so.1
2300                 /usr/lib/libsec.so.1
2301                 /usr/lib/libsocket.so.1
2302                 /usr/lib/libtecla.so.1
2303         "
2304 fi
2305 
2306 # add dlopen()'ed stuff
2307 bfulib="
2308         $bfulib
2309         /lib/ld.so.1
2310         /usr/lib/nss_*
2311 "
2312 
2313 # add libc_psr.so.1, if available and not empty
2314 if [ -s /platform/`uname -i`/lib/libc_psr.so.1 ]; then
2315         bfulib="
2316                 $bfulib
2317                 /platform/`uname -i`/lib/libc_psr.so.1
2318         "
2319 fi
2320 
2321 rm -rf /tmp/bfulib /tmp/bl
2322 mkdir /tmp/bfulib /tmp/bl
2323 
2324 #
2325 # Create 64 bit directory structure and determine 64 bit arch name.
2326 #
2327 if [ -h /usr/lib/64 ]
2328 then
2329         link=`ls -dl /usr/lib/64  | awk '{print $NF}'`
2330         ln -s $link /tmp/bfulib/64
2331         ln -s $link /tmp/bl/64
2332         mkdir /tmp/bfulib/$link /tmp/bl/$link
2333         bfulib="$bfulib /usr/lib/64/nss_*"
2334         #
2335         # Copy libraries to proper directories
2336         #
2337         for lib in $bfulib
2338         do
2339                 case $lib in
2340                 */64/* | */$link/*)
2341                         cp $lib /tmp/bfulib/64;;
2342                 *)
2343                         cp $lib /tmp/bfulib;;
2344                 esac
2345         done
2346         #
2347         # Private 64 bit runtime linker.
2348         #
2349         cp /lib/64/ld.so.1 /tmp/bfulib/64/bf.1
2350         cp /lib/64/ld.so.1 /tmp/bl/64/bf.1
2351 else
2352         cp $bfulib /tmp/bfulib
2353 fi
2354 cp /lib/ld.so.1 /tmp/bfulib/bf.1        # bfu's private runtime linker
2355 cp /lib/ld.so.1 /tmp/bl/bf.1
2356 
2357 ${BFULD-$GATE/public/bin/$bfu_isa/bfuld} /tmp/bfubin/* || fail "bfuld failed"
2358 
2359 for x in $bfuscr
2360 do
2361         sed -e 's/\/usr\/bin\//\/tmp\/bfubin\//g' \
2362             -e 's/\/bin\//\/tmp\/bfubin\//g' < $x > /tmp/bfubin/`basename $x`
2363         chmod +x /tmp/bfubin/`basename $x`
2364 done
2365 
2366 #
2367 # scripts used together with multiboot
2368 #
2369 multiboot_scr="
2370         /boot/solaris/bin/create_ramdisk
2371         /boot/solaris/bin/create_diskmap
2372         /boot/solaris/bin/root_archive
2373 "
2374 
2375 if [ $multiboot_archives = yes ]; then
2376         for cmd in $multiboot_scr
2377         do
2378                 if [ -f $cmd ]; then
2379                         cp $cmd /tmp/bfubin
2380                 else
2381                         if [ ! -d $MULTIBOOT_BIN_DIR ]; then
2382                                 echo "$MULTIBOOT_BIN_DIR: not found"
2383                                 fail ""
2384                         fi
2385 
2386                         file=`basename $cmd`
2387                         if [ ! -f $MULTIBOOT_BIN_DIR/$file ]; then
2388                                 echo "$MULTIBOOT_BIN_DIR/$file: not found"
2389                                 fail ""
2390                         fi
2391                         echo "copying $file from $MULTIBOOT_BIN_DIR"
2392                         cp $MULTIBOOT_BIN_DIR/$file /tmp/bfubin
2393                 fi
2394 
2395                 file=`basename $cmd`
2396                 mv /tmp/bfubin/${file} /tmp/bfubin/${file}-
2397                 sed 's/\/usr\/bin\//\/tmp\/bfubin\//g' \
2398                     < /tmp/bfubin/${file}- > /tmp/bfubin/${file}
2399                 chmod +x /tmp/bfubin/${file}
2400         done
2401 fi
2402 
2403 create_datalink_conf()
2404 {
2405         # /etc/datalink.conf needs to be populated.
2406         drivers="bge rge xge"
2407         conf=$rootprefix/etc/datalink.conf
2408 
2409         if [ ! -f $conf ]; then
2410                 # nothing to do if we bfu'ed from an archive that doesn't
2411                 # provide /etc/datalink.conf
2412                 return
2413         fi
2414 
2415         ls -1 $rootprefix/etc | egrep -e '^hostname.|^hostname6.|^dhcp.' | \
2416             cut -d . -f2 | sort -u > /tmp/ifnames.$$
2417 
2418         for driver in $drivers
2419         do
2420                 grep $driver /tmp/ifnames.$$ | \
2421                 while read ifname
2422                 do
2423                         devnum=`echo $ifname | sed "s/$driver//g"`
2424                         if [ "$driver$devnum" != $ifname -o \
2425                             -n "`echo $devnum | tr -d '[0-9]'`" ]; then
2426                                 echo "skipping invalid interface $ifname"
2427                                 continue
2428                         fi
2429 
2430                         vid=`expr $devnum / 1000`
2431                         inst=`expr $devnum % 1000`
2432 
2433                         awk '{ print $1 }' $conf | grep $ifname > /dev/null
2434                         if [ $? -ne 0 ]; then 
2435                                 # An entry for that interface does not exist
2436                                 printf \
2437                                     "$ifname\t$driver$inst\t0\t$vid\n" \
2438                                     >> $conf
2439                         fi
2440                 done
2441         done
2442 
2443         rm -f /tmp/ifnames.$$
2444 }
2445 
2446 remove_initd_links()
2447 {
2448         # If we're delivering a new version of an existing /etc/init.d script,
2449         # remove all hard links to the existing file in /etc/rc?.d whose
2450         # names begin with [SK][0-9][0-9].  Additionally, in case an S or K
2451         # file was previously delivered as a symbolic link or the hard link
2452         # was broken, remove any file in /etc/rc?.d whose name is
2453         # [SK][0-9][0-9] followed by the basename of the file we're going
2454         # to update in /etc/init.d.
2455 
2456         print "Removing init.d links ... \c"
2457         scripts=`$ZCAT $cpiodir/generic.root$ZFIX |
2458                 cpio -it 2>/dev/null | grep '^etc/init\.d/'`
2459         if [ -n "$scripts" ]; then
2460                 inodes=`ls -li $scripts 2>/dev/null | \
2461                         nawk '{ print "-inum " $1 " -o " }'`
2462                 names=`ls -1 $scripts 2>/dev/null | \
2463                         nawk -F/ '{ print "-name [SK][0-9][0-9]" $NF }'`
2464                 find etc/rc?.d \( $inodes $names \) -print | xargs rm -f
2465         fi
2466         print "done."
2467 }
2468 
2469 #
2470 # Remove the old 5.005_03 version of perl.
2471 #
2472 remove_perl_500503()
2473 {
2474         # Packages to remove.
2475         typeset -r perl_pkgs='SUNWopl5m SUNWopl5p SUNWopl5u'
2476         typeset -r pkgroot=${rootprefix:+-R $rootprefix}
2477         typeset pkg
2478 
2479         #
2480         # First, attempt to remove the packages cleanly if possible.
2481         #
2482         printf 'Removing perl 5.005_03 packages'
2483         for pkg in $perl_pkgs
2484         do
2485                 if pkginfo $pkgroot -q $pkg; then
2486                         printf ' %s' $pkg
2487                         pkgrm $pkgroot -n $pkg >/dev/null 2>&1
2488                 fi
2489         done
2490         printf '\n'
2491 
2492         #
2493         # In case that didn't work, do it manually.
2494         #
2495         printf 'Removing perl 5.005_03 from %s/var/sadm/install/contents' \
2496             $rootprefix
2497         for pkg in $PKGS
2498         do
2499                 printf ' %s' $pkg
2500                 if [ -d $rootprefix/var/sadm/pkg/$pkg ]; then
2501                         rm -rf $rootprefix/var/sadm/pkg/$pkg
2502                         grep -vw $pkg $rootprefix/var/sadm/install/contents > \
2503                             /tmp/contents.$$
2504                         cp /tmp/contents.$$ /var/sadm/install/contents.$$
2505                         rm /tmp/contents.$$
2506                 fi
2507         done
2508         printf '\n'
2509 
2510         #
2511         # Remove any remaining 5.005_03 files,
2512         #
2513         printf 'Removing perl 5.005_03 from %s/perl5\n' $usr
2514 
2515         # Directories.
2516         rm -rf $usr/perl5/5.00503
2517         rm -rf $usr/perl5/site_perl/5.005
2518 }
2519 
2520 #
2521 # Remove ASET
2522 #
2523 remove_eof_aset()
2524 {
2525         # Packages to remove
2526         typeset -r aset_pkgs='SUNWast'
2527         typeset -r pkgroot=${rootprefix:+-R $rootprefix}
2528         typeset pkg
2529 
2530         printf 'Removing ASET... '
2531 
2532         #
2533         # First, attempt to remove the packages cleanly if possible.
2534         #
2535         for pkg in $aset_pkgs
2536         do
2537                 if pkginfo $pkgroot -q $pkg; then
2538                         printf ' %s' $pkg
2539                         pkgrm $pkgroot -n $pkg >/dev/null 2>&1
2540                 fi
2541         done
2542         printf '\n'
2543 
2544         #
2545         # In case that didn't work, do it manually.
2546         # Remove ASET from $rootprefix/var/sadm/install/contents
2547         #
2548         for pkg in $aset_pkgs
2549         do
2550                 if [ -d $rootprefix/var/sadm/pkg/$pkg ]; then
2551                         rm -rf $rootprefix/var/sadm/pkg/$pkg
2552                         grep -vw $pkg $rootprefix/var/sadm/install/contents > \
2553                             /tmp/contents.$$
2554                         cp /tmp/contents.$$ $rootprefix/var/sadm/install/contents.$$
2555                         rm /tmp/contents.$$
2556                 fi
2557         done
2558 
2559         #
2560         # Cleanup any remaining ASET files, symlinks, and directories.
2561         #
2562         rm -rf $usr/aset
2563 }
2564 
2565 #
2566 # Remove BIND 8 named server/tools packages
2567 #
2568 remove_eof_bind8()
2569 {
2570         # Packages to remove
2571         typeset -r bind8_pkg='SUNWinamd'
2572         typeset -r pkgroot=${rootprefix:+-R $rootprefix}
2573         typeset pkg
2574 
2575         printf 'Removing BIND 8 named server/tools... '
2576 
2577         #
2578         # We cann't pkgrm SUNWinamd at this time as the BIND 9 binaries are
2579         # already in /usr/sbin.
2580         # Remove BIND 8 packages from $rootprefix/var/sadm/install/contents
2581         #
2582         for pkg in $bind8_pkgs
2583         do
2584                 if [ -d $rootprefix/var/sadm/pkg/$pkg ]; then
2585                         rm -rf $rootprefix/var/sadm/pkg/$pkg
2586                         grep -vw $pkg $rootprefix/var/sadm/install/contents > \
2587                             /tmp/contents.$$
2588                         cp /tmp/contents.$$ /var/sadm/install/contents.$$
2589                         rm /tmp/contents.$$
2590                 fi
2591         done
2592 
2593         #
2594         # Cleanup any BIND 8 specific files, symlinks.
2595         #
2596 
2597         # files and symlinks.
2598         rm -f $usr/sbin/named-xfer
2599         rm -f $usr/lib/nslookup.help
2600         rm -f $usr/sbin/dnskeygen
2601         rm -f $usr/sbin/named-bootconf
2602         rm -f $usr/sbin/nstest
2603         rm -rf $rootprefix/var/run/ndc.d
2604         printf 'done.\n'
2605 }
2606 
2607 #
2608 # Remove the 5.8.3 version of perl.
2609 #
2610 remove_perl_583()
2611 {
2612         #
2613         # Copy perl 5.8.3 into the new 5.8.4 locations.  This will preserve
2614         # any add-on modules that might have been installed, and any 5.8.3
2615         # core files that get copied over will be replaced by the new 5.8.4
2616         # versions when the cpio archives are subsequently extracted.
2617         #
2618         printf 'Preserving user-installed perl modules...\n'
2619         mkdir -p $usr/perl5/5.8.4
2620         cp -rp $usr/perl5/5.8.3/* \
2621             $usr/perl5/5.8.4
2622         mkdir -p $usr/perl5/site_perl/5.8.4
2623         cp -rp $usr/perl5/site_perl/5.8.3/* \
2624             $usr/perl5/site_perl/5.8.4
2625         mkdir -p $usr/perl5/vendor_perl/5.8.4
2626         cp -rp $usr/perl5/vendor_perl/5.8.3/* \
2627             $usr/perl5/vendor_perl/5.8.4
2628 
2629         #
2630         # Update the #! lines in any scripts in /usr/perl5/5.8.4/bin to refer
2631         # to 5.8.4 instead of 5.8.3.  Take care to edit only scripts.
2632         #
2633         typeset bindir="$usr/perl5/5.8.4/bin"
2634         typeset script
2635         for script in $(ls $bindir); do
2636                 script="$bindir/$script"
2637                 if [[ $script = "$usr/perl5/5.8.4/bin/perl5.8.3" ]]; then
2638                         rm -f $script
2639                 elif file $script | \
2640                     egrep -s 'executable .*perl .*script'; then
2641                         sed -e \
2642                             's!/usr/perl5/5.8.3/bin/perl!/usr/perl5/5.8.4/bin/perl!g' \
2643                             < $script > $script.tmp
2644                         mv -f $script.tmp $script
2645                 fi
2646         done
2647 
2648         #
2649         # Packages to remove.
2650         #
2651         typeset -r perl_pkgs='SUNWperl583man SUNWperl583usr SUNWperl583root'
2652         typeset -r pkgroot=${rootprefix:+-R $rootprefix}
2653 
2654         #
2655         # First, attempt to remove the packages cleanly if possible.
2656         #
2657         typeset pkg
2658         printf 'Removing perl 5.8.3 packages'
2659         for pkg in $perl_pkgs
2660         do
2661                 if pkginfo $pkgroot -q $pkg; then
2662                         printf ' %s' $pkg
2663                         pkgrm $pkgroot -n $pkg >/dev/null 2>&1
2664                 fi
2665         done
2666         printf '\n'
2667 
2668         #
2669         # In case that didn't work, do it manually.
2670         #
2671         printf 'Removing perl 5.8.3 from %s/var/sadm/install/contents' \
2672             $rootprefix
2673         for pkg in $PKGS
2674         do
2675                 printf ' %s' $pkg
2676                 if [ -d $rootprefix/var/sadm/pkg/$pkg ]; then
2677                         rm -rf $rootprefix/var/sadm/pkg/$pkg
2678                         grep -vw $pkg $rootprefix/var/sadm/install/contents > \
2679                             /tmp/contents.$$
2680                         cp /tmp/contents.$$ /var/sadm/install/contents.$$
2681                         rm /tmp/contents.$$
2682                 fi
2683         done
2684         printf '\n'
2685 
2686         #
2687         # Remove any remaining 5.8.3 files,
2688         # and fix up the symlinks if necessary.
2689         #
2690         printf 'Removing perl 5.8.3 from %s/perl5\n' $usr
2691 
2692         # Directories.
2693         rm -rf $usr/perl5/5.8.3
2694         rm -rf $usr/perl5/site_perl/5.8.3
2695         rm -rf $usr/perl5/vendor_perl/5.8.3
2696 
2697         # bin symlink.
2698         rm -f $usr/perl5/bin
2699         ln -s ./5.8.4/bin $usr/perl5/bin
2700 
2701         # pod symlink.
2702         rm -f $usr/perl5/pod
2703         ln -s ./5.8.4/lib/pod $usr/perl5/pod
2704 
2705         #
2706         # man symlink.  In earlier S10 builds the man symlink mistakenly points
2707         # to the 5.6.1 manpages, instead of 5.8.3.  Fix to point to 5.8.4.
2708         #
2709         rm -f $usr/perl5/man
2710         ln -s ./5.8.4/man $usr/perl5/man
2711 
2712         # Symlink /bin/perl to 5.8.4.
2713         rm -f $usr/bin/perl
2714         ln -s ../perl5/5.8.4/bin/perl $usr/bin/perl
2715 }
2716 
2717 #
2718 # Remove FNS/XFN packages
2719 #
2720 remove_eof_fns()
2721 {
2722         # Packages to remove
2723         typeset -r fns_pkgs='SUNWfnx5x SUNWfnsx5 SUNWfnsx SUNWfns'
2724         typeset -r pkgroot=${rootprefix:+-R $rootprefix}
2725         typeset pkg
2726 
2727         printf 'Removing FNS/XFN ... '
2728 
2729         #
2730         # First, attempt to remove the packages cleanly if possible.
2731         #
2732         for pkg in $fns_pkgs
2733         do
2734                 if pkginfo $pkgroot -q $pkg; then
2735                         printf ' %s' $pkg
2736                         pkgrm $pkgroot -n $pkg >/dev/null 2>&1
2737                 fi
2738         done
2739         printf '\n'
2740 
2741         #
2742         # In case that didn't work, do it manually.
2743         # Remove FNS/XFN from $rootprefix/var/sadm/install/contents
2744         #
2745         for pkg in $fns_pkgs
2746         do
2747                 if [ -d $rootprefix/var/sadm/pkg/$pkg ]; then
2748                         rm -rf $rootprefix/var/sadm/pkg/$pkg
2749                         grep -vw $pkg $rootprefix/var/sadm/install/contents > \
2750                             /tmp/contents.$$
2751                         cp /tmp/contents.$$ $rootprefix/var/sadm/install/contents.$$
2752                         rm /tmp/contents.$$
2753                 fi
2754         done
2755 
2756         #
2757         # Cleanup if any remaining FNS/XFN files, symlinks, and directories.
2758         #
2759 
2760         # directories.
2761         rm -rf $rootprefix/etc/fn
2762         rm -rf $usr/include/xfn
2763         rm -rf $usr/lib/fn
2764         rm -rf $rootprefix/var/fn
2765 
2766         # files and symlinks.
2767         rm -f $rootprefix/etc/fn.conf
2768         rm -f $usr/bin/fnattr
2769         rm -f $usr/bin/fnbind
2770         rm -f $usr/bin/fncreate_printer
2771         rm -f $usr/bin/fnlist
2772         rm -f $usr/bin/fnlookup
2773         rm -f $usr/bin/fnrename
2774         rm -f $usr/bin/fnsearch
2775         rm -f $usr/bin/fnunbind
2776         rm -f $usr/sbin/fncheck
2777         rm -f $usr/sbin/fncopy
2778         rm -f $usr/sbin/fncreate
2779         rm -f $usr/sbin/fncreate_fs
2780         rm -f $usr/sbin/fndestroy
2781         rm -f $usr/sbin/fnselect
2782         rm -f $usr/sbin/fnsypd
2783         rm -f $usr/lib/libfn_p.so
2784         rm -f $usr/lib/libfn_p.so.1
2785         rm -f $usr/lib/libfn_spf.so
2786         rm -f $usr/lib/libfn_spf.so.1
2787         rm -f $usr/lib/libxfn.so
2788         rm -f $usr/lib/libxfn.so.1
2789         rm -f $usr/lib/libxfn.so.2
2790         rm -f $usr/lib/sparcv9/libfn_p.so
2791         rm -f $usr/lib/sparcv9/libfn_p.so.1
2792         rm -f $usr/lib/sparcv9/libfn_spf.so
2793         rm -f $usr/lib/sparcv9/libfn_spf.so.1
2794         rm -f $usr/lib/sparcv9/libxfn.so
2795         rm -f $usr/lib/sparcv9/libxfn.so.1
2796         rm -f $usr/lib/sparcv9/libxfn.so.2
2797 }
2798 
2799 remove_eof_face() {
2800         # Packages to remove
2801         typeset -r face_pkgs='SUNWfac'
2802         typeset -r pkgroot=${rootprefix:+-R $rootprefix}
2803         typeset pkg
2804 
2805         printf 'Removing AT&T FACE... '
2806 
2807         #
2808         # First, attempt to remove the packages cleanly if possible.
2809         #
2810         for pkg in $face_pkgs
2811         do
2812                 if pkginfo $pkgroot -q $pkg; then
2813                         printf ' %s' $pkg
2814                         pkgrm $pkgroot -n $pkg >/dev/null 2>&1
2815                 fi
2816         done
2817         printf '\n'
2818 
2819         #
2820         # In case that didn't work, do it manually.
2821         # Remove FACE from $rootprefix/var/sadm/install/contents
2822         #
2823         for pkg in $face_pkgs
2824         do
2825                 if [ -d $rootprefix/var/sadm/pkg/$pkg ]; then
2826                         rm -rf $rootprefix/var/sadm/pkg/$pkg
2827                         grep -vw $pkg $rootprefix/var/sadm/install/contents > \
2828                             /tmp/contents.$$
2829                         cp /tmp/contents.$$ $rootprefix/var/sadm/install/contents.$$
2830                         rm /tmp/contents.$$
2831                 fi
2832         done
2833 
2834         #
2835         # Cleanup any remaining FACE files, symlinks, and directories.
2836         #
2837         rm -rf $usr/oasys
2838         rm -rf $usr/vmsys
2839 }
2840 
2841 remove_properties() {
2842 
2843         #
2844         # Remove obsolete smartii setprop from bootenv.rc
2845         #
2846         srcbootenvrc=$root/boot/solaris/bootenv.rc
2847         tmpbootenvrc=/tmp/tmp.bootenvrc.$$
2848 
2849         # Don't touch bootenv.rc unless it contains obsolete property
2850         egrep -s 'target-driver-for-smartii' $srcbootenvrc 2>/dev/null
2851         res=$?
2852         if [ -f $srcbootenvrc -a $res -eq 0 ]; then
2853                 egrep -v "target-driver-for-smartii"\
2854                         $srcbootenvrc > $tmpbootenvrc 2>/dev/null
2855                 cp $tmpbootenvrc $srcbootenvrc
2856         fi
2857         rm -f $tmpbootenvrc
2858 }
2859 
2860 enable_crypto_unlimited()
2861 {
2862 # This is a "copy" of the SUNWcry* postinstall scripts.
2863 # We enable the encryption kit aes256, arcfour2048, and blowfish448 modules.
2864 # This is needed to ensure bfu users continue to have the full strength of
2865 # cryptographic algorithms they use.
2866 
2867         print "Simulating SUNWcry* installation...\c"
2868         kcfconf=$rootprefix/etc/crypto/kcf.conf
2869         ipsecalgs=$rootprefix/etc/inet/ipsecalgs
2870 
2871         cp $kcfconf ${kcfconf}.tmp
2872 
2873         sed -e 's/^aes:/aes256:/' -e 's/^blowfish:/blowfish448:/' -e \
2874             's/^arcfour:/arcfour2048:/'\
2875                 $kcfconf > ${kcfconf}.tmp
2876 
2877         mv -f ${kcfconf}.tmp $kcfconf
2878 
2879         cp $ipsecalgs ${ipsecalgs}.tmp
2880 
2881         sed -e 's/_CBC|128\/32-128,8/_CBC|128\/32-448,8/' \
2882             -e 's/AES_CBC|128|/AES_CBC|128\/128-256,64|/' \
2883             $ipsecalgs > ${ipsecalgs}.tmp
2884 
2885         mv -f ${ipsecalgs}.tmp $ipsecalgs
2886 
2887         # Since we do that for the kernel we do it for userland as well.
2888 
2889         # "Clone" the policy for pkcs11_softtoken to the encryption kit version
2890         # and "disable" pkcs11_softoken.
2891 
2892         pkcs11conf=$rootprefix/etc/crypto/pkcs11.conf
2893 
2894         cp $pkcs11conf ${pkcs11conf}.tmp
2895 
2896         sed 's/pkcs11_softtoken\.so/pkcs11_softtoken_extra.so/' \
2897                 $pkcs11conf > ${pkcs11conf}.tmp
2898 
2899         mv -f ${pkcs11conf}.tmp $pkcs11conf
2900         print "\n"
2901 
2902 }
2903 
2904 #
2905 # Add metaslot configuration to pkcs11.conf if it doesn't already exist
2906 #
2907 enable_crypto_metaslot()
2908 {
2909         pkcs11conf=$rootprefix/etc/crypto/pkcs11.conf
2910         egrep '^metaslot' ${pkcs11conf} > /dev/null 2>& 1
2911         if [ $? != 0 ] ; then
2912                 print "Adding cryptographic framework's meta slot feature"
2913                 cp $pkcs11conf ${pkcs11conf}.tmp
2914                 export metaslot_config=\
2915 "metaslot:metaslot_status=enabled;metaslot_auto_key_migrate=enabled;"\
2916 "metaslot_token=Sun Software PKCS#11 softtoken;"\
2917 "metaslot_slot=Sun Crypto Softtoken"
2918                 nawk '/^# End SUNWcsr/ \
2919                         { print ENVIRON["metaslot_config"] } \
2920                         { print } \
2921                 ' ${pkcs11conf} > ${pkcs11conf}.tmp
2922                 mv -f ${pkcs11conf}.tmp $pkcs11conf
2923                 print "\n"
2924         fi
2925 }
2926 
2927 cleanup_kerberos_mechanisms()
2928 {
2929 #
2930 # This checks to see if the old 'gl' and 'do' directories
2931 # for the Kerberos GSS-API mechanisms can be deleted.
2932 # If the mechanism exists in /usr/lib/gss, then the old
2933 # subdirs may be deleted.
2934 #
2935         print "Cleaning up old Kerberos GSS-API mechanisms...\c"
2936 
2937         kerneldir=kernel/misc/kgss
2938         kerneldir_sparc=kernel/misc/kgss/sparcv9
2939 
2940         newmech=no;
2941         if [ -f $usr/lib/gss/mech_krb5.so.1 ]; then
2942                 #
2943                 # There is a mech  in the "new" location, so
2944                 # the old stuff can be deleted.
2945                 #
2946                 if [ -d $usr/lib/gss/gl ]; then
2947                         rm -rf $usr/lib/gss/gl
2948                 fi
2949                 if [ -d $usr/lib/gss/do ]; then
2950                         rm -rf $usr/lib/gss/do
2951                 fi
2952                 newmech=yes;
2953         fi
2954         if [ -f $usr/lib/sparcv9/gss/mech_krb5.so.1 ]; then
2955                 if [ -d $usr/lib/sparcv9/gss/gl ]; then
2956                         rm -rf $usr/lib/sparcv9/gss/gl
2957                 fi
2958                 if [ -d $usr/lib/sparcv9/gss/do ]; then
2959                         rm -rf $usr/lib/sparcv9/gss/do
2960                 fi
2961         fi
2962         #
2963         # Cleanup kernel mechanisms from default location
2964         #
2965         if [ -f $rootprefix/$kerneldir/kmech_krb5 ]; then
2966                 if [ -f $rootprefix/$kerneldir/gl_kmech_krb5 ]; then
2967                         rm -f $rootprefix/$kerneldir/gl_kmech_krb5
2968                 fi
2969                 if [ -f $rootprefix/$kerneldir/do_kmech_krb5 ]; then
2970                         rm -f $rootprefix/$kerneldir/do_kmech_krb5
2971                 fi
2972         fi
2973         #
2974         # For SPARC, cleanup from 2 locations.
2975         #
2976         # 1.  /kernel/misc/kgss/sparcv9
2977         #
2978         if [ -f $rootprefix/$kerneldir_sparc/kmech_krb5 ]; then
2979                 if [ -f $rootprefix/$kerneldir_sparc/gl_kmech_krb5 ]; then
2980                         rm -f $rootprefix/$kerneldir_sparc/gl_kmech_krb5
2981                 fi
2982                 if [ -f $rootprefix/$kerneldir_sparc/do_kmech_krb5 ]; then
2983                         rm -f $rootprefix/$kerneldir_sparc/do_kmech_krb5
2984                 fi
2985         fi
2986         #
2987         # 2.  /platform/sun4u/kernel/misc/kgss/sparcv9
2988         #
2989         kerneldir_sparc=platform/$karch/$kerneldir_sparc
2990         if [ -f $rootprefix/$kerneldir_sparc/kmech_krb5 ]; then
2991                 if [ -f $rootprefix/$kerneldir_sparc/gl_kmech_krb5 ]; then
2992                         rm -f $rootprefix/$kerneldir_sparc/gl_kmech_krb5
2993                 fi
2994                 if [ -f $rootprefix/$kerneldir_sparc/do_kmech_krb5 ]; then
2995                         rm -f $rootprefix/$kerneldir_sparc/do_kmech_krb5
2996                 fi
2997         fi
2998         #
2999         # Make sure the GSS mechanism configuration file is correct
3000         #
3001         if [ "$newmech" = "yes" ]; then
3002                 gssmechconf=$rootprefix/etc/gss/mech
3003 
3004                 sed -e 's/gl\/mech_krb5\.so/mech_krb5\.so/' \
3005                 -e 's/do\/mech_krb5\.so/mech_krb5\.so/' \
3006                 -e 's/gl_kmech_krb5/kmech_krb5/' \
3007                 -e 's/do_kmech_krb5/kmech_krb5/'\
3008                 $gssmechconf > ${gssmechconf}.tmp
3009 
3010                 if [ $? -eq 0 ]; then
3011                         mv -f ${gssmechconf}.tmp $gssmechconf
3012                 else
3013                         echo  "WARNING: update of $gssmechconf failed."
3014                         return 1
3015                 fi
3016         fi
3017         print "\n"
3018 }
3019 
3020 mpxiodisableno='^[      ]*mpxio-disable[        ]*=[    ]*"no"[         ]*;'
3021 mpxiodisableyes='^[     ]*mpxio-disable[        ]*=[    ]*"yes"[        ]*;'
3022 
3023 #
3024 # disable mpxio on fp(7D) ports using fp.conf
3025 #
3026 disable_mpxio_using_fpconf()
3027 {
3028         conffile=$rootprefix/kernel/drv/fp.conf
3029         test -f $conffile || return
3030         egrep -s "$mpxiodisableyes" $conffile && return
3031 
3032         print "To preserve device names, disabled mpxio on fp(7D) ports by"
3033 
3034         if egrep -s "$mpxiodisableno" $conffile; then
3035                 tmpfile=/tmp/fp.conf.$$
3036                 sed "s/$mpxiodisableno/mpxio-disable=\"yes\";/" $conffile \
3037                     > $tmpfile
3038                 cp $tmpfile $conffile
3039                 rm -f $tmpfile
3040                 print "changing the value of mpxio-disable to \"yes\" in" \
3041                   "$conffile"
3042         else
3043                 echo 'mpxio-disable="yes";' >> $conffile
3044                 print "adding mpxio-disable=\"yes\" entry to $conffile"
3045         fi
3046 }
3047 
3048 #
3049 # enable mpxio in scsi_vhci
3050 #
3051 enable_mpxio_using_scsivhciconf()
3052 {
3053         #
3054         # depending on whether the bfu restored the child's or parent's version
3055         # of scsi_vhci.conf file, we may already have the file with the change
3056         # we need in place. So make the change only if necessary.
3057         #
3058 
3059         conffile=$rootprefix/kernel/drv/scsi_vhci.conf
3060         egrep -s "$mpxiodisableno" $conffile && return
3061 
3062         print "To preserve device names, restored your current mpxio" \
3063             "configuration by"
3064 
3065         if egrep -s "$mpxiodisableyes" $conffile; then
3066                 tmpfile=/tmp/scsi_vhci.conf.$$
3067                 sed "s/$mpxiodisableyes/mpxio-disable=\"no\";/" $conffile \
3068                     > $tmpfile
3069                 cp $tmpfile $conffile
3070                 rm -f $tmpfile
3071                 print "changing the value of mpxio-disable to \"no\" in" \
3072                   "$conffile"
3073         else
3074                 echo 'mpxio-disable="no";' >> $conffile
3075                 print "adding mpxio-disable=\"no\" entry to $conffile"
3076         fi
3077 }
3078 
3079 #
3080 # restore the pre-bfu MPxIO on/off setting to the post-bfued configuration
3081 #
3082 fixup_mpxio()
3083 {
3084         conffile=$rootprefix/kernel/drv/scsi_vhci.conf
3085         parentconffile=$rootprefix/bfu.parent/kernel/drv/scsi_vhci.conf
3086         childconffile=$rootprefix/bfu.child/kernel/drv/scsi_vhci.conf
3087         ancestorconffile=$rootprefix/bfu.ancestor/kernel/drv/scsi_vhci.conf
3088 
3089         # if scsi_vhci.conf doesn't exist return
3090         test -f $conffile || return
3091 
3092         #
3093         # Determine the mpxio setting in the child. If the system was bfued
3094         # before and running with mpxio on by deafult bits, can't rely on the
3095         # mpxio-disable entry in the child's scsi_vhci.conf file as it may
3096         # contain stale left over entries.
3097         #
3098         mpxio_child=1
3099         if [ -f $ancestorconffile ]; then
3100                 if egrep -s "$mpxiodisableyes" $ancestorconffile; then
3101                         #
3102                         # prior to the bfu the system was running with
3103                         # mpxio off by default bits.
3104                         #
3105                         mpxio_child=0
3106                         egrep -s "$mpxiodisableno" $childconffile && \
3107                             mpxio_child=1
3108                 fi
3109         else
3110                 egrep -s "$mpxiodisableyes" $childconffile && mpxio_child=0
3111         fi
3112 
3113         if egrep -s "$mpxiodisableyes" $parentconffile; then
3114                 # these bits require explicit enabling of mpxio at in scsi_vhci
3115                 if [ $mpxio_child -eq 1 ]; then
3116                         egrep -s "$mpxiodisableyes" \
3117                             $rootprefix/kernel/drv/fp.conf || \
3118                             enable_mpxio_using_scsivhciconf
3119                 fi
3120         else
3121                 #
3122                 # these bits have mpxio enabled by default in scsi_vhci.
3123                 # if mpxio is disabled in the child, disable mpxio on all
3124                 # fp(7D) ports using fp.conf.
3125                 #
3126                 [ $mpxio_child -eq 0 ] && disable_mpxio_using_fpconf
3127         fi
3128 }
3129 
3130 
3131 #
3132 # Check to see if root in $1 has a mounted boot, and that
3133 # it's mounted at the right place for bfu to handle it.
3134 #
3135 # Returns 0 (true) if bfu can handle the upgrade; fails if not
3136 #
3137 
3138 boot_is_upgradeable()
3139 {
3140         ROOT=$1
3141         if [ "$ROOT" = "/" ] ; then ROOT=""; fi
3142 
3143         BOOTPARTDEV="$(grep -s -v '^#' ${ROOT}/etc/vfstab | \
3144             grep "[     ]/boot[         ]*pcfs[         ]" | \
3145             awk '{print $1}')"
3146 
3147         # find out if, and where, boot is mounted
3148 
3149         if [ -n "$BOOTPARTDEV" ] ; then 
3150                 if [ -n "$ROOT" ] ; then
3151                 
3152                         BOOTMNT=$(mount | grep "$BOOTPARTDEV" | \
3153                             awk '{print $1}')
3154                 else
3155                         BOOTMNT="/boot"
3156                 fi
3157                 if [ "$BOOTMNT" != ${ROOT}/boot ] ; then
3158                         cat << BOOTMOUNTERR
3159 
3160 ${ROOT} refers to an x86 boot partition, but it's not mounted 
3161 at ${ROOT}/boot.
3162 
3163 BOOTMOUNTERR
3164                         fail "Mount ${ROOT}s bootpart at ${ROOT}/boot.\n\n"
3165                 fi
3166         fi
3167 
3168         return 0
3169 }
3170 
3171 # update the realmode boot programs at $1 (root) 
3172 # from classic boot psm/stand/bootblks/ufs/i386/installboot.sh
3173 
3174 install_boot_i386()
3175 {
3176         PBOOT=$1
3177         BOOTBLK=$2
3178         DEVICE=$3
3179         if [ ! -f $PBOOT ]; then
3180                 echo "$PBOOT: File not found"
3181                 return 1
3182         fi
3183         if [ ! -f $BOOTBLK ]; then
3184                 echo "$BOOTBLK: File not found"
3185                 return 1
3186         fi
3187         if [ ! -c $DEVICE ]; then
3188                 echo "$DEVICE: Not a character device"
3189                 return 1
3190         fi
3191         if [ ! -w $DEVICE ]; then
3192                 echo "$DEVICE: Not writeable"
3193                 return 1
3194         fi
3195 
3196         # pboot at block 0, label at blocks 1 and 2, bootblk from block 3 on
3197         dd if=$PBOOT of=$DEVICE bs=1b count=1 conv=sync >/dev/null 2>&1
3198 
3199         dd if=$BOOTBLK of=$DEVICE bs=1b oseek=3 conv=sync >/dev/null 2>&1
3200 
3201         return 0
3202 }
3203 
3204 update_realmode_booters()
3205 {
3206         ROOT=$1
3207         
3208         TMPDIR=/tmp/rmupdate.$$
3209         trap "rm -rf $TMPDIR" EXIT
3210 
3211         # go get new versions of boot files into TMPDIR
3212 
3213         OLD_PWD=$(pwd)
3214         mkdir $TMPDIR
3215         cd $TMPDIR
3216 
3217         # i86pc.boot archive
3218         REQFILES="boot/mdboot boot/strap.com"
3219         $ZCAT $cpiodir/i86pc.boot$ZFIX |  cpio -id $REQFILES 2>/dev/null 
3220         mv $REQFILES $TMPDIR
3221 
3222         # i86pc.usr archive
3223         REQFILES="usr/platform/i86pc/lib/fs/ufs/pboot"
3224         REQFILES="$REQFILES usr/platform/i86pc/lib/fs/ufs/bootblk"
3225         $ZCAT $cpiodir/i86pc.usr$ZFIX | cpio -id $REQFILES 2>/dev/null
3226         mv $REQFILES $TMPDIR
3227 
3228         cd $OLD_PWD
3229 
3230         grep -s -v '^#' ${ROOT}/etc/vfstab | \
3231             grep "[     ]/boot[         ]*pcfs[         ]" >/dev/null
3232 
3233         if [ $? -eq 0 ] ; then
3234                 echo 'Updating /boot on x86 boot partition.'
3235 
3236                 REQFILES="mdboot strap.com"
3237                 for f in ${REQFILES}; do
3238                         if [ ! -f ${TMPDIR}/$f ]; then
3239                                 fail "Missing $f, aborting."
3240                         fi
3241                 done
3242 
3243                 MDBOOT=${TMPDIR}/mdboot
3244                 STRAP=${TMPDIR}/strap.com
3245 
3246                 LUBIN=/usr/lib/lu
3247                 TMP_FDFILE1=${TMPDIR}/fdfile1.$$
3248                 LOGFILE=${TMPDIR}/mkfs.log.$$
3249                 DDCOPY=${TMPDIR}/.dd_x86_boot_copy
3250 
3251                 DISKID="$(grep -s -v '^#' ${ROOT}/etc/vfstab | \
3252                     grep "[     ]/boot[         ]*pcfs[         ]" |\
3253                     awk '{print $1}' | sed -e 's:p0\:boot::g')"
3254 
3255                 DISKID="$(basename ${DISKID})"
3256 
3257                 # Obtain the disk table; it will look something like the following:
3258                 #
3259 # * Id    Act  Bhead  Bsect  Bcyl    Ehead  Esect  Ecyl    Rsect    Numsect
3260 #   130   128  27     28     0       242    9      553     1728     8897472
3261                 # 
3262                 # Delete all blank lines, and all lines that begin with *,
3263                 # leaving only actual fdisk entries that we can scan
3264                 # looking for the X86BOOT partition
3265 
3266                 fdisk -W - /dev/rdsk/${DISKID}p0 | \
3267                     grep -v '^*' | grep -v '^$' > ${TMP_FDFILE1}
3268 
3269                 num=1
3270 
3271                 while read id act bhead bcyl ehead ecyl rsect numsect
3272                 do
3273                         # Ignore entry if not X86 /boot partition
3274                         # ID '190' is the X86BOOT partition (see man fdisk(1M))
3275 
3276                         if [ $id -ne "190" ] ; then
3277                                 num=$(expr $num + 1)
3278                                 continue
3279                         fi
3280 
3281                         # Found X86 boot partition - save contents to $DDCOPY
3282                         BOOTPART=/dev/rdsk/${DISKID}p${num}
3283                         echo "Boot device is <${BOOTPART}>"
3284 
3285                         ERRMSG="$(dd if=${BOOTPART} of=${DDCOPY} 2>&1)"
3286                         if [ $? -ne 0 ] ; then
3287                                 [ -n "${ERRMSG}" ] && echo "${ERRMSG}"
3288                                 fail "Unable to save copy of <${BOOTPART}>."
3289                         fi
3290 
3291                         # mount copy of old /boot partition 
3292                         LOBOOTDEV=$(lofiadm -a ${DDCOPY} 2>&1)
3293                         if [ $? -ne 0 ] ; then
3294                                 [ -n "${LOBOOTDEV}" ] && echo "${LOBOOTDEV}"
3295                                 fail "Unable to make lo-device <${DDCOPY}>"
3296                         fi
3297                         SOURCE_BOOT_DEV="${TMPDIR}/tmpbootdev.$$"
3298                         mkdir ${SOURCE_BOOT_DEV}
3299                         ERRMSG=$(mount -F pcfs ${LOBOOTDEV} \
3300                             ${SOURCE_BOOT_DEV})
3301                         if [ $? -ne 0 ] ; then
3302                                 [ -n "${ERRMSG}" ] && echo "${ERRMSG}"
3303                                 fail "Unable to mount lo-device <${LOBOOTDEV}>."
3304                         fi
3305 
3306                         # recreate existing boot partition with updated 
3307                         # boot files
3308 
3309                         # umount ${ROOT}'s /boot if mounted
3310 
3311                         BOOTMOUNTPT=$(mount | grep ${DISKID}p0:boot 2>&1 | \
3312                             awk '{print $1;}')
3313 
3314                         if [ -n "${BOOTMOUNTPT}" ] ; then
3315                                 echo "unmounting /dev/dsk/${DISKID}p0:boot"
3316                                 ERRMSG=$(umount \
3317                                     /dev/dsk/${DISKID}p0:boot 2>&1)
3318                                 if [ $? -ne 0 ] ; then
3319                                         [ -n "${ERRMSG}" ] && echo "${ERRMSG}"
3320                                         fail "Unable to umount X86 boot device."
3321                                 fi
3322                         fi
3323 
3324                         echo "Making new pcfs file system on ${DISKID}"
3325 
3326                         echo y | /usr/lib/fs/pcfs/mkfs -F pcfs \
3327                             -o S,s,B=$MDBOOT,b=BOOT,i=$STRAP \
3328                             /dev/rdsk/${DISKID}p0:boot >> ${LOGFILE} 2>&1
3329                         if [ $? -ne 0 ] ; then
3330                                 echo "Unable to make pcfs:"
3331                                 cat ${LOGFILE}
3332                                 fail ""
3333                         fi
3334 
3335                         echo "Copying x86 boot partition contents back\c"
3336                         echo " to new /boot fs."
3337 
3338                         OLD_PWD=$(pwd)
3339 
3340                         echo "Remounting freshened /boot partition"
3341 
3342                         if [ -z "${BOOTMOUNTPT}" ] ; then 
3343                                 # boot ptn wasn't mounted
3344                                 BOOTMOUNT="/tmp/bootpart"
3345                                 mkdir ${BOOTMOUNT}
3346                         else
3347                                 BOOTMOUNT=${BOOTMOUNTPT}
3348                         fi
3349 
3350                         ERRMSG=$(mount -F pcfs \
3351                             /dev/dsk/${DISKID}p0:boot ${BOOTMOUNT} 2>&1)
3352 
3353                         if [ $? -ne 0 ] ; then
3354                                 [ -n "${ERRMSG}" ] && echo "${ERRMSG}"
3355                                 fail "Unable to mount X86 boot device."
3356                         fi
3357 
3358                         # copy old /boot contents
3359                         cd ${SOURCE_BOOT_DEV}
3360                         find . -mount \! -type s -print | \
3361                             cpio -pcdum ${BOOTMOUNT} 2>&1 | \
3362                             ${LUBIN}/lustripcpioerr
3363 
3364                         if [ $? -ne 0 ] ; then
3365                                 fail "Unable to copy boot partition contents."
3366                         fi
3367 
3368                         cd ${OLD_PWD}
3369 
3370                         # unmount and rm our boot mount, if we created it
3371                         if [ -z "${BOOTMOUNTPT}" ] ; then
3372                                 ERRMSG=$(umount ${BOOTMOUNT} 2>&1)
3373                                 if [ $? -ne 0 ] ; then
3374                                         [ -n "${ERRMSG}" ] && echo "${ERRMSG}"
3375                                         fail "Unable to umount <$BOOTMOUNT>." 
3376                                 fi
3377                                 rm -rf ${BOOTMOUNT}
3378                         fi
3379 
3380                         # unmount, un-lofi, and rm SOURCE_BOOT_DEV
3381 
3382                         ERRMSG=$(umount ${SOURCE_BOOT_DEV} 2>&1)
3383                         if [ $? -ne 0 ] ; then
3384                                 [ -n "${ERRMSG}" ] && echo "${ERRMSG}"
3385                                 fail "Cannot umount lo-device <${LOBOOTDEV}>." 
3386                         fi
3387 
3388                         ERRMSG=$(lofiadm -d ${DDCOPY} 2>&1)
3389                         if [ $? -ne 0 ] ; then
3390                                 [ -n "${ERRMSG}" ] && echo "${ERRMSG}"
3391                                 fail "Cannot remove lo-device <${LOBOOTDEV}>." 
3392                         fi
3393                 
3394                         rm -rf ${SOURCE_BOOT_DEV}
3395 
3396                 done < ${TMP_FDFILE1}
3397                 rm ${TMP_FDFILE1} ${LOGFILE} ${DDCOPY}
3398 
3399         else
3400 
3401                 # non boot-partition: use installboot to get pboot and bootblk
3402                 echo "Updating /boot on Solaris partition."
3403 
3404                 if [ -z "${ROOT}" ] ; then SEARCH="/"; else SEARCH="${ROOT}"; fi
3405 
3406                 ROOTRAWDEV=$(mount | grep "^${SEARCH} on " | \
3407                     awk '{print $3}' | sed 's;/dsk;/rdsk;')
3408 
3409                 if [ -z "${ROOTRAWDEV}" ] ; then
3410                         [ -n "${ROOTRAWDEV}" && echo "${ROOTRAWDEV}" ] 
3411                         fail "${SEARCH} must be a mounted filesystem"
3412                 fi
3413 
3414                 echo "Updating Solaris partition ${ROOTRAWDEV} with installboot"
3415                 REQFILES="pboot bootblk"
3416                 for f in ${REQFILES}; do
3417                         if [ ! -f ${TMPDIR}/$f ]; then
3418                                 fail "Missing $f, aborting."
3419                         fi
3420                 done
3421                 PBOOT=${TMPDIR}/pboot
3422                 BOOTBLK=${TMPDIR}/bootblk
3423                 install_boot_i386 $PBOOT $BOOTBLK ${ROOTRAWDEV}
3424                 if [ $? -ne 0 ] ; then
3425                         fail "Unable to installboot to <${ROOTRAWDEV}>." 
3426                 fi
3427         fi
3428 }
3429 
3430 print "Verifying archives ..."
3431 
3432 for a in generic $allarchs $rootarchs
3433 do
3434         test -r $cpiodir/$a.root$ZFIX ||
3435                 fail "bfu archive $cpiodir/$a.root$ZFIX missing"
3436 done
3437 
3438 if [ ! -r $cpiodir/generic.lib$ZFIX -o ! -r $cpiodir/generic.kernel$ZFIX -o \
3439     ! -r $cpiodir/generic.sbin$ZFIX ]; then
3440         old_style_archives="true"
3441         $ZCAT $cpiodir/generic.root$ZFIX | cpio -it 2>/dev/null | \
3442             egrep -s '^etc/zones' && \
3443                 fail "bfu archive $cpiodir/generic.{kernel,lib,sbin}$ZFIX" \
3444                      "missing;\npossible mkbfu version mismatch: pre-zones" \
3445                      "style archives with zones files."
3446 fi
3447 
3448 for a in generic $allarchs $usrarchs
3449 do
3450         test -r $cpiodir/$a.usr$ZFIX ||
3451                 fail "bfu archive $cpiodir/$a.usr$ZFIX missing"
3452 done
3453 
3454 for root in $rootlist
3455 do
3456         cd $root || fail "Cannot cd $root"
3457         prologue=${root%/}/bfu.prologue
3458         if [ -f $prologue ]; then
3459                 print "Executing $prologue"
3460                 $prologue || fail "$prologue failed with code $?"
3461         fi
3462 done
3463 
3464 print "Performing basic sanity checks ..."
3465 
3466 for dir in $usr $rootlist
3467 do
3468         test -d $dir || fail "$dir does not exist"
3469         test -w $dir || fail "$dir is not writable"
3470         cd $dir || fail "Cannot cd $dir"
3471 done
3472 
3473 RM_32BIT_KERNEL=0;
3474 if [ "$karch" = "sun4u" ] &&
3475    ($ZCAT $cpiodir/sun4u.root$ZFIX | cpio -itv 2>&1 |
3476     grep "^l.*platform/sun4u/kernel/unix -> sparcv9/unix$" > /dev/null);
3477     then
3478         RM_32BIT_KERNEL=1;
3479         if [ "$force_override" = "no" ] && 
3480            (prtconf -F 2>&1 | egrep '(cgthree|bwtwo)' > /dev/null);
3481             then
3482                 print "\n\nERROR: You are upgrading to a 64-bit-only OS. " \
3483                       "Your frame buffer does not have a 64-bit driver and " \
3484                       "will not work after reboot.  To proceed you must run " \
3485                       "bfu with the -f flag.";
3486                 exit;
3487         fi;
3488 fi;
3489 
3490 if [ $plat = "SUNW,Ultra-1" ] && [ ! -f $cpiodir/SUNW,Ultra-1.root$ZFIX ] &&
3491    [ "$force_override" = "no" ];
3492    then
3493         print "\nERROR: These archives do not have Ultra-1 platform support." \
3494               "\nProceeding with this BFU may render this machine unbootable." \
3495               "\nTo proceed anyway, you must run bfu with the -f flag.\n";
3496         exit;
3497 fi;
3498 
3499 for root in $rootlist
3500 do
3501         rootprefix=${root%/}
3502         smf_check_repository
3503 done
3504 
3505 MINIMUM_OS_REV=9
3506 
3507 #
3508 # Perform additional sanity checks if we are upgrading the live system.
3509 #
3510 if [ "$rootlist" = "/" ]
3511 then
3512         #
3513         # Disallow from older releases
3514         #
3515         os_rev=`uname -r | sed -e s/5.//`
3516         if [ $os_rev -lt $MINIMUM_OS_REV -a "$force_override" = "no" ]; then
3517                 fail "Cannot bfu from pre-Solaris $MINIMUM_OS_REV"
3518         fi
3519 
3520         #
3521         # Filesystem space checks
3522         #
3523         set $root 4 $usr 6
3524         while [ $# -gt 0 ]
3525         do
3526                 test "`df -b $1 | tail -1 | nawk '{ print $2 }'`" -ge ${2}000 ||
3527                         fail "Less than $2 MB free on $1 -- bfu not safe."
3528                 shift 2
3529         done
3530         #
3531         # Disable kernel module unloading
3532         #
3533         print "Disabling kernel module unloading ... \c"
3534         test -x /usr/bin/adb || fail "/usr/bin/adb not found: bfu not safe."
3535         echo "moddebug/W20000" | adb -kw /dev/ksyms /dev/mem | grep moddebug
3536         #
3537         # Load modules and drivers here not to reload them when you access
3538         # /devices or its subdirectories later.
3539         #
3540         cut -d' ' -f1 /etc/name_to_major | while read driver
3541         do
3542                 modload -p drv/${driver} >/dev/null 2>&1
3543         done
3544         ls $cpiodir >>/dev/null           # loads elfexec and networking
3545 
3546         # exec/intpexec and sys/kaio are needed by lofi
3547         modload -p exec/intpexec >/dev/null 2>&1
3548         modload -p sys/kaio >/dev/null 2>&1
3549 
3550         #
3551         # Stop init(1M) so extraction/manipulation of inittab is safe.
3552         #
3553         print "Quiescing init ..."
3554         pstop 1
3555 
3556         # umount /lib/libc.so.1 if necessary
3557         if [ -n "`mount | grep '^/lib/libc.so.1'`" ]
3558         then
3559                 print "Unmounting /lib/libc.so.1 ..."
3560                 umount /lib/libc.so.1
3561         fi
3562 
3563         PLAT=`/usr/bin/uname -i`
3564         ARCH=`/usr/bin/uname -m`
3565         # umount /platform/$PLAT/lib/libc_psr.so.1 if necessary
3566         if [ -n "`mount | grep "^/platform/$PLAT/lib/libc_psr.so.1"`" ]
3567         then
3568                 print "Unmounting /platform/$PLAT/lib/libc_psr.so.1 ..."
3569                 umount /platform/$PLAT/lib/libc_psr.so.1
3570         else
3571                 # umount /platform/$ARCH/lib/libc_psr.so.1 if necessary
3572                 if [ -n "`mount | grep "^/platform/$ARCH/lib/libc_psr.so.1"`" ]
3573                 then
3574                         print "Unmounting /platform/$ARCH/lib/libc_psr.so.1 ..."
3575                         umount /platform/$ARCH/lib/libc_psr.so.1
3576                 fi
3577         fi
3578 
3579         # umount /platform/$PLAT/lib/sparcv9/libc_psr.so.1 if necessary
3580         if [ -n "`mount | grep "^/platform/$PLAT/lib/sparcv9/libc_psr.so.1"`" ]
3581         then
3582                 print "Unmounting /platform/$PLAT/lib/sparcv9/libc_psr.so.1 ..."
3583                 umount /platform/$PLAT/lib/sparcv9/libc_psr.so.1
3584         else
3585                 # umount /platform/$ARCH/lib/sparcv9/libc_psr.so.1 if necessary
3586                 if [ -n "`mount | grep \
3587                     "^/platform/$ARCH/lib/sparcv9/libc_psr.so.1"`" ]
3588                 then
3589                         print "Unmounting \c"
3590                         print "/platform/$ARCH/lib/sparcv9/libc_psr.so.1 ..."
3591                         umount /platform/$ARCH/lib/sparcv9/libc_psr.so.1
3592                 fi
3593         fi
3594 
3595         # umount /platform/sun4u-us3/lib/libc_psr.so.1 if necessary
3596         if [ -n "`mount | grep '^/platform/sun4u-us3/lib/libc_psr.so.1'`" ]
3597         then
3598                 print "Unmounting /platform/sun4u-us3/lib/libc_psr.so.1 ..."
3599                 umount /platform/sun4u-us3/lib/libc_psr.so.1
3600         fi
3601 
3602         # umount /platform/sun4u-us3/lib/sparcv9/libc_psr.so.1 if necessary
3603         if [ -n "`mount | grep '^/platform/sun4u-us3/lib/sparcv9/libc_psr.so.1'`" ]
3604         then
3605                 print "Unmounting /platform/sun4u-us3/lib/sparcv9/libc_psr.so.1 ..."
3606                 umount /platform/sun4u-us3/lib/sparcv9/libc_psr.so.1
3607         fi
3608 
3609         if [ -x /usr/sbin/zoneadm ]; then
3610                 #
3611                 # Stop any running zones: the init script will print a
3612                 # message if needed.
3613                 #
3614                 if [ -x /etc/init.d/zones ]; then
3615                         /etc/init.d/zones stop
3616                 elif [ -x /lib/svc/method/svc-zones ]; then
3617                         #
3618                         # Calling the zone service method directly is
3619                         # the most straightforward way to block until
3620                         # all zones are halted.  Finding a way that
3621                         # works once zones are made restartable is an
3622                         # exercise left to the reader.
3623                         #
3624                         /lib/svc/method/svc-zones stop
3625                 fi
3626 
3627                 [ -z `zoneadm list | grep -v global` ] || \
3628                     fail "zone(s) failed to halt"
3629                 #
3630                 # Determine the installed zones, which we will want to do
3631                 # after we're done with the global zone.  This is done now
3632                 # rather than later in case bfu'ing the global zone causes
3633                 # the zone configuration to become unreadable (e.g., via a
3634                 # DTD flag day).
3635                 #
3636                 zoneadm list -pi | nawk -F: '{
3637                         if ($3 == "installed") {
3638                                 printf "%s %s\n", $2, $4
3639                         }
3640                 }' > $local_zone_info_file
3641         fi
3642 
3643         #
3644         # Stop sendmail so that mail doesn't bounce during the interval
3645         # where /etc/mail/aliases is (effectively) empty.
3646         #
3647         # (note that unlike other services here, /etc/init.d/sendmail
3648         # remains post-smf(5) because it is a public interface.)
3649         #
3650         if [ -r /etc/svc/volatile/repository_door ]; then
3651                 print "Disabling sendmail temporarily ..."
3652                 svcadm disable -t network/smtp
3653         else
3654                 print "Killing sendmail ..."
3655                 /etc/init.d/sendmail stop
3656         fi
3657 
3658         print "Disabling remote logins ..."
3659         echo "bfu in progress -- remote logins disabled" >/etc/nologin
3660 
3661         #
3662         # Stop syslogd so it doesn't interfere with saving preserved files.
3663         #
3664         if [ -f /etc/init.d/syslog ]; then
3665                 print "Killing syslogd ..."
3666                 /etc/init.d/syslog stop
3667         elif [ -r /etc/svc/volatile/repository_door ]; then
3668                 print "Disabling syslog temporarily ..."
3669                 svcadm disable -t system/system-log
3670         fi
3671 
3672         #
3673         # Stop apache so it doesn't get upset when the entire world changes
3674         # out from underneath it.
3675         #
3676         if [ -f /etc/init.d/apache ]; then
3677                 print "Killing httpd ..."
3678                 /etc/init.d/apache stop
3679         elif [ -r /etc/svc/volatile/repository_door ]; then
3680                 print "Disabling httpd temporarily ..."
3681                 svcadm disable -t network/http
3682         fi
3683 
3684         #
3685         # Kill off fmd so it doesn't get upset when the entire world changes
3686         # out from underneath it.
3687         #
3688         if [ -f /etc/init.d/savecore ]; then
3689                 print "Killing fmd ..."
3690                 pkill -x fmd
3691         elif [ -r /etc/svc/volatile/repository_door ]; then
3692                 print "Disabling fmd temporarily ..."
3693                 svcadm disable -t system/fmd
3694         fi
3695 
3696         #
3697         # Stop nscd so it doesn't interfere with stuff.
3698         #
3699         if [ -x /etc/init.d/nscd ]; then
3700                 print "Killing nscd ..."
3701                 /etc/init.d/nscd stop
3702         elif [ -r /etc/svc/volatile/repository_door ]; then
3703                 print "Disabling nscd temporarily ..."
3704                 svcadm disable -t system/name-service-cache:default
3705         fi
3706 
3707         if grep -v "^#" $rootprefix/etc/vfstab | grep boot | \
3708                 grep "[         ]pcfs[  ]" >/dev/null 2>&1
3709         then
3710                 boot_is_pcfs=yes
3711         fi
3712 
3713         smf_new_profiles
3714 
3715 else
3716         #
3717         # Check ${root}/etc/motd for SunOS value to get `uname -r`
3718         #
3719         os_rev=`head -1 ${root}/etc/motd | sed -e 's/^.*SunOS //' | \
3720                 awk '{print $1}' | sed -e s/5.//`
3721         if [ $os_rev -lt $MINIMUM_OS_REV -a "$force_override" = "no" ]; then
3722                 fail "Cannot bfu from pre-Solaris $MINIMUM_OS_REV"
3723         fi
3724 fi
3725 
3726 export PATH=/tmp/bfubin:$PATH
3727 export LD_LIBRARY_PATH=/tmp/bfulib
3728 
3729 if [ -h /tmp/bfulib/64 ]
3730 then
3731         ldlib64="LD_LIBRARY_PATH_64=/tmp/bfulib/64"
3732         export LD_LIBRARY_PATH_64=/tmp/bfulib/64
3733 fi
3734 
3735 # turn off auxiliary filters, since they can cause objects to be loaded
3736 # from outside of the protected environment.
3737 export LD_NOAUXFLTR=1
3738 
3739 #
3740 # Since we've turned off auxiliary filters, libc_psr will normally not
3741 # be loaded at all.  But libc_psr was overriding broken code in libc
3742 # for over a week before the fix for 6324631, so we need to explicitly
3743 # LD_PRELOAD it to allow users to bfu from the broken libc.  This can be
3744 # removed once there are no sun4u machines bfued to Nevada bits between
3745 # 9/7/2005 and 9/15/2005.
3746 #
3747 if [ -f /tmp/bfulib/libc_psr.so.1 ]; then
3748         export LD_PRELOAD_32=/tmp/bfulib/libc_psr.so.1
3749 fi
3750 
3751 print "Turning on delayed i/o ..."
3752 fastfs -f $rootlist $usr
3753 fastfs $rootlist $usr
3754 
3755 #
3756 # The "| tee -a $EXTRACT_LOG" following do_extraction() is not pulled into the
3757 # function itself because it interferes with the cpio exit status detection.
3758 # pcfs boot is an exception, since its cpio exit status is expected to be bad,
3759 # so a heuristic must be employed to infer whether or not any errors occurred.
3760 #
3761 do_extraction() {
3762         compressed_archive=$1
3763         shift
3764         $ZCAT $compressed_archive | cpio -idmucB $* 2>&1 \
3765                 || extraction_error "extracting archive $1"
3766 }
3767 
3768 do_pcfs_boot_extraction() {
3769         PCFS_BOOT_LOG=/tmp/bfu-pcfs-boot-log.$$
3770         $ZCAT $1 | cpio -idmucB 2>&1 | grep -v "error.s" | \
3771                 grep -v "cpio: Cannot chown()" | \
3772                 grep -v "cpio: Error during chown()" | tee $PCFS_BOOT_LOG
3773         cat $PCFS_BOOT_LOG >> $EXTRACT_LOG
3774         egrep -s -v blocks $PCFS_BOOT_LOG
3775         if [ $? -eq 0 ]; then
3776                 extraction_error "extracting archive $1 ... see $PCFS_BOOT_LOG"
3777         else
3778                 rm -f $PCFS_BOOT_LOG
3779         fi
3780 }
3781 
3782 #
3783 # Usage: extract_archives (root|usr|lib|sbin|kernel) arch-list
3784 #
3785 extract_archives() {
3786         base=$1
3787         shift
3788         test $base = usr && cd $usrroot || cd $root
3789         for archive in $*
3790         do
3791                 print "Extracting $archive.$base$ZFIX ... \c" \
3792                         | tee -a $EXTRACT_LOG
3793                 test -h platform/$archive && rm platform/$archive
3794                 if [ $base = root ]; then
3795                         exclude="-f dev/fd home proc etc/mnttab"
3796                         [ -d system/contract ] &&
3797                                 exclude="$exclude system/contract"
3798                         [ -d system/object ] &&
3799                                 exclude="$exclude system/object"
3800                         [ -f etc/svc/repository.db ] &&
3801                                 exclude="$exclude etc/svc/repository.db"
3802                         [ -e etc/repository_door ] &&
3803                                 exclude="$exclude etc/repository_door"
3804                         [ -f etc/svc/volatile ] &&
3805                                 exclude="$exclude etc/svc/volatile"
3806                         do_extraction $cpiodir/$archive.$base$ZFIX $exclude |
3807                                 tee -a $EXTRACT_LOG
3808                 elif [ $base = usr ]; then
3809                         do_extraction $cpiodir/$archive.$base$ZFIX \
3810                                 -f "usr/openwin" | tee -a $EXTRACT_LOG
3811                 else
3812                         do_extraction $cpiodir/$archive.$base$ZFIX \
3813                                 | tee -a $EXTRACT_LOG
3814                 fi
3815         done
3816         cd $root
3817 }
3818 
3819 extract_boot_archives() {
3820         base=$1
3821         shift
3822         cd $root
3823         for archive in $*
3824         do
3825                 if [ ! -f $cpiodir/$archive.$base$ZFIX ]; then
3826                         continue
3827                 fi
3828                 print "Extracting $archive.$base$ZFIX ... \c" \
3829                         | tee -a $EXTRACT_LOG
3830                 if [ $boot_is_pcfs = yes ]; then
3831                         do_pcfs_boot_extraction $cpiodir/$archive.$base$ZFIX
3832                 else
3833                         do_extraction $cpiodir/$archive.$base$ZFIX | \
3834                                 tee -a $EXTRACT_LOG
3835                 fi
3836                 $ZCAT $cpiodir/$archive.$base$ZFIX | cpio -it 2>&1 | \
3837                     grep  "boot/solaris/devicedb/master" >/dev/null 2>&1
3838                 if [ "$?" = "0" ]; then
3839                         have_realmode=yes
3840                 fi
3841         done
3842         cd $root
3843 }
3844 
3845 #
3846 # Classic boot pboot and bootblk compatibility with old archives
3847 #
3848 setup_pboot()
3849 {
3850         NEWPBOOTDIR=$GATE/public/pboot
3851         NEWPBOOT=${NEWPBOOTDIR}/pboot
3852         NEWBOOTBLK=${NEWPBOOTDIR}/bootblk
3853         PBOOTDIR=$usr/platform/$karch/lib/fs/ufs
3854         PBOOT=${PBOOTDIR}/pboot
3855         BOOTBLK=${PBOOTDIR}/bootblk
3856 
3857         # they should already be there, but...
3858         if [ -f $NEWPBOOT -a ! -f $PBOOT ]; then
3859                 print "Installing pboot from $NEWPBOOTDIR"
3860                 cp $NEWPBOOT $PBOOT
3861         fi
3862         if [ -f $NEWBOOTBLK -a ! -f $BOOTBLK ]; then
3863                 print "Installing bootblk from $NEWPBOOTDIR"
3864                 cp $NEWBOOTBLK $BOOTBLK
3865         fi
3866 
3867         if [ -f $NEWPBOOT -a -f $PBOOT ]; then
3868                 LATEST=`ls -Lt $PBOOT $NEWPBOOT | head -1`
3869                 if [ "$LATEST" = "$NEWPBOOT" ]; then
3870                         print "Updating pboot from $NEWPBOOT"
3871                         cp $NEWPBOOT $PBOOT
3872                 fi
3873         fi
3874         if [ -f $NEWBOOTBLK -a -f $BOOTBLK ]; then
3875                 LATEST=`ls -Lt $BOOTBLK $NEWBOOTBLK | head -1`
3876                 if [ "$LATEST" = "$NEWBOOTBLK" ]; then
3877                         print "Updating bootblk from $NEWBOOTBLK"
3878                         cp $NEWBOOTBLK $BOOTBLK
3879                 fi
3880         fi
3881         if [[ "$rootslice" = /dev/rdsk/* ]]; then
3882                 print "Installing boot block."
3883                 ( cd $PBOOTDIR ;
3884                     install_boot_i386 ./pboot ./bootblk ${rootslice%??}s2 )
3885         fi
3886         #
3887         # Since /platform/i86pc/boot/solaris/boot.bin is moved
3888         # to /boot/solaris, remove the old one if it really
3889         # exists.
3890         #
3891         OLDBOOTDIR=${root}/platform/i86pc/boot/solaris
3892         OLDBOOTBIN=${OLDBOOTDIR}/boot.bin
3893         if [ ! -h ${OLDBOOTDIR} -a -f ${OLDBOOTBIN} ] ;
3894         then
3895                 print "Removing old boot.bin."
3896                 rm -rf ${OLDBOOTBIN}
3897         fi
3898 }
3899 
3900 #
3901 # Multiboot support
3902 #
3903 
3904 saved_boot_files="
3905         solaris/bootenv.rc
3906         solaris/devicedb/master
3907 "
3908 
3909 #
3910 # transition from multiboot to dca
3911 #
3912 check_multi_to_dca_boot()
3913 {
3914         bootdev=`grep p0:boot $rootprefix/etc/vfstab | \
3915                 grep pcfs | nawk '{print $1}'`
3916         if [ "$bootdev" != "" ]; then
3917                 is_pcfs_boot=yes
3918         fi
3919 
3920         if [ $is_pcfs_boot = yes ]; then
3921                 df -h | grep stubboot >/dev/null 2>&1
3922                 if [ $? -eq 0 ]; then
3923 
3924                         # save configurable files from /boot
3925                         # before remounting /stubboot.
3926                         # files are relative to /boot.
3927                         for file in $saved_boot_files
3928                         do
3929                                 dir="`dirname $rootprefix/stubboot/$file`"
3930                                 mkdir -p $dir
3931                                 cp $rootprefix/boot/$file $dir
3932                         done
3933 
3934                         echo "unmount $bootdev at $rootprefix/stubboot"
3935                         ERRMSG=$(umount $bootdev 2>&1)
3936                         if [ $? -ne 0 ] ; then
3937                                 [ -n "${ERRMSG}" ] && echo "${ERRMSG}"
3938                                 fail "Unable to umount $bootdev on $rootprefix/stubboot."
3939                         fi
3940 
3941                         # adjust vfstab
3942                         sed -e "s/[     ]\/stubboot[    ]/      \/boot  /" \
3943                             <$rootprefix/etc/vfstab >$rootprefix/etc/vfstab+
3944                         mv $rootprefix/etc/vfstab $rootprefix/etc/vfstab-
3945                         mv $rootprefix/etc/vfstab+ $rootprefix/etc/vfstab
3946 
3947                         ERRMSG=$(mount -F pcfs $bootdev $rootprefix/boot 2>&1)
3948                         if [ $? -ne 0 ] ; then
3949                                 [ -n "${ERRMSG}" ] && echo "${ERRMSG}"
3950                                 fail "Unable to mount $bootdev on $rootprefix/boot."
3951                         fi
3952                 fi
3953         fi
3954 }
3955 
3956 check_dca_to_multiboot()
3957 {
3958         # ensure bootpath is in $rootprefix/boot/solaris/bootenv.rc
3959         # It's ok to put a meta device path in there
3960         bootenvrc=$rootprefix/boot/solaris/bootenv.rc
3961         grep "^setprop[  ]*bootpath[     ]" $bootenvrc > /dev/null
3962         if [ $? != 0 ]; then
3963                 rootdev=`grep -v "^#" $rootprefix/etc/vfstab | \
3964                     grep "[      ]/[     ]" | nawk '{print $1}'`
3965                 bootpath=`ls -l $rootdev | nawk '{ print $NF }' |\
3966                     sed "s#../../devices##"`
3967                 echo "setprop bootpath '$bootpath'" >> $bootenvrc
3968         fi
3969 
3970         bootdev=`grep p0:boot $rootprefix/etc/vfstab | \
3971             grep pcfs | nawk '{print $1}'`
3972         if [ "$bootdev" != "" ]; then
3973                 is_pcfs_boot=yes
3974         fi
3975         if [ ! -f $rootprefix/boot/mdboot ]; then
3976                 return
3977         fi
3978         dca_to_multi=yes
3979         rm -f $rootprefix/boot/mdboot
3980 }
3981 
3982 #
3983 # Detect SVM root and return the list of raw devices under the mirror
3984 #
3985 get_rootdev_list()
3986 {
3987         metadev=`grep -v "^#" $rootprefix/etc/vfstab | \
3988                 grep "[  ]/[    ]" | nawk '{print $2}'`
3989         if [[ $metadev = /dev/rdsk/* ]]; then
3990                 rootdevlist=`echo "$metadev" | sed -e "s#/dev/rdsk/##"`
3991         elif [[ $metadev = /dev/md/rdsk/* ]]; then
3992                 metavol=`echo "$metadev" | sed -e "s#/dev/md/rdsk/##"`
3993                 rootdevlist=`metastat -p $metavol |\
3994                     grep -v "^$metavol[         ]" | nawk '{print $4}'`
3995         fi
3996         for rootdev in $rootdevlist
3997         do
3998                 echo /dev/rdsk/$rootdev
3999         done
4000 }
4001 
4002 #
4003 # Done once per transition from classic (dca) to multi boot
4004 #
4005 setup_stubboot()
4006 {
4007         bootdev=`grep -v "^#" $rootprefix/etc/vfstab | grep pcfs | \
4008                 grep "[         ]/boot[         ]"`
4009         if [[ -n $bootdev ]] ; then
4010 
4011                 bootdev=`echo "$bootdev" | nawk '{print $1}'`
4012                 rbootdev=`echo "$bootdev" | sed -e "s/dev\/dsk/dev\/rdsk/"`
4013 
4014                 # Remount boot partition as /stubboot, set up new /boot
4015                 mkdir -p $rootprefix/stubboot
4016 
4017                 ERRMSG=$(umount $bootdev 2>&1)
4018                 if [ $? -ne 0 ] ; then
4019                         [ -n "${ERRMSG}" ] && echo "${ERRMSG}"
4020                         fail "Unable to umount $bootdev."
4021                 fi
4022                 ERRMSG=$(mount -F pcfs $bootdev $rootprefix/stubboot 2>&1)
4023                 if [ $? -ne 0 ] ; then
4024                         [ -n "${ERRMSG}" ] && echo "${ERRMSG}"
4025                         fail "Unable to mount $bootdev on $rootprefix/stubboot."
4026                 fi
4027 
4028                 mkdir -p $rootprefix/boot
4029                 cp -r $rootprefix/stubboot/* $rootprefix/boot
4030         
4031                 # adjust /etc/vfstab
4032                 sed <$rootprefix/etc/vfstab \
4033                     -e "s/[     ]\/boot[        ]/      \/stubboot      /" | \
4034                         sed -n >$rootprefix/etc/vfstab+ '
4035                         /p0:boot/ {
4036                                 s/[     ]no/    yes/
4037                                 }
4038                                 p
4039                         '
4040 
4041                 mv $rootprefix/etc/vfstab $rootprefix/etc/vfstab-
4042                 mv $rootprefix/etc/vfstab+ $rootprefix/etc/vfstab
4043         fi
4044 }
4045 
4046 #
4047 # multiboot: install grub on the boot slice
4048 #
4049 install_grub()
4050 {
4051         STAGE1=$root/boot/grub/stage1
4052         STAGE2=$root/boot/grub/stage2
4053 
4054         if [ $is_pcfs_boot = no ]; then
4055                 get_rootdev_list | while read rootdev
4056                 do 
4057                         print "Install grub on $rootdev"
4058                         PATH=/tmp/bfubin /tmp/bfubin/installgrub \
4059                                 $STAGE1 $STAGE2 $rootdev
4060                 done
4061         else
4062                 # copy /boot grub & solaris to /stubboot
4063                 cp -r $rootprefix/boot/grub $rootprefix/stubboot/grub
4064                 cp -r $rootprefix/boot/solaris $rootprefix/stubboot/solaris
4065 
4066                 # Adjust grub paths relative to pcfs filesystem
4067                 rm -rf $rootprefix/stubboot/boot
4068                 mkdir -p $rootprefix/stubboot/boot
4069                 mv $rootprefix/stubboot/grub $rootprefix/stubboot/boot
4070                 mv $rootprefix/stubboot/solaris $rootprefix/stubboot/boot
4071 
4072                 #
4073                 # Run installgrub after copying stubboot to avoid overwriting
4074                 # /stubboot/boot/grub/stage2, which must stay untouched.
4075                 #
4076                 bootdev=`grep -v "^#" $rootprefix/etc/vfstab | grep pcfs | \
4077                         grep "[         ]/stubboot[     ]" | nawk '{print $1}'`
4078                 rbootdev=`echo "$bootdev" | sed -e "s/dev\/dsk/dev\/rdsk/"`
4079                 if [ "$rbootdev" != "" ]; then
4080                         print "Install grub on $rbootdev"
4081                         PATH=/tmp/bfubin /tmp/bfubin/installgrub $STAGE1 $STAGE2 $rbootdev
4082                 fi
4083         fi
4084 }
4085 
4086 get_biosdisk()
4087 {
4088         rootdev=$1
4089         rootphys=`ls -l $rootdev | nawk '{ print $NF }' | \
4090             sed -e "s/\.\.\/\.\.\/devices//" -e "s/:[abcdefgh],raw//"`
4091         rbootdev=`echo "$rootdev" | sed -e "s/s[0-7]/p0/"`
4092 
4093         #
4094         # Use biosdev to get the bios disk number
4095         #
4096         biosdisk=`biosdev | grep $rootphys | \
4097                 nawk '{print $1}' | sed -e "s/0x8//"`
4098 }
4099 
4100 #
4101 # multiboot: set up initial grub menu
4102 #
4103 update_grub_menu()
4104 {
4105         BOOT_PROG=/platform/i86pc/multiboot
4106         BOOT_ARCHIVE=/platform/i86pc/boot_archive
4107         MENU=$rootprefix/boot/grub/menu.lst
4108 
4109         grubhd=$1
4110 
4111         #
4112         # Append some useful entries to the existing menu
4113         #
4114         echo "Update GRUB menu $MENU with entries for $grubhd"
4115 
4116         grep ^default $MENU > /dev/null
4117         [ $? = 0 ] || echo "default=0" >> $MENU
4118         grep ^timeout $MENU > /dev/null
4119         [ $? = 0 ] || echo "timeout=10" >> $MENU
4120 
4121         echo "#serial --unit=0 --speed=9600" >> $MENU
4122         echo "#terminal serial" >> $MENU
4123         echo "#splashimage=$grubhd/boot/grub/splash.xpm.gz" >> $MENU
4124         echo "title Solaris" >> $MENU
4125         echo "  root $grubhd" >> $MENU
4126         echo "  kernel ${BOOT_PROG}" >> $MENU
4127         echo "  module ${BOOT_ARCHIVE}" >> $MENU
4128 
4129         echo "GRUB menu entry 'Solaris' boots to eeprom(1m) settings"
4130 
4131         if [ -f ${rootprefix}/boot/multiboot ] &&
4132             [ -f ${rootprefix}/boot/x86.miniroot-safe ] ; then
4133 
4134                 TTY=`grep "^setprop input-device" \
4135                     ${rootprefix}/boot/solaris/bootenv.rc | cut -f 2 -d \'`
4136                 if [ -z "${TTY}" ] ; then
4137                         TTY=`grep "^setprop console" \
4138                             ${rootprefix}/boot/solaris/bootenv.rc | \
4139                             cut -f 2 -d \'`
4140                 fi
4141 
4142                 if [ "${TTY}" = "ttya" ] || [ "${TTY}" = "ttyb" ] ; then
4143                         FS_CONSOLE="-B console=${TTY}"
4144                 fi
4145 
4146                 echo "title Solaris failsafe" >> $MENU
4147                 echo "  root $grubhd" >> $MENU
4148                 echo "  kernel /boot/multiboot kernel/unix $FS_CONSOLE -s" \
4149                     >> $MENU
4150                 echo "  module /boot/x86.miniroot-safe" >> $MENU
4151         fi
4152 }
4153 
4154 install_failsafe()
4155 {
4156         if [ ! -f /boot/multiboot -o ! -f /boot/x86.miniroot-safe ] && \
4157             [ -x ${GATEPATH}/public/bin/update_failsafe ] ; then
4158                 echo Updating boot/multiboot and boot/x86.miniroot-safe
4159                 ${GATEPATH}/public/bin/update_failsafe
4160         fi
4161 }
4162 
4163 setup_grub_menu()
4164 {
4165         BOOT_PROG=/platform/i86pc/multiboot
4166         BOOT_ARCHIVE=/platform/i86pc/boot_archive
4167         MENU=$rootprefix/boot/grub/menu.lst
4168 
4169         get_rootdev_list | while read rootdev
4170         do
4171                 rootphys=`ls -l $rootdev | nawk '{print $NF}' | \
4172                     sed -e "s/\.\.\/\.\.\/devices//"`
4173                 gslice=`echo "$rootphys" | cut -f 2 -d : | sed s/,raw//`
4174                 rootphys=`echo "$rootphys" | sed -e "s/:[abcdefgh],raw//"`
4175                 rbootdev=`echo "$rootdev" | sed -e "s/s[0-7]/p0/"`
4176 
4177                 #
4178                 # Wallow through fdisk to get the active partition number
4179                 # Partition numbering is zero-based
4180                 #
4181                 part=0
4182                 fdisk -W - $rbootdev | grep -v '^*' | grep -v '^$' | \
4183                 while read id act bhead bcyl ehead ecyl rsect numsect
4184                 do
4185                         # Find solaris partition, either older 130 or 191
4186                         if [ $id -eq "191" -o $id -eq "130" ] ; then
4187                                 break
4188                         fi
4189                         part=`expr "$part" + 1`
4190                 done
4191 
4192                 get_biosdisk $rootdev
4193                 grubhd="(hd${biosdisk},${part},${gslice})"
4194 
4195                 #
4196                 # update the grub menu if it doesn't exist or
4197                 # doesn't have usable boot entries
4198                 #
4199                 if [ -f $MENU ]; then
4200                         grep -v "^#" $MENU | grep $grubhd >/dev/null 2>&1
4201                         if [ $? -eq 1 ]; then
4202                                 update_grub_menu $grubhd
4203                         fi
4204                 else
4205                         update_grub_menu $grubhd
4206                 fi
4207         done
4208 }
4209 
4210 #
4211 # Build the multiboot boot archive
4212 #
4213 build_boot_archive()
4214 {
4215         echo "Create ${rootprefix}/platform/i86pc/boot_archive"
4216 
4217         #
4218         # We should be able to run bootadm here but that's a
4219         # little more complicated than one would think
4220         #bootadm_args=${rootprefix:+-R $rootprefix}
4221         #PATH=/tmp/bfubin /tmp/bfubin/bootadm update $bootadm_args
4222 
4223         cr_args=${rootprefix:+ -R $rootprefix}
4224         LD_LIBRARY_PATH=/tmp/bfulib PATH=/tmp/bfubin \
4225             /tmp/bfubin/ksh /tmp/bfubin/create_ramdisk $cr_args
4226 
4227         #
4228         # Disable the boot-archive service on the first boot
4229         # to silence complaints about new files
4230         # svccfg -s system/boot-archive setprop start/exec = true
4231 
4232         mkdir -p $rootprefix/bfu.conflicts/lib/svc/method
4233         cp $rootprefix/lib/svc/method/boot-archive \
4234             $rootprefix/bfu.conflicts/lib/svc/method/boot-archive
4235         cat >$rootprefix/lib/svc/method/boot-archive <<"EOF"
4236 #!/sbin/sh
4237 exit 0
4238 EOF
4239 
4240         cat >$rootprefix/etc/rc2.d/S99postbfu <<EOF
4241 #!/bin/sh
4242 #
4243 case "\$1" in
4244 'start')
4245         cp /bfu.conflicts/lib/svc/method/boot-archive /lib/svc/method/boot-archive
4246         chmod +x /lib/svc/method/boot-archive
4247         rm -f /etc/rc2.d/S99postbfu
4248         ;;
4249 *)
4250         echo "usage: \$0 start"
4251         exit 1
4252         ;;
4253 esac
4254 exit 0
4255 EOF
4256 
4257         chmod +x $rootprefix/etc/rc2.d/S99postbfu
4258         chmod +x $rootprefix/lib/svc/method/boot-archive
4259         chmod +x $rootprefix/bfu.conflicts/lib/svc/method/boot-archive
4260 }
4261 
4262 disable_boot_service()
4263 {
4264         svccfg -s system/boot-archive setprop start/exec = true
4265         cat >$rootprefix/lib/svc/method/boot-archive <<EOF
4266 #!/sbin/sh
4267 . /lib/svc/share/smf_include.sh
4268 . /lib/svc/share/fs_include.sh
4269 exit 0
4270 EOF
4271 }
4272 
4273 mondo_loop() {
4274         typeset pkgroot
4275         typeset pkg
4276         root=$1
4277         zone=$2
4278 
4279         # If the archives being installed contain i86pc.boot, 
4280         # check to see if it contains strap.com, one of the
4281         # four possibly-required booters.  If i86pc.boot does,
4282         # try to upgrade the realmode booters from the current 
4283         # archive set.
4284         #
4285         # Don't bother doing the upgrade for diskless bfu, as the boot
4286         # will be done with floppy or PXE, which must match the build
4287         # anyway (floppy must match or add_install_client must be 
4288         # rerun), and in any event we can't touch the boot bits
4289         # for diskless boot from here.  Also don't do this for
4290         # any zone but 'global'.
4291 
4292         cd $root || fail "Cannot cd $root"
4293         rootprefix=${root%/}
4294 
4295         if [ "$karch" = "i86pc" -a "$diskless" = "no" -a "$zone" = "global" ]
4296         then
4297                 remove_properties
4298                 if boot_is_upgradeable $root && \
4299                     [ -f $cpiodir/i86pc.boot$ZFIX ] && \
4300                     $ZCAT $cpiodir/i86pc.boot$ZFIX | cpio -it | \
4301                     grep strap.com >/dev/null 2>&1 ; then
4302                         check_multi_to_dca_boot
4303                         print "\nUpdating realmode boot loaders\n"
4304                         update_realmode_booters $root
4305                         setup_pboot
4306                 fi
4307                 if [ $multiboot_archives = yes ]; then
4308                         check_dca_to_multiboot
4309                         if [ $is_pcfs_boot = yes ]; then
4310                                 setup_stubboot
4311                         fi
4312                 fi
4313         fi
4314 
4315         SECONDS=0               # time each iteration
4316 
4317         print "\nSaving configuration files in $rootprefix/bfu.child ... \c"
4318         cd $root
4319         rm -rf bfu.default bfu.restore  # historical
4320         rm -rf bfu.child bfu.conflicts
4321         mkdir bfu.child bfu.conflicts
4322         filelist $zone | cpio -pdmu bfu.child || \
4323             fail 'failed to save config files'
4324         test -f etc/motd && mv etc/motd etc/motd.old
4325 
4326         #
4327         # If the var/sadm/system/admin/INST_RELEASE file still exists,
4328         # this system has never been bfu'd before.  Therefore, the
4329         # information in var/sadm/install/contents is still valid and
4330         # can be used to determine whether files have been modified
4331         # since installation (the bfu.ancestors directory serves this
4332         # purpose for systems that have already been bfu'd.)
4333         #
4334         if [ -f var/sadm/system/admin/INST_RELEASE ] ; then
4335                 firstbfu=yes
4336         else
4337                 firstbfu=no
4338         fi
4339 
4340         #
4341         # bfu'ed systems are not upgradeable; prevent suninstall from
4342         # even *presenting* the upgrade option by removing INST_RELEASE.
4343         #
4344         rm -f var/sadm/system/admin/INST_RELEASE
4345 
4346         #
4347         # Hacks to work around minor annoyances and make life more pleasant.
4348         # Part 1 of 2: pre-archive-extraction stuff
4349         #
4350 
4351         #
4352         # Do not remove remove_initd_links, since this makes sure things
4353         # work properly when init scripts are shuffled around.
4354         #
4355         remove_initd_links
4356 
4357         #
4358         # Remove rc.d scripts and things made superfluous by smf.
4359         # Backwards BFUs will resurrect them from the archives.
4360         #
4361         smf_cleanup
4362 
4363         #
4364         # New, enabled-by-default services need to be checked for, such
4365         # that their enabled status is not flipped by BFU after their
4366         # initial arrival.
4367         #
4368         smf_handle_new_services
4369 
4370         #
4371         # Remove obsolete disassembler module
4372         #
4373         if [ $target_isa = sparc ]; then 
4374                 rm -rf $usr/lib/mdb/disasm/*
4375                 rm -f $root/kernel/kmdb/sparcv9/sparc
4376         fi
4377 
4378         #
4379         # Remove obsolete Sun-Fire-880 (daktari) FMA Fault Tree directory
4380         # and file.  Backwards BFUs will resurrect them from the archives.
4381         #
4382         if [ $target_isa = sparc ]; then
4383                 rm -rf $usr/platform/SUNW,Sun-Fire-880/lib/fm
4384         fi
4385 
4386         #
4387         # Remove old FMA dictionary files
4388         #
4389         rm -f $usr/lib/fm/FMD.dict
4390         rm -f $usr/lib/fm/SUN4U.dict
4391         rm -f $usr/lib/fm/SUNOS.dict
4392 
4393         #
4394         # Remove old FMA .eft files and directories
4395         #
4396         rm -f $usr/platform/sun4u/lib/fm/eft/pci-sun4u.eft
4397         rm -rf $usr/platform/SUNW,Serverblade1/lib/fm
4398         rm -rf $usr/platform/SUNW,Sun-Fire/lib/fm
4399         rm -rf $usr/platform/SUNW,Sun-Fire-15000/lib/fm
4400 
4401         #
4402         # Remove old topology data
4403         #
4404         rm -rf $usr/lib/fm/topo
4405 
4406         #
4407         # Remove old prtopo and obsoleted include file.
4408         #
4409         rm -f $usr/include/fm/libtopo_enum.h
4410         rm -f $usr/lib/fm/prtopo
4411 
4412         #
4413         # Remove obsolete buildmnttab script.  Backwards BFUs will
4414         # resurrect it by extracting it from the archives.
4415         #
4416         rm -f $root/etc/init.d/buildmnttab
4417         rm -f $root/etc/rcS.d/S70buildmnttab.sh
4418 
4419         #
4420         # Break-up of inetsvc, inetinit & network -- remove both the old
4421         # and new init scripts.  The correct ones will be extracted from
4422         # the archives whether bfu'ing backwards or forwards.
4423         #
4424         # old: need to remove going forwards:
4425         #
4426         rm -f $root/etc/rc0.d/K42inetsvc
4427         rm -f $root/etc/rc1.d/K42inetsvc
4428         rm -f $root/etc/rcS.d/K42inetsvc
4429         rm -f $root/etc/rcS.d/S29network.sh
4430         #
4431         # new: need to remove going backwards:
4432         #
4433         rm -f $root/etc/init.d/domainname
4434         rm -f $root/etc/init.d/inetd
4435         rm -f $root/etc/init.d/named
4436         rm -f $root/etc/init.d/nodename
4437         rm -f $root/etc/rc0.d/K40inetd
4438         rm -f $root/etc/rc0.d/K42named
4439         rm -f $root/etc/rc1.d/K40inetd
4440         rm -f $root/etc/rc1.d/K42named
4441         rm -f $root/etc/rc2.d/S69domainname
4442         rm -f $root/etc/rc2.d/S72named
4443         rm -f $root/etc/rc2.d/S77inetd
4444         rm -f $root/etc/rcS.d/K40inetd
4445         rm -f $root/etc/rcS.d/K42named
4446         rm -f $root/etc/rcS.d/S28network.sh
4447         rm -f $root/etc/rcS.d/S29nodename.sh
4448 
4449         #
4450         # Remove Zones init scripts: they will be extracted properly
4451         # going forwards; after going backwards, they will be gone,
4452         # thus preventing scary warnings on subsequent bfu's.
4453         #
4454         rm -f $root/etc/init.d/zones
4455         rm -f $root/etc/rc0.d/K01zones
4456         rm -f $root/etc/rc1.d/K01zones
4457         rm -f $root/etc/rc2.d/K01zones
4458         rm -f $root/etc/rc3.d/S99zones
4459         rm -f $root/etc/rcS.d/K01zones
4460 
4461         #
4462         # Remove <inet>6 STREAMS modules; these no longer exist (and
4463         # should never have existed in the first place).
4464         #
4465         rm -f $root/kernel/strmod/icmp6         \
4466             $root/kernel/strmod/ip6             \
4467             $root/kernel/strmod/tcp6            \
4468             $root/kernel/strmod/udp6            \
4469 
4470         rm -f $root/kernel/strmod/sparcv9/icmp6 \
4471             $root/kernel/strmod/sparcv9/ip6     \
4472             $root/kernel/strmod/sparcv9/tcp6    \
4473             $root/kernel/strmod/sparcv9/udp6    \
4474 
4475         #
4476         # Remove old ZFS binaries (back when it was three modules)
4477         #
4478         find $root/kernel/drv -name zpool | xargs rm -f
4479         rm -f $root/kernel/drv/zpool.conf
4480         rm -f $root/kernel/drv/zpool.cache
4481 
4482         find $root/kernel/drv -name zvol | xargs rm -f
4483         rm -f $root/kernel/drv/zvol.conf
4484 
4485         #
4486         # Remove /usr/lib/old_libthread since support for it has
4487         # been removed from the kernel in Solaris 10.  If this is
4488         # a backwards BFU, it will all be extracted again by cpio.
4489         rm -rf $usr/lib/old_libthread
4490 
4491         # Remove libconfig 
4492         rm -f $usr/lib/drv/config_md.so.1
4493         rm -f $usr/include/config_md.h
4494         # remove libssd
4495         rm -f $usr/lib/libssd.a
4496         rm -f $usr/lib/libssd.so
4497         rm -f $usr/lib/libssd.so.1
4498         # remove libap
4499         rm -f $usr/lib/libap_dmd.a
4500         rm -f $usr/lib/libap_dmd.so.1
4501         # remove libintpos
4502         rm -f $usr/lib/libintpos.a
4503         rm -f $usr/lib/libintpos.so.1
4504 
4505         # Remove obsolete abi subdirectories
4506         if [ -d $usr/platform/*/lib/abi ]; then
4507                 rm -rf $usr/platform/*/lib/abi
4508         fi
4509         rm -rf $usr/lib/gss/abi
4510         rm -rf $usr/lib/krb5/abi
4511         rm -rf $usr/xpg4/lib/abi
4512         rm -rf $usr/ucblib/abi
4513 
4514         #
4515         # Remove old stuff related to libthread now that libthread has
4516         # been folded into libc and libthread_db has been renamed libc_db.
4517         # In addition, all the apptrace's tracing libraries (i.e., abi_*.so*)
4518         # are no longer needed, should be removed.
4519         rm -f   \
4520             $usr/lib/mdb/proc/libthread.so                      \
4521             $usr/lib/mdb/proc/sparcv9/libthread.so              \
4522             $usr/lib/abi/abi_*.so*              \
4523             $usr/lib/abi/sparcv9/abi_*.so*
4524 
4525         #
4526         # Remove the old symlink /lib => usr/lib, if necessary.
4527         # /lib is now a real directory in the root filesystem.
4528         # Remove all of the old static libraries and commands now
4529         # that we no longer build them.  If this is a backwards
4530         # BFU, all this will all be extracted again by cpio.
4531         rm $root/lib 2>/dev/null
4532         rm -rf $usr/lib/pics
4533         rm -rf $usr/sbin/static
4534         rm -f   \
4535             $usr/ccs/lib/libcurses.a                    \
4536             $usr/ccs/lib/libform.a                      \
4537             $usr/ccs/lib/libgen.a                       \
4538             $usr/ccs/lib/libl.a                         \
4539             $usr/ccs/lib/libmalloc.a                    \
4540             $usr/ccs/lib/libmenu.a                      \
4541             $usr/ccs/lib/libpanel.a                     \
4542             $usr/ccs/lib/libtermcap.a                   \
4543             $usr/ccs/lib/libtermlib.a                   \
4544             $usr/ccs/lib/liby.a                         \
4545             $usr/lib/lib300.a                           \
4546             $usr/lib/lib300s.a                          \
4547             $usr/lib/lib4014.a                          \
4548             $usr/lib/lib450.a                           \
4549             $usr/lib/libTL.a                            \
4550             $usr/lib/libadm.a                           \
4551             $usr/lib/libadt_jni.a                       \
4552             $usr/lib/libbsdmalloc.a                     \
4553             $usr/lib/libbsm.a                           \
4554             $usr/lib/libc.a                             \
4555             $usr/lib/libc2.a                            \
4556             $usr/lib/libc2stubs.a                       \
4557             $usr/lib/libcmd.a                           \
4558             $usr/lib/libcrypt.a                         \
4559             $usr/lib/libcrypt_d.a                       \
4560             $usr/lib/libcrypt_i.a                       \
4561             $usr/lib/libcurses.a                        \
4562             $usr/lib/libdevid.a                         \
4563             $usr/lib/libdevinfo.a                       \
4564             $usr/lib/libdhcpagent.a                     \
4565             $usr/lib/libdhcputil.a                      \
4566             $usr/lib/libdl_stubs.a                      \
4567             $usr/lib/libefi.a                           \
4568             $usr/lib/libelf.a                           \
4569             $usr/lib/libform.a                          \
4570             $usr/lib/libgen.a                           \
4571             $usr/lib/libgenIO.a                         \
4572             $usr/lib/libike.a                           \
4573             $usr/lib/libinetcfg.a                       \
4574             $usr/lib/libinetutil.a                      \
4575             $usr/lib/libintl.a                          \
4576             $usr/lib/libkstat.a                         \
4577             $usr/lib/libl.a                             \
4578             $usr/lib/libldfeature.a                     \
4579             $usr/lib/libmail.a                          \
4580             $usr/lib/libmalloc.a                        \
4581             $usr/lib/libmapmalloc.a                     \
4582             $usr/lib/libmenu.a                          \
4583             $usr/lib/libmeta.a                          \
4584             $usr/lib/libmp.a                            \
4585             $usr/lib/libnisdb.a                         \
4586             $usr/lib/libnls.a                           \
4587             $usr/lib/libnsl.a                           \
4588             $usr/lib/libnss_compat.a                    \
4589             $usr/lib/libnss_dns.a                       \
4590             $usr/lib/libnss_files.a                     \
4591             $usr/lib/libnss_nis.a                       \
4592             $usr/lib/libnss_nisplus.a                   \
4593             $usr/lib/libp/libc.a                        \
4594             $usr/lib/libpam.a                           \
4595             $usr/lib/libpanel.a                         \
4596             $usr/lib/libplot.a                          \
4597             $usr/lib/librac.a                           \
4598             $usr/lib/libresolv.a                        \
4599             $usr/lib/librpcsvc.a                        \
4600             $usr/lib/libsec.a                           \
4601             $usr/lib/libsendfile.a                      \
4602             $usr/lib/libsocket.a                        \
4603             $usr/lib/libstraddr.a                       \
4604             $usr/lib/libtermcap.a                       \
4605             $usr/lib/libtermlib.a                       \
4606             $usr/lib/libuuid.a                          \
4607             $usr/lib/libvolmgt.a                        \
4608             $usr/lib/libvt0.a                           \
4609             $usr/lib/libw.a                             \
4610             $usr/lib/liby.a                             \
4611             $usr/lib/null.a                             \
4612             $usr/lib/sparcv9/libadt_jni.a               \
4613             $usr/lib/sparcv9/libinetutil.a              \
4614             $usr/lib/sparcv9/libldfeature.a             \
4615             $usr/lib/sparcv9/libsendfile.a              \
4616             $usr/platform/sun4u/lib/libwrsmconf.a       \
4617             $usr/ucblib/libcurses.a                     \
4618             $usr/ucblib/libdbm.a                        \
4619             $usr/ucblib/libtermcap.a                    \
4620             $usr/ucblib/libucb.a
4621 
4622         #
4623         # Remove other obsolete files, too
4624         rm -f   \
4625             $usr/include/table.h                        \
4626             $usr/include/libgenIO.h                     \
4627             $usr/lib/llib-lTL                           \
4628             $usr/lib/llib-lTL.ln
4629 
4630         #
4631         # libc_psr.so.1 and libmd5_psr.so.1 have been moved
4632         # from /usr/platform/*/lib to /platform/*/lib.
4633         # Remove the old files and their containing directories
4634         rm -f $usr/platform/*/lib/libc_psr.so.1
4635         rm -f $usr/platform/*/lib/sparcv9/libc_psr.so.1
4636         rm -f $usr/platform/*/lib/libmd5_psr.so.1
4637         rm -f $usr/platform/*/lib/sparcv9/libmd5_psr.so.1
4638         rmdir $usr/platform/*/lib/sparcv9 2>/dev/null
4639         rmdir $usr/platform/*/lib 2>/dev/null
4640 
4641         #
4642         # Remove obsolete profile libc symlinks
4643         rm -f $usr/lib/libp/libc.so
4644         rm -f $usr/lib/libp/sparcv9/libc.so
4645 
4646         #
4647         # Remove Legacy DR files, now obsolete due to NGDR Phase II putback
4648         #
4649         STARFIRE_PLAT=platform/SUNW,Ultra-Enterprise-10000 
4650                 rm -f \
4651                 $root/$STARFIRE_PLAT/kernel/drv/dr              \
4652                 $root/$STARFIRE_PLAT/kernel/drv/dr.conf         \
4653                 $root/$STARFIRE_PLAT/kernel/misc/drmach         \
4654                 $root/$STARFIRE_PLAT/kernel/drv/sparcv9/dr      \
4655                 $root/$STARFIRE_PLAT/kernel/misc/sparcv9/drmach \
4656                 $root/$STARFIRE_PLAT/lib/dr_daemon              \
4657                 $usr/platform/sun4u/include/sys/dr.h    \
4658                 $usr/platform/sun4u/include/sys/sfdr.h
4659 
4660         # Solstice Enterprise Agent(SEA) : mib-II subagent mibiisa
4661         # needs to be disabled during startup. SMA(System Management Agent)
4662         # has the capability to support mib-II requests.
4663         # The correct ones will be extracted from
4664         # the archives whether bfu'ing backwards or forwards.
4665         #
4666         # old: need to remove going forwards:
4667         rm -f $root/etc/snmp/conf/mibiisa.rsrc
4668         #
4669         # new: need to remove going backwards:
4670         rm -f $root/etc/snmp/conf/mibiisa.rsrc-
4671 
4672         # remove old terminal emulator module:
4673         # (renamed from 'terminal-emulator' to 'tem')
4674         #
4675         # old: need to remove going forwards:
4676         rm -f $root/kernel/misc/terminal-emulator
4677         rm -f $root/kernel/misc/amd64/terminal-emulator
4678         #
4679         # new: need to remove going backwards:
4680         rm -f $root/kernel/misc/tem
4681         rm -f $root/kernel/misc/amd64/tem
4682         rm -f $root/kernel/misc/sparcv9/tem
4683 
4684         #
4685         # Remove /dev/mc symlink and /platform/sun4u/kernel/drv/mc-us3.conf
4686         # if any.
4687         #
4688         if [ -h $root/dev/mc ]; then
4689                 rm -f $root/dev/mc
4690         fi
4691 
4692         if [ -f $root/platform/sun4u/kernel/drv/mc-us3.conf ]; then
4693                 rm -f $root/platform/sun4u/kernel/drv/mc-us3.conf
4694         fi
4695 
4696         #
4697         # Remove the snowbird sbin and include symlinks
4698         #
4699 
4700         if [[ -h $usr/platform/SUNW,Netra-CP2300/sbin ]] ; then
4701                 rm -f $usr/platform/SUNW,Netra-CP2300/sbin
4702         fi
4703 
4704         if [[ -h $usr/platform/SUNW,Netra-CP2300/include ]] ; then
4705                 rm -f $usr/platform/SUNW,Netra-CP2300/include
4706         fi
4707 
4708         # If we still have the old lp(7D) driver, remove it and its symlinks
4709         # and header file. (If driver already gone, don't trample new symlinks.)
4710         #
4711         if [ -f $root/platform/i86pc/kernel/drv/lp -a \
4712             -h $root/dev/lp[012] ]; then
4713                 rm -f $root/dev/lp[012]
4714         fi
4715         rm -f $root/platform/i86pc/kernel/drv/lp.conf
4716         rm -f $root/platform/i86pc/kernel/drv/lp
4717         rm -f $root/usr/include/sys/lp.h
4718 
4719         #
4720         # Remove V880 CPU DR files, program cancelled
4721         #
4722         DAKTARI_PLAT=platform/SUNW,Sun-Fire-880
4723                 rm -f \
4724                 $root/$DAKTARI_PLAT/kernel/drv/gptwo.conf       \
4725                 $root/$DAKTARI_PLAT/kernel/drv/sparcv9/bbc      \
4726                 $root/$DAKTARI_PLAT/kernel/drv/sparcv9/gptwo    \
4727                 $root/$DAKTARI_PLAT/kernel/misc/sparcv9/sbdp    \
4728                 $usr/platform/sun4u/include/sys/sbdp.h
4729 
4730         #
4731         # Remove crash(1M), now obsoleted by mdb(1).  If this is a backwards
4732         # BFU, it will be extracted again by cpio.
4733         #
4734         rm -f $root/etc/crash $usr/sbin/crash $usr/sbin/i86/crash \
4735             $usr/sbin/sparcv7/crash $usr/sbin/sparcv9/crash
4736 
4737         #
4738         # Remove kadb(1M), now obsoleted by kmdb(1M)
4739         #
4740         rm -f $root/platform/*/kadb
4741 
4742         #
4743         # Remove old platform dmod symlinks
4744         #
4745         for dir in $usr/platform/*/lib/mdb ; do
4746                 [[ -h $dir ]] && rm -f $dir
4747         done
4748 
4749         #
4750         # Remove ADB macros
4751         #
4752         rm -fr $usr/lib/adb
4753 
4754         for dir in $usr/platform/*/lib/adb ; do
4755                 rm -fr $dir
4756         done
4757 
4758         #
4759         # Remove the SGENV driver from the Sun-Fire directory structure.
4760         # If this is a backwards BFU, it will be extracted again by cpio.
4761         #
4762         SERENGETI_PLAT=platform/SUNW,Sun-Fire
4763         rm -f $root/$SERENGETI_PLAT/kernel/drv/sgenv.conf \
4764             $root/$SERENGETI_PLAT/kernel/drv/sparcv9/sgenv
4765 
4766         #
4767         # Remove sun4m
4768         #
4769         rm -rf $root/platform/sun4m
4770         rm -rf $usr/platform/sun4m
4771         if [ $target_isa = sparc ]; then
4772                 rm -f $root/kernel/genunix
4773         fi
4774         rm -f $root/kernel/drv/xbox
4775         rm -f $usr/include/sys/comvec.h
4776         rm -f $usr/include/sys/openprom.h
4777         rm -f $usr/include/sys/cg14io.h
4778         rm -f $usr/include/sys/cg14reg.h
4779         rm -f $usr/include/sys/cg8reg.h
4780         rm -f $usr/include/sys/cg8var.h
4781 
4782         #
4783         # Remove perl 5.005_03.  If this is a backwards bfu,
4784         # it will be extracted again by cpio.
4785         #
4786         if [[ -d $usr/perl5/5.00503 ]]; then
4787                 remove_perl_500503
4788         fi
4789 
4790         #
4791         # Remove perl 5.8.3, but only if the generic.usr archive contains 5.8.4.
4792         # If this is a backwards bfu, 5.8.3 will be extracted again by cpio.
4793         #
4794         if [[ -d $usr/perl5/5.8.3 ]] && $ZCAT $cpiodir/generic.usr$ZFIX | \
4795             cpio -it 2>/dev/null |  egrep -s '^usr/perl5/5.8.4/'; then
4796                 remove_perl_583
4797         fi
4798 
4799         #
4800         # Clean up legacy versions of the FMA CPU/Mem DE which may be still
4801         # be laying around.  This check may be removed when a sufficient time
4802         # has lapsed between the FMA putback as to ensure that no test machines
4803         # still have development FMA bits.
4804         #
4805         for platdir in $usr/platform/SUNW,* ; do
4806                 [[ -h $platdir ]] && continue
4807 
4808                 rm -f $platdir/lib/fm/fmd/plugins/cpumem-diagnosis.so
4809                 rm -f $platdir/lib/fm/fmd/plugins/cpumem-diagnosis.conf 
4810         done
4811 
4812         # Remove pam_unix
4813         #
4814         rm -f $usr/lib/security/pam_unix.so.1
4815         rm -f $usr/lib/security/pam_unix.so
4816         rm -f $usr/lib/security/sparcv9/pam_unix.so.1
4817         rm -f $usr/lib/security/sparcv9/pam_unix.so
4818 
4819         #
4820         # Remove libldap.so.3
4821         #
4822         rm -f $usr/lib/libldap.so.3
4823         rm -f $usr/lib/sparcv9/libldap.so.3
4824 
4825         #
4826         # Remove nss XFN support no longer used by printing
4827         #
4828         sed -e '/printers:/s/xfn[  ]*//' \
4829                 $rootprefix/bfu.child/etc/nsswitch.conf > /tmp/nssw.$$
4830         cp /tmp/nssw.$$ $rootprefix/bfu.child/etc/nsswitch.conf
4831         rm -f /tmp/nssw.$$
4832         rm -f $usr/lib/nss_xfn.so.1
4833         rm -f $usr/lib/sparcv9/nss_xfn.so.1
4834 
4835         #
4836         # Remove FNS/XFN.
4837         #
4838         if [ -d $rootprefix/etc/fn -o \
4839              -d $usr/include/xfn -o \
4840              -d $usr/lib/fn -o \
4841              -d $rootprefix/var/fn ]; then
4842                 remove_eof_fns
4843         fi
4844 
4845         #
4846         # Remove AT&T FACE
4847         #
4848         if [ -d $usr/oasys -o -d $usr/vmsys ]; then
4849                 remove_eof_face
4850         fi
4851 
4852         #
4853         # Remove ASET
4854         #
4855         if [ -d $usr/aset ]; then
4856                 remove_eof_aset
4857         fi
4858 
4859         #
4860         # Remove BIND 8, but only if the generic.usr archive doesn't contains
4861         # BIND 8 named server/tools. If this is a backwards bfu, BIND 8 will
4862         # be extracted again by cpio.
4863         #
4864         if [[ -f $usr/sbin/dnskeygen ]] && ! $ZCAT $cpiodir/generic.usr$ZFIX \
4865             | cpio -it 2>/dev/null |  egrep -s '^usr/sbin/ndc' ; then
4866                 remove_eof_bind8
4867         fi
4868 
4869         #
4870         # Remove any sendmailvars: line from /etc/nsswitch.conf
4871         #
4872         sed -e '/^sendmailvars:/d' $rootprefix/bfu.child/etc/nsswitch.conf > \
4873                 /tmp/nssw.$$
4874         cp /tmp/nssw.$$ $rootprefix/bfu.child/etc/nsswitch.conf
4875         rm -f /tmp/nssw.$$
4876 
4877         #
4878         # Remove SUNWcoff package
4879         #
4880         pkgroot=${rootprefix:+-R $rootprefix}
4881         pkg=SUNWcoff
4882         if [ $target_isa = i386 ]; then
4883                 if pkginfo $pkgroot -q $pkg; then
4884                         pkgrm $pkgroot -n $pkg >/dev/null 2>&1
4885                 fi
4886 
4887                 # In case that did not work, do it manually.
4888                 if [ -d $rootprefix/var/sadm/pkg/$pkg ]; then
4889                         rm -rf $rootprefix/var/sadm/pkg/$pkg
4890                         rm $rootprefix/kernel/exec/coffexec
4891                 fi
4892         fi
4893 
4894         #
4895         # Remove GMT* zoneinfo files
4896         #
4897         rm -f $usr/share/lib/zoneinfo/GMT-12
4898         rm -f $usr/share/lib/zoneinfo/GMT-11
4899         rm -f $usr/share/lib/zoneinfo/GMT-10
4900         rm -f $usr/share/lib/zoneinfo/GMT-9
4901         rm -f $usr/share/lib/zoneinfo/GMT-8
4902         rm -f $usr/share/lib/zoneinfo/GMT-7
4903         rm -f $usr/share/lib/zoneinfo/GMT-6
4904         rm -f $usr/share/lib/zoneinfo/GMT-5
4905         rm -f $usr/share/lib/zoneinfo/GMT-4
4906         rm -f $usr/share/lib/zoneinfo/GMT-3
4907         rm -f $usr/share/lib/zoneinfo/GMT-2
4908         rm -f $usr/share/lib/zoneinfo/GMT-1
4909         rm -f $usr/share/lib/zoneinfo/GMT+1
4910         rm -f $usr/share/lib/zoneinfo/GMT+2
4911         rm -f $usr/share/lib/zoneinfo/GMT+3
4912         rm -f $usr/share/lib/zoneinfo/GMT+4
4913         rm -f $usr/share/lib/zoneinfo/GMT+5
4914         rm -f $usr/share/lib/zoneinfo/GMT+6
4915         rm -f $usr/share/lib/zoneinfo/GMT+7
4916         rm -f $usr/share/lib/zoneinfo/GMT+8
4917         rm -f $usr/share/lib/zoneinfo/GMT+9
4918         rm -f $usr/share/lib/zoneinfo/GMT+10
4919         rm -f $usr/share/lib/zoneinfo/GMT+11
4920         rm -f $usr/share/lib/zoneinfo/GMT+12
4921         rm -f $usr/share/lib/zoneinfo/GMT+13
4922 
4923         # Remove stc(7d)-related files
4924         rm -f $usr/include/sys/stcio.h
4925         rm -f $usr/include/sys/stcvar.h
4926         rm -f $usr/include/sys/stcreg.h
4927         rm -f $usr/include/sys/stcconf.h
4928         SUN4U_DRV=platform/sun4u/kernel/drv
4929         rm -f $rootprefix/$SUN4U_DRV/stc.conf
4930         rm -f $rootprefix/$SUN4U_DRV/stc
4931         rm -f $rootprefix/$SUN4U_DRV/sparcv9/stc
4932 
4933         # Remove old CPC adb macros.
4934         rm -f $usr/lib/adb/cpc_ctx
4935         rm -f $usr/lib/adb/cpc_event
4936         if [ $target_isa = sparc ]; then
4937             rm -f $usr/lib/adb/sparcv9/cpc_ctx
4938             rm -f $usr/lib/adb/sparcv9/cpc_event
4939         fi;
4940 
4941         # Remove obsolete DTrace demos
4942         rm -f $usr/demo/dtrace/cputick.d
4943 
4944         # Remove flashprom-related files.
4945         if [ $target_isa = sparc ]; then
4946             for x in $FLASHPROMLIST
4947             do
4948                 rm -f $root/$x;
4949             done
4950         fi;
4951 
4952         if [ $RM_32BIT_KERNEL -eq 1 -a $zone = global ];
4953         then
4954             print "Removing 32-bit commands and kernel binaries ... \c";
4955             rm -rf \
4956                 $usr/bin/sparcv7/amt \
4957                 $usr/bin/sparcv7/cputrack \
4958                 $usr/bin/sparcv7/newtask \
4959                 $usr/bin/sparcv7/nohup \
4960                 $usr/bin/sparcv7/pargs \
4961                 $usr/bin/sparcv7/pcred \
4962                 $usr/bin/sparcv7/pfiles \
4963                 $usr/bin/sparcv7/pflags \
4964                 $usr/bin/sparcv7/pldd \
4965                 $usr/bin/sparcv7/plimit \
4966                 $usr/bin/sparcv7/pmap \
4967                 $usr/bin/sparcv7/ppgsz \
4968                 $usr/bin/sparcv7/ppriv \
4969                 $usr/bin/sparcv7/prctl \
4970                 $usr/bin/sparcv7/preap \
4971                 $usr/bin/sparcv7/prex \
4972                 $usr/bin/sparcv7/prstat \
4973                 $usr/bin/sparcv7/prun \
4974                 $usr/bin/sparcv7/ps \
4975                 $usr/bin/sparcv7/psig \
4976                 $usr/bin/sparcv7/pstack \
4977                 $usr/bin/sparcv7/pstop \
4978                 $usr/bin/sparcv7/ptime \
4979                 $usr/bin/sparcv7/ptree \
4980                 $usr/bin/sparcv7/pwait \
4981                 $usr/bin/sparcv7/pwdx \
4982                 $usr/bin/sparcv7/setuname \
4983                 $usr/bin/sparcv7/sort \
4984                 $usr/bin/sparcv7/tnfxtract \
4985                 $usr/bin/sparcv7/uptime \
4986                 $usr/bin/sparcv7/w \
4987                 $usr/sbin/sparcv7/intrstat \
4988                 $usr/sbin/sparcv7/lockstat \
4989                 $usr/sbin/sparcv7/prtconf \
4990                 $usr/sbin/sparcv7/swap \
4991                 $usr/sbin/sparcv7/sysdef \
4992                 $usr/sbin/sparcv7/whodo \
4993                 $root/kernel/dacf/consconfig_dacf \
4994                 $root/kernel/drv/arp \
4995                 $root/kernel/drv/audiocs \
4996                 $root/kernel/drv/audioens \
4997                 $root/kernel/drv/bofi \
4998                 $root/kernel/drv/bpp \
4999                 $root/kernel/drv/clone \
5000                 $root/kernel/drv/cn \
5001                 $root/kernel/drv/conskbd \
5002                 $root/kernel/drv/consms \
5003                 $root/kernel/drv/dad \
5004                 $root/kernel/drv/devinfo \
5005                 $root/kernel/drv/ecpp \
5006                 $root/kernel/drv/ehci \
5007                 $root/kernel/drv/esp \
5008                 $root/kernel/drv/fas \
5009                 $root/kernel/drv/fcip \
5010                 $root/kernel/drv/fcp \
5011                 $root/kernel/drv/fp \
5012                 $root/kernel/drv/glm \
5013                 $root/kernel/drv/hid \
5014                 $root/kernel/drv/hme \
5015                 $root/kernel/drv/hubd \
5016                 $root/kernel/drv/icmp \
5017                 $root/kernel/drv/icmp6 \
5018                 $root/kernel/drv/ifp \
5019                 $root/kernel/drv/ip \
5020                 $root/kernel/drv/ip6 \
5021                 $root/kernel/drv/ippctl \
5022                 $root/kernel/drv/ipsecah \
5023                 $root/kernel/drv/ipsecesp \
5024                 $root/kernel/drv/isp \
5025                 $root/kernel/drv/iwscn \
5026                 $root/kernel/drv/keysock \
5027                 $root/kernel/drv/le \
5028                 $root/kernel/drv/lebuffer \
5029                 $root/kernel/drv/llc1 \
5030                 $root/kernel/drv/lofi \
5031                 $root/kernel/drv/log \
5032                 $root/kernel/drv/md \
5033                 $root/kernel/drv/mm \
5034                 $root/kernel/drv/mpt \
5035                 $root/kernel/drv/nca \
5036                 $root/kernel/drv/ohci \
5037                 $root/kernel/drv/openeepr \
5038                 $root/kernel/drv/options \
5039                 $root/kernel/drv/pcata \
5040                 $root/kernel/drv/pcelx \
5041                 $root/kernel/drv/pcic \
5042                 $root/kernel/drv/pcmem \
5043                 $root/kernel/drv/pcram \
5044                 $root/kernel/drv/pcs \
5045                 $root/kernel/drv/pcser \
5046                 $root/kernel/drv/pem \
5047                 $root/kernel/drv/pln \
5048                 $root/kernel/drv/poll \
5049                 $root/kernel/drv/pseudo \
5050                 $root/kernel/drv/ptc \
5051                 $root/kernel/drv/ptsl \
5052                 $root/kernel/drv/qlc \
5053                 $root/kernel/drv/random \
5054                 $root/kernel/drv/rts \
5055                 $root/kernel/drv/sad \
5056                 $root/kernel/drv/scsa2usb \
5057                 $root/kernel/drv/scsi_vhci \
5058                 $root/kernel/drv/sd \
5059                 $root/kernel/drv/se \
5060                 $root/kernel/drv/ses \
5061                 $root/kernel/drv/sgen \
5062                 $root/kernel/drv/soc \
5063                 $root/kernel/drv/socal \
5064                 $root/kernel/drv/spdsock \
5065                 $root/kernel/drv/ssd \
5066                 $root/kernel/drv/st \
5067                 $root/kernel/drv/stp4020 \
5068                 $root/kernel/drv/sy \
5069                 $root/kernel/drv/sysmsg \
5070                 $root/kernel/drv/tcp \
5071                 $root/kernel/drv/tcp6 \
5072                 $root/kernel/drv/tl \
5073                 $root/kernel/drv/uata \
5074                 $root/kernel/drv/udp \
5075                 $root/kernel/drv/udp6 \
5076                 $root/kernel/drv/ugen \
5077                 $root/kernel/drv/usb_ac \
5078                 $root/kernel/drv/usb_as \
5079                 $root/kernel/drv/usb_mid \
5080                 $root/kernel/drv/usbprn \
5081                 $root/kernel/drv/usbser_edge \
5082                 $root/kernel/drv/usoc \
5083                 $root/kernel/drv/wc \
5084                 $root/kernel/exec/aoutexec \
5085                 $root/kernel/exec/elfexec \
5086                 $root/kernel/exec/intpexec \
5087                 $root/kernel/fs/autofs \
5088                 $root/kernel/fs/cachefs \
5089                 $root/kernel/fs/devfs \
5090                 $root/kernel/fs/fifofs \
5091                 $root/kernel/fs/hsfs \
5092                 $root/kernel/fs/lofs \
5093                 $root/kernel/fs/mntfs \
5094                 $root/kernel/fs/nfs \
5095                 $root/kernel/fs/procfs \
5096                 $root/kernel/fs/sockfs \
5097                 $root/kernel/fs/specfs \
5098                 $root/kernel/fs/tmpfs \
5099                 $root/kernel/fs/udfs \
5100                 $root/kernel/fs/ufs \
5101                 $root/kernel/ipp/dlcosmk \
5102                 $root/kernel/ipp/dscpmk \
5103                 $root/kernel/ipp/flowacct \
5104                 $root/kernel/ipp/ipgpc \
5105                 $root/kernel/ipp/tokenmt \
5106                 $root/kernel/ipp/tswtclmt \
5107                 $root/kernel/misc/amsrc1 \
5108                 $root/kernel/misc/audiosup \
5109                 $root/kernel/misc/busra \
5110                 $root/kernel/misc/consconfig \
5111                 $root/kernel/misc/dada \
5112                 $root/kernel/misc/des \
5113                 $root/kernel/misc/diaudio \
5114                 $root/kernel/misc/fctl \
5115                 $root/kernel/misc/fssnap_if \
5116                 $root/kernel/misc/gld \
5117                 $root/kernel/misc/hidparser \
5118                 $root/kernel/misc/hpcsvc \
5119                 $root/kernel/misc/ipc \
5120                 $root/kernel/misc/kbtrans \
5121                 $root/kernel/misc/kgss/do_kmech_krb5 \
5122                 $root/kernel/misc/kgss/gl_kmech_krb5 \
5123                 $root/kernel/misc/kgssapi \
5124                 $root/kernel/misc/klmmod \
5125                 $root/kernel/misc/klmops \
5126                 $root/kernel/misc/krtld \
5127                 $root/kernel/misc/md5 \
5128                 $root/kernel/misc/md_hotspares \
5129                 $root/kernel/misc/md_mirror \
5130                 $root/kernel/misc/md_notify \
5131                 $root/kernel/misc/md_raid \
5132                 $root/kernel/misc/md_sp \
5133                 $root/kernel/misc/md_stripe \
5134                 $root/kernel/misc/md_trans \
5135                 $root/kernel/misc/mixer \
5136                 $root/kernel/misc/mpxio \
5137                 $root/kernel/misc/nfs_dlboot \
5138                 $root/kernel/misc/nfssrv \
5139                 $root/kernel/misc/pcicfg \
5140                 $root/kernel/misc/pcihp \
5141                 $root/kernel/misc/phx \
5142                 $root/kernel/misc/rpcsec \
5143                 $root/kernel/misc/rpcsec_gss \
5144                 $root/kernel/misc/rsmops \
5145                 $root/kernel/misc/scsi \
5146                 $root/kernel/misc/seg_drv \
5147                 $root/kernel/misc/seg_mapdev \
5148                 $root/kernel/misc/sha1 \
5149                 $root/kernel/misc/strplumb \
5150                 $root/kernel/misc/swapgeneric \
5151                 $root/kernel/misc/tlimod \
5152                 $root/kernel/misc/ufs_log \
5153                 $root/kernel/misc/usba \
5154                 $root/kernel/misc/usbser \
5155                 $root/kernel/sched/TS \
5156                 $root/kernel/sched/TS_DPTBL \
5157                 $root/kernel/strmod/6to4tun \
5158                 $root/kernel/strmod/arp \
5159                 $root/kernel/strmod/atun \
5160                 $root/kernel/strmod/authmd5h \
5161                 $root/kernel/strmod/authsha1 \
5162                 $root/kernel/strmod/bufmod \
5163                 $root/kernel/strmod/connld \
5164                 $root/kernel/strmod/dedump \
5165                 $root/kernel/strmod/drcompat \
5166                 $root/kernel/strmod/encr3des \
5167                 $root/kernel/strmod/encraes \
5168                 $root/kernel/strmod/encrbfsh \
5169                 $root/kernel/strmod/encrdes \
5170                 $root/kernel/strmod/icmp \
5171                 $root/kernel/strmod/ip \
5172                 $root/kernel/strmod/ipsecah \
5173                 $root/kernel/strmod/ipsecesp \
5174                 $root/kernel/strmod/keysock \
5175                 $root/kernel/strmod/ldterm \
5176                 $root/kernel/strmod/ms \
5177                 $root/kernel/strmod/nca \
5178                 $root/kernel/strmod/pckt \
5179                 $root/kernel/strmod/pfmod \
5180                 $root/kernel/strmod/pipemod \
5181                 $root/kernel/strmod/ptem \
5182                 $root/kernel/strmod/redirmod \
5183                 $root/kernel/strmod/rpcmod \
5184                 $root/kernel/strmod/rts \
5185                 $root/kernel/strmod/tcp \
5186                 $root/kernel/strmod/timod \
5187                 $root/kernel/strmod/tirdwr \
5188                 $root/kernel/strmod/ttcompat \
5189                 $root/kernel/strmod/tun \
5190                 $root/kernel/strmod/udp \
5191                 $root/kernel/strmod/usb_ah \
5192                 $root/kernel/strmod/usbkbm \
5193                 $root/kernel/strmod/usbms \
5194                 $root/kernel/sys/c2audit \
5195                 $root/kernel/sys/doorfs \
5196                 $root/kernel/sys/inst_sync \
5197                 $root/kernel/sys/kaio \
5198                 $root/kernel/sys/msgsys \
5199                 $root/kernel/sys/nfs \
5200                 $root/kernel/sys/pipe \
5201                 $root/kernel/sys/pset \
5202                 $root/kernel/sys/rpcmod \
5203                 $root/kernel/sys/semsys \
5204                 $root/kernel/sys/shmsys \
5205                 $root/platform/SUNW,Ultra-250/kernel/drv/envctrltwo \
5206                 $root/platform/SUNW,Ultra-250/kernel/misc/platmod \
5207                 $root/platform/SUNW,Ultra-4/kernel/drv/envctrl \
5208                 $root/platform/SUNW,Ultra-4/kernel/misc/platmod \
5209                 $root/platform/SUNW,Ultra-5_10/kernel/misc/platmod \
5210                 $root/platform/SUNW,Ultra-80/kernel/misc/platmod \
5211                 $root/platform/SUNW,Ultra-Enterprise-10000/kernel/cpu/SUNW,UltraSPARC \
5212                 $root/platform/SUNW,Ultra-Enterprise-10000/kernel/cpu/SUNW,UltraSPARC-II \
5213                 $root/platform/SUNW,Ultra-Enterprise-10000/kernel/drv/cvc \
5214                 $root/platform/SUNW,Ultra-Enterprise-10000/kernel/drv/cvcredir \
5215                 $root/platform/SUNW,Ultra-Enterprise-10000/kernel/drv/idn \
5216                 $root/platform/SUNW,Ultra-Enterprise-10000/kernel/drv/ngdr \
5217                 $root/platform/SUNW,Ultra-Enterprise-10000/kernel/drv/pcipsy \
5218                 $root/platform/SUNW,Ultra-Enterprise-10000/kernel/drv/rootnex \
5219                 $root/platform/SUNW,Ultra-Enterprise-10000/kernel/drv/sbus \
5220                 $root/platform/SUNW,Ultra-Enterprise-10000/kernel/misc/ngdrmach \
5221                 $root/platform/SUNW,Ultra-Enterprise-10000/kernel/misc/platmod \
5222                 $root/platform/SUNW,Ultra-Enterprise-10000/kernel/unix \
5223                 $root/platform/SUNW,Ultra-Enterprise/kernel/drv/ac \
5224                 $root/platform/SUNW,Ultra-Enterprise/kernel/drv/central \
5225                 $root/platform/SUNW,Ultra-Enterprise/kernel/drv/environ \
5226                 $root/platform/SUNW,Ultra-Enterprise/kernel/drv/fhc \
5227                 $root/platform/SUNW,Ultra-Enterprise/kernel/drv/simmstat \
5228                 $root/platform/SUNW,Ultra-Enterprise/kernel/drv/sram \
5229                 $root/platform/SUNW,Ultra-Enterprise/kernel/drv/sysctrl \
5230                 $root/platform/SUNW,Ultra-Enterprise/kernel/misc/platmod \
5231                 $root/platform/sun4u/boot.conf \
5232                 $root/platform/sun4u/kernel/cpu/SUNW,UltraSPARC \
5233                 $root/platform/sun4u/kernel/cpu/SUNW,UltraSPARC-II \
5234                 $root/platform/sun4u/kernel/cpu/SUNW,UltraSPARC-III \
5235                 $root/platform/sun4u/kernel/cpu/SUNW,UltraSPARC-III+ \
5236                 $root/platform/sun4u/kernel/cpu/SUNW,UltraSPARC-IIIi \
5237                 $root/platform/sun4u/kernel/cpu/SUNW,UltraSPARC-IIe \
5238                 $root/platform/sun4u/kernel/cpu/SUNW,UltraSPARC-IIi \
5239                 $root/platform/sun4u/kernel/cpu/SUNW,UltraSPARC-IV \
5240                 $root/platform/sun4u/kernel/drv/bwtwo \
5241                 $root/platform/sun4u/kernel/drv/cgsix \
5242                 $root/platform/sun4u/kernel/drv/cgthree \
5243                 $root/platform/sun4u/kernel/drv/cpc \
5244                 $root/platform/sun4u/kernel/drv/db21554 \
5245                 $root/platform/sun4u/kernel/drv/dma \
5246                 $root/platform/sun4u/kernel/drv/ebus \
5247                 $root/platform/sun4u/kernel/drv/fd \
5248                 $root/platform/sun4u/kernel/drv/ledma \
5249                 $root/platform/sun4u/kernel/drv/memtest \
5250                 $root/platform/sun4u/kernel/drv/pci_pci \
5251                 $root/platform/sun4u/kernel/drv/pcipsy \
5252                 $root/platform/sun4u/kernel/drv/power \
5253                 $root/platform/sun4u/kernel/drv/rootnex \
5254                 $root/platform/sun4u/kernel/drv/sbbc \
5255                 $root/platform/sun4u/kernel/drv/sbus \
5256                 $root/platform/sun4u/kernel/drv/sbusmem \
5257                 $root/platform/sun4u/kernel/drv/sf \
5258                 $root/platform/sun4u/kernel/drv/simba \
5259                 $root/platform/sun4u/kernel/drv/su \
5260                 $root/platform/sun4u/kernel/drv/tod \
5261                 $root/platform/sun4u/kernel/drv/trapstat \
5262                 $root/platform/sun4u/kernel/drv/zs \
5263                 $root/platform/sun4u/kernel/drv/zsh \
5264                 $root/platform/sun4u/kernel/genunix \
5265                 $root/platform/sun4u/kernel/misc/bootdev \
5266                 $root/platform/sun4u/kernel/misc/cpr \
5267                 $root/platform/sun4u/kernel/misc/forthdebug \
5268                 $root/platform/sun4u/kernel/misc/kgss/do_kmech_krb5 \
5269                 $root/platform/sun4u/kernel/misc/kgss/gl_kmech_krb5 \
5270                 $root/platform/sun4u/kernel/misc/md5 \
5271                 $root/platform/sun4u/kernel/misc/obpsym \
5272                 $root/platform/sun4u/kernel/misc/pcmcia \
5273                 $root/platform/sun4u/kernel/misc/platmod \
5274                 $root/platform/sun4u/kernel/misc/vis \
5275                 $root/platform/sun4u/kernel/strmod/kb \
5276                 $root/platform/sun4u/kernel/sys/cpc \
5277                 $root/platform/sun4u/kernel/tod/todmostek \
5278                 $root/platform/sun4u/kernel/tod/todstarfire \
5279                 $usr/include/v7/sys/mon_clock.h \
5280                 $usr/kernel/drv/dump \
5281                 $usr/kernel/drv/fssnap \
5282                 $usr/kernel/drv/gen_drv \
5283                 $usr/kernel/drv/kstat \
5284                 $usr/kernel/drv/ksyms \
5285                 $usr/kernel/drv/llc2 \
5286                 $usr/kernel/drv/lo \
5287                 $usr/kernel/drv/lockstat \
5288                 $usr/kernel/drv/logindmux \
5289                 $usr/kernel/drv/pm \
5290                 $usr/kernel/drv/pshot \
5291                 $usr/kernel/drv/ptm \
5292                 $usr/kernel/drv/pts \
5293                 $usr/kernel/drv/rsm \
5294                 $usr/kernel/drv/sppp \
5295                 $usr/kernel/drv/sppptun \
5296                 $usr/kernel/drv/sysevent \
5297                 $usr/kernel/drv/tidg \
5298                 $usr/kernel/drv/tivc \
5299                 $usr/kernel/drv/tmux \
5300                 $usr/kernel/drv/tnf \
5301                 $usr/kernel/drv/vol \
5302                 $usr/kernel/drv/winlock \
5303                 $usr/kernel/exec/javaexec \
5304                 $usr/kernel/fs/fdfs \
5305                 $usr/kernel/fs/namefs \
5306                 $usr/kernel/fs/pcfs \
5307                 $usr/kernel/sched/FSS \
5308                 $usr/kernel/sched/FX \
5309                 $usr/kernel/sched/FX_DPTBL \
5310                 $usr/kernel/sched/IA \
5311                 $usr/kernel/sched/RT \
5312                 $usr/kernel/sched/RT_DPTBL \
5313                 $usr/kernel/strmod/cryptmod \
5314                 $usr/kernel/strmod/lmodb \
5315                 $usr/kernel/strmod/lmode \
5316                 $usr/kernel/strmod/lmodr \
5317                 $usr/kernel/strmod/lmodt \
5318                 $usr/kernel/strmod/rlmod \
5319                 $usr/kernel/strmod/spppasyn \
5320                 $usr/kernel/strmod/spppcomp \
5321                 $usr/kernel/strmod/sppptun \
5322                 $usr/kernel/strmod/telmod \
5323                 $usr/kernel/sys/acctctl \
5324                 $usr/kernel/sys/exacctsys \
5325                 $usr/kernel/sys/sysacct \
5326                 $usr/lib/gss/mech_spnego.so \
5327                 $usr/lib/gss/mech_spnego.so.1 \
5328                 $usr/lib/mdb/kvm/cpc.so \
5329                 $usr/lib/mdb/kvm/genunix.so \
5330                 $usr/lib/mdb/kvm/ip.so \
5331                 $usr/lib/mdb/kvm/ipc.so \
5332                 $usr/lib/mdb/kvm/ipp.so \
5333                 $usr/lib/mdb/kvm/isp.so \
5334                 $usr/lib/mdb/kvm/krtld.so \
5335                 $usr/lib/mdb/kvm/lofs.so \
5336                 $usr/lib/mdb/kvm/logindmux.so \
5337                 $usr/lib/mdb/kvm/mdb_ks.so \
5338                 $usr/lib/mdb/kvm/nca.so \
5339                 $usr/lib/mdb/kvm/nfs.so \
5340                 $usr/lib/mdb/kvm/ptm.so \
5341                 $usr/lib/mdb/kvm/random.so \
5342                 $usr/lib/mdb/kvm/sd.so \
5343                 $usr/lib/mdb/kvm/sppp.so \
5344                 $usr/lib/mdb/kvm/ssd.so \
5345                 $usr/lib/mdb/kvm/ufs_log.so \
5346                 $usr/lib/mdb/kvm/usba.so \
5347                 $usr/lib/sparcv9/gss/mech_spnego.so \
5348                 $usr/lib/sparcv9/gss/mech_spnego.so.1 \
5349                 $usr/platform/SUNW,Ultra-1 \
5350                 $usr/platform/SUNW,Ultra-250/doc \
5351                 $usr/platform/SUNW,Ultra-250/lib/flash-update.sh \
5352                 $usr/platform/SUNW,Ultra-250/lib/prom \
5353                 $usr/platform/SUNW,Ultra-Enterprise-10000/doc \
5354                 $usr/platform/SUNW,Ultra-Enterprise-10000/lib/flash-update.sh \
5355                 $usr/platform/SUNW,Ultra-Enterprise-10000/lib/prom \
5356                 $usr/platform/sun4u/lib/mdb/kvm/unix.so \
5357                 $usr/platform/sun4u/lib/prom/SUNW,Ultra-1 > /dev/null 2>&1;
5358                 print "done.";
5359         fi;
5360 
5361         #
5362         # Remove kmdbmod from /kernel
5363         #
5364         rm -f $root/kernel/misc/sparcv9/kmdbmod
5365 
5366         #
5367         # Remove obsolete drivers/header files as a result of sun4v source
5368         # code reorg
5369         #
5370         rm -f $root/platform/sun4u/kernel/drv/sparcv9/pci_pci
5371         rm -f $root/platform/sun4u/kernel/misc/sparcv9/pcmcia
5372         rm -f $usr/include/v9/sys/traptrace.h
5373         rm -f $usr/platform/sun4u/include/sys/spitasi.h
5374         rm -f $usr/kernel/pcbe/sparcv9/pcbe.SUNW,UltraSPARC-T1
5375 
5376         #
5377         # Remove the IPsec encryption and authentication modules.
5378         # IPsec now uses the Kernel Crypto Framework for crypto.
5379         #
5380         rm -f $rootprefix/kernel/strmod/encr3des
5381         rm -f $rootprefix/kernel/strmod/encrdes
5382         rm -f $rootprefix/kernel/strmod/encrbfsh
5383         rm -f $rootprefix/kernel/strmod/encraes
5384         rm -f $rootprefix/kernel/strmod/authmd5h
5385         rm -f $rootprefix/kernel/strmod/authsha1
5386         rm -f $rootprefix/kernel/strmod/sparcv9/encr3des
5387         rm -f $rootprefix/kernel/strmod/sparcv9/encrdes
5388         rm -f $rootprefix/kernel/strmod/sparcv9/encrbfsh
5389         rm -f $rootprefix/kernel/strmod/sparcv9/encraes
5390         rm -f $rootprefix/kernel/strmod/sparcv9/authmd5h
5391         rm -f $rootprefix/kernel/strmod/sparcv9/authsha1
5392 
5393         #
5394         # Remove obsolete SSA utility, firmware and fcode.
5395         # usr/lib/firmware/ssa contains ssafirmware 
5396         #
5397         rm -rf $usr/lib/firmware/ssa
5398         rm -f $usr/lib/firmware/fc_s/fc_s_fcode
5399         rm -f $usr/sbin/ssaadm
5400 
5401         #
5402         # Remove seg_drv, seg_mapdev driver
5403         #
5404         rm -f $root/kernel/misc/seg_drv
5405         rm -f $root/kernel/misc/sparcv9/seg_drv
5406         rm -f $usr/include/sys/seg_drv.h
5407         rm -f $root/kernel/misc/seg_mapdev
5408         rm -f $root/kernel/misc/sparcv9/seg_mapdev
5409 
5410         #
5411         # Remove mpxio module
5412         #
5413         rm -f $root/kernel/misc/sparcv9/mpxio
5414 
5415         #
5416         # Remove mpxio/vhci adb macros.
5417         #
5418         if [ $target_isa = sparc -a $zone = global ]; then
5419                 rm -f $usr/lib/adb/mdi_client
5420                 rm -f $usr/lib/adb/sparcv9/mdi_client
5421                 rm -f $usr/lib/adb/mdi_pathinfo
5422                 rm -f $usr/lib/adb/sparcv9/mdi_pathinfo
5423                 rm -f $usr/lib/adb/mdi_phci
5424                 rm -f $usr/lib/adb/sparcv9/mdi_phci
5425                 rm -f $usr/lib/adb/mdi_vhci
5426                 rm -f $usr/lib/adb/sparcv9/mdi_vhci
5427                 rm -f $usr/lib/adb/scsi_vhci_pkt
5428                 rm -f $usr/lib/adb/sparcv9/scsi_vhci_pkt
5429                 rm -f $usr/lib/adb/scsi_vhci_softstate
5430                 rm -f $usr/lib/adb/sparcv9/scsi_vhci_softstate
5431         fi
5432 
5433         #
5434         # new: need to remove going backwards:
5435         #
5436         # Diskless clients have already extracted /usr so don't delete this
5437         # Non-global zones never extracts /usr so don't delete these
5438         #
5439         if [ $diskless = no -a $zone = global ]; then
5440                 rm -f $usr/sbin/stmsboot
5441         fi
5442         rm -f $root/lib/mpxio/mpxio
5443         rm -f $root/lib/mpxio/stmsboot_util
5444 
5445         #
5446         # Remove rpcib misc module (converted to driver)
5447         #
5448         rm -f $root/kernel/misc/sparcv9/rpcib
5449         rm -f $root/kernel/drv/sparcv9/rpcib
5450 
5451         #
5452         # Remove old smartcard header files
5453         #
5454 
5455         rm -f \
5456                 $usr/include/smartcard.h \
5457                 $usr/include/smartcard/ocf_authenticate.h \
5458                 $usr/include/smartcard/ocf_core.h \
5459                 $usr/include/smartcard/ocf_core_cardservices.h
5460 
5461         #
5462         # Remove smartcard libraries that should not have been shipped.
5463         #
5464         rm -rf  $usr/lib/smartcard/sparcv9/ \
5465                 $usr/share/lib/smartcard/scmtester.jar
5466 
5467         #
5468         # Remove external smartcard reader driver
5469         #
5470         rm -f $usr/share/lib/smartcard/scmrsr3.jar
5471 
5472         #
5473         # Remove old internal smartcard reader driver
5474         #
5475         rm -f $usr/share/lib/smartcard/scmiscr.jar
5476         rm -f $usr/lib/smartcard/libSCMI2CNative.so
5477         rm -f $usr/lib/smartcard/libSCMI2CNative.so.1
5478 
5479         #
5480         # Remove Smart OS
5481         #
5482         rm -f $usr/share/lib/smartcard/smartos.jar
5483 
5484         #
5485         # Remove drivers & header files for EOL of soc & pln drivers
5486         # as per PSARC/2003/233
5487         #
5488         rm -f $root/kernel/drv/pln.conf
5489         rm -f $root/kernel/drv/sparcv9/pln
5490         rm -f $root/kernel/drv/sparcv9/soc
5491         rm -f $usr/include/sys/socvar.h
5492         rm -f $usr/include/sys/socmap.h
5493         rm -f $usr/include/sys/soc_cq_defs.h
5494         rm -f $usr/include/sys/socreg.h
5495         rm -f $usr/include/sys/scsi/adapters/plndef.h
5496         rm -f $usr/include/sys/scsi/adapters/plnvar.h
5497         rm -f $usr/include/sys/scsi/adapters/ssaisp.h
5498         rm -f $usr/include/sys/scsi/targets/pln_ctlr.h
5499         rm -f $usr/include/sys/scsi/targets/osesio.h
5500 
5501         #
5502         # PSARC/2003/629 Common Solaris Target Disk Driver
5503         # remove adb macro "scsi_disk" for the x86 platform
5504         #
5505         if [ $target_isa = i386 ]; then
5506                 rm -f $usr/lib/adb/scsi_disk
5507         fi
5508 
5509         # Remove CPCv1 API header per PSARC/2004/648
5510         rm -f $usr/include/sys/cpc_event.h
5511 
5512         # Remove headers per PSARC/2005/561
5513         rm -f $usr/include/sys/nexusintr.h
5514         rm -f $usr/platform/sun4u/include/sys/nexusintr_impl.h
5515         rm -f $usr/platform/sun4v/include/sys/nexusintr_impl.h
5516 
5517         # Remove usr/lib/mail which has moved to etc/mail/cf, but first,
5518         # attempt to migrate any user-added files, which primarily live
5519         # under usr/lib/mail/cf .  Blow away the seven files which we
5520         # ship under that directory, then move any that remain to the
5521         # new location, which we will `mkdir -p` just to be safe.
5522         # If the zone in question is non-global, then skip all this.
5523         #
5524         if [ $zone = "global" ]; then
5525                 # -d follow sym-links: make sure it's not a link.
5526                 if [ -d $usr/lib/mail -a ! -h $usr/lib/mail ]; then
5527                         # Only do this if usr/lib/mail is still a directory;
5528                         # bfu'ing backwards does not merit such migration.
5529                         rm -f $usr/lib/mail/cf/Makefile
5530                         rm -f $usr/lib/mail/cf/main.cf
5531                         rm -f $usr/lib/mail/cf/main.mc
5532                         rm -f $usr/lib/mail/cf/submit.cf
5533                         rm -f $usr/lib/mail/cf/submit.mc
5534                         rm -f $usr/lib/mail/cf/subsidiary.cf
5535                         rm -f $usr/lib/mail/cf/subsidiary.mc
5536                         mkdir -p -m 0755 $root/etc/mail/cf/cf
5537                         mv $usr/lib/mail/cf/* $root/etc/mail/cf/cf >/dev/null 2>&1
5538                 fi
5539                 rm -rf $usr/lib/mail
5540         fi
5541 
5542         #
5543         # Remove drivers and header files for EOF of Lance Ethernet
5544         # driver(le) as per PSARC/2003/335.
5545         #
5546         rm -f $root/kernel/drv/le
5547         rm -f $root/kernel/drv/sparcv9/le
5548         rm -f $root/kernel/drv/lebuffer
5549         rm -f $root/kernel/drv/sparcv9/lebuffer
5550         rm -f $root/platform/sun4u/kernel/drv/ledma
5551         rm -f $root/platform/sun4u/kernel/drv/sparcv9/ledma
5552         rm -f $usr/include/sys/le.h
5553         rm -f $usr/include/sys/lance.h
5554         rm -f $usr/lib/adb/le
5555         rm -f $usr/lib/adb/lestr
5556 
5557         #
5558         # Remove drivers and header files for EOF of ieef driver as
5559         # per PSARC/2003/009
5560         #
5561         rm -f $root/kernel/drv/ieef
5562         rm -f $root/kernel/drv/ieef.conf
5563         rm -f $usr/include/sys/ieef.h
5564         rm -f $root/boot/solaris/drivers/notisa.010/ieef.bef
5565 
5566         #
5567         # Remove drivers and header files for EOF of elx driver as
5568         # per PSARC/2003/770
5569         #
5570         rm -f $root/platform/i86pc/kernel/drv/elx
5571         rm -f $root/platform/i86pc/kernel/drv/elx.conf
5572         rm -f $usr/include/sys/elx.h
5573         rm -f $root/boot/solaris/drivers/isa.175/elx.bef
5574 
5575         #
5576         # Remove drivers for EOF of pe driver as per PSARC/2004/051
5577         #
5578         rm -f $root/kernel/drv/pe
5579         rm -f $root/kernel/drv/pe.conf
5580         rm -f $root/boot/solaris/drivers/isa.125/pe3.bef
5581 
5582         #
5583         # Remove drivers for EOF of Compaq NCR, Compaq SMART2, AMI Mega
5584         # card and /usr/bin/smart2cfg as per PSARC/2003/701 and
5585         # PSARC/2004/207
5586         #
5587         rm -f $root/kernel/drv/cpqncr
5588         rm -f $root/kernel/drv/cpqncr.conf
5589         rm -f $root/boot/solaris/drivers/notisa.020/cpqncr.bef
5590         rm -f $root/platform/i86pc/kernel/drv/smartii
5591         rm -f $root/platform/i86pc/kernel/drv/smartii.conf
5592         rm -f $usr/bin/smart2cfg
5593         rm -f $root/kernel/drv/mega
5594         rm -f $root/kernel/drv/mega.conf
5595         rm -f $root/boot/solaris/drivers/notisa.010/mega.bef
5596         rm -f $root/kernel/mach/compaq
5597         rm -f $root/kernel/mach/corollary
5598 
5599         #
5600         # Remove eisa nexus driver and header files for EOF of EISA
5601         # support as per PSARC/2003/650
5602         #
5603         rm -f $root/platform/i86pc/kernel/drv/eisa
5604         rm -f $usr/platform/i86pc/include/sys/eisarom.h
5605         rm -f $usr/platform/i86pc/include/sys/nvm.h
5606 
5607         #
5608         # Remove xmem headers (they moved back to usr/include/sys/fs)
5609         #
5610         rm -f $usr/include/ia32/sys/fs/xmem.h
5611         rm -f $usr/include/ia32/sys/fs/seg_xmem.h
5612         rm -rf $usr/include/ia32/sys/fs
5613 
5614         #
5615         # Remove junk headers
5616         #
5617         rm -f $usr/platform/i86pc/include/sys/mcdma.h
5618         rm -f $usr/platform/i86pc/include/sys/xque.h
5619 
5620         #
5621         # Remove obsolete x86 hat layer and associated adb scripts
5622         #
5623         rm -f $root/platform/i86pc/kernel/mmu/mmu32
5624         rm -f $root/platform/i86pc/kernel/mmu/mmu36
5625         rm -rf $root/platform/i86pc/kernel/mmu
5626         rm -f $usr/lib/adb/hwpp
5627         rm -f $usr/lib/adb/hatppp
5628         rm -f $usr/lib/adb/hat.nxt
5629         rm -f $usr/lib/adb/hwpp.nxt
5630         
5631         #
5632         # Remove drivers for EOF of chs as per PSARC/2005/581
5633         #
5634         rm -f $root/kernel/drv/chs
5635         rm -f $root/kernel/drv/chs.conf
5636         rm -f $root/boot/solaris/drivers/notisa.020/chs.bef
5637 
5638         #
5639         # Remove drivers & header files for EOF of dbri as per PSARC 2005/582
5640         #
5641         rm -f $root/kernel/drv/sparcv9/dbri
5642         rm -f $root/usr/include/sys/dbriio.h
5643         rm -f $root/usr/include/sys/mmcodecreg.h
5644 
5645         #
5646         # Remove drivers for EOF of pcscsi as per PSARC/2005/003
5647         #
5648         rm -f $root/kernel/drv/pcscsi
5649         rm -f $root/kernel/drv/pcscsi.conf
5650         rm -f $root/boot/solaris/drivers/notisa.010/pcscsi.bef
5651         
5652         #
5653         # Remove drivers for EOF of dpt as per PSARC/2003/701
5654         #
5655         rm -f $root/boot/solaris/drivers/isa.125/dpt.bef
5656         rm -f $root/platform/i86pc/kernel/drv/dpt
5657         rm -f $root/platform/i86pc/kernel/drv/dpt.conf
5658         rm -rf $usr/include/sys/dktp/dpt
5659 
5660         #
5661         # Remove drivers for EOF of mlx driver as per PSARC/2003/701
5662         #
5663         rm -f $root/boot/solaris/drivers/notisa.010/mlx.bef
5664         rm -f $root/platform/i86pc/kernel/drv/mlx
5665         rm -f $root/platform/i86pc/kernel/drv/mlx.conf
5666         rm -rf $usr/include/sys/dktp/mlx
5667 
5668         #
5669         # Remove snlb
5670         #
5671         rm -f $root/kernel/misc/snlb
5672         rm -f $root/kernel/misc/amd64/snlb
5673         rm -f $root/usr/include/sys/dktp/dklb.h
5674         rm -f $root/usr/include/sys/dktp/snlb.h
5675 
5676         #
5677         # Remove objmgr
5678         #
5679         rm -f $root/kernel/drv/objmgr.conf
5680         rm -f $root/kernel/drv/objmgr
5681         rm -f $root/kernel/drv/amd64/objmgr
5682         rm -f $root/usr/include/sys/dktp/objmgr.h
5683  
5684         #
5685         # Remove Floating Point Emulator for EOF as per PSARC/2003/651
5686         #
5687         rm -f $root/platform/i86pc/kernel/misc/emul_80387
5688 
5689         #
5690         # Remove 64-bit adp, cadp and cpqhpc
5691         #
5692         rm -f $root/kernel/drv/amd64/adp
5693         rm -f $root/kernel/drv/amd64/cadp
5694         rm -f $root/kernel/drv/amd64/cpqhpc
5695 
5696         #
5697         # Remove 64-bit i2o_bs, i2o_msg, i2o_scsi, pci_to_i2o, mscsi, ncrs,
5698         # msm, spwr, bscv, bscbus
5699         #
5700         rm -f $root/kernel/drv/amd64/i2o_bs
5701         rm -f $root/kernel/misc/amd64/i2o_msg
5702         rm -f $root/kernel/drv/amd64/i2o_scsi
5703         rm -f $root/kernel/drv/amd64/pci_to_i2o
5704         rm -f $root/platform/i86pc/kernel/drv/amd64/mscsi
5705         rm -f $root/kernel/drv/amd64/ncrs
5706         rm -f $root/platform/i86pc/kernel/drv/amd64/msm
5707         rm -f $root/kernel/drv/amd64/spwr
5708         rm -f $root/platform/i86pc/kernel/drv/amd64/bscv
5709         rm -f $root/platform/i86pc/kernel/drv/amd64/bscbus
5710 
5711         # Remove obsolete atomic_prim.h file.
5712         rm -f $usr/include/v9/sys/atomic_prim.h
5713 
5714         #
5715         # Remove sc_nct binary and the corresponding symlink to sc_nct from the
5716         # Montecarlo platform specific directories (Reference: PSARC 2003/606). 
5717         # To be specific, the following binary will be removed.
5718         # /platform/SUNW,UltraSPARC-IIe-NetraCT-40/kernel/drv/sparcv9/sc_nct 
5719         # Also, the following symlink will be removed.
5720         # /platform/SUNW,UltraSPARC-IIe-NetraCT-60/kernel/drv/sparcv9/sc_nct
5721         #
5722         if [ -f $root/platform/SUNW,UltraSPARC-IIe-NetraCT-40/kernel/drv/sparcv9/sc_nct ]; then
5723                 rm -f $root/platform/SUNW,UltraSPARC-IIe-NetraCT-40/kernel/drv/sparcv9/sc_nct
5724                 rm -f $root/platform/SUNW,UltraSPARC-IIe-NetraCT-60/kernel/drv/sparcv9/sc_nct
5725         fi
5726 
5727         #
5728         # In case of bfu to an older release, remove traces of "new"
5729         # Kerberos mechanisms.  Kerberos libraries and paths are corrected
5730         # after extraction is complete.
5731         #
5732         rm -f $root/kernel/misc/kgss/kmech_krb5
5733         rm -f $root/kernel/misc/kgss/sparcv9/kmech_krb5
5734         rm -f $root/platform/$karch/kernel/misc/kgss/sparcv9/kmech_krb5
5735         #
5736         # Diskless clients have already extracted /usr so don't delete these
5737         # Non-global zones never extracts /usr so don't delete these
5738         #
5739         if [ $diskless = no -a $zone = global ]; then
5740                 rm -f $usr/lib/gss/mech_krb5.so
5741                 rm -f $usr/lib/gss/mech_krb5.so.1
5742                 rm -f $usr/lib/sparcv9/gss/mech_krb5.so
5743                 rm -f $usr/lib/sparcv9/gss/mech_krb5.so.1
5744         fi
5745 
5746         # Remove old OpenSSL stuff from SUNWwbint
5747         rm -rf $usr/include/openssl
5748         rm -rf $usr/lib/openssl
5749 
5750         #Remove ufs logging module - now merged into ufs module
5751         rm -f $rootprefix/kernel/misc/ufs_log
5752         rm -f $rootprefix/kernel/misc/sparcv9/ufs_log
5753 
5754         #Remove ufs_log mdb/kmdb modules - now merged in to ufs module
5755         rm -f $rootprefix/kernel/kmdb/ufs_log
5756         rm -f $rootprefix/kernel/kmdb/sparcv9/ufs_log
5757         rm -f $rootprefix/kernel/kmdb/amd64/ufs_log
5758         rm -f $rootprefix/usr/lib/mdb/kvm/ufs_log.so
5759         rm -f $rootprefix/usr/lib/mdb/kvm/sparcv9/ufs_log.so
5760         rm -f $rootprefix/usr/lib/mdb/kvm/amd64/ufs_log.so
5761 
5762         #Remove diskmgtd. If backward BFU, will get re-installed from
5763         #archive.
5764         rm -f $usr/lib/diskmgtd
5765 
5766         #
5767         # Remove old ia64 cruft
5768         #
5769         if [ $target_isa = i386 ]; then
5770                 rm -f $usr/include/sys/ia64_archext.h
5771                 rm -f $usr/include/sys/sysia64.h
5772                 rm -rf $usr/include/ia64
5773         fi
5774 
5775         #
5776         # Remove machpage-related stuff
5777         #
5778         rm -f $usr/platform/*/include/vm/mach_page.h
5779         rm -f $usr/lib/adb/machpp
5780 
5781         #
5782         # Remove old cacheos
5783         #
5784         rm -f $root/etc/init.d/cacheos
5785         rm -f $root/etc/init.d/cacheos.finish
5786         rm -f $root/etc/init.d/cachefs.root
5787         rm -f $root/etc/rcS.d/S35cacheos.sh
5788         rm -f $root/etc/rc2.d/S93cacheos.finish
5789         rm -f $root/etc/rcS.d/S41cachefs.root
5790 
5791         #
5792         # Remove unneeded nfsmapid entries
5793         #
5794         nfsmapid_cfg
5795 
5796         #
5797         # Move the original manifests aside; later we will restore
5798         # unchanged originals to avoid superfluous re-import on reboot.
5799         # (First blow away the old dir path just to be safe.)
5800         #
5801         rm -rf $root/$old_mfst_dir
5802         [ -d $root/$new_mfst_dir ] && mv $root/$new_mfst_dir $root/$old_mfst_dir
5803 
5804         #
5805         # Remove obsolete sum.h
5806         #
5807         rm -f $usr/include/sum.h
5808 
5809         #
5810         # Remove obsolete std.h
5811         #
5812         rm -f $usr/include/std.h
5813 
5814         #
5815         # Remove obsolete rpc/trace.h
5816         #
5817         rm -f $usr/include/rpc/trace.h
5818 
5819         #
5820         # Remove acpi_intp module
5821         #
5822         if [ $target_isa = i386 ]; then
5823                 rm -f $root/kernel/misc/acpi_intp
5824                 rm -f $root/kernel/misc/amd64/acpi_intp
5825         fi
5826 
5827         #
5828         # Remove obsolete librac
5829         #
5830         rm -f $usr/include/rpc/rac.h
5831         rm -f $usr/lib/llib-lrac
5832         rm -f $usr/lib/llib-lrac.ln
5833         rm -f $usr/lib/amd64/llib-lrac.ln
5834         rm -f $usr/lib/sparcv9/llib-lrac.ln
5835         rm -f $usr/lib/librac.so
5836         rm -f $usr/lib/librac.so.1
5837         rm -f $usr/lib/amd64/librac.so
5838         rm -f $usr/lib/amd64/librac.so.1
5839         rm -f $usr/lib/sparcv9/librac.so
5840         rm -f $usr/lib/sparcv9/librac.so.1
5841 
5842         # End of pre-archive extraction hacks.
5843 
5844         if [ $diskless = no -a $zone = global ]; then
5845                 print "Extracting ufs modules for boot block ... \c" | \
5846                         tee -a $EXTRACT_LOG
5847                 do_extraction $cpiodir/$karch.usr$ZFIX \
5848                         'usr/platform/'$karch'/lib/fs/ufs/*' | \
5849                         tee -a $EXTRACT_LOG
5850                 case $target_isa in
5851                     sparc)
5852                         if [[ "$rootslice" = /dev/rdsk/* ]]; then
5853                                 print "Installing boot block on $rootslice."
5854                                 cd $usr/platform/$karch/lib/fs/ufs
5855                                 installboot ./bootblk $rootslice
5856                         fi
5857                         ;;
5858                     i386)
5859                         ;;
5860                     *)
5861                         ;;      # unknown ISA
5862                 esac
5863         fi
5864 
5865         if [ $diskless = yes ]; then
5866                 node=${root##*/}
5867                 archlist=""
5868                 for arch in $allarchs
5869                 do
5870                         egrep -s '/export/exec/.*'$arch'/usr/kvm' \
5871                                 $root/etc/vfstab ||
5872                                 test -d $root/platform/$arch &&
5873                                 archlist="$archlist $arch"
5874                 done
5875                 if [ -z "$old_style_archives" ]; then
5876                         extract_archives lib generic
5877                         extract_archives sbin generic
5878                         extract_archives kernel generic
5879                 fi
5880                 extract_archives root generic $archlist
5881                 if [ $target_isa = i386 ]; then
5882                         extract_boot_archives boot $archlist
5883                 fi
5884         else
5885                 export PATH=/tmp/bfubin
5886                 node=`uname -n`
5887                 if [ $zone = global ]; then
5888                         extract_archives usr generic $usrarchs
5889                         if [ -z "$old_style_archives" ]; then
5890                                 extract_archives lib generic
5891                                 extract_archives sbin generic
5892                                 extract_archives kernel generic
5893                         fi
5894                         extract_archives root generic $rootarchs
5895                         if [ $target_isa = i386 ]; then
5896                                 #
5897                                 #  The assumption here is that if boot
5898                                 #  archives exist at all, they only exist
5899                                 #  for architectures where we also have
5900                                 #  .root archives.
5901                                 #
5902                                 extract_boot_archives boot $rootarchs
5903                         fi
5904                 else
5905                         extract_archives root generic
5906                 fi
5907         fi
5908 
5909         touch reconfigure
5910 
5911         #
5912         # UltraSparc III platforms have aes module in platform directory
5913         #
5914         if [ ! -f $root/platform/$plat/kernel/crypto/sparcv9/aes ]; then
5915                 rm -f $root/platform/sun4u-us3/kernel/crypto/sparcv9/aes
5916                 rm -f $root/platform/sun4u-us3/kernel/crypto/sparcv9/aes256
5917         fi
5918 
5919         if [ $zone = global ]; then
5920                 print "\nRemoving duplicate kernel binaries ..."
5921                 #
5922                 # First, find all regular files underneath the */kernel
5923                 # directories we extracted, and mark them as older or newer
5924                 # than our reference file -- if newer, they were extracted
5925                 # during the bfu.
5926                 #
5927                 # We then split out the pre-/kernel part from the post-/kernel
5928                 # part, sort by post-/kernel part and age (new first), and
5929                 # delete old files which have new counterparts.
5930                 #
5931                 dirs="$rootprefix/kernel $usr/kernel"
5932                 for plat in $archlist $rootarchs $usrarchs; do
5933                         dir=$rootprefix/platform/$plat/kernel
5934                         [[ -d $dir ]] && dirs="$dirs $dir"
5935                 done
5936 
5937                 age=new
5938                 ls -ct $time_ref `find $dirs -type f 2>/dev/null` | uniq |
5939                     while read f; do
5940                         if [[ $f = $time_ref ]] then
5941                                 age=old
5942                         else
5943                                 echo $age $f
5944                         fi
5945                 done |
5946                     sed 's@\(.*/kernel\)/@\1 @' | sort -k 3 -k 1 | nawk '
5947                         /^new/ { lastname = $3 }
5948                         /^old/ { if (lastname == $3) { print $2 "/" $3 } }
5949                     ' | while read x; do
5950                         echo rm $x
5951                         rm $x
5952                 done
5953         fi
5954 
5955         echo
5956         # Simulate installation of SUNWcry* - these are in the bfu archives.
5957         if [ -f $rootprefix/etc/crypto/kcf.conf -a \
5958             -f $rootprefix/etc/crypto/pkcs11.conf ]; then
5959                 enable_crypto_unlimited
5960         fi
5961 
5962         # Add uCF's metaslot feature
5963         if [ -f $rootprefix/etc/crypto/pkcs11.conf ] ; then
5964                 enable_crypto_metaslot
5965         fi
5966 
5967         # Cleanup old Kerberos mechanisms
5968         cleanup_kerberos_mechanisms
5969 
5970         # Fix network datalink configuration
5971         if [ $zone = global -a $need_datalink = yes ]; then
5972                 create_datalink_conf
5973         fi
5974 
5975         print "\nRestoring configuration files.\n"
5976 
5977         cd $root
5978         rm -rf bfu.ancestor
5979         test -d bfu.parent && mv bfu.parent bfu.ancestor
5980         mkdir bfu.parent
5981         print "Restoring configuration files ... \c" >> $EXTRACT_LOG
5982         filelist $zone | cpio -pdmu bfu.parent 2>>$EXTRACT_LOG || \
5983             extraction_error "restoring configuration files"
5984         if [ $multiboot_archives = no ]; then
5985                 if [ $have_realmode = yes ]; then
5986                         if [ -d bfu.realmode ]; then
5987                                 ( cd bfu.realmode ; realmode_filelist | \
5988                                     cpio -pdmu ../bfu.ancestor 2>/dev/null )
5989                                 rm -rf bfu.realmode
5990                         fi
5991                         mkdir bfu.realmode
5992                         ( cd bfu.parent ; realmode_filelist | \
5993                                 cpio -pdmu ../bfu.realmode 2>/dev/null )
5994                 else
5995                         for file in $realmode_files
5996                         do
5997                                 rm -rf bfu.parent/$file
5998                         done
5999                 fi
6000         fi
6001         if [ $zone != global ]; then
6002                 rm -rf $global_zone_only_files $superfluous_local_zone_files
6003         fi
6004         cd bfu.child
6005 
6006         for file in `filelist $zone`
6007         do
6008                 # parent: freshly-BFUed version
6009                 # child: pre-BFU version
6010                 # ancestor: installed from archives the last time you BFUed
6011                 # actual: in the root filesystem at this moment (same as parent)
6012 
6013                 parent=$rootprefix/bfu.parent/$file
6014                 child=$rootprefix/bfu.child/$file
6015                 ancestor=$rootprefix/bfu.ancestor/$file
6016                 conflicts=$rootprefix/bfu.conflicts/$file
6017                 actual=$rootprefix/$file
6018 
6019                 # if a superfluous-to-local-zones file was blown away, skip it
6020                 [ -f $actual ] || continue
6021 
6022                 # if there's been no change by the BFU, skip it
6023                 cmp -s $child $actual && continue
6024 
6025                 # if the file was not installed by the BFU, skip it
6026                 [  -f $parent ] || continue
6027 
6028                 # if this is a file which should never be updated by BFU,
6029                 # preserve the original (child) version
6030                 if (echo $preserve_files | grep $file >/dev/null 2>&1)
6031                 then
6032                         print "    preserve: $file"
6033                         cp -p $child $actual
6034                         continue
6035                 fi
6036 
6037                 # if the file was accepted from the parent on the last BFU,
6038                 # then accept it again this time without argument.  Or, if
6039                 # this is the first bfu after an standard Solaris install
6040                 # or upgrade, compare the file to one installed from packages.
6041                 # If it hasn't been modified since installation, accept
6042                 # the file from the parent.
6043                 if [ -f $ancestor ] ; then
6044                         if cmp -s $child $ancestor; then
6045                                 print "      update: $file"
6046                                 continue
6047                         fi
6048                 elif [ "$firstbfu" = "yes" ] ; then
6049                         installedsum=$(grep "^/$file " \
6050                             $rootprefix/var/sadm/install/contents |
6051                             awk '{ print $8 }')
6052                         if [ -n "$installedsum" ] ; then
6053                                 actualsum=`sum $child | sed 's/ .*//'`
6054                                 if [ "$installedsum" -eq "$actualsum" ] ; then
6055                                         print "      update: $file"
6056                                         continue
6057                                 fi
6058                         fi
6059                 fi
6060 
6061                 # if the BFU'ed file is the same as the beginning of the
6062                 # pre-BFUed file, assume the user has added lines to the
6063                 # end, and restore the pre-BFUed version
6064                 if (cmp $child $parent 2>&1) | egrep -s 'EOF on '$parent; then
6065                         print "     restore: $file"
6066                         cp -p $child $actual
6067                         continue
6068                 fi
6069 
6070                 # if the new version is the same as it was the last time
6071                 # BFU was run, but still different than the pre-BFU version,
6072                 # this is an "old" conflict; otherwise, it's a "NEW"
6073                 # conflict.  Old conflicts can usually be safely ignored.
6074                 if cmp -s $parent $ancestor; then
6075                         print "old \c"
6076                 else
6077                         print "NEW \c"
6078                         print $file >>$rootprefix/bfu.conflicts/NEW
6079                 fi
6080                 print "conflict: $file"
6081                 (cd $root; print $file | cpio -pdmu bfu.conflicts 2>/dev/null)
6082 
6083                 # for all conflicts, restore the pre-BFU version and let
6084                 # the user decide what to do.
6085                 cp -p $child $actual
6086         done
6087 
6088         if [ $zone = global ]; then
6089                 #
6090                 # correct permissions using /etc/minor_perm from the parent and
6091                 # child, prefer parent.
6092                 #
6093                 mperm=$rootprefix/etc/minor_perm
6094                 pmperm=$rootprefix/bfu.parent/etc/minor_perm
6095                 if [ -f $pmperm ]
6096                 then
6097                         mperm="$pmperm $mperm"
6098                 fi
6099 
6100                 #
6101                 # Devices with changed permissions should be added here much
6102                 # like in i.minorperm.  The "ssm" devices are special in that
6103                 # they have no /dev links associated with them.
6104                 #
6105                 while read minor dev
6106                 do (
6107                         set -- `fgrep -h "$minor" $mperm` "";
6108                         if [ ! -z "$2" ]
6109                         then
6110                                 chmod $2 $rootprefix/dev/$dev 2>/dev/null
6111                                 chown $3:$4 $rootprefix/dev/$dev 2>/dev/null
6112                         fi
6113                 ) done <<-EOF
6114                         ssm:*                   ../devices/ssm*:*
6115                         cpc:shared              ../devices/pseudo/cpc*
6116                         icmp:icmp               icmp
6117                         icmp6:icmp6             icmp6
6118                         ip:ip                   ip
6119                         ip6:ip6                 ip6
6120                         rts:rts                 rts
6121                         keysock:keysock         keysock
6122                         ipsecah:ipsecah         ipsecah
6123                         ipsecesp:ipsecesp       ipsecesp
6124                         spdsock:spdsock         spdsock
6125                         sad:admin               sad/admin
6126                         fssnap:ctl              fssnapctl
6127                         fssnap:*                fssnap/*
6128                         clone:ce                ce
6129                         clone:eri               eri
6130                         clone:ge                ge
6131                         clone:hme               hme
6132                         clone:le                le
6133                         clone:qfe               qfe
6134                         clone:bge               bge
6135                         bge:*                   bge*
6136                         clone:dmfe              dmfe
6137                         dmfe:*                  dmfe*
6138                         clone:pcelx             pcelx
6139                         pcelx:*                 pcelx*
6140                         clone:dnet              dnet
6141                         dnet:*                  dnet*
6142                         clone:elxl              elxl
6143                         elxl:*                  elxl*
6144                         clone:iprb              iprb
6145                         iprb:*                  iprb*
6146                         clone:spwr              spwr
6147                         spwr:*                  spwr*
6148                 EOF
6149 
6150                 if [ $target_isa = i386 ] && [[ $rootslice = /dev/rdsk/* || \
6151                     $rootslice = /dev/md/rdsk/* ]]; then
6152                         if [ $multiboot_archives = yes ]; then
6153                                 if [ $dca_to_multi = yes ]; then
6154                                         install_failsafe
6155                                         setup_grub_menu
6156                                         install_grub
6157                                 fi
6158                                 build_boot_archive
6159                         else
6160                                 disable_boot_service
6161                         fi
6162                 fi
6163 
6164                 # Check for damage due to CR 6379341.  This was actually fixed
6165                 # back in snv_24, but users BFUing from an S10 build up to
6166                 # Nevada can still encounter it.
6167                 rzi=$root/etc/zones/index
6168                 if [ -f $rzi ]; then
6169                         # Look for duplicated UUIDs.  If there are any, then
6170                         # just wipe them out.
6171                         if nawk -F: '
6172                                 /^\#/ || NF != 4 { print $0; next; }
6173                                 {
6174                                         if (flags[$4])
6175                                                 sub(/:[-0-9a-z]*$/,":");
6176                                         print $0;
6177                                         flags[$4]=1;
6178                                 }
6179                         ' < $rzi > ${rzi}.bfu.$$; then
6180                                 if cmp -s $rzi ${rzi}.bfu.$$; then
6181                                         rm -f ${rzi}.bfu.$$
6182                                 else
6183                                         chown root:sys ${rzi}.bfu.$$
6184                                         chmod 644 ${rzi}.bfu.$$
6185                                         mv ${rzi}.bfu.$$ $rzi
6186                                 fi
6187                         else
6188                                 rm -f ${rzi}.bfu.$$
6189                         fi
6190                 fi
6191         fi
6192 
6193 
6194         print "\nFor each file in conflict, your version has been restored."
6195         print "The new versions are under $rootprefix/bfu.conflicts."
6196         print "\nMAKE SURE YOU RESOLVE ALL CONFLICTS BEFORE REBOOTING.\n"
6197         if [ $multiboot_archives = yes ]; then
6198                 print "To install resolved changes required for reboot in the boot"
6199                 print "archive, invoke 'bootadm update-archive${cr_args}'\n"
6200         fi
6201 
6202         if [ $zone != global ]; then
6203                 print "Resolve conflicts in the global zone first.  Many of"
6204                 print "the conflicts in non-global zones can be resolved by"
6205                 print "copying the corresponding file from the global zone.\n"
6206         else
6207                 fixup_mpxio
6208         fi
6209 
6210         cd $root
6211 
6212         smf_apply_conf
6213 
6214         update_policy_conf
6215 
6216         print "bfu'ed from $cpiodir on `date +%Y-%m-%d`" >>etc/motd
6217         tail +`nawk '/bfu.ed from/ { x=NR }; END { print x+1 }' \
6218                 etc/motd.old` etc/motd.old >> etc/motd
6219 
6220         #
6221         # Hacks to work around minor annoyances and make life more pleasant.
6222         # Part 2 of 2: post-archive-extraction stuff
6223         #
6224 
6225         rm -f var/statmon/state         # to prevent lockd/statd hangs
6226         for f in etc/auto_*             # to make autofs happy
6227         do
6228                 file $f | grep executable >/dev/null || chmod -x $f
6229         done
6230 
6231         epilogue=$rootprefix/bfu.epilogue
6232         if [ -f $epilogue ]; then
6233                 print "Executing $epilogue"
6234                 $epilogue || print "WARNING: $epilogue failed with code $?"
6235         fi
6236 
6237         ((seconds = SECONDS))
6238         ((min = seconds / 60))
6239         ((sec = seconds % 60))
6240 
6241         if [ $zone = global ]; then
6242                 target=$node
6243         else
6244                 target=$zone
6245         fi
6246         printf "Upgrade of $target took ${min}:%02d.\n" $sec
6247 
6248         #
6249         # Do logging in the background so that if the automounter is gone,
6250         # bfu doesn't wedge at this point.
6251         #
6252         log=$GATE/public/bfu.log
6253         (test -w $log && printf \
6254                 "`date +%Y'%'m%d` $node `uname -rv` $karch $cpiodir ${min}:%02d\n" \
6255                 $sec >>$log) &
6256 }
6257 
6258 #
6259 # make sure the time reference is older than anything extracted
6260 #
6261 test $time_ref_seconds -eq $SECONDS && sleep 1
6262 
6263 test $diskless = yes && extract_archives usr generic $allarchs
6264 
6265 for root in $rootlist
6266 do
6267         mondo_loop $root global
6268         lastroot=$root
6269 done
6270 
6271 if [ -s $local_zone_info_file ]; then
6272         cat $local_zone_info_file | while read zone zonepath; do
6273                 print "\nNow for zone $zone..."
6274                 mondo_loop $zonepath/root $zone
6275         done
6276         rm -f $local_zone_info_file
6277 fi
6278 
6279 print "Turning off delayed i/o and syncing filesystems ..."
6280 sync
6281 fastfs -s $rootlist $usr
6282 fastfs $rootlist $usr
6283 sync
6284 lockfs -f $rootlist $usr
6285 
6286 egrep -s "^error " $EXTRACT_LOG
6287 if [ $? -eq 0 ]; then
6288         print "\nWARNING: archive extraction errors occurred.\n"
6289         print "See $EXTRACT_LOG for details.\n"
6290 fi
6291 
6292 lastrootprefix=${lastroot%/}
6293 
6294 if [ -t 0 -a -t 1 -a -t 2 ]; then
6295         print "\nEntering post-bfu protected environment (shell: ksh)."
6296         print "Edit configuration files as necessary, then reboot.\n"
6297         cd $lastrootprefix/bfu.conflicts
6298         PS1='bfu# ' ksh -ip
6299 fi
6300 
6301 print "Exiting post-bfu protected environment.  To reenter, type:"
6302 print LD_NOAUXFLTR=1 LD_LIBRARY_PATH=/tmp/bfulib $ldlib64 PATH=/tmp/bfubin \
6303     /tmp/bfubin/ksh
6304 
6305 # Allow init(1M) to continue, if we're leaving.
6306 print "Reactivating init ..."
6307 prun 1
6308 
6309 exit 0