2N/A#!/bin/ksh -p
2N/A#
2N/A# CDDL HEADER START
2N/A#
2N/A# The contents of this file are subject to the terms of the
2N/A# Common Development and Distribution License (the "License").
2N/A# You may not use this file except in compliance with the License.
2N/A#
2N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A# or http://www.opensolaris.org/os/licensing.
2N/A# See the License for the specific language governing permissions
2N/A# and limitations under the License.
2N/A#
2N/A# When distributing Covered Code, include this CDDL HEADER in each
2N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A# If applicable, add the following below this CDDL HEADER, with the
2N/A# fields enclosed by brackets "[]" replaced with your own identifying
2N/A# information: Portions Copyright [yyyy] [name of copyright owner]
2N/A#
2N/A# CDDL HEADER END
2N/A#
2N/A
2N/A#
2N/A# Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
2N/A#
2N/A
2N/A#
2N/A# common shell script functions
2N/A#
2N/A. /usr/lib/brand/shared/common.ksh
2N/A. /usr/lib/brand/solaris/common.ksh
2N/A. /usr/lib/brand/shared/uninstall.ksh
2N/A
2N/Atrap_exit() {
2N/A finish_log zone
2N/A exit $EXIT_CODE
2N/A}
2N/AEXIT_CODE=$ZONE_SUBPROC_USAGE
2N/A
2N/A#
2N/A# options processing
2N/A#
2N/A
2N/A# If we weren't passed at least two arguments, exit now.
2N/A(( $# < 2 )) && fail_fatal "$f_abort"
2N/A
2N/A# used by start_log()
2N/Aset -A save_args "$0" "$@"
2N/A
2N/Atypeset zone
2N/Ainit_zone zone "$1" "$2"
2N/Aeval $(bind_legacy_zone_globals zone)
2N/Ashift 2
2N/A
2N/Atrap trap_exit EXIT
2N/A
2N/Aoptions="FhHnvx:"
2N/Aoptions_repeat=""
2N/Aoptions_seen=""
2N/A
2N/Aopt_F=""
2N/Aopt_n=""
2N/Aopt_v=""
2N/A
2N/A# check for bad or duplicate options
2N/AOPTIND=1
2N/Awhile getopts $options OPT ; do
2N/Acase $OPT in
2N/A x) ;; # zoneadm only
2N/A \? ) uninstall_usage_err ;; # invalid argument
2N/A : ) uninstall_usage_err ;; # argument expected
2N/A * )
2N/A opt=`echo $OPT | sed 's/-\+//'`
2N/A if [ -n "$options_repeat" ]; then
2N/A echo $options_repeat | grep $opt >/dev/null
2N/A [ $? = 0 ] && break
2N/A fi
2N/A ( echo $options_seen | grep $opt >/dev/null ) &&
2N/A uninstall_usage_err
2N/A options_seen="${options_seen}${opt}"
2N/A ;;
2N/Aesac
2N/Adone
2N/A
2N/A# check for a help request
2N/AOPTIND=1
2N/Awhile getopts :$options OPT ; do
2N/Acase $OPT in
2N/A h|H ) uninstall_usage
2N/Aesac
2N/Adone
2N/A
2N/A# process options
2N/AOPTIND=1
2N/Awhile getopts :$options OPT ; do
2N/Acase $OPT in
2N/A F) opt_F="-F" ;;
2N/A n) opt_n="-n" ;;
2N/A v) opt_v="-v" ;;
2N/Aesac
2N/Adone
2N/Ashift `expr $OPTIND - 1`
2N/A
2N/A[ $# -gt 0 ] && uninstall_usage_err
2N/A
2N/A#
2N/A# main
2N/A#
2N/AEXIT_CODE=$ZONE_SUBPROC_TRYAGAIN
2N/Astart_log zone uninstall "${save_args[@]}"
2N/A
2N/Anop=""
2N/Aif [[ -n "$opt_n" ]]; then
2N/A nop="echo"
2N/A #
2N/A # in '-n' mode we should never return success (since we haven't
2N/A # actually done anything). so override ZONE_SUBPROC_OK here.
2N/A #
2N/A ZONE_SUBPROC_OK=$ZONE_SUBPROC_FATAL
2N/Afi
2N/A
2N/Aget_current_gzbe
2N/A
2N/A# find all the zone BEs associated with this global zone BE.
2N/Atypeset -a belist
2N/Aif [[ -n "$CURRENT_GZBE" ]]; then
2N/A zfs list -H -t filesystem -r -d 1 -o \
2N/A $PROP_PARENT,$PROP_ACTIVE,$PROP_CANDIDATE,name "${zone.ROOT_ds}" \
2N/A 2>/dev/null | while IFS=$'\t' read parent active candidate fs; do
2N/A
2N/A # Skip the ROOT dataset
2N/A [[ "$fs" == "${zone.ROOT_ds}" ]] && continue
2N/A
2N/A zbe=$(basename "$fs")
2N/A #
2N/A # match by PROP_PARENT uuid. If the uuid is not set ("-"), the
2N/A # BE is invalid (interrupted install?) and should be deleted.
2N/A #
2N/A if [[ $parent == "-" || $parent == "${CURRENT_GZBE}" ]]; then
2N/A a_push belist "$zbe"
2N/A continue
2N/A fi
2N/A
2N/A #
2N/A # If 'install -a' or 'attach -a' extracted multiple ZBEs and
2N/A # could not figure out which one to attach, the multiple ZBEs
2N/A # may have been left behind. In such a case, the zone will
2N/A # be in the "unavailable" state.
2N/A #
2N/A if [[ $candidate == "$CURRENT_GZBE" ]]; then
2N/A a_push belist "$zbe"
2N/A continue
2N/A fi
2N/A done
2N/Afi
2N/A
2N/Adestroy_zone_datasets zone -b belist
2N/A
2N/Afinish_log zone
2N/A# Set exit code for trap handler
2N/AEXIT_CODE=$ZONE_SUBPROC_OK
2N/Aexit $ZONE_SUBPROC_OK