src/brand/attach
author Andrzej Szeszo <aszeszo@gmail.com>
Wed, 01 Jun 2011 13:04:31 +0100
changeset 2390 f1c659f5c28e
parent 2235 1f446820dcb0
child 2391 90c532b69592
permissions -rw-r--r--
Backed out changeset 1f446820dcb0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
654
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
     1
#!/bin/ksh -p
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
     2
#
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
     3
# CDDL HEADER START
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
     4
#
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
     5
# The contents of this file are subject to the terms of the
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
     6
# Common Development and Distribution License (the "License").
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
     7
# You may not use this file except in compliance with the License.
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
     8
#
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
     9
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
    10
# or http://www.opensolaris.org/os/licensing.
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
    11
# See the License for the specific language governing permissions
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
    12
# and limitations under the License.
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
    13
#
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
    14
# When distributing Covered Code, include this CDDL HEADER in each
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
    15
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
    16
# If applicable, add the following below this CDDL HEADER, with the
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
    17
# fields enclosed by brackets "[]" replaced with your own identifying
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
    18
# information: Portions Copyright [yyyy] [name of copyright owner]
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
    19
#
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
    20
# CDDL HEADER END
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
    21
#
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
    22
654
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
    23
#
2170
6e5ddf75b5ea 17309 brand attach global zone sanity check needs updating
Dan Price <daniel.price@oracle.com>
parents: 2148
diff changeset
    24
# Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
654
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
    25
#
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
    26
1483
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
    27
. /usr/lib/brand/ipkg/common.ksh
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
    28
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
    29
m_attach_log=$(gettext "Log File: %s")
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
    30
m_zfs=$(gettext "A ZFS file system was created for the zone.")
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
    31
m_usage=$(gettext  "attach [-a archive] [-d dataset] [-n] [-r zfs-recv] [-u]\n\tThe -a archive option specifies a tar file or cpio archive.\n\tThe -d dataset option specifies an existing dataset.\n\tThe -r zfs-recv option receives the output of a 'zfs send' command\n\tof an existing zone root dataset.\n\tThe -u option indicates that the software should be updated to match\n\tthe current host.")
2174
f11c77f93a8a 15594 zone attach code needs more error checking
Dan Price <daniel.price@oracle.com>
parents: 2170
diff changeset
    32
m_attach_root=$(gettext "               Attach Path: %s")
f11c77f93a8a 15594 zone attach code needs more error checking
Dan Price <daniel.price@oracle.com>
parents: 2170
diff changeset
    33
m_attach_ds=$(gettext   "        Attach ZFS Dataset: %s")
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
    34
m_gzinc=$(gettext       "       Global zone version: %s")
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
    35
m_zinc=$(gettext        "   Non-Global zone version: %s")
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
    36
m_need_update=$(gettext "                Evaluation: Packages in zone %s are out of sync with the global zone. To proceed, retry with the -u flag.")
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
    37
m_cache=$(gettext       "                     Cache: Using %s.")
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
    38
m_updating=$(gettext    "  Updating non-global zone: Output follows")
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
    39
m_sync_done=$(gettext   "  Updating non-global zone: Zone updated.")
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
    40
m_complete=$(gettext    "                    Result: Attach Succeeded.")
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
    41
m_failed=$(gettext      "                    Result: Attach Failed.")
2174
f11c77f93a8a 15594 zone attach code needs more error checking
Dan Price <daniel.price@oracle.com>
parents: 2170
diff changeset
    42
f11c77f93a8a 15594 zone attach code needs more error checking
Dan Price <daniel.price@oracle.com>
parents: 2170
diff changeset
    43
#
f11c77f93a8a 15594 zone attach code needs more error checking
Dan Price <daniel.price@oracle.com>
parents: 2170
diff changeset
    44
# These two messages are used by the install_image function in
f11c77f93a8a 15594 zone attach code needs more error checking
Dan Price <daniel.price@oracle.com>
parents: 2170
diff changeset
    45
# /usr/lib/brand/shared/common.ksh.  Yes, this is terrible.
f11c77f93a8a 15594 zone attach code needs more error checking
Dan Price <daniel.price@oracle.com>
parents: 2170
diff changeset
    46
#
f11c77f93a8a 15594 zone attach code needs more error checking
Dan Price <daniel.price@oracle.com>
parents: 2170
diff changeset
    47
installing=$(gettext    "                Installing: This may take several minutes...")
f11c77f93a8a 15594 zone attach code needs more error checking
Dan Price <daniel.price@oracle.com>
parents: 2170
diff changeset
    48
no_installing=$(gettext "                Installing: Using pre-existing data in zonepath")
f11c77f93a8a 15594 zone attach code needs more error checking
Dan Price <daniel.price@oracle.com>
parents: 2170
diff changeset
    49
2170
6e5ddf75b5ea 17309 brand attach global zone sanity check needs updating
Dan Price <daniel.price@oracle.com>
parents: 2148
diff changeset
    50
f_sanity_variant=$(gettext "  Sanity Check: FAILED, couldn't determine %s from image.")
6e5ddf75b5ea 17309 brand attach global zone sanity check needs updating
Dan Price <daniel.price@oracle.com>
parents: 2148
diff changeset
    51
f_sanity_global=$(gettext  "  Sanity Check: FAILED, appears to be a global zone (%s=%s).")
654
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
    52
f_update=$(gettext "Could not update attaching zone")
1091
fc73bc2d78ce 7490 ipkg brand attach needs similar logic to pkgcreatezone for 'entire' incorporation
Dan Price <dp@eng.sun.com>
parents: 752
diff changeset
    53
f_no_pref_publisher=$(gettext "Unable to get preferred publisher information for zone '%s'.")
1111
26c3e2407c53 8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents: 1091
diff changeset
    54
f_nosuch_key=$(gettext "Failed to find key %s for global zone publisher")
26c3e2407c53 8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents: 1091
diff changeset
    55
f_nosuch_cert=$(gettext "Failed to find cert %s for global zone publisher")
2174
f11c77f93a8a 15594 zone attach code needs more error checking
Dan Price <daniel.price@oracle.com>
parents: 2170
diff changeset
    56
f_ds_config=$(gettext  "Failed to configure dataset %s: could not set %s.")
f11c77f93a8a 15594 zone attach code needs more error checking
Dan Price <daniel.price@oracle.com>
parents: 2170
diff changeset
    57
f_no_active_ds_mounted=$(gettext  "Failed to locate any dataset mounted at %s.  Attach requires a mounted dataset.")
1091
fc73bc2d78ce 7490 ipkg brand attach needs similar logic to pkgcreatezone for 'entire' incorporation
Dan Price <dp@eng.sun.com>
parents: 752
diff changeset
    58
1483
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
    59
# Clean up on interrupt
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
    60
trap_cleanup() {
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
    61
	typeset msg=$(gettext "Installation cancelled due to interrupt.")
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
    62
1483
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
    63
	log "$msg"
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
    64
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
    65
	# umount any mounted file systems
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
    66
	umnt_fs
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
    67
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
    68
	trap_exit
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
    69
}
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
    70
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
    71
# If the attach failed then clean up the ZFS datasets we created.
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
    72
trap_exit() {
1483
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
    73
	if [[ $EXIT_CODE == $ZONE_SUBPROC_OK ]]; then
1493
625950c12e71 3979 zone fs only available from Global zone, when zone is booted
<gerald.jelinek@sun.com>
parents: 1483
diff changeset
    74
		# unmount the zoneroot if labeled brand
625950c12e71 3979 zone fs only available from Global zone, when zone is booted
<gerald.jelinek@sun.com>
parents: 1483
diff changeset
    75
		is_brand_labeled
625950c12e71 3979 zone fs only available from Global zone, when zone is booted
<gerald.jelinek@sun.com>
parents: 1483
diff changeset
    76
		(( $? == 1 )) && ( umount $ZONEROOT || \
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
    77
		    log "$f_zfs_unmount" "$ZONEPATH/root" )
1483
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
    78
	else
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
    79
		if [[ "$install_media" != "-" ]]; then
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
    80
			/usr/lib/brand/ipkg/uninstall $ZONENAME $ZONEPATH -F
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
    81
		else
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
    82
			# Restore the zone properties for the pre-existing
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
    83
			# dataset.
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
    84
			if [[ -n "$ACTIVE_DS" ]]; then
2174
f11c77f93a8a 15594 zone attach code needs more error checking
Dan Price <daniel.price@oracle.com>
parents: 2170
diff changeset
    85
				zfs set zoned=off $ACTIVE_DS
f11c77f93a8a 15594 zone attach code needs more error checking
Dan Price <daniel.price@oracle.com>
parents: 2170
diff changeset
    86
				(( $? != 0 )) && error "$f_ds_config" \
f11c77f93a8a 15594 zone attach code needs more error checking
Dan Price <daniel.price@oracle.com>
parents: 2170
diff changeset
    87
				    "$ACTIVE_DS" "zoned=off"
2390
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
    88
				zfs set canmount=on $ACTIVE_DS
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
    89
				(( $? != 0 )) && error "$f_ds_config" \
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
    90
				    "$ACTIVE_DS" "canmount=on"
2235
1f446820dcb0 17791 ipkg brand needs to be in sync with revised dataset layout
Mike Gerdts <mike.gerdts@oracle.com>
parents: 2219
diff changeset
    91
				zfs set mountpoint=$ZONEROOT $ACTIVE_DS
1f446820dcb0 17791 ipkg brand needs to be in sync with revised dataset layout
Mike Gerdts <mike.gerdts@oracle.com>
parents: 2219
diff changeset
    92
				(( $? != 0 )) && error "$f_ds_config" \
1f446820dcb0 17791 ipkg brand needs to be in sync with revised dataset layout
Mike Gerdts <mike.gerdts@oracle.com>
parents: 2219
diff changeset
    93
				    "$ACTIVE_DS" "mountpoint=$ZONEROOT"
1483
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
    94
			fi
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
    95
		fi
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
    96
		log "$m_failed"
1483
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
    97
	fi
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
    98
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
    99
	exit $EXIT_CODE
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   100
}
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   101
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   102
EXIT_CODE=$ZONE_SUBPROC_USAGE
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   103
install_media="-"
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   104
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   105
trap trap_cleanup INT
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   106
trap trap_exit EXIT
654
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   107
2390
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   108
#set -o xtrace
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   109
1111
26c3e2407c53 8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents: 1091
diff changeset
   110
PKG="/usr/bin/pkg"
26c3e2407c53 8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents: 1091
diff changeset
   111
KEYDIR=/var/pkg/ssl
26c3e2407c53 8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents: 1091
diff changeset
   112
1483
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   113
# If we weren't passed at least two arguments, exit now.
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   114
(( $# < 2 )) && exit $ZONE_SUBPROC_USAGE
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   115
2390
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   116
ZONENAME="$1"
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   117
ZONEPATH="$2"
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   118
# XXX shared/common script currently uses lower case zonename & zonepath
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   119
zonename="$ZONENAME"
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   120
zonepath="$ZONEPATH"
1483
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   121
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   122
shift; shift	# remove ZONENAME and ZONEPATH from arguments array
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   123
2390
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   124
ZONEROOT="$ZONEPATH/root"
1483
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   125
logdir="$ZONEROOT/var/log"
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   126
1111
26c3e2407c53 8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents: 1091
diff changeset
   127
#
26c3e2407c53 8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents: 1091
diff changeset
   128
# Resetting GZ_IMAGE to something besides slash allows for simplified
26c3e2407c53 8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents: 1091
diff changeset
   129
# debugging of various global zone image configurations-- simply make
26c3e2407c53 8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents: 1091
diff changeset
   130
# an image somewhere with the appropriate interesting parameters.
26c3e2407c53 8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents: 1091
diff changeset
   131
#
26c3e2407c53 8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents: 1091
diff changeset
   132
GZ_IMAGE=${GZ_IMAGE:-/}
26c3e2407c53 8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents: 1091
diff changeset
   133
PKG_IMAGE=$GZ_IMAGE
26c3e2407c53 8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents: 1091
diff changeset
   134
export PKG_IMAGE
1091
fc73bc2d78ce 7490 ipkg brand attach needs similar logic to pkgcreatezone for 'entire' incorporation
Dan Price <dp@eng.sun.com>
parents: 752
diff changeset
   135
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   136
allow_update=0
654
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   137
noexecute=0
1483
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   138
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   139
unset inst_type
654
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   140
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   141
# Get publisher information for global zone.  These structures are used
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   142
# to store information about the global zone publishers and
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   143
# incorporations.
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   144
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   145
typeset -A gz_publishers
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   146
typeset gz_incorporations=""
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   147
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   148
#
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   149
# Gather the zone publisher details. $1 is the location of the image we
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   150
# are processing and $2 is an associative array used to store publisher
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   151
# details.
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   152
#
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   153
gather_zone_publisher_details() {
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   154
	STORED_IMAGE=$PKG_IMAGE
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   155
	PKG_IMAGE=$1;export PKG_IMAGE
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   156
	typeset -n publishers=$2
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   157
	typeset -li publisher_count=0
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   158
	typeset -li url_count=0
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   159
	typeset line=
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   160
	typeset name=
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   161
	typeset mirror=
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   162
	typeset origin=
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   163
	typeset opublisher=
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   164
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   165
	#
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   166
	# Store publisher, origin and security details. It is assumed
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   167
	# that mirrors all use the same key as the origins.
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   168
	#
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   169
	for line in $(get_publisher_urls all origin); do
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   170
		print $line | IFS="=" read name origin
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   171
		# When a publisher has multiple origins, the
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   172
		# additional origins don't contain the publisher
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   173
		# name. Correct for this by checking if origin is not
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   174
		# set by get_publisher_urls() and, if so, use the
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   175
		# "name" as the origin and set the name to the value
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   176
		# we have already saved.
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   177
		if [[ -z $origin ]]; then
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   178
			origin=$name
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   179
			name=${publisher.name}
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2193
diff changeset
   180
		elif [[ "$origin" == "None" ]]; then
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2193
diff changeset
   181
			# Publisher with no origins.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2193
diff changeset
   182
			origin=""
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   183
		fi
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2193
diff changeset
   184
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   185
		# Use a compound variable to store all the data
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   186
		# relating to a publisher.
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   187
		if [[ -z ${publishers[$name]} ]]; then
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   188
			typeset -C publisher_$publisher_count
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   189
			typeset -n publisher=publisher_$publisher_count
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   190
			typeset publisher.sticky=""
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   191
			typeset publisher.preferred=""
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   192
			typeset publisher.enabled=""
2390
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   193
			typeset -a publisher.origins=""
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   194
			typeset -a publisher.mirrors=""
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   195
			typeset publisher.name=$name
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   196
			typeset publisher.keyfile=""
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   197
			typeset publisher.certfile=""
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   198
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   199
			get_publisher_attrs ${publisher.name} origin | \
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   200
			    IFS=" " read publisher.sticky publisher.preferred \
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   201
			    publisher.enabled
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2193
diff changeset
   202
			if [[ -n "$origin" ]]; then
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2193
diff changeset
   203
				get_pub_secinfo ${publisher.name} | \
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2193
diff changeset
   204
				    read publisher.keyfile publisher.certfile
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2193
diff changeset
   205
				[[ ${publisher.keyfile} != "None" && \
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2193
diff changeset
   206
				    ! -f ${PKG_IMAGE}/${publisher.keyfile} ]] && \
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2193
diff changeset
   207
				    fail_usage "$f_nosuch_key" \
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2193
diff changeset
   208
				        ${publisher.keyfile}
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2193
diff changeset
   209
				[[ ${publisher.certfile} != "None" && \
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2193
diff changeset
   210
				    ! -f ${PKG_IMAGE}/${publisher.certfile} ]] && \
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2193
diff changeset
   211
				    fail_usage "$f_nosuch_cert" \
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2193
diff changeset
   212
				        ${publisher.certfile}
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2193
diff changeset
   213
			else
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2193
diff changeset
   214
				# Publisher has no origins.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2193
diff changeset
   215
				publisher.keyfile="None"
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2193
diff changeset
   216
				publisher.certfile="None"
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2193
diff changeset
   217
			fi
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   218
			publisher_count=publisher_count+1
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   219
			url_count=0
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   220
		fi
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   221
		publisher.origins[$url_count]=$origin
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   222
		publishers[$name]=${publisher}
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   223
		url_count=url_count+1
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   224
	done
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   225
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   226
	#
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   227
	# Store mirror details
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   228
	#
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   229
	url_count=0
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   230
	for line in $(get_publisher_urls all mirror); do
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   231
		print $line | IFS="=" read name mirror
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   232
		if [[ -z $mirror ]]; then
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   233
			mirror=$name
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   234
			name=${publisher.name}
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   235
		fi
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   236
		if [[ -z $opublisher || $opublisher != $name ]]; then
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   237
			opublisher=$name
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   238
			eval publisher="${publishers[$name]}"
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   239
			url_count=0
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   240
		fi
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   241
		publisher.mirrors[$url_count]=$mirror
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   242
		publishers[$name]=${publisher}
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   243
		url_count=url_count+1
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   244
	done
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   245
	
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   246
	PKG_IMAGE=$STORED_IMAGE;export PKG_IMAGE
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   247
}
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   248
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   249
#
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   250
# $1 is an associative array of publishers. Search this array and
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   251
# return the preferred publisher.
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   252
#
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   253
get_preferred_publisher() {
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   254
	typeset -n publishers=$1
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   255
	typeset publisher=
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   256
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   257
	for key in ${!publishers[*]}; do
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   258
		eval publisher="${publishers[$key]}"
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   259
		if [[ ${publisher.preferred}  ==  "true" ]]; then
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   260
			print ${key}
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   261
			return 0
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   262
		fi
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   263
	done
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   264
	return 1
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   265
}
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   266
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   267
#
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   268
# $1 is an empty string to be populated with a list of incorporation
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   269
# fmris.
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   270
#
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   271
gather_incorporations() {
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   272
	typeset -n incorporations=$1
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   273
	typeset p=
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   274
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   275
	for p in \
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   276
	    $(LC_ALL=C $PKG search -Hl -o pkg.name \
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   277
	    ':pkg.depend.install-hold:core-os*');do
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   278
		incorporations="$incorporations $(get_pkg_fmri $p)"
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   279
	done
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   280
}
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   281
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   282
#
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   283
# Print the pkg(1) command which defines a publisher. $1 is an associative 
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   284
# array of publisher details and $2 is the publisher to be printed.
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   285
#
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   286
print_publisher_pkg_defn() {
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   287
	typeset -n publishers=$1
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   288
	typeset pname=$2
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   289
	typeset publisher=
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   290
	typeset args=""
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   291
	typeset origin=
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   292
	typeset mirror=
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   293
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   294
	eval publisher="${publishers[$pname]}"
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   295
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   296
	if [[ ${publisher.preferred} == "true" ]]; then
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   297
		args="$args -P"
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   298
	fi
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   299
2390
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   300
	for origin in ${publisher.origins[*]}; do
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   301
		args="$args -g $origin"
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   302
	done
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   303
2390
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   304
	for mirror in ${publisher.mirrors[*]}; do
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   305
		args="$args -m $mirror"
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   306
	done
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   307
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   308
	if [[ ${publisher.sticky} == "true" ]]; then
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   309
		args="$args --sticky"
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   310
	else
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   311
		args="$args --non-sticky"
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   312
	fi
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   313
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   314
	if [[ ${publisher.enabled} == "true" ]]; then
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   315
		args="$args --enable"
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   316
	else
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   317
		args="$args --disable"
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   318
	fi
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   319
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   320
	echo "$args"
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   321
}
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   322
654
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   323
# Other brand attach options are invalid for this brand.
1483
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   324
while getopts "a:d:nr:u" opt; do
654
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   325
	case $opt in
1483
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   326
		a)
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   327
			if [[ -n "$inst_type" ]]; then
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   328
				fatal "$incompat_options" "$m_usage"
654
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   329
			fi
1483
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   330
		 	inst_type="archive"
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   331
			install_media="$OPTARG"
654
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   332
			;;
1483
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   333
		d)
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   334
			if [[ -n "$inst_type" ]]; then
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   335
				fatal "$incompat_options" "$m_usage"
752
e5ad1cf6281f 4513 need option to attach existing dataset
<gerald.jelinek@sun.com>
parents: 654
diff changeset
   336
			fi
1483
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   337
		 	inst_type="directory"
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   338
			install_media="$OPTARG"
752
e5ad1cf6281f 4513 need option to attach existing dataset
<gerald.jelinek@sun.com>
parents: 654
diff changeset
   339
			;;
654
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   340
		n)	noexecute=1 ;;
1483
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   341
		r)
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   342
			if [[ -n "$inst_type" ]]; then
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   343
				fatal "$incompat_options" "$m_usage"
654
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   344
			fi
1483
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   345
		 	inst_type="stdin"
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   346
			install_media="$OPTARG"
654
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   347
			;;
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   348
		u)	allow_update=1 ;;
1483
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   349
		?)	fail_usage "" ;;
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   350
		*)	fail_usage "";;
654
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   351
	esac
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   352
done
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   353
shift $((OPTIND-1))
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   354
1483
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   355
if [[ $noexecute == 1 && -n "$inst_type" ]]; then
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   356
	fatal "$m_usage"
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   357
fi
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   358
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   359
[[ -z "$inst_type" ]] && inst_type="directory"
654
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   360
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   361
if [ $noexecute -eq 1 ]; then
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   362
	#
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   363
	# The zone doesn't have to exist when the -n option is used, so do
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   364
	# this work early.
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   365
	#
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   366
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   367
	# XXX There is no sw validation for IPS right now, so just pretend
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   368
	# everything will be ok.
1483
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   369
	EXIT_CODE=$ZONE_SUBPROC_OK
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   370
	exit $ZONE_SUBPROC_OK
654
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   371
fi
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   372
2390
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   373
LOGFILE=$(/usr/bin/mktemp -t -p /var/tmp $ZONENAME.attach_log.XXXXXX)
1483
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   374
if [[ -z "$LOGFILE" ]]; then
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   375
	fatal "$e_tmpfile"
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   376
fi
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   377
exec 2>>"$LOGFILE"
2390
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   378
1483
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   379
log "$m_attach_log" "$LOGFILE"
654
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   380
2390
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   381
#
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   382
# TODO - once sxce is gone, move the following block into
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   383
# usr/lib/brand/shared/common.ksh code to share with other brands using
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   384
# the same zfs dataset logic for attach. This currently uses get_current_gzbe
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   385
# so we can't move it yet since beadm isn't in sxce.
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   386
#
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   387
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   388
# Validate that the zonepath is not in the root dataset.
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   389
pdir=`dirname $ZONEPATH`
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   390
get_zonepath_ds $pdir
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   391
fail_zonepath_in_rootds $ZONEPATH_DS
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   392
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   393
EXIT_CODE=$ZONE_SUBPROC_NOTCOMPLETE
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   394
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   395
if [[ "$install_media" == "-" ]]; then
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   396
	#
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   397
	# Since we're using a pre-existing dataset, the dataset currently
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   398
	# mounted on the {zonepath}/root becomes the active dataset.  We
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   399
	# can't depend on the usual dataset attributes to detect this since
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   400
	# the dataset could be a detached zone or one that the user set up by
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   401
	# hand and lacking the proper attributes.  However, since the zone is
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   402
	# not attached yet, the 'install_media == -' means the dataset must be
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   403
	# mounted at this point.
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   404
	#
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   405
	ACTIVE_DS=`mount -p | nawk -v zroot=$ZONEROOT '{
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   406
	    if ($3 == zroot && $4 == "zfs")
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   407
		    print $1
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   408
	}'`
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   409
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   410
	[[ -z "$ACTIVE_DS" ]] && fatal "$f_no_active_ds_mounted" $ZONEROOT
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   411
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   412
	# Set up proper attributes on the ROOT dataset.
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   413
	get_zonepath_ds $ZONEPATH
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   414
	zfs list -H -t filesystem -o name $ZONEPATH_DS/ROOT >/dev/null 2>&1
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   415
	(( $? != 0 )) && fatal "$f_no_active_ds"
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   416
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   417
	# need to ensure zoned is off to set mountpoint=legacy.
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   418
	zfs set zoned=off $ZONEPATH_DS/ROOT
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   419
	(( $? != 0 )) && fatal "$f_ds_config" $ZONEPATH_DS/ROOT "zoned=off"
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   420
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   421
	zfs set mountpoint=legacy $ZONEPATH_DS/ROOT
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   422
	(( $? != 0 )) && fatal "$f_ds_config" $ZONEPATH_DS/ROOT \
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   423
	    "mountpoint=legacy"
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   424
	zfs set zoned=on $ZONEPATH_DS/ROOT
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   425
	(( $? != 0 )) && fatal "$f_ds_config" $ZONEPATH_DS/ROOT "zoned=on"
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   426
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   427
	#
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   428
	# We're typically using a pre-existing mounted dataset so setting the
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   429
	# following propery changes will cause the {zonepath}/root dataset to
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   430
	# be unmounted.  However, a p2v with an update-on-attach will have
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   431
	# created the dataset with the correct properties, so setting these
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   432
	# attributes won't unmount the dataset.  Thus, we check the mount
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   433
	# and attempt the remount if necessary.
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   434
	#
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   435
	get_current_gzbe
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   436
	zfs set $PROP_PARENT=$CURRENT_GZBE $ACTIVE_DS
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   437
	(( $? != 0 )) && fatal "$f_ds_config" $ACTIVE_DS \
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   438
	    "$PROP_PARENT=$CURRENT_GZBE"
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   439
	zfs set $PROP_ACTIVE=on $ACTIVE_DS
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   440
	(( $? != 0 )) && fatal "$f_ds_config" $ACTIVE_DS "$PROP_ACTIVE=on"
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   441
	zfs set canmount=noauto $ACTIVE_DS
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   442
	(( $? != 0 )) && fatal "$f_ds_config" $ACTIVE_DS "canmount=noauto"
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   443
	zfs set zoned=off $ACTIVE_DS
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   444
	(( $? != 0 )) && fatal "$f_ds_config" $ACTIVE_DS "zoned=off"
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   445
	zfs inherit mountpoint $ACTIVE_DS
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   446
	(( $? != 0 )) && fatal "$f_ds_config" $ACTIVE_DS "'inherit mountpoint'"
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   447
	zfs inherit zoned $ACTIVE_DS
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   448
	(( $? != 0 )) && fatal "$f_ds_config" $ACTIVE_DS "'inherit zoned'"
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   449
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   450
	mounted_ds=`mount -p | nawk -v zroot=$ZONEROOT '{
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   451
	    if ($3 == zroot && $4 == "zfs")
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   452
		    print $1
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   453
	}'`
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   454
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   455
	if [[ -z $mounted_ds ]]; then
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   456
		mount -F zfs $ACTIVE_DS $ZONEROOT || fatal "$f_zfs_mount"
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   457
	fi
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   458
else
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   459
	#
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   460
	# Since we're not using a pre-existing ZFS dataset layout, create
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   461
	# the zone datasets and mount them.  Start by creating the zonepath
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   462
	# dataset, similar to what zoneadm would do for an initial install.
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   463
	#
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   464
	zds=$(zfs list -H -t filesystem -o name $pdir 2>/dev/null)
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   465
	if (( $? == 0 )); then
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   466
		pnm=$(/usr/bin/basename $ZONEPATH)
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   467
		# The zonepath dataset might already exist.
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   468
		zfs list -H -t filesystem -o name $zds/$pnm >/dev/null 2>&1
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   469
		if (( $? != 0 )); then
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   470
			zfs create "$zds/$pnm"
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   471
			(( $? != 0 )) && fatal "$f_zfs_create"
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   472
			vlog "$m_zfs"
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   473
		fi
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   474
	fi
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   475
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   476
	create_active_ds
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   477
fi
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   478
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   479
#
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   480
# The zone's datasets are now in place.
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   481
#
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   482
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   483
log "$m_attach_root" "$ZONEROOT"
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   484
# note \n to add whitespace
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   485
log "$m_attach_ds\n" "$ACTIVE_DS"
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   486
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   487
install_image "$inst_type" "$install_media"
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   488
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   489
#
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   490
# End of TODO block to move to common code.
f1c659f5c28e Backed out changeset 1f446820dcb0
Andrzej Szeszo <aszeszo@gmail.com>
parents: 2235
diff changeset
   491
#
654
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   492
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   493
#
2170
6e5ddf75b5ea 17309 brand attach global zone sanity check needs updating
Dan Price <daniel.price@oracle.com>
parents: 2148
diff changeset
   494
# Perform a sanity check to confirm that the image is not a global zone.
654
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   495
#
2170
6e5ddf75b5ea 17309 brand attach global zone sanity check needs updating
Dan Price <daniel.price@oracle.com>
parents: 2148
diff changeset
   496
VARIANT=variant.opensolaris.zone
6e5ddf75b5ea 17309 brand attach global zone sanity check needs updating
Dan Price <daniel.price@oracle.com>
parents: 2148
diff changeset
   497
variant=$(LC_ALL=C $PKG -R $ZONEROOT variant -H $VARIANT)
6e5ddf75b5ea 17309 brand attach global zone sanity check needs updating
Dan Price <daniel.price@oracle.com>
parents: 2148
diff changeset
   498
[[ $? -ne 0 ]] && fatal "$f_sanity_variant" $VARIANT
6e5ddf75b5ea 17309 brand attach global zone sanity check needs updating
Dan Price <daniel.price@oracle.com>
parents: 2148
diff changeset
   499
6e5ddf75b5ea 17309 brand attach global zone sanity check needs updating
Dan Price <daniel.price@oracle.com>
parents: 2148
diff changeset
   500
echo $variant | IFS=" " read variantname variantval
6e5ddf75b5ea 17309 brand attach global zone sanity check needs updating
Dan Price <daniel.price@oracle.com>
parents: 2148
diff changeset
   501
[[ $? -ne 0 ]] && fatal "$f_sanity_variant"
6e5ddf75b5ea 17309 brand attach global zone sanity check needs updating
Dan Price <daniel.price@oracle.com>
parents: 2148
diff changeset
   502
6e5ddf75b5ea 17309 brand attach global zone sanity check needs updating
Dan Price <daniel.price@oracle.com>
parents: 2148
diff changeset
   503
# Check that we got the output we expect...
6e5ddf75b5ea 17309 brand attach global zone sanity check needs updating
Dan Price <daniel.price@oracle.com>
parents: 2148
diff changeset
   504
[[ $variantname = "$VARIANT" ]] || fatal "$f_sanity_variant" $VARIANT
6e5ddf75b5ea 17309 brand attach global zone sanity check needs updating
Dan Price <daniel.price@oracle.com>
parents: 2148
diff changeset
   505
6e5ddf75b5ea 17309 brand attach global zone sanity check needs updating
Dan Price <daniel.price@oracle.com>
parents: 2148
diff changeset
   506
# Check that the variant is non-global, else fail
6e5ddf75b5ea 17309 brand attach global zone sanity check needs updating
Dan Price <daniel.price@oracle.com>
parents: 2148
diff changeset
   507
[[ $variantval = "nonglobal" ]] || fatal "$f_sanity_global" $VARIANT $variantval
1111
26c3e2407c53 8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents: 1091
diff changeset
   508
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   509
# We would like to ensure that our NGZ publishers are a superset of
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   510
# those in the GZ. We do this by building a list of all publishers in
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   511
# the GZ. We then process this list in the NGZ, first removing (if
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   512
# present) and then installing all publishers in this list. Other
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   513
# publisher, i.e. those not in the GZ list, are left as is.
654
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   514
1091
fc73bc2d78ce 7490 ipkg brand attach needs similar logic to pkgcreatezone for 'entire' incorporation
Dan Price <dp@eng.sun.com>
parents: 752
diff changeset
   515
#
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   516
# Gather all the publisher details for the global zone
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   517
#
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   518
gather_zone_publisher_details $PKG_IMAGE gz_publishers
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   519
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   520
#
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   521
# Get the preferred publisher for the global zone
1091
fc73bc2d78ce 7490 ipkg brand attach needs similar logic to pkgcreatezone for 'entire' incorporation
Dan Price <dp@eng.sun.com>
parents: 752
diff changeset
   522
# If we were not able to get the zone's preferred publisher, complain.
fc73bc2d78ce 7490 ipkg brand attach needs similar logic to pkgcreatezone for 'entire' incorporation
Dan Price <dp@eng.sun.com>
parents: 752
diff changeset
   523
#
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   524
gz_publisher_pref=$(get_preferred_publisher gz_publishers)
1091
fc73bc2d78ce 7490 ipkg brand attach needs similar logic to pkgcreatezone for 'entire' incorporation
Dan Price <dp@eng.sun.com>
parents: 752
diff changeset
   525
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   526
if [[ $? -ne 0 ]]; then
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   527
	fail_usage "$f_no_pref_publisher" "global"
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   528
fi
1504
265a1d6b86bd 9969 client support for multiple origins desired
Shawn Walker <srw@sun.com>
parents: 1493
diff changeset
   529
2174
f11c77f93a8a 15594 zone attach code needs more error checking
Dan Price <daniel.price@oracle.com>
parents: 2170
diff changeset
   530
vlog "Preferred global publisher: $gz_publisher_pref"
1091
fc73bc2d78ce 7490 ipkg brand attach needs similar logic to pkgcreatezone for 'entire' incorporation
Dan Price <dp@eng.sun.com>
parents: 752
diff changeset
   531
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   532
#
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   533
# Try to find the "entire" incorporation's FMRI in the gz.
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   534
#
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   535
gz_entire_fmri=$(get_entire_incorp)
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   536
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   537
#
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   538
# If entire isn't installed, create an array of global zone core-os
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   539
# incorporations.
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   540
#
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   541
if [[ -z $gz_entire_fmri ]]; then
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   542
	gather_incorporations gz_incorporations
1111
26c3e2407c53 8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents: 1091
diff changeset
   543
fi
26c3e2407c53 8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents: 1091
diff changeset
   544
26c3e2407c53 8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents: 1091
diff changeset
   545
#
26c3e2407c53 8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents: 1091
diff changeset
   546
# We're done with the global zone: switch images to the non-global
26c3e2407c53 8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents: 1091
diff changeset
   547
# zone.
26c3e2407c53 8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents: 1091
diff changeset
   548
#
1483
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   549
PKG_IMAGE="$ZONEROOT"
1091
fc73bc2d78ce 7490 ipkg brand attach needs similar logic to pkgcreatezone for 'entire' incorporation
Dan Price <dp@eng.sun.com>
parents: 752
diff changeset
   550
fc73bc2d78ce 7490 ipkg brand attach needs similar logic to pkgcreatezone for 'entire' incorporation
Dan Price <dp@eng.sun.com>
parents: 752
diff changeset
   551
#
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   552
# Try to find the "entire" incorporation's FMRI in the ngz.
1091
fc73bc2d78ce 7490 ipkg brand attach needs similar logic to pkgcreatezone for 'entire' incorporation
Dan Price <dp@eng.sun.com>
parents: 752
diff changeset
   553
#
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   554
ngz_entire_fmri=$(get_entire_incorp)
654
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   555
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   556
[[ -n $gz_entire_fmri ]] && log "$m_gzinc" "$gz_entire_fmri"
2174
f11c77f93a8a 15594 zone attach code needs more error checking
Dan Price <daniel.price@oracle.com>
parents: 2170
diff changeset
   557
[[ -n $ngz_entire_fmri ]] && log "$m_zinc" "$ngz_entire_fmri"
1091
fc73bc2d78ce 7490 ipkg brand attach needs similar logic to pkgcreatezone for 'entire' incorporation
Dan Price <dp@eng.sun.com>
parents: 752
diff changeset
   558
fc73bc2d78ce 7490 ipkg brand attach needs similar logic to pkgcreatezone for 'entire' incorporation
Dan Price <dp@eng.sun.com>
parents: 752
diff changeset
   559
#
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   560
# Create the list of incorporations we wish to install/update in the
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   561
# ngz.
1091
fc73bc2d78ce 7490 ipkg brand attach needs similar logic to pkgcreatezone for 'entire' incorporation
Dan Price <dp@eng.sun.com>
parents: 752
diff changeset
   562
#
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   563
typeset -n incorp_list
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   564
if [[ -n $gz_entire_fmri ]]; then
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   565
    incorp_list=gz_entire_fmri
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   566
else
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   567
    incorp_list=gz_incorporations
1091
fc73bc2d78ce 7490 ipkg brand attach needs similar logic to pkgcreatezone for 'entire' incorporation
Dan Price <dp@eng.sun.com>
parents: 752
diff changeset
   568
fi
654
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   569
1091
fc73bc2d78ce 7490 ipkg brand attach needs similar logic to pkgcreatezone for 'entire' incorporation
Dan Price <dp@eng.sun.com>
parents: 752
diff changeset
   570
#
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   571
# If there is a cache, use it.
1091
fc73bc2d78ce 7490 ipkg brand attach needs similar logic to pkgcreatezone for 'entire' incorporation
Dan Price <dp@eng.sun.com>
parents: 752
diff changeset
   572
#
2148
5625d3707d5b 17424 zone cache usage needs adjustment for new image format
Shawn Walker <shawn.walker@oracle.com>
parents: 2123
diff changeset
   573
if [[ -f /var/pkg/pkg5.image && -d /var/pkg/publisher ]]; then
5625d3707d5b 17424 zone cache usage needs adjustment for new image format
Shawn Walker <shawn.walker@oracle.com>
parents: 2123
diff changeset
   574
	PKG_CACHEROOT=/var/pkg/publisher
5625d3707d5b 17424 zone cache usage needs adjustment for new image format
Shawn Walker <shawn.walker@oracle.com>
parents: 2123
diff changeset
   575
	export PKG_CACHEROOT
5625d3707d5b 17424 zone cache usage needs adjustment for new image format
Shawn Walker <shawn.walker@oracle.com>
parents: 2123
diff changeset
   576
	log "$m_cache" "$PKG_CACHEROOT"
654
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   577
fi
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   578
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   579
log "$m_updating"
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   580
654
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   581
#
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   582
# The NGZ publishers must be a superset of the GZ publisher. Process
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   583
# the GZ publishers and make the NGZ publishers match them.
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   584
# You can't remove a preferred publisher, so temporarily create
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   585
# a preferred publisher
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   586
RANDOM=$$
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   587
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   588
ZNAME=za$RANDOM
1091
fc73bc2d78ce 7490 ipkg brand attach needs similar logic to pkgcreatezone for 'entire' incorporation
Dan Price <dp@eng.sun.com>
parents: 752
diff changeset
   589
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   590
LC_ALL=C $PKG set-publisher --no-refresh -P -g http://localhost:10000 $ZNAME
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   591
for key in ${!gz_publishers[*]}; do
1909
7b234f0eff79 16008 zoneadm attach -u fails when publishers are configured with SSL certificate and key
Gary Pennington <gary.pennington@oracle.com>
parents: 1879
diff changeset
   592
	typeset newloc=""
1091
fc73bc2d78ce 7490 ipkg brand attach needs similar logic to pkgcreatezone for 'entire' incorporation
Dan Price <dp@eng.sun.com>
parents: 752
diff changeset
   593
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   594
	args=$(print_publisher_pkg_defn gz_publishers $key)
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   595
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   596
	# Copy credentials from global zone.
1483
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   597
	safe_dir var
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   598
	safe_dir var/pkg
1111
26c3e2407c53 8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents: 1091
diff changeset
   599
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   600
	eval publisher="${gz_publishers[$key]}"
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   601
	if [[ ${publisher.keyfile} != "None" || \
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   602
	    ${publisher.certfile} != "None" ]]; then
1483
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   603
		if [[ -e $ZONEROOT/$KEYDIR ]]; then
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   604
			safe_dir $KEYDIR
1111
26c3e2407c53 8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents: 1091
diff changeset
   605
		else
1483
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   606
			mkdir -m 755 $ZONEROOT/$KEYDIR
1111
26c3e2407c53 8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents: 1091
diff changeset
   607
		fi
26c3e2407c53 8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents: 1091
diff changeset
   608
	fi
26c3e2407c53 8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents: 1091
diff changeset
   609
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   610
	if [[ ${publisher.keyfile} != "None" ]]; then
2193
c22e53ceb4fc 17715 Update on attach not working when keys & certs are in play
Dan Price <daniel.price@oracle.com>
parents: 2174
diff changeset
   611
		relnewloc="$KEYDIR/$(basename ${publisher.keyfile})"
c22e53ceb4fc 17715 Update on attach not working when keys & certs are in play
Dan Price <daniel.price@oracle.com>
parents: 2174
diff changeset
   612
		newloc="$ZONEROOT/$relnewloc"
1909
7b234f0eff79 16008 zoneadm attach -u fails when publishers are configured with SSL certificate and key
Gary Pennington <gary.pennington@oracle.com>
parents: 1879
diff changeset
   613
		safe_copy ${publisher.keyfile} $newloc
7b234f0eff79 16008 zoneadm attach -u fails when publishers are configured with SSL certificate and key
Gary Pennington <gary.pennington@oracle.com>
parents: 1879
diff changeset
   614
		chmod 644 $newloc
7b234f0eff79 16008 zoneadm attach -u fails when publishers are configured with SSL certificate and key
Gary Pennington <gary.pennington@oracle.com>
parents: 1879
diff changeset
   615
		chown -h root:root $newloc
2193
c22e53ceb4fc 17715 Update on attach not working when keys & certs are in play
Dan Price <daniel.price@oracle.com>
parents: 2174
diff changeset
   616
		args="$args -k $relnewloc"
1111
26c3e2407c53 8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents: 1091
diff changeset
   617
	fi
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   618
	if [[ ${publisher.certfile} != "None" ]]; then
2193
c22e53ceb4fc 17715 Update on attach not working when keys & certs are in play
Dan Price <daniel.price@oracle.com>
parents: 2174
diff changeset
   619
		relnewloc="$KEYDIR/$(basename ${publisher.certfile})"
c22e53ceb4fc 17715 Update on attach not working when keys & certs are in play
Dan Price <daniel.price@oracle.com>
parents: 2174
diff changeset
   620
		newloc="$ZONEROOT/$relnewloc"
1909
7b234f0eff79 16008 zoneadm attach -u fails when publishers are configured with SSL certificate and key
Gary Pennington <gary.pennington@oracle.com>
parents: 1879
diff changeset
   621
		safe_copy ${publisher.certfile} $newloc
7b234f0eff79 16008 zoneadm attach -u fails when publishers are configured with SSL certificate and key
Gary Pennington <gary.pennington@oracle.com>
parents: 1879
diff changeset
   622
		chmod 644 $newloc
7b234f0eff79 16008 zoneadm attach -u fails when publishers are configured with SSL certificate and key
Gary Pennington <gary.pennington@oracle.com>
parents: 1879
diff changeset
   623
		chown -h root:root $newloc
2193
c22e53ceb4fc 17715 Update on attach not working when keys & certs are in play
Dan Price <daniel.price@oracle.com>
parents: 2174
diff changeset
   624
		args="$args -c $relnewloc"
1504
265a1d6b86bd 9969 client support for multiple origins desired
Shawn Walker <srw@sun.com>
parents: 1493
diff changeset
   625
	fi
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   626
	LC_ALL=C $PKG unset-publisher $key >/dev/null 2>&1
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   627
	LC_ALL=C $PKG set-publisher $args $key
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   628
	
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   629
done
1504
265a1d6b86bd 9969 client support for multiple origins desired
Shawn Walker <srw@sun.com>
parents: 1493
diff changeset
   630
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   631
#
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   632
# Now remove our temporary publisher
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   633
#
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   634
LC_ALL=C $PKG unset-publisher $ZNAME
1504
265a1d6b86bd 9969 client support for multiple origins desired
Shawn Walker <srw@sun.com>
parents: 1493
diff changeset
   635
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   636
#
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   637
# Bring the ngz entire incorporation into sync with the gz as follows:
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   638
# - First compare the existence of entire in both global and non-global
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   639
#   zone and update the non-global zone accordingly.
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   640
# - Then, if updates aren't allowed check if we can attach because no
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   641
#   updates are required. If we can, then we are finished.
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   642
# - Finally, we know we can do updates and they are required, so update
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   643
#   all the non-global zone incorporations using the list we gathered
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   644
#   from the global zone earlier.
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   645
#
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   646
if [[ -z $gz_entire_fmri && -n $ngz_entire_fmri ]]; then
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   647
	if [[ $allow_update == 1 ]]; then
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   648
		LC_ALL=C $PKG uninstall entire || pkg_err_check "$f_update"
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   649
	else
2174
f11c77f93a8a 15594 zone attach code needs more error checking
Dan Price <daniel.price@oracle.com>
parents: 2170
diff changeset
   650
		log "\n$m_need_update" "$ZONENAME"
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   651
		EXIT_CODE=$ZONE_SUBPROC_NOTCOMPLETE
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   652
		exit $EXIT_CODE
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   653
    fi
654
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   654
fi
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   655
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   656
if [[ $allow_update == 0 ]]; then
2123
33e0355a44f1 17316 zones create and attach fail with must-accept license
Mark J. Nelson <Mark.J.Nelson@Oracle.COM>
parents: 1909
diff changeset
   657
	LC_ALL=C $PKG install --accept --no-refresh -n $incorp_list
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   658
	if [[ $? == 4 ]]; then
2174
f11c77f93a8a 15594 zone attach code needs more error checking
Dan Price <daniel.price@oracle.com>
parents: 2170
diff changeset
   659
		log "\n$m_complete"
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   660
		EXIT_CODE=$ZONE_SUBPROC_OK
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   661
		exit $EXIT_CODE
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   662
	else
2174
f11c77f93a8a 15594 zone attach code needs more error checking
Dan Price <daniel.price@oracle.com>
parents: 2170
diff changeset
   663
		log "\n$m_need_update" "$ZONENAME"
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   664
		EXIT_CODE=$ZONE_SUBPROC_NOTCOMPLETE
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   665
		exit $EXIT_CODE
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   666
	fi
1680
c058e5b3e759 13282 zoneadm attach -u always re-downloads pkgs
<gerald.jelinek@sun.com>
parents: 1568
diff changeset
   667
fi
1091
fc73bc2d78ce 7490 ipkg brand attach needs similar logic to pkgcreatezone for 'entire' incorporation
Dan Price <dp@eng.sun.com>
parents: 752
diff changeset
   668
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   669
#
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   670
# If the NGZ doesn't have entire, but the GZ does, then we have to install
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   671
# entire twice. First time we don't specify a version and let constraining
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   672
# incorporations determine the version. Second time, we try to install the
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   673
# same version as we have in the GZ.
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   674
#
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   675
if [[ -n $gz_entire_fmri && -z $ngz_entire_fmri ]]; then
2123
33e0355a44f1 17316 zones create and attach fail with must-accept license
Mark J. Nelson <Mark.J.Nelson@Oracle.COM>
parents: 1909
diff changeset
   676
	LC_ALL=C $PKG install --accept --no-refresh entire  || \
33e0355a44f1 17316 zones create and attach fail with must-accept license
Mark J. Nelson <Mark.J.Nelson@Oracle.COM>
parents: 1909
diff changeset
   677
	    pkg_err_check "$f_update"
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   678
fi
1091
fc73bc2d78ce 7490 ipkg brand attach needs similar logic to pkgcreatezone for 'entire' incorporation
Dan Price <dp@eng.sun.com>
parents: 752
diff changeset
   679
2123
33e0355a44f1 17316 zones create and attach fail with must-accept license
Mark J. Nelson <Mark.J.Nelson@Oracle.COM>
parents: 1909
diff changeset
   680
LC_ALL=C $PKG install --accept --no-refresh $incorp_list  || \
33e0355a44f1 17316 zones create and attach fail with must-accept license
Mark J. Nelson <Mark.J.Nelson@Oracle.COM>
parents: 1909
diff changeset
   681
    pkg_err_check "$f_update"
654
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   682
2174
f11c77f93a8a 15594 zone attach code needs more error checking
Dan Price <daniel.price@oracle.com>
parents: 2170
diff changeset
   683
log "\n$m_sync_done"
1879
7dc50f542f19 14684 zone attach incorporation logic needs enhancement
Gary Pennington <gary.pennington@sun.com>
parents: 1797
diff changeset
   684
log "$m_complete"
654
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   685
1483
2276b6786711 6793 p2v support for ipkg-branded zones
<gerald.jelinek@sun.com>
parents: 1111
diff changeset
   686
EXIT_CODE=$ZONE_SUBPROC_OK
654
8b6868dc3da1 4287 support for migration and update using detach/attach
<gerald.jelinek@sun.com>
parents:
diff changeset
   687
exit $ZONE_SUBPROC_OK