Print this page
3762 nawk 'continue illegal outside of loops'
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/brand/solaris10/zone/p2v.ksh
+++ new/usr/src/lib/brand/solaris10/zone/p2v.ksh
1 1 #!/bin/ksh -p
2 2 #
3 3 # CDDL HEADER START
4 4 #
5 5 # The contents of this file are subject to the terms of the
6 6 # Common Development and Distribution License (the "License").
7 7 # You may not use this file except in compliance with the License.
8 8 #
9 9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 # or http://www.opensolaris.org/os/licensing.
11 11 # See the License for the specific language governing permissions
12 12 # and limitations under the License.
13 13 #
14 14 # When distributing Covered Code, include this CDDL HEADER in each
15 15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 # If applicable, add the following below this CDDL HEADER, with the
17 17 # fields enclosed by brackets "[]" replaced with your own identifying
18 18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 19 #
20 20 # CDDL HEADER END
21 21 #
22 22 # Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 #
24 24
25 25 # NOTE: this script runs in the global zone and touches the non-global
26 26 # zone, so care should be taken to validate any modifications so that they
27 27 # are safe.
28 28
29 29 . /usr/lib/brand/solaris10/common.ksh
30 30
31 31 LOGFILE=
32 32 MSG_PREFIX="p2v: "
33 33 EXIT_CODE=1
34 34
35 35 usage()
36 36 {
37 37 echo "$0 [-s] [-m msgprefix] [-u] [-v] [-b patchid]* zonename" >&2
38 38 exit $EXIT_CODE
39 39 }
40 40
41 41 # Clean up on interrupt
42 42 trap_cleanup()
43 43 {
44 44 msg=$(gettext "Postprocessing cancelled due to interrupt.")
45 45 error "$msg"
46 46
47 47 if (( $zone_is_running != 0 )); then
48 48 error "$e_shutdown" "$ZONENAME"
49 49 /usr/sbin/zoneadm -z $ZONENAME halt
50 50 fi
51 51
52 52 #
53 53 # Delete temporary files created during the hollow package removal
54 54 # process.
55 55 #
56 56 rm -f $hollow_pkgs $hollow_file_list $hollow_dir_list
57 57
58 58 exit $EXIT_CODE
59 59 }
60 60
61 61 #
62 62 # Disable any existing live-upgrade configuration.
63 63 # We have already called safe_dir to validate the etc/lu directory.
64 64 #
65 65 fix_lu()
66 66 {
67 67 ludir=$ZONEROOT/etc/lu
68 68
69 69 [[ ! -d $ludir ]] && return
70 70
71 71 safe_rm etc/lutab
72 72 safe_rm etc/lu/.BE_CONFIG
73 73 safe_rm etc/lu/.CURR_VARS
74 74 safe_rm etc/lu/ludb.local.xml
75 75 for i in $ludir/ICF* $ludir/vtoc* $ludir/GRUB*
76 76 do
77 77 nm=`basename $i`
78 78 safe_rm etc/lu/$nm
79 79 done
80 80 }
81 81
82 82 #
83 83 # For an exclusive stack zone, fix up the network configuration files.
84 84 # We need to do this even if unconfiguring the zone so sys-unconfig works
85 85 # correctly.
86 86 #
87 87 fix_net()
88 88 {
89 89 [[ "$STACK_TYPE" == "shared" ]] && return
90 90
91 91 NETIF_CNT=$(/usr/bin/ls $ZONEROOT/etc/hostname.* 2>/dev/null | \
92 92 /usr/bin/wc -l)
93 93 if (( $NETIF_CNT != 1 )); then
94 94 vlog "$v_nonetfix"
95 95 return
96 96 fi
97 97
98 98 NET=$(LC_ALL=C /usr/sbin/zonecfg -z $ZONENAME info net)
99 99 if (( $? != 0 )); then
100 100 error "$e_badinfo" "net"
101 101 return
102 102 fi
103 103
104 104 NETIF=$(echo $NET | /usr/bin/nawk '{
105 105 for (i = 1; i < NF; i++) {
106 106 if ($i == "physical:") {
107 107 if (length(net) == 0) {
108 108 i++
109 109 net = $i
110 110 } else {
111 111 multiple=1
112 112 }
113 113 }
114 114 }
115 115 }
116 116 END { if (!multiple)
117 117 print net
118 118 }')
119 119
120 120 if [[ -z "$NETIF" ]]; then
121 121 vlog "$v_nonetfix"
122 122 return
123 123 fi
124 124
125 125 OLD_HOSTNET=$(/usr/bin/ls $ZONEROOT/etc/hostname.*)
126 126 if [[ "$OLD_HOSTNET" != "$ZONEROOT/etc/hostname.$NETIF" ]]; then
127 127 safe_move $OLD_HOSTNET $ZONEROOT/etc/hostname.$NETIF
128 128 fi
129 129 }
130 130
131 131 #
132 132 # Disable all of the shares since the zone cannot be an NFS server.
133 133 # Note that we disable the various instances of the svc:/network/shares/group
134 134 # SMF service in the fix_smf function.
135 135 #
136 136 fix_nfs()
137 137 {
138 138 zonedfs=$ZONEROOT/etc/dfs
139 139
140 140 [[ ! -d $zonedfs ]] && return
141 141
142 142 if [[ -h $zonedfs/dfstab || ! -f $zonedfs/dfstab ]]; then
143 143 error "$e_badfile" "/etc/dfs/dfstab"
144 144 return
145 145 fi
146 146
147 147 tmpfile=$(mktemp -t)
148 148 if [[ $? == 1 || -z "$tmpfile" ]]; then
149 149 error "$e_tmpfile"
150 150 return
151 151 fi
152 152
153 153 /usr/bin/nawk '{
154 154 if (substr($1, 0, 1) == "#") {
155 155 print $0
156 156 } else {
157 157 print "#", $0
158 158 modified=1
159 159 }
160 160 }
161 161 END {
162 162 if (modified == 1) {
163 163 printf("# Modified by p2v ")
164 164 system("/usr/bin/date")
165 165 exit 0
166 166 }
167 167 exit 1
168 168 }' $zonedfs/dfstab >>$tmpfile
169 169
170 170 if (( $? == 0 )); then
171 171 if [[ ! -f $zonedfs/dfstab.pre_p2v ]]; then
172 172 safe_copy $zonedfs/dfstab $zonedfs/dfstab.pre_p2v
173 173 fi
174 174 safe_copy $tmpfile $zonedfs/dfstab
175 175 chown root:sys $zonedfs/dfstab || \
176 176 fail_fatal "$f_chown" "$zonedfs/dfstab"
177 177 chmod 644 $zonedfs/dfstab || \
178 178 fail_fatal "$f_chmod" "$zonedfs/dfstab"
179 179 fi
180 180 /usr/bin/rm -f $tmpfile
181 181 }
182 182
183 183 #
184 184 # Comment out most of the old mounts since they are either unneeded or
185 185 # likely incorrect within a zone. Specific mounts can be manually
186 186 # reenabled if the corresponding device is added to the zone.
187 187 #
188 188 fix_vfstab()
189 189 {
190 190 if [[ -h $ZONEROOT/etc/vfstab || ! -f $ZONEROOT/etc/vfstab ]]; then
191 191 error "$e_badfile" "/etc/vfstab"
192 192 return
193 193 fi
194 194
195 195 tmpfile=$(mktemp -t)
196 196 if [[ $? == 1 || -z "$tmpfile" ]]; then
197 197 error "$e_tmpfile"
198 198 return
199 199 fi
200 200
201 201 /usr/bin/nawk '{
202 202 if (substr($1, 0, 1) == "#") {
203 203 print $0
204 204 } else if ($1 == "fd" || $1 == "/proc" || $1 == "swap" ||
205 205 $1 == "ctfs" || $1 == "objfs" || $1 == "sharefs" ||
206 206 $4 == "nfs" || $4 == "lofs") {
207 207 print $0
208 208 } else {
209 209 print "#", $0
210 210 modified=1
211 211 }
212 212 }
213 213 END {
214 214 if (modified == 1) {
215 215 printf("# Modified by p2v ")
216 216 system("/usr/bin/date")
217 217 exit 0
218 218 }
219 219 exit 1
220 220 }' $ZONEROOT/etc/vfstab >>$tmpfile
221 221
222 222 if (( $? == 0 )); then
223 223 if [[ ! -f $ZONEROOT/etc/vfstab.pre_p2v ]]; then
224 224 safe_copy $ZONEROOT/etc/vfstab \
225 225 $ZONEROOT/etc/vfstab.pre_p2v
226 226 fi
227 227 safe_copy $tmpfile $ZONEROOT/etc/vfstab
228 228 chown root:sys $ZONEROOT/etc/vfstab || \
229 229 fail_fatal "$f_chown" "$ZONEROOT/etc/vfstab"
230 230 chmod 644 $ZONEROOT/etc/vfstab || \
231 231 fail_fatal "$f_chmod" "$ZONEROOT/etc/vfstab"
232 232 fi
233 233 /usr/bin/rm -f $tmpfile
234 234 }
235 235
236 236 #
237 237 # Collect the data needed to delete SMF services. Since we're p2v-ing a
238 238 # physical image there are SMF services which must be deleted.
239 239 #
240 240 fix_smf_pre_uoa()
241 241 {
242 242 #
243 243 # Start by getting the svc manifests that are delivered by hollow
244 244 # pkgs then use 'svccfg inventory' to get the names of the svcs
245 245 # delivered by those manifests. The svc names are saved into a
246 246 # temporary file.
247 247 #
248 248
249 249 SMFTMPFILE=$(mktemp -t smf.XXXXXX)
250 250 if [[ $? == 1 || -z "$SMFTMPFILE" ]]; then
251 251 error "$e_tmpfile"
252 252 return
253 253 fi
254 254
255 255 for i in $ZONEROOT/var/sadm/pkg/*
256 256 do
257 257 pkg=$(/usr/bin/basename $i)
258 258 [[ ! -f $ZONEROOT/var/sadm/pkg/$pkg/save/pspool/$pkg/pkgmap ]] \
259 259 && continue
260 260
261 261 /usr/bin/egrep -s "SUNW_PKG_HOLLOW=true" \
262 262 $ZONEROOT/var/sadm/pkg/$pkg/pkginfo || continue
263 263
264 264 for j in $(/usr/bin/nawk '{if ($2 == "f" &&
265 265 substr($4, 1, 17) == "var/svc/manifest/") print $4}' \
266 266 $ZONEROOT/var/sadm/pkg/$pkg/save/pspool/$pkg/pkgmap)
267 267 do
268 268 svcs=$(SVCCFG_NOVALIDATE=1 \
269 269 SVCCFG_REPOSITORY=$ZONEROOT/etc/svc/repository.db \
270 270 /usr/sbin/svccfg inventory $ZONEROOT/$j)
271 271 for k in $svcs
272 272 do
273 273 echo $k /$j >> $SMFTMPFILE
274 274 done
275 275 done
276 276 done
277 277 }
278 278
279 279 #
280 280 # Delete or disable SMF services.
281 281 # Zone is booted to milestone=none when this function is called.
282 282 # Use the SMF data collected by fix_smf_pre_uoa() to delete the services.
283 283 #
284 284 fix_smf()
285 285 {
286 286 #
287 287 # Zone was already booted to milestone=none, wait until SMF door exists.
288 288 #
289 289 for i in 0 1 2 3 4 5 6 7 8 9
290 290 do
291 291 [[ -r $ZONEROOT/etc/svc/volatile/repository_door ]] && break
292 292 sleep 5
293 293 done
294 294
295 295 if [[ $i -eq 9 && ! -r $ZONEROOT/etc/svc/volatile/repository_door ]];
296 296 then
297 297 #
298 298 # The zone never booted, something is wrong.
299 299 #
300 300 error "$e_nosmf"
301 301 error "$e_bootfail"
302 302 /usr/bin/rm -f $SMFTMPFILE
303 303 return 1
304 304 fi
305 305
306 306 insttmpfile=$(mktemp -t instsmf.XXXXXX)
307 307 if [[ $? == 1 || -z "$insttmpfile" ]]; then
308 308 error "$e_tmpfile"
309 309 /usr/bin/rm -f $SMFTMPFILE
310 310 return 1
311 311 fi
312 312
313 313 vlog "$v_rmhollowsvcs"
314 314 while read fmri mfst
315 315 do
316 316 # Delete the svc.
317 317 vlog "$v_delsvc" "$fmri"
318 318 echo "/usr/sbin/svccfg delete -f $fmri"
319 319 echo "/usr/sbin/svccfg delhash -d $mfst"
320 320 echo "rm -f $mfst"
321 321 done < $SMFTMPFILE > $ZONEROOT/tmp/smf_rm
322 322
323 323 /usr/sbin/zlogin -S $ZONENAME /bin/sh /tmp/smf_rm >/dev/null 2>&1
324 324
325 325 /usr/bin/rm -f $SMFTMPFILE
326 326
327 327 # Get a list of the svcs that now exist in the zone.
328 328 LANG=C /usr/sbin/zlogin -S $ZONENAME /usr/bin/svcs -aH | \
329 329 /usr/bin/nawk '{print $3}' >>$insttmpfile
330 330
331 331 [[ -n $LOGFILE ]] && \
332 332 printf "[$(date)] ${MSG_PREFIX}${v_svcsinzone}\n" >&2
333 333 [[ -n $LOGFILE ]] && cat $insttmpfile >&2
334 334
335 335 #
336 336 # Import ip-interface-management service in S10C, network
337 337 # loopback service requires ipmgmtd in exclusive stack zones.
338 338 #
339 339 /usr/sbin/zlogin -S $ZONENAME /usr/sbin/svccfg import \
340 340 $ZONEROOT/var/svc/manifest/network/network-ipmgmt.xml
341 341
342 342 #
343 343 # Fix network services if shared stack.
344 344 #
345 345 if [[ "$STACK_TYPE" == "shared" ]]; then
346 346 vlog "$v_fixnetsvcs"
347 347
348 348 NETPHYSDEF="svc:/network/physical:default"
349 349 NETPHYSNWAM="svc:/network/physical:nwam"
350 350
351 351 /usr/bin/egrep -s "$NETPHYSDEF" $insttmpfile
352 352 if (( $? == 0 )); then
353 353 vlog "$v_enblsvc" "$NETPHYSDEF"
354 354 /usr/sbin/zlogin -S $ZONENAME \
355 355 /usr/sbin/svcadm enable $NETPHYSDEF || \
356 356 error "$e_dissvc" "$NETPHYSDEF"
357 357 fi
358 358
359 359 /usr/bin/egrep -s "$NETPHYSNWAM" $insttmpfile
360 360 if (( $? == 0 )); then
361 361 vlog "$v_dissvc" "$NETPHYSNWAM"
362 362 /usr/sbin/zlogin -S $ZONENAME \
363 363 /usr/sbin/svcadm disable $NETPHYSNWAM || \
364 364 error "$e_enblsvc" "$NETPHYSNWAM"
365 365 fi
366 366
367 367 for i in $(/usr/bin/egrep network/routing $insttmpfile)
368 368 do
369 369 # Disable the svc.
370 370 vlog "$v_dissvc" "$i"
371 371 /usr/sbin/zlogin -S $ZONENAME \
372 372 /usr/sbin/svcadm disable $i || \
373 373 error "$e_dissvc" $i
374 374 done
375 375 fi
376 376
377 377 #
378 378 # Disable well-known services that don't run in a zone.
379 379 #
380 380 vlog "$v_rminvalidsvcs"
381 381 for i in $(/usr/bin/egrep -hv "^#" \
382 382 /usr/lib/brand/solaris10/smf_disable.lst \
383 383 /etc/brand/solaris10/smf_disable.conf)
384 384 do
385 385 # Skip svcs not installed in the zone.
386 386 /usr/bin/egrep -s "$i:" $insttmpfile || continue
387 387
388 388 # Disable the svc.
389 389 vlog "$v_dissvc" "$i"
390 390 /usr/sbin/zlogin -S $ZONENAME /usr/sbin/svcadm disable $i || \
391 391 error "$e_dissvc" $i
392 392 done
393 393
394 394 #
395 395 # Since zones can't be NFS servers, disable all of the instances of
396 396 # the shares svc.
397 397 #
398 398 for i in $(/usr/bin/egrep network/shares/group $insttmpfile)
399 399 do
400 400 vlog "$v_dissvc" "$i"
401 401 /usr/sbin/zlogin -S $ZONENAME /usr/sbin/svcadm disable $i || \
402 402 error "$e_dissvc" $i
403 403 done
404 404
405 405 /usr/bin/rm -f $insttmpfile
406 406
407 407 return 0
408 408 }
409 409
410 410 #
411 411 # Remove well-known pkgs that do not work inside a zone.
412 412 #
413 413 rm_pkgs()
414 414 {
415 415 /usr/bin/cat <<-EOF > $ZONEROOT/tmp/admin || fatal "$e_adminf"
416 416 mail=
417 417 instance=overwrite
418 418 partial=nocheck
419 419 runlevel=nocheck
420 420 idepend=nocheck
421 421 rdepend=nocheck
422 422 space=nocheck
423 423 setuid=nocheck
424 424 conflict=nocheck
425 425 action=nocheck
426 426 basedir=default
427 427 EOF
428 428
429 429 for i in $(/usr/bin/egrep -hv "^#" /usr/lib/brand/solaris10/pkgrm.lst \
430 430 /etc/brand/solaris10/pkgrm.conf)
431 431 do
432 432 [[ ! -d $ZONEROOT/var/sadm/pkg/$i ]] && continue
433 433
434 434 vlog "$v_rmpkg" "$i"
435 435 /usr/sbin/zlogin -S $ZONENAME \
436 436 /usr/sbin/pkgrm -na /tmp/admin $i >&2 || error "$e_rmpkg" $i
437 437 done
438 438 }
439 439
440 440 #
441 441 # Zoneadmd writes a one-line index file into the zone when the zone boots,
442 442 # so any information about installed zones from the original system will
443 443 # be lost at that time. Here we'll warn the sysadmin about any pre-existing
444 444 # zones that they might want to clean up by hand, but we'll leave the zonepaths
445 445 # in place in case they're on shared storage and will be migrated to
446 446 # a new host.
447 447 #
448 448 warn_zones()
449 449 {
450 450 zoneconfig=$ZONEROOT/etc/zones
↓ open down ↓ |
450 lines elided |
↑ open up ↑ |
451 451
452 452 [[ ! -d $zoneconfig ]] && return
453 453
454 454 if [[ -h $zoneconfig/index || ! -f $zoneconfig/index ]]; then
455 455 error "$e_badfile" "/etc/zones/index"
456 456 return
457 457 fi
458 458
459 459 NGZ=$(/usr/bin/nawk -F: '{
460 460 if (substr($1, 0, 1) == "#" || $1 == "global")
461 - continue
461 + next
462 462
463 463 if ($2 == "installed")
464 464 printf("%s ", $1)
465 465 }' $zoneconfig/index)
466 466
467 467 # Return if there are no installed zones to warn about.
468 468 [[ -z "$NGZ" ]] && return
469 469
470 470 log "$v_rmzones" "$NGZ"
471 471
472 472 NGZP=$(/usr/bin/nawk -F: '{
473 473 if (substr($1, 0, 1) == "#" || $1 == "global")
474 - continue
474 + next
475 475
476 476 if ($2 == "installed")
477 477 printf("%s ", $3)
478 478 }' $zoneconfig/index)
479 479
480 480 log "$v_rmzonepaths"
481 481
482 482 for i in $NGZP
483 483 do
484 484 log " %s" "$i"
485 485 done
486 486 }
487 487
488 488 #
489 489 # ^C Should cleanup; if the zone is running, it should try to halt it.
490 490 #
491 491 zone_is_running=0
492 492 trap trap_cleanup INT
493 493
494 494 #
495 495 # Parse the command line options.
496 496 #
497 497 OPT_U=
498 498 OPT_V=
499 499 OPT_M=
500 500 OPT_L=
501 501 while getopts "uvm:l:" opt
502 502 do
503 503 case "$opt" in
504 504 u) OPT_U="-u";;
505 505 v) OPT_V="-v";;
506 506 m) MSG_PREFIX="$OPTARG"; OPT_M="-m \"$OPTARG\"";;
507 507 l) LOGFILE="$OPTARG"; OPT_L="-l \"$OPTARG\"";;
508 508 *) usage;;
509 509 esac
510 510 done
511 511 shift OPTIND-1
512 512
513 513 (( $# < 1 )) && usage
514 514
515 515 (( $# > 2 )) && usage
516 516
517 517 [[ -n $LOGFILE ]] && exec 2>>$LOGFILE
518 518
519 519 ZONENAME=$1
520 520 ZONEPATH=$2
521 521 # XXX shared/common script currently uses lower case zonename & zonepath
522 522 zonename="$ZONENAME"
523 523 zonepath="$ZONEPATH"
524 524 ZONEROOT=$ZONEPATH/root
525 525
526 526 e_badinfo=$(gettext "Failed to get '%s' zone resource")
527 527 e_badfile=$(gettext "Invalid '%s' file within the zone")
528 528 v_mkdirs=$(gettext "Creating mount points")
529 529 v_nonetfix=$(gettext "Cannot update /etc/hostname.{net} file")
530 530 v_adjust=$(gettext "Updating the image to run within a zone")
531 531 v_stacktype=$(gettext "Stack type '%s'")
532 532 v_booting=$(gettext "Booting zone to single user mode")
533 533 e_bootfail=$(gettext "Failed to boot zone to single user mode.")
534 534 e_nosmf=$(gettext "SMF repository unavailable.")
535 535 v_svcsinzone=$(gettext "The following SMF services are installed:")
536 536 v_rmhollowsvcs=$(gettext "Deleting SMF services from hollow packages")
537 537 v_fixnetsvcs=$(gettext "Adjusting network SMF services")
538 538 v_rminvalidsvcs=$(gettext "Disabling invalid SMF services")
539 539 v_delsvc=$(gettext "Delete SMF svc '%s'")
540 540 e_delsvc=$(gettext "deleting SMF svc '%s'")
541 541 v_enblsvc=$(gettext "Enable SMF svc '%s'")
542 542 e_enblsvc=$(gettext "enabling SMF svc '%s'")
543 543 v_dissvc=$(gettext "Disable SMF svc '%s'")
544 544 e_dissvc=$(gettext "disabling SMF svc '%s'")
545 545 e_adminf=$(gettext "Unable to create admin file")
546 546 v_rmpkg=$(gettext "Remove package '%s'")
547 547 e_rmpkg=$(gettext "removing package '%s'")
548 548 v_rmzones=$(gettext "The following zones in this image will be unusable: %s")
549 549 v_rmzonepaths=$(gettext "These zonepaths could be removed from this image:")
550 550 v_halting=$(gettext "Halting zone")
551 551 e_shutdown=$(gettext "Shutting down zone %s...")
552 552 e_badhalt=$(gettext "Zone halt failed")
553 553 v_exitgood=$(gettext "Postprocessing successful.")
554 554 e_exitfail=$(gettext "Postprocessing failed.")
555 555
556 556 #
557 557 # Do some validation on the paths we'll be accessing
558 558 #
559 559 safe_dir /etc
560 560 safe_dir /var
561 561 safe_dir /var/sadm
562 562 safe_dir /var/sadm/install
563 563 safe_dir /var/sadm/pkg
564 564 safe_opt_dir /etc/dfs
565 565 safe_opt_dir /etc/lu
566 566 safe_opt_dir /etc/zones
567 567
568 568 mk_zone_dirs
569 569
570 570 # Now do the work to update the zone.
571 571
572 572 # Check for zones inside of image.
573 573 warn_zones
574 574 fix_smf_pre_uoa
575 575
576 576 log "$v_adjust"
577 577
578 578 #
579 579 # Any errors in these functions are not considered fatal. The zone can be
580 580 # be fixed up manually afterwards and it may need some additional manual
581 581 # cleanup in any case.
582 582 #
583 583
584 584 STACK_TYPE=$(/usr/sbin/zoneadm -z $ZONENAME list -p | \
585 585 /usr/bin/nawk -F: '{print $7}')
586 586 if (( $? != 0 )); then
587 587 error "$e_badinfo" "stacktype"
588 588 fi
589 589 vlog "$v_stacktype" "$STACK_TYPE"
590 590
591 591 fix_lu
592 592 fix_net
593 593 fix_nfs
594 594 fix_vfstab
595 595
596 596 vlog "$v_booting"
597 597
598 598 #
599 599 # Boot the zone so that we can do all of the SMF updates needed on the zone's
600 600 # repository.
601 601 #
602 602
603 603 zone_is_running=1
604 604
605 605 /usr/sbin/zoneadm -z $ZONENAME boot -f -- -m milestone=none
606 606 if (( $? != 0 )); then
607 607 error "$e_badboot"
608 608 /usr/bin/rm -f $SMFTMPFILE
609 609 fatal "$e_exitfail"
610 610 fi
611 611
612 612 #
613 613 # Remove all files and directories installed by hollow packages. Such files
614 614 # and directories shouldn't exist inside zones.
615 615 #
616 616 hollow_pkgs=$(mktemp -t .hollow.pkgs.XXXXXX)
617 617 hollow_file_list=$(mktemp $ZONEROOT/.hollow.pkgs.files.XXXXXX)
618 618 hollow_dir_list=$(mktemp $ZONEROOT/.hollow.pkgs.dirs.XXXXXX)
619 619 [ -f "$hollow_pkgs" -a -f "$hollow_file_list" -a -f "$hollow_dir_list" ] || {
620 620 error "$e_tmpfile"
621 621 rm -f $hollow_pkgs $hollow_file_list $hollow_dir_list
622 622 fatal "$e_exitfail"
623 623 }
624 624 for pkg_name in $ZONEROOT/var/sadm/pkg/*; do
625 625 grep 'SUNW_PKG_HOLLOW=true' $pkg_name/pkginfo >/dev/null 2>&1 && \
626 626 basename $pkg_name >>$hollow_pkgs
627 627 done
628 628 /usr/bin/nawk -v hollowpkgs=$hollow_pkgs -v filelist=$hollow_file_list \
629 629 -v dirlist=$hollow_dir_list '
630 630 BEGIN {
631 631 while (getline p <hollowpkgs > 0)
632 632 pkgs[p] = 1;
633 633 close(hollowpkgs);
634 634 }
635 635 {
636 636 # fld is the field where the pkg names begin.
637 637 # nm is the file/dir entry name.
638 638 if ($2 == "f") {
639 639 fld=10;
640 640 nm=$1;
641 641 } else if ($2 == "d") {
642 642 fld=7;
643 643 nm=$1;
644 644 } else if ($2 == "s" || $2 == "l") {
645 645 fld=4;
646 646 split($1, a, "=");
647 647 nm=a[1];
648 648 } else {
649 649 next;
650 650 }
651 651
652 652 # Determine whether the file or directory is delivered by any
653 653 # non-hollow packages. Files and directories can be
654 654 # delivered by multiple pkgs. The file or directory should only
655 655 # be removed if it is only delivered by hollow packages.
656 656 for (i = fld; i <= NF; i++) {
657 657 if (pkgs[get_pkg_name($i)] != 1) {
658 658 # We encountered a non-hollow package. Skip
659 659 # this entry.
660 660 next;
661 661 }
662 662 }
663 663
664 664 # The file or directory is only delivered by hollow packages.
665 665 # Mark it for removal.
666 666 if (fld != 7)
667 667 print nm >>filelist
668 668 else
669 669 print nm >>dirlist
670 670 }
671 671
672 672 # Get the clean pkg name from the fld entry.
673 673 function get_pkg_name(fld) {
674 674 # Remove any pkg control prefix (e.g. *, !)
675 675 first = substr(fld, 1, 1)
676 676 if (match(first, /[A-Za-z]/)) {
677 677 pname = fld
678 678 } else {
679 679 pname = substr(fld, 2)
680 680 }
681 681
682 682 # Then remove any class action script name
683 683 pos = index(pname, ":")
684 684 if (pos != 0)
685 685 pname = substr(pname, 1, pos - 1)
686 686 return (pname)
687 687 }
688 688 ' $ZONEROOT/var/sadm/install/contents
689 689 /usr/sbin/zlogin -S $ZONENAME "cat /$(basename $hollow_file_list) | xargs rm -f"
690 690 /usr/sbin/zlogin -S $ZONENAME "sort -r /$(basename $hollow_dir_list) | \
691 691 xargs rmdir >/dev/null 2>&1"
692 692 rm -f $hollow_pkgs $hollow_file_list $hollow_dir_list
693 693
694 694 # cleanup SMF services
695 695 fix_smf || failed=1
696 696
697 697 # remove invalid pkgs
698 698 [[ -z $failed ]] && rm_pkgs
699 699
700 700 if [[ -z $failed && -n $OPT_U ]]; then
701 701 vlog "$v_unconfig"
702 702
703 703 sysunconfig_zone
704 704 if (( $? != 0 )); then
705 705 failed=1
706 706 fi
707 707 fi
708 708
709 709 vlog "$v_halting"
710 710 /usr/sbin/zoneadm -z $ZONENAME halt
711 711 if (( $? != 0 )); then
712 712 error "$e_badhalt"
713 713 failed=1
714 714 fi
715 715 zone_is_running=0
716 716
717 717 if [[ -n $failed ]]; then
718 718 fatal "$e_exitfail"
719 719 fi
720 720
721 721 vlog "$v_exitgood"
722 722 exit 0
↓ open down ↓ |
238 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX