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 DIR=$(dirname $0)
  29 NAME=$(basename $0)
  30 
  31 . $STC_NFSUTILS/include/nfs-util.kshlib
  32 
  33 # Turn on debug info, if requested
  34 export STC_GENUTILS_DEBUG=$STC_GENUTILS_DEBUG:$SHAREMNT_DEBUG
  35 [[ :$SHAREMNT_DEBUG: == *:$NAME:* \
  36         || :$SHAREMNT_DEBUG: == *:all:* ]] && set -x
  37 
  38 function cleanup {              # cleanup and exit
  39         rm -f $STF_TMPDIR/sharemnt.misc_opts $STF_TMPDIR/*.out.$$
  40         exit $1
  41 }
  42 
  43 #
  44 # Now setup the server..
  45 #
  46 # Firstly add environment variables to srv_setup script and
  47 # create a new script called sharemnt.misc_opts which will be
  48 # copied over to the server:
  49 sed -e "s%STF_TMPDIR_from_client%$SRV_TMPDIR%" \
  50     -e "s%SHAREMNT_DEBUG_from_client%$SHAREMNT_DEBUG%" \
  51         $DIR/srv_setup > $STF_TMPDIR/sharemnt.misc_opts \
  52         2> $STF_TMPDIR/sed.out.$$
  53 if (( $? != 0 )); then
  54         echo "$NAME: failed to create [sharemnt.others] file:"
  55         cat $STF_TMPDIR/sed.out.$$
  56         echo "PATH is $PATH"
  57         cleanup $STF_UNINITIATED
  58 fi
  59 
  60 scp $STF_TMPDIR/sharemnt.misc_opts root@$SERVER:$SRV_TMPDIR \
  61         > $STF_TMPDIR/scp.out.$$ 2>&1
  62 if (( $? != 0 )); then
  63         echo "$NAME: failed to copy \
  64                 <$STF_TMPDIR/sharemnt.misc_opts> to $SERVER:"
  65         cat $STF_TMPDIR/scp.out.$$
  66         cleanup $STF_FAIL
  67 fi
  68 
  69 # ..finally execute the script on the server.
  70 SRVDEBUG=$STC_GENUTILS_DEBUG:$SHAREMNT_DEBUG
  71 [[ :$SRVDEBUG: == *:RSH:* ]] && SRVDEBUG=all
  72 RSH root $SERVER \
  73         "export SHAREMNT_DEBUG=$SRVDEBUG; \
  74          F=$SRV_TMPDIR/sharemnt.misc_opts; \
  75          chmod 0555 \$F && \$F -s" \
  76         > $STF_TMPDIR/rsh.out.$$ 2>&1
  77 rc=$?
  78 [[ :$SRVDEBUG: == *:all:* ]] && cat $STF_TMPDIR/rsh.out.$$
  79 grep "Done" $STF_TMPDIR/rsh.out.$$ > /dev/null 2>&1
  80 if (( $? != 0 || $rc != 0 )); then
  81         echo "$NAME: run <$SRV_TMPDIR/sharemnt.misc_opts -s> \
  82                 in $SERVER failed:"
  83         cat $STF_TMPDIR/rsh.out.$$
  84         cleanup $STF_FAIL
  85 fi
  86 
  87 cleanup $STF_PASS