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