File: pssh

package info (click to toggle)
sshproxy 0.6.0~beta2-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 956 kB
  • ctags: 1,296
  • sloc: python: 8,932; sh: 268; sql: 40; makefile: 38; xml: 21
file content (48 lines) | stat: -rwxr-xr-x 1,045 bytes parent folder | download
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 -- "$@"