xref: /onnv-gate/usr/src/cmd/tsol/zones/zoneunshare.sh (revision 4746:0bc0c48f4304)
1*4746Srica#!/sbin/sh
2*4746Srica#
3*4746Srica# CDDL HEADER START
4*4746Srica#
5*4746Srica# The contents of this file are subject to the terms of the
6*4746Srica# Common Development and Distribution License (the "License").
7*4746Srica# You may not use this file except in compliance with the License.
8*4746Srica#
9*4746Srica# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*4746Srica# or http://www.opensolaris.org/os/licensing.
11*4746Srica# See the License for the specific language governing permissions
12*4746Srica# and limitations under the License.
13*4746Srica#
14*4746Srica# When distributing Covered Code, include this CDDL HEADER in each
15*4746Srica# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*4746Srica# If applicable, add the following below this CDDL HEADER, with the
17*4746Srica# fields enclosed by brackets "[]" replaced with your own identifying
18*4746Srica# information: Portions Copyright [yyyy] [name of copyright owner]
19*4746Srica#
20*4746Srica# CDDL HEADER END
21*4746Srica#
22*4746Srica# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23*4746Srica# Use is subject to license terms.
24*4746Srica#
25*4746Srica#ident	"%Z%%M%	%I%	%E% SMI"
26*4746Srica#
27*4746Srica# zoneunshare  -- unshare zone resources
28*4746Srica
29*4746Srica# Processes the specified sharetab file and unshare
30*4746Srica# all entries shared by the specfied zone
31*4746Srica
32*4746SricaUSAGE="zoneunshare -z zonename [- | file]"
33*4746Sricaset -- `getopt z: $*`
34*4746Sricaif [ $? != 0 ]		# invalid options
35*4746Srica	then
36*4746Srica	echo $USAGE >&2
37*4746Srica	exit 1
38*4746Sricafi
39*4746Sricafor i in $*		# pick up the options
40*4746Sricado
41*4746Srica	case $i in
42*4746Srica	-z)  zonename=$2; shift 2;;
43*4746Srica	--)  shift; break;;
44*4746Srica	esac
45*4746Sricadone
46*4746Srica
47*4746Sricazoneattr=`/usr/sbin/zoneadm -z $zonename list -p 2> /dev/null`
48*4746Sricaif [ $? -ne 0 ]		# invalid zone
49*4746Srica	then
50*4746Srica	echo $USAGE >&2
51*4746Srica	exit 1
52*4746Sricafi
53*4746Srica
54*4746Sricaprefix=`echo $zoneattr | cut -d ":" -f4`
55*4746Sricarootpath=$prefix/root
56*4746Srica
57*4746Sricaif [ $# -gt 1 ]		# accept only one argument
58*4746Sricathen
59*4746Srica	echo $USAGE >&2
60*4746Srica	exit 1
61*4746Sricaelif [ $# = 1 ]
62*4746Sricathen
63*4746Srica	case $1 in
64*4746Srica	-)	infile=;;	# use stdin
65*4746Srica	*)	infile=$1;;	# use a given source file
66*4746Srica	esac
67*4746Sricaelse
68*4746Srica	infile=/etc/dfs/sharetab	# default
69*4746Sricafi
70*4746Srica
71*4746Srica# Run unshare for each resource in its own shell
72*4746Srica
73*4746Sricawhile read line				# get complete lines
74*4746Sricado
75*4746Srica	echo $line
76*4746Sricadone < $infile |
77*4746Srica	`egrep "^$rootpath"|nawk '{ print "/usr/sbin/unshare " $1 ";" }'|/sbin/sh`
78