-#!/bin/bash\r
-#\r
-\r
-. /etc/sysconfig/rc \r
-. ${rc_functions}\r
-\r
-# Stop if nothing is configured\r
-if [ ! -s "/var/ipfire/ppp/settings" ];then\r
- exit 0\r
-fi\r
-\r
-eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings)\r
-\r
-MAX=160\r
-ATTEMPTS=0\r
-COUNT=0\r
-if [ ! $HOLDOFF ]; then\r
- HOLDOFF=30\r
-fi\r
-\r
-if [ "$RECONNECTION" = "dialondemand" ]; then\r
- exit 0\r
-fi\r
-\r
-msg_log () {\r
- logger -t $(basename $0)[$$] $*\r
-}\r
-\r
-msg_log "Connectd ($1) started with PID $$"\r
-\r
-\r
-if [ -s "/var/ipfire/red/keepconnected" ]; then\r
- ATTEMPTS=$(cat /var/ipfire/red/keepconnected)\r
-else\r
- echo "0" > /var/ipfire/red/keepconnected\r
-fi\r
-\r
-case "$1" in\r
- start)\r
- boot_mesg "Starting connection daemon..."\r
- echo_ok\r
- \r
- while [ "$COUNT" -lt "$MAX" ]; do\r
- if [ ! -e "/var/ipfire/red/keepconnected" ]; then\r
- # User pressed disconnect in gui\r
- msg_log "Stopping by user request. Exiting."\r
- /etc/rc.d/init.d/network stop red\r
- exit 0\r
- fi\r
- if [ -e "/var/ipfire/red/active" ]; then\r
- # Successfully connected in time\r
- echo "0" > /var/ipfire/red/keepconnected\r
- msg_log "System is online. Exiting."; exit 0\r
- fi\r
- if ( ! ps ax | grep -q [p]ppd ); then\r
- msg_log "No pppd is running. Trying reconnect."\r
- break # because pppd died\r
- fi\r
- sleep 5\r
- (( COUNT+=1 ))\r
- done\r
- \r
- /etc/rc.d/init.d/network stop red\r
- \r
- (( ATTEMPTS+=1 ))\r
- msg_log "Reconnecting: Attempt ${ATTEMPTS} of ${MAXRETRIES}"\r
- if [ "${ATTEMPTS}" -ge "${MAXRETRIES}" ]; then\r
- echo "0" > /var/ipfire/red/keepconnected\r
- if [ "$BACKUPPROFILE" != '' ]; then\r
- rm -f /var/ipfire/ppp/settings\r
- cp "/var/ipfire/ppp/settings-${BACKUPPROFILE}" /var/ipfire/ppp/settings\r
- msg_log "Switched to backup profile ${BACKUPPROFILE}"\r
- # to be shure the right secrets are used\r
- eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings-${BACKUPPROFILE})\r
- echo "'$USERNAME' * '$PASSWORD'" > /var/ipfire/ppp/secrets\r
- else\r
- msg_log "No backup profile given. Exiting."\r
- exit 0\r
- fi\r
- else\r
- echo $ATTEMPTS > /var/ipfire/red/keepconnected\r
- sleep ${HOLDOFF}\r
- fi\r
- \r
- /etc/rc.d/init.d/network start red &\r
- ;;\r
- \r
- reconnect)\r
- while ( ps ax | grep -q [p]ppd ); do\r
- msg_log "There is a pppd still running. Waiting 2 seconds for exit."\r
- sleep 2\r
- done\r
- \r
- /etc/rc.d/init.d/network restart red\r
- ;;\r
- \r
- *)\r
- echo "Usage: $0 {start|reconnect}"\r
- exit 1\r
- ;;\r
-esac\r
-\r
-msg_log "Exiting gracefully connectd with PID $$."\r
+#!/bin/bash
+#
+
+. /etc/sysconfig/rc
+. ${rc_functions}
+
+# Stop if nothing is configured
+if [ ! -s "/var/ipfire/ppp/settings" ];then
+ exit 0
+fi
+
+eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings)
+
+MAX=160
+ATTEMPTS=0
+COUNT=0
+if [ ! $HOLDOFF ]; then
+ HOLDOFF=30
+fi
+
+if [ "$RECONNECTION" = "dialondemand" ]; then
+ exit 0
+fi
+
+msg_log () {
+ logger -t $(basename $0)[$$] $*
+}
+
+msg_log "Connectd ($1) started with PID $$"
+
+
+if [ -s "/var/ipfire/red/keepconnected" ]; then
+ ATTEMPTS=$(cat /var/ipfire/red/keepconnected)
+else
+ echo "0" > /var/ipfire/red/keepconnected
+fi
+
+case "$1" in
+ start)
+ boot_mesg "Starting connection daemon..."
+ echo_ok
+
+ while [ "$COUNT" -lt "$MAX" ]; do
+ if [ ! -e "/var/ipfire/red/keepconnected" ]; then
+ # User pressed disconnect in gui
+ msg_log "Stopping by user request. Exiting."
+ /etc/rc.d/init.d/network stop red
+ exit 0
+ fi
+ if [ -e "/var/ipfire/red/active" ]; then
+ # Successfully connected in time
+ echo "0" > /var/ipfire/red/keepconnected
+ msg_log "System is online. Exiting."; exit 0
+ fi
+ if ( ! ps ax | grep -q [p]ppd ); then
+ msg_log "No pppd is running. Trying reconnect."
+ break # because pppd died
+ fi
+ sleep 5
+ (( COUNT+=1 ))
+ done
+
+ /etc/rc.d/init.d/network stop red
+
+ (( ATTEMPTS+=1 ))
+ msg_log "Reconnecting: Attempt ${ATTEMPTS} of ${MAXRETRIES}"
+ if [ "${ATTEMPTS}" -ge "${MAXRETRIES}" ]; then
+ echo "0" > /var/ipfire/red/keepconnected
+ if [ "$BACKUPPROFILE" != '' ]; then
+ rm -f /var/ipfire/ppp/settings
+ cp "/var/ipfire/ppp/settings-${BACKUPPROFILE}" /var/ipfire/ppp/settings
+ msg_log "Switched to backup profile ${BACKUPPROFILE}"
+ # to be shure the right secrets are used
+ eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings-${BACKUPPROFILE})
+ echo "'$USERNAME' * '$PASSWORD'" > /var/ipfire/ppp/secrets
+ else
+ msg_log "No backup profile given. Exiting."
+ exit 0
+ fi
+ else
+ echo $ATTEMPTS > /var/ipfire/red/keepconnected
+ sleep ${HOLDOFF}
+ fi
+
+ /etc/rc.d/init.d/network start red &
+ ;;
+
+ reconnect)
+ while ( ps ax | grep -q [p]ppd ); do
+ msg_log "There is a pppd still running. Waiting 2 seconds for exit."
+ sleep 2
+ done
+
+ /etc/rc.d/init.d/network restart red
+ ;;
+
+ *)
+ echo "Usage: $0 {start|reconnect}"
+ exit 1
+ ;;
+esac
+
+msg_log "Exiting gracefully connectd with PID $$."