1#!/bin/ksh93 -p
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22#
23# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24# Use is subject to license terms.
25#
26
27#
28# common shell script functions
29#
30. /usr/lib/brand/solaris10/common.ksh
31. /usr/lib/brand/shared/uninstall.ksh
32
33#
34# options processing
35#
36zonename=$1
37if [ -z "$zonename" ]; then
38	printf "$f_abort\n" >&2
39	exit $ZONE_SUBPROC_FATAL
40fi
41zonepath=$2
42if [ -z "$zonepath" ]; then
43	printf "$f_abort" >&2
44	exit $ZONE_SUBPROC_FATAL
45fi
46shift 2
47
48options="FhHnv"
49options_repeat=""
50options_seen=""
51
52opt_F=""
53opt_n=""
54opt_v=""
55
56# check for bad or duplicate options
57OPTIND=1
58while getopts $options OPT ; do
59case $OPT in
60	\? ) usage_err ;; # invalid argument
61	: ) usage_err ;; # argument expected
62	* )
63		opt=`echo $OPT | sed 's/-\+//'`
64		if [ -n "$options_repeat" ]; then
65			echo $options_repeat | grep $opt >/dev/null
66			[ $? = 0 ] && break
67		fi
68		( echo $options_seen | grep $opt >/dev/null ) &&
69			usage_err
70		options_seen="${options_seen}${opt}"
71		;;
72esac
73done
74
75# check for a help request
76OPTIND=1
77while getopts :$options OPT ; do
78case $OPT in
79	h|H ) usage
80esac
81done
82
83# process options
84OPTIND=1
85while getopts :$options OPT ; do
86case $OPT in
87	F ) opt_F="-F" ;;
88	n ) opt_n="-n" ;;
89	v ) opt_v="-v" ;;
90esac
91done
92shift `expr $OPTIND - 1`
93
94[ $# -gt 0 ]  && usage_err
95
96#
97# main
98#
99zoneroot=$zonepath/root
100
101nop=""
102if [[ -n "$opt_n" ]]; then
103	nop="echo"
104	#
105	# in '-n' mode we should never return success (since we haven't
106	# actually done anything). so override ZONE_SUBPROC_OK here.
107	#
108	ZONE_SUBPROC_OK=$ZONE_SUBPROC_FATAL
109fi
110
111#
112# We want uninstall to work in the face of various problems, such as a
113# zone with no delegated root dataset or multiple active datasets, so we
114# don't use the common functions.  Instead, we do our own work and
115# are tolerant of errors.
116#
117uninstall_get_zonepath_ds
118uninstall_get_zonepath_root_ds
119
120# find all the zone BE datasets.
121unset fs_all
122(( fs_all_c = 0 ))
123/sbin/zfs list -H -t filesystem -o name -r $ZONEPATH_RDS | while read fs; do
124	# only look at filesystems directly below $ZONEPATH_RDS
125	[[ "$fs" != ~()($ZONEPATH_RDS/+([^/])) ]] && continue
126
127	fs_all[$fs_all_c]=$fs
128	(( fs_all_c = $fs_all_c + 1 ))
129done
130
131destroy_zone_datasets
132
133exit $ZONE_SUBPROC_OK
134