+macro editor ALT-w: wrap text (subject line) to " [WAS: &]"
[nethome.git] / bin / ppp9k
1 #!/bin/sh
2 #
3 # $Id$
4
5 # IP address for N9K, "192.168.90.1" if not provided (either here or from
6 # some ~/.profile etc.)
7 #NOKIA9K=
8
9 # Nameserver for N9K, taken from /etc/resolv.conf if not provided
10 #NS=
11
12 # Serial port with attached N9K, default is /dev/ttyS1 (AKA COM2:)
13 #PORT=/dev/ttyS1
14
15 # Nokia baudrate, usually 19200 or 38400, default is 19200
16 #NOKIABAUD=19200
17
18 # No user-servicable parts below!
19
20 pid="/var/run/ppp9k.pid"
21 if [ -f "$pid" ];then
22         if kill -0 `head -n 1 "$pid"` 2>/dev/null;then
23                 echo "Killing previous ppp9k on PID(s):" `cat "$pid"`
24                 kill `cat "$pid"`
25                 rm -f "$pid"
26                 exit 0
27         else
28                 echo "Removing state lock of PID(s):" `cat "$pid"`
29                 rm -f "$pid"
30         fi
31 fi
32
33 IP="${NOKIA9K:-192.168.90.1}"
34 NS="`grep '^nameserver' /etc/resolv.conf|head -n 1|cut -f 2 -d ' '`"
35 NS="${NS:-127.0.0.1}"
36 if [ "$NS" = localhost -o "${NS#127.}" != "$NS" ];then NS="`hostname -f`";fi
37 PORT="${PORT:-ttyS1}"
38 if [ "${PORT#*/}" = "$PORT" ];then PORT="/dev/$PORT";fi
39 NOKIABAUD="${NOKIABAUD:-19200}"
40
41 # Some rules for the chat script:
42 # 9000i starts with: ATZ, AT&F  (the need for TIMEOUT 2, "-OK^M^J-AT&F")
43 # 9110  starts with:      AT&F
44 # user can have global     custom initialization string (need for one "OK^M^J")
45 # user can have connection custom initialization string (need for one "OK^M^J")
46
47 (trap "" HUP
48         while [ '!' -f "$pid" ];do sleep 1;done
49         me="`cat "$pid"`"
50         while :;do
51                 pppd "$PORT" "$NOKIABAUD" modem lock -crtscts xonxoff :$IP asyncmap 0 ms-dns "$NS" \
52                         connect 'chat -v                              \
53                                 "TIMEOUT" "86400"                     \
54                                 "AT"      "\c"                        \
55                                 "TIMEOUT" "2"                         \
56                                 "&F-OK^M^J-AT&F" "OK^M^JOK^M^JOK^M^J" \
57                                 "TIMEOUT" "20"                        \
58                                 "ATD"     "CONNECT^M^J"               \
59                                 ' \
60                         -ccp nodefaultroute proxyarp lcp-echo-interval 30 lcp-echo-failure 2 lcp-max-configure 30 -detach \
61                         -chap noauth "$@" &
62                 echo -e "$me\n$!" >"$pid"
63                 wait
64                 echo "$me" >"$pid"
65                 sleep 10
66         done) </dev/null &>/dev/null &
67
68 he="$!"
69 echo "$he" >"$pid"
70 echo "Starting up: PID=$he, port=$PORT, baud=$NOKIABAUD, remoteIP=$IP, nameserver=$NS"