]>
Commit | Line | Data |
---|---|---|
905fbf3e MT |
1 | #!/bin/bash |
2 | # | |
3 | ||
4 | . /etc/sysconfig/rc | |
5 | . ${rc_functions} | |
6 | ||
3ca6c05a MT |
7 | # Stop if nothing is configured |
8 | if [ ! -s "/var/ipfire/ppp/settings" ];then | |
9 | exit 0 | |
10 | fi | |
11 | ||
905fbf3e MT |
12 | eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings) |
13 | ||
14 | MAX=160 | |
15 | ATTEMPTS=0 | |
16 | COUNT=0 | |
17 | if [ ! $HOLDOFF ]; then | |
18 | HOLDOFF=30 | |
19 | fi | |
20 | ||
21 | msg_log () { | |
22 | logger -t $(basename $0)[$$] $* | |
23 | } | |
24 | ||
25 | msg_log "Connectd ($1) started with PID $$" | |
26 | ||
27 | ||
28 | if [ -s "/var/ipfire/red/keepconnected" ]; then | |
29 | ATTEMPTS=$(cat /var/ipfire/red/keepconnected) | |
30 | else | |
31 | echo "0" > /var/ipfire/red/keepconnected | |
32 | fi | |
33 | ||
34 | case "$1" in | |
35 | start) | |
36 | boot_mesg "Starting connection daemon..." | |
37 | echo_ok | |
38 | ||
3ca6c05a MT |
39 | while [ "$COUNT" -lt "$MAX" ]; do |
40 | if [ ! -e "/var/ipfire/red/keepconnected" ]; then | |
41 | # User pressed disconnect in gui | |
42 | msg_log "Stopping by user request. Exiting." | |
43 | /etc/rc.d/init.d/network stop red | |
44 | exit 0 | |
45 | fi | |
46 | if [ -e "/var/ipfire/red/active" ]; then | |
47 | # Successfully connected in time | |
48 | echo "0" > /var/ipfire/red/keepconnected | |
49 | msg_log "System is online. Exiting."; exit 0 | |
50 | fi | |
51 | if ( ! ps ax | grep -q [p]ppd ); then | |
52 | msg_log "No pppd is running. Trying reconnect." | |
53 | break # because pppd died | |
54 | fi | |
55 | sleep 5 | |
56 | (( COUNT+=1 )) | |
57 | done | |
905fbf3e MT |
58 | |
59 | /etc/rc.d/init.d/network stop red | |
60 | ||
61 | (( ATTEMPTS+=1 )) | |
62 | msg_log "Reconnecting: Attempt ${ATTEMPTS} of ${MAXRETRIES}" | |
63 | if [ "${ATTEMPTS}" -ge "${MAXRETRIES}" ]; then | |
64 | echo "0" > /var/ipfire/red/keepconnected | |
65 | if [ "$BACKUPPROFILE" != '' ]; then | |
66 | rm -f /var/ipfire/ppp/settings | |
67 | cp "/var/ipfire/ppp/settings-${BACKUPPROFILE}" /var/ipfire/ppp/settings | |
68 | msg_log "Switched to backup profile ${BACKUPPROFILE}" | |
cdfc1e52 CS |
69 | # to be shure the right secrets are used |
70 | eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings-${BACKUPPROFILE}) | |
71 | echo "'$USERNAME' * '$PASSWORD'" > /var/ipfire/ppp/secrets | |
905fbf3e MT |
72 | else |
73 | msg_log "No backup profile given. Exiting." | |
74 | exit 0 | |
75 | fi | |
76 | else | |
77 | echo $ATTEMPTS > /var/ipfire/red/keepconnected | |
78 | sleep ${HOLDOFF} | |
79 | fi | |
80 | ||
4ea7607d | 81 | /etc/rc.d/init.d/network start red >/dev/tty12 2>&1 </dev/tty12 & |
905fbf3e MT |
82 | ;; |
83 | ||
84 | reconnect) | |
85 | while ( ps ax | grep -q [p]ppd ); do | |
352e626f | 86 | msg_log "There is a pppd still running. Waiting 2 seconds for exit." |
905fbf3e MT |
87 | sleep 2 |
88 | done | |
89 | ||
352e626f | 90 | /etc/rc.d/init.d/network restart red |
905fbf3e MT |
91 | ;; |
92 | ||
93 | *) | |
94 | echo "Usage: $0 {start|reconnect}" | |
95 | exit 1 | |
96 | ;; | |
97 | esac | |
98 | ||
99 | msg_log "Exiting gracefully connectd with PID $$." |