#!/bin/sh #LGPL 2006,2007 www.puppyos.com #v2.14 rc.network now a separate process. #this file is included (inserted) in rc.local0 #setup the networking. #note, analog modem dialup is configured after bootup, by the #Modem Wizard and Gkdial (or ppp). #Ethernet network is configured after bootup, by the Puppy Ethernet Wizard. #note, "> out.txt 2>&1" is syntax required to redirect both stdout and #stderr to a file, using BusyBox Ash shell (not "&>"). #v2.14 SERIALSTUFF is set in rc.local0... SERIALSTUFF="" [ -f /tmp/serialstuff ] && SERIALSTUFF="`cat /tmp/serialstuff`" echoBoth () { echo $@ echo $@ > /dev/console } #Color mnemonics to use for messages color_red="\\033[1;31m" color_green="\\033[1;32m" color_yellow="\\033[1;33m" color_blue="\\033[1;34m" color_purple="\\033[1;35m" color_aquablue="\\033[1;36m" color_black="\\033[1;38m" color_normal="\\033[0;39m" #echo "Setting up interface lo..." ifconfig lo 127.0.0.1 route add -net 127.0.0.0 netmask 255.0.0.0 lo #autodetect serial mouse and serial modem, puppyserialdetect run in rc.local0... rm -f /dev/modem 2>/dev/null #must remove. rc.local0 depends on it. #puppyserialdetect output format: "Type:modem|Port:/dev/ttyS0|Speed:230000" MODEMPORT="`echo "$SERIALSTUFF" | grep "modem" | head -n 1 | cut -f 2 -d '|' | cut -f 3 -d '/'`" #jcoder24 has mouse thinks it is a modem... if [ ! "$MODEMPORT" = "" ];then [ ! "`echo "$SERIALSTUFF" | grep "mouse" | grep "$MODEMPORT"`" = "" ] && MODEMPORT="" fi [ ! "$MODEMPORT" = "" ] && ln -s /dev/$MODEMPORT /dev/modem #...run modem-wizard to override autodetection. #d*m*, running setserial if eth0 or eth1 "up" causes setserial to hang. #dunno why, just doing a quick fix here, moved this modem code up before #the ethernet setup code... #...maybe conflicting with dhcpcd daemon. #Modem Wizard creates this file, also pinstall.sh of ltmodem pupget pkg... if [ -e /etc/modemdevice ];then #do this every bootup, as /dev is pristine, not saved (except for full h.d. install)... rm -f /dev/modem 2>/dev/null DEVM="`cat /etc/modemdevice`" echo "Linking /dev/modem to $DEVM" ln -s $DEVM /dev/modem #k2.6 has serial_core, 8250, 8250_pci builtin, else need to load them. if [ "$DEVM" = "/dev/ttyLT0" ];then #Lucent Linmodem #precaution, in case modprobe.conf gets changed... cat /etc/modprobe.conf | grep "ltserial" > /dev/null 2>&1 if [ ! $? -eq 0 ];then #=0 found. echo "alias char-major-62 ltserial" >> /etc/modprobe.conf echo "alias /dev/ttyLT0 ltserial" >> /etc/modprobe.conf echo "alias /dev/modem ltserial" >> /etc/modprobe.conf touch -t 0512010101 /etc/modprobe.conf #set modify date back before modules.dep. fi modprobe ltmodem modprobe ltserial fi if [ "$DEVM" = "/dev/ttySL0" ];then #Smart-Link Linmodem #precaution in case modprobe.conf gets changed... if [ "`cat /etc/modprobe.conf | grep "slamr"`" = "" ];then #rerwin found, need to change 212,213 to 242,243... echo "alias char-major-242 slamr" >> /etc/modprobe.conf #v2.02 rerwin dev t=1533 to auto load modules... echo "install slamr modprobe --ignore-install ungrab-winmodem ; modprobe --ignore-install slamr" >> /etc/modprobe.conf echo "alias char-major-243 slusb" >> /etc/modprobe.conf touch -t 0512010101 /etc/modprobe.conf #set modify date back before modules.dep. #v2.02 rerwin, moved if down from here, as modules autoloaded. #v2.01 bug, rerwin found needs ungrab-winmodem before load slamr... #v2.02 rerwin, rmmod... rmmod slamr #unload for ungrab, in case slamr misloaded as serial driver. modprobe ungrab-winmodem modprobe slamr modprobe slusb #ok to load both. sleep 1 fi #and also start the daemon... if [ -f /usr/sbin/slmodemdshell ];then /usr/sbin/slmodemdshell & else echo echo "ERROR: /usr/sbin/slmodemdshell does not exist." echo "Run Modem Wizard and setup Smartlink modem properly." #sleep 10 fi #...note, this is created by Modem Wizard. fi if [ "$DEVM" = "/dev/ttyS_ESS0" ];then #ESS2898 Linmodem #No, now taken care of in /etc/modprobe.conf... ##to avoid conflict with pctel linmodem.ko... #modprobe -o linmodem linmodem_ess #modem wizard also put country-code param into /etc/modprobe.conf... modprobe esscom #will also load esscom_hw. fi if [ "$DEVM" = "/dev/ttyS_PCTEL0" ];then #PCTEL pct789 Linmodem #modem wizard put country-code param into /etc/modprobe.conf... modprobe pctel #also loads linmodem,pctel_hw. fi #YOU MAY NOT NEED TO USE SETSERIAL... the docs are vague, even #suggesting setserial can sometimes mess things up... #v1.0.2 do not use setserial for linmodems... #ummm, will leave it in for now... #if [ "`echo "$DEVM" | grep --extended-regexp "ttyLT0|ttySL0"`" = "" ];then setserial -v -b $DEVM auto_irq skip_test autoconfig #fi #v1.0.2 perhaps should also disable setserial for a pcmcia modem, as #pcmcia startup in /etc/pcmcia/ calls setserial. fi #most modules are loaded in /etc/rc.d/rc.modules. #after running the Puppy Ethernet wizard, the files /etc/eth0mode, #/etc/eth1mode and /etc/ethernetmodules may exist and have to be #handled here. #/etc/ethernetmodules has extra modules to load, not detected by #Antonio's libhardware program (see rc.modules). Loading... if [ -s /etc/ethernetmodules ];then #-s tests file not zero size. echo "Loading extra ethernet driver modules..." #each line of ethernetmodules has a module plus optional params... EMODULE="`cat /etc/ethernetmodules | head -n 1`" modprobe $EMODULE FMODULE="`cat /etc/ethernetmodules | head -n 2 | tail -n 1`" if [ ! "$EMODULE" = "$FMODULE" ];then modprobe $FMODULE fi fi #v0.9.4 wacha reported need sleep 3 secs after loading e1000 module... #v2.14 must have a pause after loading module, before ifconfig... # why not delay for wireless also... if [ -f /etc/eth[0-9]mode -o -f /etc/ethernetmodules -o -f /etc/*wireless ];then sleep 3 fi #Try to connect each ethernet interface found INTERFACES="`ifconfig -a | grep "Link encap:Ethernet" | cut -f 1 -d " " | tr "\n" " "`" echo "The following interfaces have been found: ${INTERFACES} Trying to connect" for INTERFACE in ${INTERFACES} do INTERFACEFAIL=0 #code inserted by rarsa for wireless... #Puppy v1.0.9 have Puppy internet wizard create /etc/${INTERFACE}wireless for wireless interfaces if [ -e /etc/${INTERFACE}wireless ] ; then echo "/etc/${INTERFACE}wireless found" . /etc/${INTERFACE}wireless fi #end rarsa patch. #Puppy v0.8.4, have Puppy Ethernet Wizard, creates /etc/${INTERFACE}mode if [ ! -f /etc/${INTERFACE}mode ];then echo "WARNING: Interface ${INTERFACE} has not been configured. Use the network wizard." INTERFACEFAIL=1 else ifconfig ${INTERFACE} up #fails if interface doesn't exist. if [ ! $? -eq 0 ];then #=0 success. echo "${INTERFACE} interface does not exist" INTERFACEFAIL=1 else # let's find out if the ethernet cable plugged in... #v1.0.0 both v0.18 and 0.25 now used, sometimes one works, not the other... #fix from GuestToo (see Forum) ifplugstatus sometimes does not work... #v2.14 fix from rarsa ( "rarsa at yahoo.com"). # Some driver/addapter combinations take longer to # initialize. Now if a connection is not found, it will wait longer # or until the user aborts the wait. echoBoth -e "\nTesting if ${INTERFACE} network is alive... (press Enter to cancel)" #echo -e "\nTesting if ${INTERFACE} network is alive... (press Enter to cancel)" UNPLUGGED='true' # Waits until: a) it finds a connection; b) The user presses Enter; c) after 30 seconds TRY_COUNT=0; TRY_MAX_COUNT=15; TRY_DELAY=2; ODDCNT=0; IFVER="" while [ "${TRY_COUNT}" != "${TRY_MAX_COUNT}" ] ; do #echo -n 'TEST: ' #ifconfig | cut -f 1 -d ' ' | tr '\n' ' ' #TEST #ifplugstatus-0.25 -v eth0 #v2.14 mighty peculiar, running rc.network as a separate process, #ifplugstatus only returns "unplugged". but, can get it to work with -v... TRY_COUNT=`expr ${TRY_COUNT} + 1` echoBoth -n "." #echo -n "." #v2.14 tried -v option also... if [ "`ifplugstatus${IFVER} ${INTERFACE} | grep "link beat detected"`" = "" ]; then read -t ${TRY_DELAY} a [ $? -eq 0 ] && TRY_COUNT=${TRY_MAX_COUNT} else UNPLUGGED='false' TRY_COUNT=${TRY_MAX_COUNT} fi [ $ODDCNT -eq 0 ] && IFVER='-0.25' [ $ODDCNT -eq 1 ] && IFVER='' [ $ODDCNT -eq 0 ] && ODDCNT=1 [ $ODDCNT -eq 1 ] && ODDCNT=0 done # UNPLUGGED="false" #Line 205 Remove # in column 1 to uncomment. if [ "$UNPLUGGED" = "true" ];then #no cable plugged in, no network connection possible... echo "ERROR: Unable to find a connection for ${INTERFACE}" echo "Possible causes:" echo "- Network unavailable" echo "- Ethernet cable or wireless card not plugged in correctly" echo "- Defective network addapter." echo "NOTICE: IF THIS IS WRONG, EDIT /etc/rc.d/rc.network AND UNCOMMENT LINE 205" ifconfig ${INTERFACE} down INTERFACEFAIL=1 #else ##i think should bring ${INTERFACE} down first, then bring up again... #ifconfig ${INTERFACE} down #if [ "`cat /etc/${INTERFACE}mode`" = "auto" ];then #see Puppy Ethernet Wizard. ##i'll tackle Puppy plugged into a network with a dhcp ##server, so we need to be assigned an ip address... #echo "Trying to get IP address from DHCP server (60sec timeout)..." #rm /etc/dhcpc/dhcpcd-${INTERFACE}.* 2>/dev/null #if left over from last session, causes trouble. #dhcpcd ${INTERFACE} #if [ ! $? -eq 0 ];then #=0 success #echo "FAILURE!" #ifconfig ${INTERFACE} down #INTERFACEFAIL=1 #else #echo "SUCCESS! nameservers written to /etc/resolv.conf, and" #echo "Assigned IP address written to /etc/dhcpc/dhcpcd-${INTERFACE}.cache" #echo "Connection information in /etc/dhcpc/dhcpcd-${INTERFACE}.info" #echo "DHCP client daemon now running" ##note, /etc/yp.conf and /etc/ntp.conf also created. #fi else #${INTERFACE}mode contains startup script, created by Ethernet Wizard... #${INTERFACE} was configured manually... #eval `cat /etc/${INTERFACE}mode` ...problem, concatenates multiple lines into one. . /etc/${INTERFACE}mode if [ ! $? -eq 0 ];then # =0 success echo "Error initializing interface ${INTERFACE}.!" ifconfig ${INTERFACE} down else echo "SUCCESS initializing interface ${INTERFACE}.!" fi fi fi fi fi done #TODO: how do we handle dhcp server that needs username and password? #end