-
Notifications
You must be signed in to change notification settings - Fork 0
/
fixsudoers.sh
executable file
·75 lines (63 loc) · 1.8 KB
/
fixsudoers.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/sh
set -eu ;
LOGDIR="log/" ;
usage () { # {{{
cat <<-USAGE
usage: $0 -i NODELIST -l SLICE [-t TIMEOUT]
this attempts to fix the sudo command on PL nodes in NODELIST. SLICE
should be a planetlab slice (e.g., upmc_ts). TIMEOUT defaults to 10.
USAGE
exit 1
} # }}}
mkdir -p $LOGDIR
slice=invalid
nodelist=invalid
timeout=20
while getopts "i:l:t:h" OPTNAME ; do # {{{
case $OPTNAME in
i)
nodelist=$OPTARG
;;
l)
slice=$OPTARG
;;
t)
timeout=$OPTARG
;;
h|*)
usage
;;
esac
done
shift $(expr $OPTIND - 1)
OPTIND=1 # }}}
test $slice != invalid || usage
test $nodelist != invalid || usage
if [ ! -f $nodelist ] ; then echo "nodelist not found." ; exit 1 ; fi
BASECMD="vxargs -pry -t $timeout -a $nodelist -o $LOGDIR/fixsudo/"
cat > sudoers.tmp <<SUDOERS
Defaults !requiretty
Defaults !authenticate
Defaults env_reset
Defaults env_keep = "COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR LS_COLORS"
Defaults env_keep += "MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE"
Defaults env_keep += "LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES"
Defaults env_keep += "LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE"
Defaults env_keep += "LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY"
Defaults logfile=/var/log/sudo
root ALL=(ALL) ALL
$slice ALL=(ALL) ALL
SUDOERS
$BASECMD scp sudoers.tmp $slice@{}:/home/$slice/sudoers
$BASECMD nohup ssh -t -t $slice@{} su -c \'mv /home/$slice/sudoers /etc/sudoers\'
$BASECMD nohup ssh -t -t $slice@{} su -c \'chmod 440 /etc/sudoers\'
$BASECMD nohup ssh -t -t $slice@{} su -c \'chown root:root /etc/sudoers\'
rm -f sudoers.tmp
$BASECMD ssh $slice@{} sudo hostname > /dev/null
echo "# reporting broken nodes:"
for file in $(ls $LOGDIR/fixsudo/*.out) ; do
name=$(cat $file)
fn=$(basename $file)
fn=${fn%.out}
if [ "$name" != "$fn" ] ; then echo $fn ; fi
done