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 # ident "@(#)go_cleanup.ksh 1.1 08/10/20 SMI" 28 # 29 # cleanup script for nfs server environment 30 # 31 32 [[ -n $DEBUG ]] && [[ $DEBUG != 0 ]] && set -x 33 34 NAME=$(basename $0) 35 DIR=$(dirname $0) 36 37 # sourcing framework global environment variables created after go_setup 38 # and for this purpose only this file should be sourced 39 CONFIGFILE=/var/tmp/nfsv4/config/config.suite 40 if [[ ! -f $CONFIGFILE ]]; then 41 echo "$NAME: CONFIGFILE[$CONFIGFILE] not found;" 42 echo "\texit UNINITIATED." 43 exit 6 44 fi 45 . $CONFIGFILE 46 47 # sourcing support functions 48 . ./testsh 49 50 id | grep "0(root)" > /dev/null 2>&1 51 if (( $? != 0 )); then 52 echo "Must be root to run this script." 53 exit $OTHER 54 fi 55 56 #make sure the MNTPTR is umounted on the client 57 mount | grep "^$MNTPTR[ \t]" | grep "on.*$SERVER:" > /dev/null 2>&1 58 if (( $? == 0 )); then 59 umount -f $MNTPTR > $TMPDIR/umount.out.$$ 2>&1 60 if (( $? != 0 )); then 61 echo "umount -f $MNTPTR on client failed - \c" 62 cat $TMPDIR/umount.out.$$ 63 exit $OTHER 64 fi 65 fi 66 67 # cleanup the SERVER 68 echo "Cleaning up server $SERVER" 69 execute $SERVER root \ 70 "export DEBUG=$DEBUG; /usr/bin/ksh $CONFIGDIR/setserver -c" \ 71 > $TMPDIR/rsh.out.$$ 2>&1 72 st=$? 73 if [[ $DEBUG == 0 ]]; then 74 grep "OKAY" $TMPDIR/rsh.out.$$ > /dev/null 2>&1 75 if (( $? == 0 && st == 0 )); then 76 # If server returned some warning, print it out 77 grep "WARNING" $TMPDIR/rsh.out.$$ | grep -v echo > \ 78 /dev/null 2>&1 79 else 80 grep ERROR $TMPDIR/rsh.out.$$ | grep -v echo > /dev/null 2>&1 81 if (( $? == 0 )); then 82 echo "$NAME: cleanup $SERVER had errors:" 83 else 84 echo "$NAME: cleanup $SERVER failed:" 85 fi 86 cat $TMPDIR/rsh.out.$$ 87 fi 88 else 89 cat $TMPDIR/rsh.out.$$ 90 fi 91 92 # Cleanup the client 93 echo "Cleaning up client $CLIENT" 94 95 # Remove added test users ... 96 res=$(mv /etc/passwd.orig /etc/passwd 2>&1) 97 res=$(mv /etc/group.orig /etc/group 2>&1) 98 res=$(chmod 444 /etc/passwd /etc/group 2>&1) 99 res=$(pwconv 2>&1) 100 res=$(/usr/xpg4/bin/egrep "2345678." /etc/passwd > $TMPDIR/users.err) 101 n=$(cat $TMPDIR/users.err | wc -l | nawk '{print $1}') 102 if (( n != 0 )); then 103 echo "WARNING: removing test users failed, \ 104 remove the following users manually:" 105 cat $TMPDIR/users.err 106 echo "\n" 107 fi 108 rm -f $TMPDIR/users.err 109 res=$(/usr/xpg4/bin/egrep "2345678." /etc/group > $TMPDIR/groups.err) 110 n=$(cat $TMPDIR/groups.err | wc -l | nawk '{print $1}') 111 if (( n != 0 )); then 112 echo "WARNING: removing test groups failed, \ 113 remove the following groups manually:" 114 cat $TMPDIR/groups.err 115 echo "\n" 116 fi 117 rm -f $TMPDIR/groups.err 118 119 # restore nfs tunable values 120 if [[ -f $CONFIGDIR/$CLIENT.nfs.flg ]]; then 121 res=$(cat $CONFIGDIR/$CLIENT.nfs.flg) 122 [[ -n $res ]] && ./set_nfstunable $res > $TMPDIR/nfs.out.$$ 2>&1 123 if (( $? != 0 )); then 124 echo "WARNING: restoring nfs tunable failed on $CLIENT:" 125 cat $TMPDIR/nfs.out.$$ 126 echo "Please restore the following nfs tunable manually: $res" 127 fi 128 fi 129 130 # Remove files 131 rm -f /suexec 132 rm -rf $MNTPTR 133 rm -rf $TMPDIR $CONFIGDIR/* 134 135 # Remove nfsh in non-global zone. 136 is_cipso "$TMPNFSMOPT" $SERVER 137 (( $? == CIPSO_NFSV4 )) && rm $ZONE_PATH/root/nfsh $ZONE_PATH/root/tclprocs 138 139 echo "$NAME: PASS" 140 exit $PASS 141