#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
#
# Allows developer to override some things like PATH and PYTHONPATH
# m_usage is used by fail_usage()
m_usage=$(gettext "Usage:\n\t attach [-uv] [-a archive | -d directory | -z zbe] [-c profile.xml | dir]\n\n\t-u\tUpdate the software in the attached zone boot environment to\n\t\tmatch the sofware in the global zone boot environment.\n\t-v\tVerbose.\n\t-c\tUpdate the zone configuration with the sysconfig profile\n\t\tspecified in the given file or directory.\n\t-a\tExtract the specified archive into the zone then attach the\n\t\tactive boot environment found in the archive. The archive\n\t\tmay be a zfs, cpio, or tar archive. It may be compressed with\n\t\tgzip or bzip2.\n\t-d\tCopy the specified directory into a new zone boot environment\n\t\tthen attach the zone boot environment.\n\t-z\tAttach the specified zone boot environment.")
m_use_install=$(gettext "Warning: The -a and -d options to the attach subcommand may be removed in a\nfuture release of Solaris. Use of the install subcommand is recommended.")
f_multiple_extractions=$(gettext "Zone already has one or more extracted zone boot environments.\nUse 'zoneadm -z <zone> attach -z <zbe>' to attach an existing zbe.\n")
# Clean up on interrupt
trap - INT
# umount any mounted file systems
}
# If the attach failed then clean up the ZFS datasets we created.
#
# Since trap_int calls trap_exit we need to cancel the exit
# handler so that we don't do two passes.
#
if [[ -n $EXIT_NOEXECUTE ]]; then
# dryrun mode, nothing to do here; exit with whatever
# EXIT_CODE is set to.
;
elif [[ $EXIT_CODE == $ZONE_SUBPROC_USAGE ]]; then
# Usage message printed, nothing to do here.
;
then
# unmount the zoneroot if labeled brand
is_brand_labeled && ( umount $ZONEROOT || \
elif [[ $EXIT_CODE == $ZONE_SUBPROC_TRYAGAIN ]]; then
else
# Remove datasets that shouldn't exist
fi
vlog "Exiting with exit code $EXIT_CODE"
exit $EXIT_CODE
}
install_media="-"
# Will be used by start_log after option processing
set -A save_args "$0" "$@"
# If we weren't passed at least two arguments, exit now.
zone=
# Set ZONEPATH, etc.
eval $(bind_legacy_zone_globals zone)
shift; shift # remove ZONENAME and ZONEPATH from arguments array
typeset -A opts # Used in option compatibility checks.
unset inst_type
unset sc_config
# Get publisher information for global zone. These structures are used
# to store information about the global zone publishers and
# incorporations.
typeset gz_incorporations=""
#
# If extracting an archive that contains multiple zbes, it is possible that
# we won't be able to automatically select which zbe to set as the active
# zbe. In such a case, discover_active_be() will suggest the use of this
# command. It may be augmented in getopts processing.
#
# Other brand attach options are invalid for this brand.
while getopts "a:c:d:n:Uuvz:x:" opt; do
a) # If the path is automounted, [[ -f ... ]] does not
# trigger a mount so we may get a false error.
inst_type="archive"
;;
;;
d) # If the path is automounted, [[ -d ... ]] does not
# trigger a mount so we may get a false error.
inst_type="directory"
;;
n) noexecute=1
;;
u) [[ $allow_update == all ]] && \
fatal "$f_bad_opt_combo" u U
[[ $allow_update == min ]] && \
fatal "$f_repeated_opt" u
;;
U)
[[ $allow_update == min ]] && \
fatal "$f_bad_opt_combo" u U
[[ $allow_update == all ]] && \
fatal "$f_repeated_opt" U
;;
v) verbose=-v
;;
;;
x) ;; # zoneadm only
?) fail_usage "" ;;
esac
done
# Configuration profile file must have .xml suffix
fi
fi
fi
fi
#
# Be sure that a previous attach -a didn't leave zbes behind.
#
if [[ $candidate == "$CURRENT_GZBE" ]]; then
fi
done
# Advise that install is the better choice these days.
fi
if [[ $noexecute == 1 ]]; then
#
# the zone doesn't have to exist when the -n option is used, so do
# this work early.
#
# LIXXX There is no sw validation for IPS right now, so just pretend
# everything will be ok.
# Exit handler not yet active, so no need to worry about it.
exit $ZONE_SUBPROC_OK
fi
trap trap_cleanup INT
# Create a ZBE and transfer data into it.
log "$m_active_zbe" "${zone.active_ds}"
# Attach the image, perhaps with updates.
# Be sure that shared data that shouldn't be in in the ZBE isn't in the ZBE.
# Apply the sysconfig profile, if needed
trap - EXIT
exit $ZONE_SUBPROC_OK