xref: /illumos-gate/usr/src/cmd/dfs.cmds/shareall/shareall.sh (revision 4bc0a2ef2b7ba50a7a717e7ddbf31472ad28e358)
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# shareall  -- share resources
29
30USAGE="shareall [-F fsys[,fsys...]] [- | file]"
31fsys=
32set -- `getopt F: $*`
33if [ $? != 0 ]		# invalid options
34	then
35	echo $USAGE >&2
36	exit 1
37fi
38for i in $*		# pick up the options
39do
40	case $i in
41	-F)  fsys=$2; shift 2;;
42	--)  shift; break;;
43	esac
44done
45
46if [ $# -gt 1 ]		# accept only one argument
47then
48	echo $USAGE >&2
49	exit 1
50elif [ $# = 1 ]
51then
52	case $1 in
53	-)	infile=;;	# use stdin
54	*)	infile=$1;;	# use a given source file
55	esac
56else
57	infile=/etc/dfs/dfstab	# default
58fi
59
60
61if [ "$fsys" ]		# for each file system ...
62then
63	while read line				# get complete lines
64	do
65		echo $line
66	done < $infile |
67
68	`egrep "^[^#]*[ 	][ 	]*-F[ 	]*(\`echo $fsys|tr ',' '|'\`)" |
69	/sbin/sh`
70
71	fsys_file=/etc/dfs/fstypes
72	if [ -f $fsys_file ]    		# get default file system type
73	then
74		def_fs=`egrep '^[^#]' $fsys_file | awk '{print $1; exit}'`
75		if [ "$def_fs" = "$fsys" ]      # if default is what we want ...
76		then            		# for every file system ...
77			while read line
78			do
79				echo $line
80			done < $infile |
81
82			# not a comment and no -F option
83			`egrep -v "(^[#]|-F)" | /sbin/sh`
84		fi
85	else
86		echo "shareall: can't open $fsys_file"
87	fi
88else			# for every file system ...
89	cat $infile|/sbin/sh
90fi
91
92# If the user has ZFS installed, invoke 'zfs share -a' to share all ZFS
93# filesystems
94if [ -x /usr/sbin/zfs ]
95then
96	/usr/sbin/zfs share -a
97fi
98