#!/bin/bash # Name: setvars # Goal: initialize global variables (used by all scripts) # Author: Tux # Version: 1.9.5 # Params: - # === Environment path === PATH="/sbin:/usr/sbin:/usr/local/sbin:/bin:/usr/bin:/usr/local/bin:/usr/sbin" export PATH # === Paths(1) === EU_DIR=/etc/eagle-usb EU_SCRIPT_DIR=/etc/eagle-usb/scripts EU_LANG_DIR=/etc/eagle-usb/lang # === Distrib capability === USE_HOTPLUG=1 USE_UPD_USB_USERMAP=1 USE_IFUPDOWN=1 # === Distrib detection === DISTRIB=Mandrake DISTVER=10 SIMPLE=0 # === Paths(2) === SBIN_DIR=/usr/sbin INIT_DIR=/etc/init.d PPP_DIR=/etc/ppp PPP_OPTIONS_DIR=/etc/ppp/peers PPP_OPTIONS_ADSL=$PPP_OPTIONS_DIR/adsl PPP_OPTIONS_MIRE=$PPP_OPTIONS_DIR/mire HOTPLUG_SCRIPT_DIR=/etc/hotplug/usb HOTPLUG_USERMAP_DIR=/usr/lib/hotplug HOTPLUG_USERMAP_FILE=/etc/hotplug/usb.usermap NET_SCRIPT_DIR=/etc/sysconfig/network-scripts # === Commands === STARTADSL=startadsl STARTMIRE=startmire STOPADSL=stopadsl EAGLECTRL=eaglectrl EAGLESTAT=eaglestat # === Strings used to determine modem state === SEND_DSP="Please send DSP (eaglectrl -d)" MODULE="eagle-usb" OPER_STR="Modem is operational" BOOTING_STR="Modem is booting" # === Encapsulation => pppoa/pppoe/none === encapsToPppox() { if [ "$1" = "00000001" ] || [ "$1" = "00000002" ] ; then pppoe -h 1>/dev/null 2>/dev/null if [ $? != 0 ] ; then echo -e "\nError: pppoe cannot be launch. Exiting...\n" exit 1 fi PPPOX="pppoe" elif [ "$1" = "00000003" ] || [ "$1" = "00000004" ] ; then PPPOX="none" elif [ "$1" = "00000005" ] || [ "$1" = "00000006" ] ; then PPPOX="pppoa" fi } # === Load config from eagle-usb.conf === # Language if [ -e $EU_DIR/eagle-usb.conf ] && grep -q "LANG=" $EU_DIR/eagle-usb.conf ; then EU_LANG="`grep 'LANG=' $EU_DIR/eagle-usb.conf | cut -d '=' -f2`" else # if --with-lang was not specified in ./configure, EU_LANG="auto" EU_LANG="auto" fi if [ "$EU_LANG" = "auto" ] ; then if [ "$LANG" = "C" -o -z "$LANG" ] ; then LANG=en fi EU_LANG=${LANG:0:2} fi # fr is usually the most up-to-date language # => it is better to display some french sentences than nothing! . $EU_LANG_DIR/fr # now read the real language-file if [ -e $EU_LANG_DIR/$EU_LANG ] ; then . $EU_LANG_DIR/$EU_LANG else . $EU_LANG_DIR/en fi # PPPOX = pppoe/pppoa/none if [ -e $EU_DIR/eagle-usb.conf ] ; then ENCAPS="`grep 'Encapsulation=' $EU_DIR/eagle-usb.conf | cut -d '=' -f2`" encapsToPppox $ENCAPS else PPPOX="pppoa" fi # Static IP if [ -e $EU_DIR/eagle-usb.conf ] && grep -q "STATIC_IP=" $EU_DIR/eagle-usb.conf ; then STATIC_IP="`grep 'STATIC_IP=' $EU_DIR/eagle-usb.conf | cut -d '=' -f2`" else STATIC_IP="none" fi # Asynchronous start if [ -e $EU_DIR/eagle-usb.conf ] && grep -q "ASYNCHRONOUS_START=" $EU_DIR/eagle-usb.conf ; then ASYNCHRONOUS_START="`grep 'ASYNCHRONOUS_START=' $EU_DIR/eagle-usb.conf | cut -d '=' -f2`" else ASYNCHRONOUS_START=1 fi # ISP if [ -e $EU_DIR/eagle-usb.conf ] && grep -q "ISP=" $EU_DIR/eagle-usb.conf ; then ISP="`grep 'ISP=' $EU_DIR/eagle-usb.conf | cut -d '=' -f2`" else ISP="?" fi # start on boot? START_ON_BOOT=0 if [ -e /etc/rc5.d/S*internet ] || [ -e /etc/rc5.d/S*eagle-usb ] || [ -e /etc/init.d/rc5.d/S*eagle-usb ] ; then START_ON_BOOT=1 fi # testconnec enabled? USE_TESTCONNEC=0 if [ -e /etc/cron.d/eagle-usb ] ; then USE_TESTCONNEC=1 fi # === Generic confirm function === confirm() { echo -en $1 if [ $2 == 1 ] ; then echo -en " $YES_DEFAULT_MSG" else echo -en " $NO_DEFAULT_MSG" fi read REP if [ -z "$REP" ] ; then return `expr 1 - $2` ; fi if echo "$REP" | grep -qiE "o|y|t|s" ; then return 0 ; fi if [ "$REP" = "n" ] ; then return 1 ; fi return `expr 1 - $2` } # === Generic ping -w function === ping_test() { touch /tmp/setvars_ping ping -n -q -c 1 -i 1 $1 1>/dev/null 2>/dev/null if [ $? == 0 ] ; then rm -f /tmp/setvars_ping fi } kill_ping() { pid_ping=$1 sleep $2 kill $pid_ping 2>/dev/null } ping_w() { ping_test $1 & PID_PING=$! kill_ping $PID_PING $2 & wait ${PID_PING} 2>/dev/null if [ -e /tmp/setvars_ping ] ; then rm -f /tmp/setvars_ping return 1 fi return 0 } # === Debug mode === echo_log() { if [ "x$DEBUG" = "x2" ] || [ "x$2" = "x2" ] ; then echo $1 elif [ "x$DEBUG" = "x1" ] || [ "x$2" = "x1" ] ; then logger $1 fi } # === ISP TO NO === isp_to_no() { if [ $1 == "BE" ] ; then NOISP=1 elif [ $1 == "DE" ] ; then NOISP=2 elif [ $1 == "ESTE" ] ; then NOISP=3 elif [ $1 == "ESTEIPF" ] ; then NOISP=4 elif [ $1 == "ESRE" ] ; then NOISP=5 elif [ $1 == "ESTIC" ] ; then NOISP=6 elif [ $1 == "FI" ] ; then NOISP=7 elif [ $1 == "FRFTA" ] ; then NOISP=8 elif [ $1 == "FRFTE" ] ; then NOISP=9 elif [ $1 == "FRTIS128" ] ; then NOISP=10 elif [ $1 == "FRFREEDEG" ] ; then NOISP=11 elif [ $1 == "FR9" ] ; then NOISP=12 elif [ $1 == "HU" ] ; then NOISP=13 elif [ $1 == "IT" ] ; then NOISP=14 elif [ $1 == "ITMC" ] ; then NOISP=15 elif [ $1 == "NE" ] ; then NOISP=16 elif [ $1 == "PL" ] ; then NOISP=17 elif [ $1 == "PO" ] ; then NOISP=18 elif [ $1 == "SW" ] ; then NOISP=19 elif [ $1 == "UK" ] ; then NOISP=20 else NOISP=0 fi } # delay for pppd to stop properly. After that, killall -9 is invoqued. DELAY_KILL_PPPD=3 # used later to extract params i=1 PARAMS=""