]>
Commit | Line | Data |
---|---|---|
f2d9af81 MT |
1 | #!/bin/bash |
2 | # | |
3 | ||
4 | eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings) | |
5 | ||
6 | # MAXRETRIES is now a count before red clear and if reconnection fail, eventually switching to a backup profil | |
7 | MAXCONFIGURE=160 | |
8 | if [ ! $HOLDOFF ]; then | |
9 | HOLDOFF=30 | |
10 | fi | |
11 | ||
12 | # Debugging. Comment it out to stop logging | |
13 | DEBUG="yes" | |
14 | msg() { | |
15 | if [ "z$DEBUG" != "z" ] ; then | |
16 | /usr/bin/logger -t red "Connectioncheck: $*" | |
17 | fi | |
18 | /bin/echo "$*" | |
19 | } | |
20 | ||
21 | if [ -s "/var/ipfire/red/keepconnected" ]; then | |
22 | ATTEMPTS=$(/bin/cat /var/ipfire/red/keepconnected) | |
23 | else | |
24 | echo "0" > /var/ipfire/red/keepconnected | |
25 | fi | |
26 | ||
27 | case "$1" in | |
28 | start) | |
29 | # waiting pppd start or sync timout set at 90 s when available in driver | |
30 | # So just wait 5 s after 'red start' end where pppd should have been started | |
31 | TIMETOSTART=0 | |
32 | while ( ! /bin/ps ax | /bin/grep -q [p]ppd ); do | |
33 | if [ ! -e "/var/ipfire/red/keepconnected" ]; then | |
34 | # user pressed disconnect in gui | |
35 | exit 0 | |
36 | fi | |
37 | RCREDSTART=`/bin/ps ax | /bin/grep 'red start'` | |
38 | if [ "$TIMETOSTART" -eq 1 ]; then | |
39 | msg "fail before pppd start : no sync, trying again" | |
f3770039 | 40 | /etc/rc.d/init.d/network restart red |
f2d9af81 MT |
41 | exit |
42 | fi | |
24249567 | 43 | # give 5 s more at pppd to be visible with ps ax after 'red start' end |
f2d9af81 MT |
44 | if [ "$RCREDSTART" = '' ]; then |
45 | TIMETOSTART=1 | |
46 | fi | |
47 | /bin/sleep 5 | |
48 | done | |
49 | ||
50 | #watching if an IP is received in $MAXCONFIGURE time to avoid some pppoa waiting forever even after LCP timeout | |
51 | COUNT=0 | |
52 | while [ "$COUNT" -le "$MAXCONFIGURE" ]; do | |
53 | if [ ! -e "/var/ipfire/red/keepconnected" ]; then | |
54 | # user pressed disconnect in gui | |
55 | exit 0 | |
56 | fi | |
57 | if [ -e "/var/ipfire/red/active" ]; then | |
58 | # connected in time so exit | |
59 | echo "0" > /var/ipfire/red/keepconnected | |
60 | exit 0 | |
61 | fi | |
62 | if [ -e "/var/ipfire/red/dial-on-demand" ]; then | |
63 | # Don't count time when dial-on-demand is not really connected | |
64 | if ( ! /sbin/ifconfig | /bin/grep -q addr:10.64.64.64 ); then | |
65 | (( COUNT += 5 )) | |
66 | fi | |
67 | else | |
68 | (( COUNT += 5 )) | |
69 | fi | |
70 | if ( ! /bin/ps ax | /bin/grep -q [p]ppd ); then | |
71 | #pppd exit, so don't need to wait MAXCONFIGURE | |
72 | break | |
73 | fi | |
74 | /bin/sleep 5 | |
75 | done | |
76 | msg "RED fail to connect" | |
77 | RCREDSTART=`/bin/ps ax | /bin/grep 'red start' | /usr/bin/cut -f1 -d ' '` | |
78 | if [ "$RCREDSTART" != '' ]; then | |
79 | /bin/kill "$RCREDSTART" | |
80 | fi | |
81 | # this attempt to connect fail, so retry | |
82 | ||
83 | #Don't erase keepconnected because it is used to watch user actions | |
24249567 | 84 | /usr/bin/touch /var/ipfire/red/redial |
f3770039 | 85 | /etc/rc.d/init.d/network stop red |
f2d9af81 MT |
86 | while ( /bin/ps ax | /bin/grep -q [p]ppd ); do |
87 | msg "waiting pppd exit" | |
88 | /bin/sleep 2 | |
89 | done | |
90 | /bin/sleep $HOLDOFF | |
91 | if [ ! -e "/var/ipfire/red/keepconnected" ]; then | |
92 | # user pressed disconnect in gui | |
93 | exit 0 | |
94 | fi | |
95 | (( ATTEMPTS += 1 )) | |
96 | msg "Restarting $ATTEMPTS/$MAXRETRIES" | |
97 | if [ "$ATTEMPTS" -ge "$MAXRETRIES" ]; then | |
98 | echo "0" > /var/ipfire/red/keepconnected | |
99 | msg "Clearing RED interface" | |
f3770039 | 100 | /etc/rc.d/init.d/network stop red |
f2d9af81 MT |
101 | if [ "$BACKUPPROFILE" != '' ]; then |
102 | /bin/rm -f /var/ipfire/ppp/settings | |
103 | /bin/cp "/var/ipfire/ppp/settings-$BACKUPPROFILE" /var/ipfire/ppp/settings | |
104 | fi | |
105 | else | |
106 | echo $ATTEMPTS > /var/ipfire/red/keepconnected | |
107 | fi | |
f3770039 | 108 | /etc/rc.d/init.d/network start red |
f2d9af81 MT |
109 | ;; |
110 | reconnect) | |
111 | while ( /bin/ps ax | /bin/grep -q [p]ppd ); do | |
112 | /bin/sleep 2 | |
113 | done | |
114 | msg "will connect again" | |
f3770039 | 115 | /etc/rc.d/init.d/network start red |
f2d9af81 MT |
116 | ;; |
117 | *) | |
118 | /bin/echo "Usage: $0 {start|reconnect}" | |
119 | exit 1 | |
120 | ;; | |
121 | esac |