wok view dropbear/stuff/sshx @ rev 18954
open-vm-tools: update bdeps
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Tue Mar 08 10:05:07 2016 +0100 (2016-03-08) |
parents | c68cd3e0f194 |
children | 1ae2567134a8 |
line source
1 #!/bin/sh
3 xdbclient()
4 {
5 read host data
6 svr=${DISPLAY#*:}
7 n=$((10+($RANDOM % 90))); dpy=localhost:$n
8 scr=${DISPLAY/${DISPLAY%.*}/$dpy}
9 r=""
10 while true; do
11 a="$1"
12 r="$r $1"; shift
13 case "$a" in
14 -[piIlLRWKBJ]) r="$r $1"; shift;;
15 -*) ;;
16 *) break ;;
17 esac
18 done
19 [ -n "$1" ] || set -- "${TERM:-xterm} -ls || ${TERM:-sakura} -l || xterm -ls"
20 exec dbclient -f -R $((6000+$n)):localhost:$((6000+${svr%.*})) $r \
21 "xauth add $dpy $data; export DISPLAY=$scr; $@ ; xauth remove $dpy" \
22 </dev/null >/dev/null
23 }
25 pppssh()
26 {
27 ssh="dbclient -y"
28 $ssh $1 true || {
29 [ -z "$DROPBEAR_PASSWORD" ] && echo -n "ssh password: " &&
30 read -s -t 30 DROPBEAR_PASSWORD && export DROPBEAR_PASSWORD
31 $ssh $1 true || exit 1
32 }
33 extra="$(route -n | awk -vd=$(nslookup ${1#*@} | \
34 sed '$!d;s/.*: \([^ ]*\).*/\1/') \
35 '$1=="0.0.0.0"{ print d " gw " $2 " dev " $8 }')"
36 for i in ${4/default/128.0.0.0/1 0.0.0.0/1} ; do
37 echo "route add -net $i dev \$1"
38 done > /etc/ppp/ip-up.d/pppssh$$
39 [ "$4" ] && echo "route add $extra" >> /etc/ppp/ip-up.d/pppssh$$
40 chmod +x /etc/ppp/ip-up.d/pppssh$$
41 n=10.$(($$%256)).$(($$/256))
42 ppp="/usr/sbin/pppd local noauth nodetach"
43 $ppp ${2:-$n.1:$n.2} passive pty "$ssh $1 $ppp ${3:-proxyarp} notty" \
44 ipparam pppssh$$
45 [ "$4" ] && route del $extra
46 rm -f /etc/ppp/ip-up.d/pppssh$$
47 }
49 xfbvnc()
50 {
51 p=5900
52 while netstat -tln | grep -q ":$p " ; do p=$(($p+1)); done
53 [ -r /dev/input/mice ] || echo "Warning: Cannot read mouse input." 1>&2
54 dbclient -f -N -L $p:127.0.0.1:${2:-5900} $1
55 fbvnc 127.0.0.1 $p
56 kill $(netstat -tlnp 2> /dev/null | \
57 sed "/:$p /!d;s|.* \\([0-9]*\\)/[^ ]*|\\1|")
58 }
60 case "$(basename $0)" in
61 *vnc) [ -z "$1" ] && cat <<EOT || xfbvnc "$@" ;;
62 Usage: $0 '[sshargs] user@remote' [vncport]
63 $(fbvnc --help 2>&1 | sed '1,/Usage:/d')
64 EOT
65 ppp*) [ -z "$1" ] && cat <<EOT || pppssh "$@" ;;
66 Usage: $0 '[sshargs] user@remote' '[localip:remoteip] [localpppargs]' 'remotepppargs' 'routes'
67 Example: $0 tux@slitaz.org '' '' '192.168.1.0/24 10.1.2.0/24'
68 EOT
69 *) [ -z "$DISPLAY" ] && exec dbclient "$@"
70 xauth list $DISPLAY | xdbclient "$@"
71 esac