]> git.ipfire.org Git - ipfire-2.x.git/blame - src/initscripts/system/connectd
Early spring clean: Remove trailing whitespaces, and correct licence headers
[ipfire-2.x.git] / src / initscripts / system / connectd
CommitLineData
0027c4e0 1#!/bin/bash
66c36198
PM
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2007-2022 IPFire Team <info@ipfire.org> #
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
0027c4e0 21
66c36198 22. /etc/sysconfig/rc
0027c4e0
AF
23. ${rc_functions}
24
25# Stop if nothing is configured
26if [ ! -s "/var/ipfire/ppp/settings" ];then
27 exit 0
28fi
29
30eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings)
31
32MAX=160
33ATTEMPTS=0
34COUNT=0
35if [ ! $HOLDOFF ]; then
36 HOLDOFF=30
37fi
38
39if [ "$RECONNECTION" = "dialondemand" ]; then
40 exit 0
41fi
42
43msg_log () {
44 logger -t $(basename $0)[$$] $*
45}
46
47msg_log "Connectd ($1) started with PID $$"
48
49
50if [ -s "/var/ipfire/red/keepconnected" ]; then
51 ATTEMPTS=$(cat /var/ipfire/red/keepconnected)
52else
53 echo "0" > /var/ipfire/red/keepconnected
54fi
55
56case "$1" in
57 start)
58 boot_mesg "Starting connection daemon..."
59 echo_ok
66c36198 60
0027c4e0
AF
61 while [ "$COUNT" -lt "$MAX" ]; do
62 if [ ! -e "/var/ipfire/red/keepconnected" ]; then
63 # User pressed disconnect in gui
64 msg_log "Stopping by user request. Exiting."
65 /etc/rc.d/init.d/network stop red
66 exit 0
67 fi
68 if [ -e "/var/ipfire/red/active" ]; then
69 # Successfully connected in time
70 echo "0" > /var/ipfire/red/keepconnected
71 msg_log "System is online. Exiting."; exit 0
72 fi
73 if ( ! ps ax | grep -q [p]ppd ); then
74 msg_log "No pppd is running. Trying reconnect."
75 break # because pppd died
76 fi
77 sleep 5
78 (( COUNT+=1 ))
79 done
66c36198 80
0027c4e0 81 /etc/rc.d/init.d/network stop red
66c36198 82
0027c4e0
AF
83 (( ATTEMPTS+=1 ))
84 msg_log "Reconnecting: Attempt ${ATTEMPTS} of ${MAXRETRIES}"
85 if [ "${ATTEMPTS}" -ge "${MAXRETRIES}" ]; then
86 echo "0" > /var/ipfire/red/keepconnected
87 if [ "$BACKUPPROFILE" != '' ]; then
88 rm -f /var/ipfire/ppp/settings
89 cp "/var/ipfire/ppp/settings-${BACKUPPROFILE}" /var/ipfire/ppp/settings
90 msg_log "Switched to backup profile ${BACKUPPROFILE}"
91 # to be shure the right secrets are used
92 eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings-${BACKUPPROFILE})
93 echo "'$USERNAME' * '$PASSWORD'" > /var/ipfire/ppp/secrets
94 else
95 msg_log "No backup profile given. Exiting."
96 exit 0
97 fi
98 else
99 echo $ATTEMPTS > /var/ipfire/red/keepconnected
100 sleep ${HOLDOFF}
101 fi
102 /etc/rc.d/init.d/network start red >/dev/tty12 2>&1 </dev/tty12 &
103 ;;
66c36198 104
0027c4e0
AF
105 reconnect)
106 while ( ps ax | grep -q [p]ppd ); do
107 msg_log "There is a pppd still running. Waiting 2 seconds for exit."
108 sleep 2
109 done
66c36198 110
0027c4e0
AF
111 /etc/rc.d/init.d/network restart red
112 ;;
66c36198 113
0027c4e0
AF
114 *)
115 echo "Usage: $0 {start|reconnect}"
116 exit 1
117 ;;
118esac
119
120msg_log "Exiting gracefully connectd with PID $$."