xref: /illumos-gate/usr/src/cmd/tsol/zones/zoneshare.sh (revision f875b4eb)
1*f875b4ebSrica#!/sbin/sh
2*f875b4ebSrica#
3*f875b4ebSrica# CDDL HEADER START
4*f875b4ebSrica#
5*f875b4ebSrica# The contents of this file are subject to the terms of the
6*f875b4ebSrica# Common Development and Distribution License (the "License").
7*f875b4ebSrica# You may not use this file except in compliance with the License.
8*f875b4ebSrica#
9*f875b4ebSrica# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*f875b4ebSrica# or http://www.opensolaris.org/os/licensing.
11*f875b4ebSrica# See the License for the specific language governing permissions
12*f875b4ebSrica# and limitations under the License.
13*f875b4ebSrica#
14*f875b4ebSrica# When distributing Covered Code, include this CDDL HEADER in each
15*f875b4ebSrica# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*f875b4ebSrica# If applicable, add the following below this CDDL HEADER, with the
17*f875b4ebSrica# fields enclosed by brackets "[]" replaced with your own identifying
18*f875b4ebSrica# information: Portions Copyright [yyyy] [name of copyright owner]
19*f875b4ebSrica#
20*f875b4ebSrica# CDDL HEADER END
21*f875b4ebSrica#
22*f875b4ebSrica# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23*f875b4ebSrica# Use is subject to license terms.
24*f875b4ebSrica#
25*f875b4ebSrica#ident	"%Z%%M%	%I%	%E% SMI"
26*f875b4ebSrica#
27*f875b4ebSrica# zoneshare  -- share zone resources
28*f875b4ebSrica
29*f875b4ebSrica# Processes a non-global zone's dfstab file after translating
30*f875b4ebSrica# its zone-relative pathnames to global zone pathnames
31*f875b4ebSrica
32*f875b4ebSricaUSAGE="zoneshare -z zonename [- | file]"
33*f875b4ebSricaset -- `getopt z: $*`
34*f875b4ebSricaif [ $? != 0 ]		# invalid options
35*f875b4ebSrica	then
36*f875b4ebSrica	echo $USAGE >&2
37*f875b4ebSrica	exit 1
38*f875b4ebSricafi
39*f875b4ebSricafor i in $*		# pick up the options
40*f875b4ebSricado
41*f875b4ebSrica	case $i in
42*f875b4ebSrica	-z)  zonename=$2; shift 2;;
43*f875b4ebSrica	--)  shift; break;;
44*f875b4ebSrica	esac
45*f875b4ebSricadone
46*f875b4ebSrica
47*f875b4ebSricazoneattr=`/usr/sbin/zoneadm -z $zonename list -p 2> /dev/null`
48*f875b4ebSricaif [ $? -ne 0 ]		# invalid zone
49*f875b4ebSrica	then
50*f875b4ebSrica	echo $USAGE >&2
51*f875b4ebSrica	exit 1
52*f875b4ebSricafi
53*f875b4ebSrica
54*f875b4ebSricaprefix=`echo $zoneattr | cut -d ":" -f4`
55*f875b4ebSricarootpath=$prefix/root
56*f875b4ebSrica
57*f875b4ebSricaif [ $# -gt 1 ]		# accept only one argument
58*f875b4ebSricathen
59*f875b4ebSrica	echo $USAGE >&2
60*f875b4ebSrica	exit 1
61*f875b4ebSricaelif [ $# = 1 ]
62*f875b4ebSricathen
63*f875b4ebSrica	case $1 in
64*f875b4ebSrica	-)	infile=;;	# use stdin
65*f875b4ebSrica	*)	infile=$1;;	# use a given source file
66*f875b4ebSrica	esac
67*f875b4ebSricaelse
68*f875b4ebSrica	infile=$prefix/etc/dfs/dfstab	# default
69*f875b4ebSricafi
70*f875b4ebSrica
71*f875b4ebSrica# Prepend each exported pathname with the zone's rootpath
72*f875b4ebSrica# Skip over comments and lines without a share command
73*f875b4ebSrica# Run each share command in its own shell
74*f875b4ebSrica
75*f875b4ebSricawhile read line				# get complete lines
76*f875b4ebSricado
77*f875b4ebSrica	echo $line
78*f875b4ebSricadone < $infile |
79*f875b4ebSrica	`egrep -v "(^[#])" | nawk  -v rootpath=$rootpath \
80*f875b4ebSrica	    '/share/ { ORS = " "; for (i = 1; i < NF; i++) print $i ; \
81*f875b4ebSrica	     print rootpath $NF ";" } ' | /sbin/sh`
82