xref: /illumos-gate/usr/src/cmd/fs.d/nfs/exportfs/exportfs.sh (revision 2aeafac3612e19716bf8164f89c3c9196342979c)
1#!/sbin/sh
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, Version 1.0 only
7# (the "License").  You may not use this file except in compliance
8# with the License.
9#
10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11# or http://www.opensolaris.org/os/licensing.
12# See the License for the specific language governing permissions
13# and limitations under the License.
14#
15# When distributing Covered Code, include this CDDL HEADER in each
16# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17# If applicable, add the following below this CDDL HEADER, with the
18# fields enclosed by brackets "[]" replaced with your own identifying
19# information: Portions Copyright [yyyy] [name of copyright owner]
20#
21# CDDL HEADER END
22#
23#	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
24#	  All Rights Reserved
25
26
27#ident	"%Z%%M%	%I%	%E% SMI"
28#!/bin/sh
29#
30#  exportfs: compatibility script for SunOs command.
31#
32
33USAGE="Usage: exportfs [-aviu] [-o options] directory"
34DFSTAB=/etc/dfs/dfstab
35OPTS="rw"
36
37#
38# Translate from exportfs opts to share opts
39#
40
41fixopts() {
42	IFS=, ; set - $OPTS ; IFS=" "
43	for i
44		do case $i in *access=* ) eval $i ;; esac ; done
45	if [ ! "$access" ] ; then return ; fi
46
47	OPTS=""
48	for i
49	do
50		case $i in
51		rw=*     ) OPTS="$OPTS$i," ;;
52		ro | rw  ) OPTS="${OPTS}$i=$access," ; ropt="true" ;;
53		access=* ) ;;
54		*        ) OPTS="$OPTS$i," ;;
55		esac
56	done
57	if [ ! "$ropt" ] ; then OPTS="ro=$access,$OPTS" ; fi
58	OPTS=`echo $OPTS | sed 's/,$//'`
59}
60
61bad() {
62	echo $USAGE >&2
63	exit 1
64}
65
66PATH=/usr/sbin:/usr/bin:$PATH
67export PATH
68
69if set -- `getopt aviuo: $*` ; then : ; else bad ; fi
70
71for i in $*
72do
73	case $i in
74	-a ) aflg="true" ; shift ;;	# share all nfs
75	-v ) vflg="true" ; shift ;;	# verbose
76	-i ) iflg="true" ; shift ;;	# ignore dfstab opts
77	-u ) uflg="true" ; shift ;;	# unshare
78	-o ) oflg="true" ; OPTS=$2 ; shift 2 ;;	# option string
79	-- ) shift ; break ;;
80	esac
81done
82
83if [ $aflg ] ; then
84	if [ "$DIR" -o "$iflg" -o "$oflg"  ] ; then bad ; fi
85	if [ $uflg ] ; then
86		if [ $vflg ] ; then echo unshareall -F nfs ; fi
87		/usr/sbin/unshareall -F nfs
88	else
89		if [ $vflg ] ; then echo shareall -F nfs ; fi
90		/usr/sbin/shareall -F nfs
91	fi
92	exit $?
93fi
94
95case $# in
96	0 ) if [ "$iflg" -o "$uflg" -o "$oflg" ] ; then bad ; fi
97	    if [ "$vflg" ] ; then echo share -F nfs ; fi
98	    /usr/sbin/share -F nfs
99	    exit $? ;;
100
101	1 ) DIR=$1 ;;
102	* ) bad ;;
103esac
104
105if [ $uflg ] ; then
106	if [ "$iflg" -o "$oflg" ] ; then bad ; fi
107	if [ $vflg ] ; then echo unshare -F nfs $DIR ; fi
108	/usr/sbin/unshare -F nfs $DIR
109	exit $?
110fi
111
112if [ $iflg ] ; then
113	fixopts
114	if [ $vflg ] ; then echo share -F nfs -o $OPTS $DIR ; fi
115	/usr/sbin/share -F nfs -o $OPTS $DIR
116else
117	CMD=`grep $DIR'[ 	]*$' $DFSTAB`
118	if [ "$CMD" = "" ] ; then
119		echo "exportfs: no entry for $DIR in $DFSTAB" >&2
120		exit 1
121	fi
122	if [ $oflg ] ; then
123		echo "exportfs: supplied options ignored" >&2
124		vflg="true"
125	fi
126	if [ $vflg ] ; then echo $CMD ; fi
127	eval $CMD
128fi
129exit $?
130
131