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
|
#!/bin/bash
PROXY_PORT=${SSHPROXY_PORT:-2242}
PROXY_HOST=${SSHPROXY_HOST:-localhost}
PROXY_USER=${SSHPROXY_USER}
if [[ -z "${PROXY_USER}" ]]; then
if [[ -n "${USER}" ]]; then
PROXY_USER=${USER}
else
PROXY_USER=admin
fi
fi
function getfd () {
fd=$(ls -l /proc/$1/fd/$2)
echo "${fd##* }"
}
sep=
opts=( )
args=( "$@" )
for arg in "${args[@]}"; do
shift
if [ "$arg" == "--" ]; then
sep=yes
break
fi
opts=( "${opts[@]}" "$arg" )
done
if [ "$sep" != "yes" ]; then
if [ "${#opts}" -gt 0 ]; then
set -- "${opts[@]}"
fi
unset opts
fi
OPTS="$OPTS ${opts[@]}"
# force tty allocation if this is a shell session
if [ "${1#-}" = "$1" -a $# -eq 1 -o "${1#--admin}" != "$1" ]; then
# don't allocate a tty if there is no local tty
if tty -s && [ "$(getfd $$ 0)" = "$(getfd $$ 1)" ]; then
OPTS="-t $OPTS"
fi
fi
[ -n "$verbose" ] && echo ssh $OPTS -p $PROXY_PORT $PROXY_USER@$PROXY_HOST -- "$@"
exec ssh $OPTS -p $PROXY_PORT $PROXY_USER@$PROXY_HOST -- "$@"
|