# # /etc/rc.early # # This is called by /etc/rc. # # We are using this script to try to detect out network # environment, and set some variables appropriately. # ####################################################################### IFACE="rl0" NETWORKS="daheim friend office" ADDR_daheim=192.168.1.12 MASK_daheim=255.255.255.0 TEST_daheim=192.168.1.1 ADDR_friend=192.168.2.12 MASK_friend=255.255.255.0 TEST_friend=192.168.2.1 ADDR_office=10.20.30.40 MASK_office=255.255.255.0 TEST_office=10.20.30.1 ####################################################################### TestNetwork() { # $1 == my IP address # $2 == my netmask # $3 == test IP address (e.g. gateway) ifconfig $IFACE inet $1 netmask $2 ping -c 3 -i 0.1 -t 1 -r -n $3 > /dev/null RESULT=$? ifconfig $IFACE down delete return $RESULT } echo "" echo "Detecting local network ..." ifconfig $IFACE down delete 2> /dev/null route flush WHERE=offline for NET in $NETWORKS $NETWORKS; do eval ADDR=\$ADDR_$NET eval MASK=\$MASK_$NET eval TEST=\$TEST_$NET if TestNetwork $ADDR $MASK $TEST; then WHERE=$NET break fi done # # Special case, if connected directly to the DSL router (PPPoE): # if [ "$WHERE" = offline ]; then case `ifconfig $IFACE` in *"media: Ethernet autoselect (10baseT/UTP)"*"status: active"*) echo "Found active 10baseT port, assuming DSL router." WHERE=pppoe ;; esac fi # # Display the result. # echo "Local network config: $WHERE" echo "" # # Open a sub-shell, so we can use "exit" to bail out. # # Note that we MUST not use "exit" otherwise, because # /etc/rc sources us! Using "exit" effectively would # abort /etc/rc! # ( # # Make sure that the root file system is # clean and mounted read/write. # case ${bootmode} in autoboot) fsck -p / || { error_code=$? echo "CANNOT REMOUNT ROOT FILE SYSTEM READ-WRITE:" echo "\"fsck -p /\" FAILED!!!" exit $error_code } ;; esac mount -u -o rw / || { error_code=$? echo "CANNOT REMOUNT ROOT FILE SYSTEM READ-WRITE:" echo "\"mount -u -o rw /\" FAILED!!!" exit $error_code } # # Update symlinks: # sh /etc/rc.setnet "$WHERE" # # Re-mount the root file system read-only before # letting /etc/rc go the rest of the way to multi-user. # If we don't do this, "fsck -p" (called by /etc/rc) # will no longer be our friend. # case ${bootmode} in autoboot) mount -u -o ro / || { error_code=$? echo "CANNOT REMOUNT ROOT FILE SYSTEM READ-ONLY:" echo "\"mount -u -o ro /\" FAILED!!!" exit $error_code } ;; esac ) # # Re-read rc.conf files, in case something has changed. # if [ -r /etc/defaults/rc.conf ]; then . /etc/defaults/rc.conf source_rc_confs elif [ -r /etc/rc.conf ]; then . /etc/rc.conf fi echo "" #--