-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsu
executable file
·98 lines (86 loc) · 2.07 KB
/
su
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/QOpenSys/usr/bin/sh
#
# NOTE: to 'su' without a password, run su-setup first
#
usage() {
echo "Usage:" $(basename $0) "<username>" "<options>"
exit 5
}
if [ "$1" == "" ] ; then
usage
fi
SSH_OPTS="-Y"
if [ "$DISPLAY" == "" ] ; then
SSH_OPTS="-x"
fi
#Input
RMT_USER=$1
RMT_DIR=$(pwd)
RMT_SHELL='$SHELL'
RMT_CMD=""
RMT_SHELL_ENVARGS=""
shift
while [ "$1" != "" ]; do
PARAM=`echo $1 | awk -F= '{print $1}'`
VALUE=`echo $1 | awk -F= '{print $2}'`
case $PARAM in
-h | --help)
usage
;;
--command|--session-command)
RMT_CMD=$VALUE
;;
-c)
shift
RMT_CMD=$1
if [ "$1" == "" ]; then
usage
fi
;;
--shell)
RMT_SHELL=$VALUE
;;
--fast|-f)
RMT_SHELL_OPTS="$RMT_SHELL_OPTS -f"
;;
-s)
shift
RMT_SHELL=$1
if [ "$1" == "" ]; then
usage
fi
;;
-m|-p|--preserve-environment)
RMT_SHELL_ENVARGS=$(env | grep -Ev '^(USER|HOME|LOGNAME|SHELL)' | awk '{printf "export \"%s\" && ",$1; }')
;;
--group|-g|-G|--supp-group)
>&2 echo "ERROR: Option $PARAM not supported"
exit 7
;;
-|-l|--login)
>&2 echo "WARNING: Option $PARAM not fully supported (always a login shell; this option causes a change to the target user's home directory)"
RMT_DIR=""
;;
--version|-V)
echo "Jesse's Poor-Man su, version 1"
exit 2
;;
*)
echo "ERROR: unknown parameter \"$PARAM\""
usage
exit 1
;;
esac
shift
done
if [ "$RMT_CMD" == "" ] ; then
if [ "$RMT_SHELL_ENVARGS" == "" ] ; then
RMT_CMD="cd $RMT_DIR && exec $RMT_SHELL "
else
RMT_CMD="cd $RMT_DIR && exec $RMT_SHELL -c '$RMT_SHELL_ENVARGS exec $RMT_SHELL' "
fi
else
RMT_CMD="cd $RMT_DIR && exec $RMT_SHELL -c '$RMT_SHELL_ENVARGS $RMT_CMD' "
fi
#echo $RMT_CMD
exec /QOpenSys/usr/bin/ssh -q -t $SSH_OPTS [email protected] $RMT_CMD