1 #! /usr/bin/ksh -p
   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 (the "License").
   7 # You may not use this file except in compliance with the License.
   8 #
   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.
  13 #
  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]
  19 #
  20 # CDDL HEADER END
  21 #
  22 
  23 #
  24 # Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  25 # Use is subject to license terms.
  26 #
  27 
  28 NAME=$(basename $0)
  29 STF_TMPDIR=${STF_TMPDIR:-"STF_TMPDIR_from_client"}
  30 SHAREMNT_DEBUG=${SHAREMNT_DEBUG:-"SHAREMNT_DEBUG_from_client"}
  31 
  32 . $STF_TMPDIR/srv_config.vars
  33 
  34 # Include common STC utility functions
  35 if [[ -s $STC_GENUTILS/include/nfs-util.kshlib ]]; then
  36         . $STC_GENUTILS/include/nfs-util.kshlib
  37 else
  38         . $STF_TMPDIR/nfs-util.kshlib
  39 fi
  40 
  41 export STC_GENUTILS_DEBUG=$SHAREMNT_DEBUG
  42 [[ :$SHAREMNT_DEBUG: == *:all:* ]] && set -x
  43 
  44 function usage {
  45         typeset FNAME=usage
  46         [[ :$SHAREMNT_DEBUG: == *:$FNAME:* \
  47                 || :$SHAREMNT_DEBUG: == *:all:* ]] && set -x
  48 
  49         [[ -n $1 ]] && echo $1
  50         echo "Usage: $NAME <group> share <directory> [options]"
  51         echo "       $NAME <group> unshare <directory>"
  52         exit 1
  53 }
  54 
  55 if [[ $# != 3 && $# != 4 ]]; then
  56         usage
  57 fi
  58 
  59 share_group=$1
  60 operate=$2
  61 dir=$3
  62 share_opts=${4:-"rw"}
  63 
  64 sharemgr list | grep -w $share_group > /dev/null 2>&1
  65 if (( $? != 0 )); then
  66         usage "$NAME: group<$share_group> is not existed"
  67 fi
  68 
  69 if [[ -z $dir ]]; then
  70         usage "$NAME: exported diretory name not found"
  71 fi
  72 
  73 ret=0
  74 case $operate in
  75 share)
  76         share_type=$(( RANDOM % 3 ))
  77         if (( share_type == 0 )); then
  78                 share2cmd="sharemgr_share $share_group $dir $share_opts"
  79         elif (( share_type == 1 )); then
  80                 share2cmd="zfs_share $dir $share_opts"
  81         else
  82                 share2cmd="share -F nfs -o $share_opts $dir"
  83         fi
  84 
  85         eval "$share2cmd" > $STF_TMPDIR/$NAME.out.$$ 2>&1
  86         ret=$?
  87         if (( $ret != 0 )); then
  88                 echo "$NAME: share $dir with $share_opts failed."
  89                 echo "command: $share2cmd"
  90                 cat $STF_TMPDIR/$NAME.out.$$
  91         fi
  92         ;;
  93 
  94 unshare)
  95         auto_unshare $dir $share_group > $STF_TMPDIR/$NAME.out.$$ 2>&1
  96         ret=$?
  97         if (( $ret != 0 )); then
  98                 echo "$NAME: unshare $dir failed."
  99                 cat $STF_TMPDIR/$NAME.out.$$
 100         fi
 101         ;;
 102 
 103 *)
 104         usage
 105         ;;
 106 esac
 107 
 108 [[ :$SHAREMNT_DEBUG: == *:all:* ]] && cat $STF_TMPDIR/$NAME.out.$$ 1>&2
 109 
 110 rm -f $STF_TMPDIR/$NAME.out.$$
 111 exit $ret