#!/bin/bash # ************************************************************ # AltEPG Project Source Code Version Control # $FileID: git::root/etc/rc.d/rc.net $ # $Revision: altepg1.0c root 2011-09-17 23:39:32 +0100 Finalising altepg1.0c $ # Description: Install network kernel modules, set the IP address and gateway, # or launch the DHCP client. # ************************************************************ Version="unconfigured" SYSTEM=$(uname -r) if [ -z "${SYSTEM##*TiVo*}" ]; then mode="normal" INSMOD=/sbin/insmod DHCLIENT=/sbin/dhclient MKDIR=mkdir ROUTE=/sbin/route.tivo IFCONFIG=/sbin/ifconfig TIVOCONF=/etc/oztivo.conf SENDTIVOMSG=sendtivomesg.tcl SYSLOG=syslog RC_PPP=/etc/rc.d/rc.ppp else mode="test" INSMOD=test.insmod DHCLIENT=test.dhclient MKDIR=test.mkdir ROUTE=test.route IFCONFIG=test.ifconfig TIVOCONF=test.oztivo.conf SENDTIVOMSG=test.sendtivomesg.tcl SYSLOG=test.syslog RC_PPP=test.rc.ppp source ./test.env fi function uc() { echo $1 | awk '{ print toupper($1) }' } function neterr() { net_status="Error" addNetStatusMessage "$1" } function addNetStatusMessage() { if [ -n "$net_status_message" ]; then net_status_message_1=$1 else net_status_message=$1 fi } function reportNetStatus() { t="/tmp/err.$$" if [ "$net_status" = "Error" ]; then echo "The following error occurred during network configuration:" >$t else echo "Network configured OK:" >$t fi echo >> $t echo $1 >> $t echo >> $t if [ -r "$TIVOCONF" ]; then echo "The network config file oztivo.conf has this:" >> $t echo >> $t cat "$TIVOCONF" >> $t fi $SENDTIVOMSG "TiVo AltEPG altepg1.0c" 'Network Config status' < $t rm -f $t $SYSLOG -t rc.net "$net_status: $1" } if [ "$1" = "-errorcheck" ]; then echo "rc.net invoked in errorcheck mode" if [ -n "$net_status_message" ]; then reportNetStatus "$net_status_message" fi if [ -n "$net_status_message_1" ]; then reportNetStatus "$net_status_message_1" fi return exit fi echo "rc.net invoked in normal mode" net_status="OK" net_status_message="" net_status_message_1="" # Check that we have a network config file if [ ! -f "$TIVOCONF" ]; then exit 99 neterr 'oztivo.conf Missing' fi function install_nic { echo "Installing $nic with command $@" if [ "$1" = "-background" ]; then shift "$@" & else "$@" fi err=$? if [ $err = 0 ]; then export NIC_INSTALLED=$nic echo "$nic installed OK" device=$(eval echo \$${nic}_DEV) if [ "$device" = "" ]; then device=$DEFAULT_DEV fi if [ "$device" != "-" ]; then export DYNAMIC_NET_DEV="$device" fi fi return $err } # Parameters required: # # nic = { AUTO, TURBONET, CACHECARD, AIRNET, TIVONET, PPPONDSS, MODEM } ; case-insensitive; default = AUTO if not defined or not within permitted set # timing = ; default = 3 (only used for TURBONET) # mac = ; only used for TURBONET, CACHECARD; default = 00:0B:AD:1D:0A:1D # wep = ; only used for AIRNET; default is null # ssid = ; only used for AIRNET; **required** : no default. # # ip = { DHCP, , NONE } ; case-insensitive; default = DHCP if doesn't match the pattern d+.d+.d+.d+ (???@@) # gateway ) # netmask ) only used if IP is # NIC="$(uc $nic)" IP="$(uc $ip)" WEPKEY="$(uc $wepkey)" TIMING="${timing:-3}" MAC="${mac:-00:0B:AD:1D:0A:1D}" SSID="$ssid" WEPKEY_CLAUSE="" if [ "$WEPKEY" != "None" -a "$WEPKEY" != "" ]; then WEPKEY_CLAUSE="key=$wepkey" fi TURBONET_INSTALL="$INSMOD -f /lib/modules/turbonet.o macaddr=$MAC timing=$TIMING" CACHECARD_INSTALL="$INSMOD -f /lib/modules/turbonet2.o macaddr=$MAC debuglevel=0" AIRNET_INSTALL="$INSMOD -f /lib/modules/airnet.o ssid=$SSID $WEPKEY_CLAUSE timing=6" TIVONET1_INSTALL="$INSMOD -f /lib/modules/8390tridge.o" TIVONET2_INSTALL="$INSMOD -f /lib/modules/tivone.o" PPPONDSS_INSTALL="-background $RC_PPP" MODEM_INSTALL=":" DEFAULT_DEV="eth0" PPPONDSS_IPCONFIG="NONE" PPPONDSS_DEV="ppp0" MODEM_IPCONFIG="NONE" MODEM_DEV="-" # can't include TIVONET1 in auto list because it installs successfully even if there is no card present AUTO_NICLIST="CACHECARD TURBONET AIRNET TIVONET2 MODEM" TIVONET_NICLIST="TIVONET1 TIVONET2" echo "Requested network device=$NIC" NICLIST=$(eval echo "\$${NIC}_NICLIST") if [ -z "$NICLIST" ]; then NICLIST=$NIC inscmd=$(eval echo "\$${NIC}_INSTALL") if [ -z "$inscmd" ] then echo "Don't know how it install '$NIC' - reverting to AUTO mode" NICLIST=$AUTO_NICLIST fi fi echo "List of devices to attempt installation: $NICLIST" err=1 for nic in $NICLIST; do inscmd=$(eval echo \$${nic}_INSTALL) install_nic $inscmd err=$? if [ $err = 0 ]; then break fi done if [ $err != 0 ]; then neterr "Error $err installing $NIC with command $inscmd" fi # Run ifconfig if the IP address is static, or use DHCP to get an IP address, # or do nothing if we are using PPPonDSS or the internal Modem if [ $err = 0 ]; then ipconfig=$(eval echo \$${NIC_INSTALLED}_IPCONFIG) ip=${ipconfig:-$IP} echo "Configuring IP address" case $ip in DHCP) $MKDIR -p /var/state/dhcp || neterr "Cannot mkdir /var/state/dhcp" $DHCLIENT -q eth0 2>/dev/null & ;; NONE) ;; *) # Set up the IP address and default router $IFCONFIG eth0 $ip netmask $netmask up || \ neterr "ifconfig failed using $ip netmask $netmask" $ROUTE add default gw $gateway || \ neterr "route failed using default gw $gateway" ;; esac addNetStatusMessage "Network device $NIC_INSTALLED started with IP=$ip, DYNAMIC_NET_DEV=$DYNAMIC_NET_DEV" fi # ---------------------------------------------------------- if [ "$mode" = "test" ]; then echo "net_status='$net_status'" >test.env echo "net_status_message='$net_status_message'" >>test.env echo "net_status_message_1='$net_status_message_1'" >>test.env fi