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