xref: /illumos-gate/usr/src/lib/brand/solaris10/zone/uninstall.ksh (revision ab5dfd5e82c7de6e8a7172573741f3c5890a82fa)
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 2010 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#
36# If we weren't passed at least two arguments, exit now.
37(( $# < 2 )) && exit $ZONE_SUBPROC_USAGE
38
39zonename=$1
40zonepath=$2
41
42shift 2
43
44options="FhHnv"
45options_repeat=""
46options_seen=""
47
48opt_F=""
49opt_n=""
50opt_v=""
51
52# check for bad or duplicate options
53OPTIND=1
54while getopts $options OPT ; do
55case $OPT in
56	\? ) usage_err ;; # invalid argument
57	: ) usage_err ;; # argument expected
58	* )
59		opt=`echo $OPT | sed 's/-\+//'`
60		if [ -n "$options_repeat" ]; then
61			echo $options_repeat | grep $opt >/dev/null
62			[ $? = 0 ] && break
63		fi
64		( echo $options_seen | grep $opt >/dev/null ) &&
65			usage_err
66		options_seen="${options_seen}${opt}"
67		;;
68esac
69done
70
71# check for a help request
72OPTIND=1
73while getopts :$options OPT ; do
74case $OPT in
75	h|H ) usage
76esac
77done
78
79# process options
80OPTIND=1
81while getopts :$options OPT ; do
82case $OPT in
83	F ) opt_F="-F" ;;
84	n ) opt_n="-n" ;;
85	v ) opt_v="-v" ;;
86esac
87done
88shift `expr $OPTIND - 1`
89
90[ $# -gt 0 ]  && usage_err
91
92#
93# main
94#
95zoneroot=$zonepath/root
96
97nop=""
98if [[ -n "$opt_n" ]]; then
99	nop="echo"
100	#
101	# in '-n' mode we should never return success (since we haven't
102	# actually done anything). so override ZONE_SUBPROC_OK here.
103	#
104	ZONE_SUBPROC_OK=$ZONE_SUBPROC_FATAL
105fi
106
107#
108# We want uninstall to work in the face of various problems, such as a
109# zone with no delegated root dataset or multiple active datasets, so we
110# don't use the common functions.  Instead, we do our own work and
111# are tolerant of errors.
112#
113uninstall_get_zonepath_ds
114uninstall_get_zonepath_root_ds
115
116# find all the zone BE datasets.
117unset fs_all
118(( fs_all_c = 0 ))
119/sbin/zfs list -H -t filesystem -o name -r $ZONEPATH_RDS | while read fs; do
120	# only look at filesystems directly below $ZONEPATH_RDS
121	[[ "$fs" != ~()($ZONEPATH_RDS/+([^/])) ]] && continue
122
123	fs_all[$fs_all_c]=$fs
124	(( fs_all_c = $fs_all_c + 1 ))
125done
126
127destroy_zone_datasets
128
129exit $ZONE_SUBPROC_OK
130