1e71ca95Gerald Jelinek#!/bin/ksh -p
2e71ca95Gerald Jelinek#
3e71ca95Gerald Jelinek# CDDL HEADER START
4e71ca95Gerald Jelinek#
5e71ca95Gerald Jelinek# The contents of this file are subject to the terms of the
6e71ca95Gerald Jelinek# Common Development and Distribution License (the "License").
7e71ca95Gerald Jelinek# You may not use this file except in compliance with the License.
8e71ca95Gerald Jelinek#
9e71ca95Gerald Jelinek# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10e71ca95Gerald Jelinek# or http://www.opensolaris.org/os/licensing.
11e71ca95Gerald Jelinek# See the License for the specific language governing permissions
12e71ca95Gerald Jelinek# and limitations under the License.
13e71ca95Gerald Jelinek#
14e71ca95Gerald Jelinek# When distributing Covered Code, include this CDDL HEADER in each
15e71ca95Gerald Jelinek# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16e71ca95Gerald Jelinek# If applicable, add the following below this CDDL HEADER, with the
17e71ca95Gerald Jelinek# fields enclosed by brackets "[]" replaced with your own identifying
18e71ca95Gerald Jelinek# information: Portions Copyright [yyyy] [name of copyright owner]
19e71ca95Gerald Jelinek#
20e71ca95Gerald Jelinek# CDDL HEADER END
21e71ca95Gerald Jelinek#
22e71ca95Gerald Jelinek#
23aaf50cd<gerald.jelinek@sun.com># Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
24e71ca95Gerald Jelinek#
25e71ca95Gerald Jelinek
26e71ca95Gerald Jelinek. /usr/lib/brand/solaris10/common.ksh
27e71ca95Gerald Jelinek
28e71ca95Gerald Jelinekm_attach_log=$(gettext "Log File: %s")
29e71ca95Gerald Jelinekm_zfs=$(gettext "A ZFS file system was created for the zone.")
30e71ca95Gerald Jelinekm_attaching=$(gettext "Attaching...")
31e71ca95Gerald Jelinekm_usage=$(gettext  "solaris10 brand usage:\n\tattach [-a archive | -d directory | -r recv_type]\n\tThe -a archive option specifies an archive name which can be a flar,\n\ttar, pax or cpio archive.\n\tThe -d directory option specifies an existing directory.\n\tThe -r recv_type option specifies the type of archive to be read from\n\tstdin.")
32e71ca95Gerald Jelinekm_complete=$(gettext "Attach complete.")
33e71ca95Gerald Jelinek
34e71ca95Gerald Jelinekinstall_fail=$(gettext  "*** Attach FAILED ***")
35e71ca95Gerald Jelinek
36e71ca95Gerald Jelinekf_n_unimpl=$(gettext "The -n option is not yet implemented.")
37e71ca95Gerald Jelinekf_zfs=$(gettext "Error creating a ZFS file system (%s) for the zone.")
38e71ca95Gerald Jelinekf_nodataset=$(gettext "Error: there is no ZFS file system for the zone.")
39e71ca95Gerald Jelinekf_zfsdestroy=$(gettext "Error destroying ZFS file system %s.")
40e71ca95Gerald Jelinek
41e71ca95Gerald Jelinekf_sanity_notzone=$(gettext "Error: this is a system image and not a zone image.")
42e71ca95Gerald Jelinek
43e71ca95Gerald Jelinekf_baddir=$(gettext "Invalid '%s' directory within the zone")
44e71ca95Gerald Jelinek
45e71ca95Gerald Jelinek# Clean up on interrupt
46e71ca95Gerald Jelinektrap_cleanup()
47e71ca95Gerald Jelinek{
48e71ca95Gerald Jelinek	msg=$(gettext "Installation cancelled due to interrupt.")
49e71ca95Gerald Jelinek	log "$msg"
50e71ca95Gerald Jelinek
51e71ca95Gerald Jelinek	# umount any mounted file systems
52e71ca95Gerald Jelinek	umnt_fs
53e71ca95Gerald Jelinek
54e71ca95Gerald Jelinek	trap_exit
55e71ca95Gerald Jelinek}
56e71ca95Gerald Jelinek
57e71ca95Gerald Jelinek# If the attach failed then clean up the ZFS datasets we created.
58e71ca95Gerald Jelinektrap_exit()
59e71ca95Gerald Jelinek{
60aaf50cd<gerald.jelinek@sun.com>	if [[ $EXIT_CODE != $ZONE_SUBPROC_OK && $rm_ds == 1 ]]; then
61e71ca95Gerald Jelinek		/usr/lib/brand/solaris10/uninstall $ZONENAME $ZONEPATH -F
62e71ca95Gerald Jelinek	fi
63e71ca95Gerald Jelinek
64e71ca95Gerald Jelinek	exit $EXIT_CODE
65e71ca95Gerald Jelinek}
66e71ca95Gerald Jelinek
67e71ca95Gerald JelinekEXIT_CODE=$ZONE_SUBPROC_USAGE
68e71ca95Gerald Jelinekinstall_media="-"
69aaf50cd<gerald.jelinek@sun.com>rm_ds=0
70e71ca95Gerald Jelinek
71e71ca95Gerald Jelinektrap trap_cleanup INT
72e71ca95Gerald Jelinektrap trap_exit EXIT
73e71ca95Gerald Jelinek
74e71ca95Gerald Jelinek# If we weren't passed at least two arguments, exit now.
75e71ca95Gerald Jelinek(( $# < 2 )) && exit $ZONE_SUBPROC_USAGE
76e71ca95Gerald Jelinek
77e71ca95Gerald JelinekZONENAME="$1"
78e71ca95Gerald JelinekZONEPATH="$2"
79e71ca95Gerald Jelinek# XXX shared/common script currently uses lower case zonename & zonepath
80e71ca95Gerald Jelinekzonename="$ZONENAME"
81e71ca95Gerald Jelinekzonepath="$ZONEPATH"
82e71ca95Gerald Jelinek
83e71ca95Gerald Jelinekshift; shift	# remove ZONENAME and ZONEPATH from arguments array
84e71ca95Gerald Jelinek
85e71ca95Gerald JelinekZONEROOT="$ZONEPATH/root"
86e71ca95Gerald Jelineklogdir="$ZONEROOT/var/log"
87e71ca95Gerald Jelinek
88e71ca95Gerald Jelineknoexecute=0
89e71ca95Gerald Jelinek
90e71ca95Gerald Jelinekunset inst_type
91e71ca95Gerald Jelinek
92e71ca95Gerald Jelinek# Other brand attach options are invalid for this brand.
93e71ca95Gerald Jelinekwhile getopts "a:d:nr:" opt; do
94e71ca95Gerald Jelinek	case $opt in
95e71ca95Gerald Jelinek		a)
96