Update the runtest set.
[nethome.git] / bin / ppp9k
1 #!/bin/sh
2 #
3 # $Id$
4 # written by Jan Kratochvil <short@ucw.cz>
5 #
6 # Note to users of:
7 #       Linux running INSIDE VMWare (e.g. on Win32 machine)
8 #   and internet connection through local ethernet card:
9 # You MUST enable masquerading (NAT) for your Communicator's IP address!
10 #   iptables -t nat -F
11 #   iptables -t nat -A POSTROUTING --source 192.168.90.1 -j MASQUERADE
12 # (replace 192.168.90.1 by your $NOKIA9K setting below, if you change it)
13 #  - problem investigation by courtesy of Hussain Akbar <Hussain@systemsltd.com>
14
15
16 # IP address for N9K, "192.168.90.1" if not provided (either here or from
17 # some ~/.profile etc.)
18 #NOKIA9K=
19
20 # Nameserver for N9K, taken from /etc/resolv.conf if not provided
21 #NS=
22
23 # Serial port with attached N9K, default is /dev/ttyS1 (AKA COM2:)
24 #PORT=/dev/ttyS1
25
26 # Nokia baudrate, usually 19200 or 38400, default is 19200
27 #NOKIABAUD=19200
28
29 # No user-servicable parts below!
30
31 pid="/var/run/ppp9k.pid"
32 if [ -f "$pid" ];then
33         if kill -0 `head -n 1 "$pid"` 2>/dev/null;then
34                 echo "Killing previous ppp9k on PID(s):" `cat "$pid"`
35                 kill `cat "$pid"`
36                 rm -f "$pid"
37                 exit 0
38         else
39                 echo "Removing state lock of PID(s):" `cat "$pid"`
40                 rm -f "$pid"
41         fi
42 fi
43
44 IP="${NOKIA9K:-192.168.90.1}"
45 NS="`grep '^nameserver' /etc/resolv.conf|head -n 1|cut -f 2 -d ' '`"
46 NS="${NS:-127.0.0.1}"
47 if [ "$NS" = localhost -o "${NS#127.}" != "$NS" ];then NS="`hostname -f`";fi
48 PORT="${PORT:-ttyS1}"
49 if [ "${PORT#*/}" = "$PORT" ];then PORT="/dev/$PORT";fi
50 NOKIABAUD="${NOKIABAUD:-19200}"
51
52 # Some rules for the chat script:
53 # 9000i starts with: ATZ, AT&F  (the need for TIMEOUT 2, "-OK^M^J-AT&F")
54 # 9110  starts with:      AT&F
55 # user can have global     custom initialization string (need for one "OK^M^J")
56 # user can have connection custom initialization string (need for one "OK^M^J")
57
58 (trap "" HUP
59         while [ '!' -f "$pid" ];do sleep 1;done
60         me="`cat "$pid"`"
61         while :;do
62                 pppd "$PORT" "$NOKIABAUD" modem lock -crtscts xonxoff :$IP asyncmap 0 ms-dns "$NS" \
63                         connect 'chat -v                              \
64                                 "TIMEOUT" "86400"                     \
65                                 "AT"      "\c"                        \
66                                 "TIMEOUT" "2"                         \
67                                 "&F-OK^M^J-AT&F" "OK^M^JOK^M^JOK^M^J" \
68                                 "TIMEOUT" "20"                        \
69                                 "ATD"     "CONNECT^M^J"               \
70                                 ' \
71                         -ccp nodefaultroute proxyarp lcp-echo-interval 30 lcp-echo-failure 2 lcp-max-configure 30 -detach \
72                         -chap noauth "$@" &
73                 echo -e "$me\n$!" >"$pid"
74                 wait
75                 echo "$me" >"$pid"
76                 sleep 10
77         done) </dev/null &>/dev/null &
78
79 he="$!"
80 echo "$he" >"$pid"
81 echo "Starting up: PID=$he, port=$PORT, baud=$NOKIABAUD, remoteIP=$IP, nameserver=$NS"