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 2008 Sun Microsystems, Inc.  All rights reserved.
  25 # Use is subject to license terms.
  26 #
  27 # For recovery testing purposes, cleanup server filesystem from
  28 # previous nfs4_gen test suite being run. Setup server with 
  29 # reboot capability.
  30 #
  31 
  32 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
  33 
  34 NAME=`basename $0`
  35 DIR=`dirname $0`
  36 TESTROOT=${TESTROOT:-"$DIR/../"}
  37 TESTSH="$TESTROOT/testsh"
  38 
  39 id | grep "0(root)" > /dev/null 2>&1
  40 if [ $? -ne 0 ]; then
  41         echo "Must be root to run this script."
  42         exit $OTHER
  43 fi
  44 
  45 # sourcing framework global environment variables created after go_setup
  46 # and for this purpose only this file should be sourced
  47 CONFIGFILE=/var/tmp/nfsv4/config/config.suite
  48 if [[ ! -f $CONFIGFILE ]]; then
  49         echo "$NAME: CONFIGFILE[$CONFIGFILE] not found;"
  50         echo "\texit UNINITIATED."
  51         exit 6
  52 fi
  53 . $CONFIGFILE
  54 
  55 #source support functions 
  56 . $TESTSH
  57 
  58 function cleanup                # ensure umount MNPTR & exit
  59 {
  60         # Need to unmount the test directory
  61         umount ${MNTPTR} > $TMPDIR/$NAME.umount.$$ 2>&1
  62         if [ $? -ne 0 ]; then
  63                 echo "$NAME: cleanup - umount ${MNTPTR} failed"
  64                 cat $TMPDIR/$NAME.umount.$$
  65         else 
  66                 rm -f $TMPDIR/$NAME.umount.$$
  67         fi
  68         exit ${1}
  69 }
  70 
  71 # setup the server ... 
  72 # add environment variables to recov_srv_setup script:
  73 rm -f $TMPDIR/recov_setserver
  74 SETD="DEBUG=0; export DEBUG"
  75 [ "$DEBUG" != "0" ] && SETD="DEBUG=1; export DEBUG; set -x"
  76 sed -e "s%Tmpdir_from_client%$TMPDIR%" -e "s%SetDebugMode%$SETD%" \
  77         -e "s%CONFIGFILE_from_client%$CONFIGFILE%" \
  78         -e "s%CONFIGDIR_from_client%$CONFIGDIR%" \
  79         recov_srv_setup > $TMPDIR/recov_setserver
  80 if [ $? -ne 0 ]; then
  81         echo "$NAME: can't setup [recov_setserver] file."
  82         exit $UNINITIATED
  83 fi
  84 
  85 # and the reboot scripts
  86 sed -e "s%Tmpdir_from_client%$TMPDIR%" \
  87         -e "s%CONFIGFILE_from_client%$CONFIGFILE%" \
  88         -e "s%CONFIGDIR_from_client%$CONFIGDIR%" \
  89         nfs4red > $TMPDIR/nfs4red
  90 if [ $? -ne 0 ]; then
  91         echo "$NAME: can't setup [nfs4red] file."
  92         exit $UNINITIATED
  93 fi
  94 sed -e "s%Tmpdir_from_client%$TMPDIR%" \
  95         -e "s%BASEDIR_from_client%$BASEDIR%" \
  96         -e "s%CONFIGDIR_from_client%$CONFIGDIR%" \
  97         S99nfs4red > $TMPDIR/S99nfs4red
  98 if [ $? -ne 0 ]; then
  99         echo "$NAME: can't setup [S99nfs4red] file."
 100         exit $UNINITIATED
 101 fi
 102 
 103 # ... now setup the $SERVER
 104 ping $SERVER > $TMPDIR/ping.out.$$ 2>&1
 105 if [ $? -ne 0 ]; then 
 106         echo "$SERVER setup failed - not responding?" 
 107         cat $TMPDIR/ping.out.$$
 108         exit $OTHER
 109 fi
 110 
 111 # copy server programs over to $SERVER for setup
 112 scp $TMPDIR/recov_setserver $TMPDIR/nfs4red root@$SERVER:$CONFIGDIR \
 113         > $TMPDIR/rcp.out.$$ 2>&1
 114 if [ $? -ne 0 ]; then
 115         echo "$NAME: copying setup files to $SERVER failed:"
 116         cat $TMPDIR/rcp.out.$$
 117         exit $OTHER
 118 fi
 119 
 120 scp $TMPDIR/S99nfs4red root@$SERVER:/etc/rc3.d > $TMPDIR/rcp.out.$$ 2>&1
 121 if [ $? -ne 0 ]; then
 122         echo "$NAME: copying S99nfs4red file to $SERVER failed:"
 123         cat $TMPDIR/rcp.out.$$
 124         exit $OTHER
 125 fi
 126 
 127 execute $SERVER root "/usr/bin/ksh $CONFIGDIR/recov_setserver -s" \
 128         > $TMPDIR/rsh.out.$$ 2>&1
 129 ret=$?
 130 grep "OKAY" $TMPDIR/rsh.out.$$ | grep -v echo > /dev/null 2>&1
 131 if [ $? -eq 0 ] && [ $ret -eq 0 ]; then
 132         # If server returned some warning, print it out
 133         grep "WARNING" $TMPDIR/rsh.out.$$ | grep -v echo > /dev/null 2>&1
 134         if [ $? -eq 0 ]; then
 135                 echo "$NAME: setup $SERVER have warnings:"
 136                 grep WARNING $TMPDIR/rsh.out.$$
 137         fi
 138 else
 139         grep "ERROR" $TMPDIR/rsh.out.$$ | grep -v echo > /dev/null 2>&1
 140         if [ $? -eq 0 ]; then
 141                 echo "$NAME: setup $SERVER had errors:"
 142         else
 143                 echo "$NAME: setup $SERVER failed:"
 144         fi
 145         cat $TMPDIR/rsh.out.$$
 146         exit $OTHER
 147 fi
 148 [ $DEBUG != "0" ] && cat $TMPDIR/rsh.out.$$
 149 
 150 echo "  SERVER=$SERVER recovery setup OK!! "
 151 echo "$NAME: PASS"
 152 exit $PASS