-
Notifications
You must be signed in to change notification settings - Fork 1
/
ssh_wrapper.sh
executable file
·58 lines (51 loc) · 2.09 KB
/
ssh_wrapper.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
#!/bin/bash
# is /usr/bin/ssh inside a container
# 05/11/2016 Antoine Schonewille
# 05/18/2016 Revision -A
# 01/06/2016 [email protected] - adjustments for bwForCluster Ulm (JUSTUS)
# 23/11/2016 [email protected] - adjustments for singularity
# works with openssh supplied in RHEL 6 and 7
_LOCALHOST='localhost'
_LOCALIP='127.0.0'
_HOSTNAME=`hostname --short`
_HAS_PARAMS="bcDeFIiLlmOopRSWw"
while (( "$#" )); do
_ONE=`echo $@|cut -f1 -d' '`
_TWO=`echo $@|cut -f2 -d' '`
# easy. if a word starts with an hyphen it's an option and it might come with a parameter
if [ "`echo $_ONE | cut -b1`" == "-" ]; then
_PARAM=$_PARAM' '$_ONE
_PREV='option'
if [ "$(echo $_HAS_PARAMS | grep `echo $_ONE | cut -b2`)" ] && [ "`echo $_ONE | cut -b3`" == "" ]; then
_PARAM=$_PARAM' '$_TWO
shift
fi
else
# if the current word does not have a hyphen (no option) then we have two possibilities
# a: previous word wasn't an option (hyphen)
# b: or the second word doesn't have a hyphen (part of command)
# both cases then assume that the host must be the first word
if [ "$_PREV" != "option" ] || [ "`echo $_TWO | cut -b1`" != "-" ]; then
_HOST=$_ONE
shift
_COMMAND=$@
break
else
_PARAM=$_PARAM' '$_ONE
_PREV=''
fi
fi
shift
done
_COMMAND=`echo $_COMMAND | tr '"' "'"`
# with no params start an singularity container remotely with a pseudy TTY
if [ "$_COMMAND" == "" ]; then
_PARAM="-t $_PARAM"
_COMMAND="/bin/bash"
else
_COMMAND='/bin/bash -c "'$_COMMAND'"'
fi
echo "====="
echo /usr/bin/ssh_orig $_PARAM $_HOST \$\(which singularity\) exec -B /etc/ssh $SINGULARITY_IMAGE $_COMMAND
/usr/bin/ssh_orig $_PARAM $_HOST \$\(which singularity\) exec -B /etc/ssh $SINGULARITY_IMAGE $_COMMAND
exit $?