wok-current annotate dropbear/stuff/sshx @ rev 18036
dropbear/sshx, ppp/pppnc-client: add default route support
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sun May 10 12:23:00 2015 +0200 (2015-05-10) |
parents | 58f4bd56c8de |
children | e726e3214807 |
rev | line source |
---|---|
pascal@10917 | 1 #!/bin/sh |
pascal@10917 | 2 |
pascal@10917 | 3 xdbclient() |
pascal@10917 | 4 { |
pascal@14027 | 5 read host data |
pascal@14027 | 6 svr=${DISPLAY#*:} |
pascal@11597 | 7 n=$((10+($RANDOM % 90))); dpy=localhost:$n |
pascal@14027 | 8 scr=${DISPLAY/${DISPLAY%.*}/$dpy} |
pascal@14027 | 9 r="" |
pascal@11597 | 10 while true; do |
pascal@14027 | 11 a="$1" |
pascal@14027 | 12 r="$r $1"; shift |
pascal@14027 | 13 case "$a" in |
pascal@14027 | 14 -[piIlLRWKBJ]) r="$r $1"; shift;; |
pascal@11597 | 15 -*) ;; |
pascal@11597 | 16 *) break ;; |
pascal@11597 | 17 esac |
pascal@11597 | 18 done |
pascal@15886 | 19 [ -n "$1" ] || set -- "${TERM:-xterm} -ls || ${TERM:-sakura} -l || xterm -ls" |
pascal@14027 | 20 exec dbclient -f -R $((6000+$n)):localhost:$((6000+${svr%.*})) $r \ |
pascal@14027 | 21 "xauth add $dpy $data; export DISPLAY=$scr; $@ ; xauth remove $dpy" \ |
pascal@14027 | 22 </dev/null >/dev/null |
pascal@10917 | 23 } |
pascal@10917 | 24 |
pascal@14027 | 25 pppssh() |
pascal@14027 | 26 { |
pascal@18015 | 27 ssh="dbclient -y" |
pascal@18015 | 28 $ssh $1 true || { |
pascal@18015 | 29 [ -z "$DROPBEAR_PASSWORD" ] && echo -n "ssh password: " && |
pascal@18015 | 30 read -s -t 30 DROPBEAR_PASSWORD && export DROPBEAR_PASSWORD |
pascal@18015 | 31 $ssh $1 true || exit 1 |
pascal@18015 | 32 } |
pascal@18036 | 33 extra="$(route -n | awk -vd=${1#*@} \ |
pascal@18036 | 34 '$1=="0.0.0.0"{ print d " gw " $2 " dev " $8 }')" |
pascal@18036 | 35 for i in ${4/default/128.0.0.0/1 0.0.0.0/1} ; do |
pascal@15886 | 36 echo "route add -net $i dev \$1" |
pascal@15886 | 37 done > /etc/ppp/ip-up.d/pppssh$$ |
pascal@18036 | 38 [ "$4" ] && echo "route add $extra" >> /etc/ppp/ip-up.d/pppssh$ |
pascal@15886 | 39 chmod +x /etc/ppp/ip-up.d/pppssh$$ |
pascal@14027 | 40 n=10.$(($$%256)).$(($$/256)) |
pascal@15886 | 41 ppp="/usr/sbin/pppd local noauth nodetach" |
pascal@15886 | 42 $ppp ${2:-$n.1:$n.2} passive pty "$ssh $1 $ppp ${3:-proxyarp} notty" \ |
pascal@15886 | 43 ipparam pppssh$$ |
pascal@18036 | 44 [ "$4" ] && route del $extra |
pascal@15886 | 45 rm -f /etc/ppp/ip-up.d/pppssh$$ |
pascal@14027 | 46 } |
pascal@14027 | 47 |
pascal@14027 | 48 case "$(basename $0)" in |
pascal@15886 | 49 ppp*) [ -z "$1" ] && cat <<EOT || pppssh "$@" ;; |
pascal@15886 | 50 Usage: $0 '[sshargs] user@remote' '[localip:remoteip] [localpppargs]' 'remotepppargs' 'routes' |
pascal@15886 | 51 Example: $0 tux@slitaz.org '' '' '192.168.1.0/24 10.1.2.0/24' |
pascal@15886 | 52 EOT |
pascal@14027 | 53 *) [ -z "$DISPLAY" ] && exec dbclient "$@" |
pascal@14027 | 54 xauth list $DISPLAY | xdbclient "$@" |
pascal@10917 | 55 esac |