8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / brand / solaris10 / zone / uninstall.ksh
blobe77a2c0ddcab678c7ebbdc65dfa1bfb6240a9032
1 #!/bin/ksh93 -p
3 # CDDL HEADER START
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.
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.
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]
20 # CDDL HEADER END
23 # Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
28 # common shell script functions
30 . /usr/lib/brand/solaris10/common.ksh
31 . /usr/lib/brand/shared/uninstall.ksh
34 # options processing
36 # If we weren't passed at least two arguments, exit now.
37 (( $# < 2 )) && exit $ZONE_SUBPROC_USAGE
39 zonename=$1
40 zonepath=$2
42 shift 2
44 options="FhHnv"
45 options_repeat=""
46 options_seen=""
48 opt_F=""
49 opt_n=""
50 opt_v=""
52 # check for bad or duplicate options
53 OPTIND=1
54 while getopts $options OPT ; do
55 case $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
64 ( echo $options_seen | grep $opt >/dev/null ) &&
65 usage_err
66 options_seen="${options_seen}${opt}"
68 esac
69 done
71 # check for a help request
72 OPTIND=1
73 while getopts :$options OPT ; do
74 case $OPT in
75 h|H ) usage
76 esac
77 done
79 # process options
80 OPTIND=1
81 while getopts :$options OPT ; do
82 case $OPT in
83 F ) opt_F="-F" ;;
84 n ) opt_n="-n" ;;
85 v ) opt_v="-v" ;;
86 esac
87 done
88 shift `expr $OPTIND - 1`
90 [ $# -gt 0 ] && usage_err
93 # main
95 zoneroot=$zonepath/root
97 nop=""
98 if [[ -n "$opt_n" ]]; then
99 nop="echo"
101 # in '-n' mode we should never return success (since we haven't
102 # actually done anything). so override ZONE_SUBPROC_OK here.
104 ZONE_SUBPROC_OK=$ZONE_SUBPROC_FATAL
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.
113 uninstall_get_zonepath_ds
114 uninstall_get_zonepath_root_ds
116 # find all the zone BE datasets.
117 unset 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
123 fs_all[$fs_all_c]=$fs
124 (( fs_all_c = $fs_all_c + 1 ))
125 done
127 destroy_zone_datasets
129 exit $ZONE_SUBPROC_OK