first base-file which now can work with ip and ifconfig
some cleanups for better reading. can anyone explain,
what the "size"-awk thing makes really?

bye, Bastian <[EMAIL PROTECTED]>

Index: package/base-files/files/etc/preinit
===================================================================
--- package/base-files/files/etc/preinit        (Revision 11157)
+++ package/base-files/files/etc/preinit        (Arbeitskopie)
@@ -1,18 +1,37 @@
 #!/bin/sh
 # Copyright (C) 2006 OpenWrt.org
+
 export PATH=/bin:/sbin:/usr/bin:/usr/sbin
 . /etc/diag.sh
 
-failsafe_ip() {
-       ifconfig $ifname 192.168.1.1 netmask 255.255.255.0 broadcast 
192.168.1.255 up
+failsafe_ip ()
+{
+       local    DEVICE="$1"                                            # ARG1
+       local        IP="192.168.1.1"
+       local      MASK="255.255.255.0"
+       local BROADCAST="$( /bin/ipcalc.sh $IP $MASK | sed -n 
's/^BROADCAST=\(.*\)/\1/p' )"
+       local       PRE="$( /bin/ipcalc.sh $IP $MASK | sed -n 
's/^PRE=\(.*\)/\1/p'       )"
+
+       ifconfig $DEVICE $IP netmask $MASK broadcast $BROADCAST up
+
+       [ "$?" -ne 0 ] && {                                             # 
returncode not 0 -> ifconfig n/a -> fallback to ip
+
+               ip addr add dev $DEVICE $IP/$PRE broadcast +            # 
broadcast is calculated (is this clean? we calc it anyway)
+               ip link set dev $DEVICE arp on                          # maybe 
not necessary
+               ip link set dev $DEVICE up
+       }
+
+       netmsg $BROADCAST "set up $IP/$PRE dev $DEVICE"
+       netmsg $BROADCAST "Entering Failsafe!"
 }
 
-failsafe() {
+failsafe ()
+{
        [ -n "$ifname" ] && grep "$ifname" /proc/net/dev >/dev/null && {
-               failsafe_ip
-               netmsg 192.168.1.255 "Entering Failsafe!"
+               failsafe_ip $ifname
                telnetd -l /bin/login <> /dev/null 2>&1
        }
+
        lock /tmp/.failsafe
        ash --login
 }
@@ -20,7 +39,7 @@
 mount proc /proc -t proc
 mount sysfs /sys -t sysfs
 
-size=$(awk '/MemTotal:/ {l=5242880;mt=($2*1024);print((s=mt/2)<l)?mt-l:s}' 
/proc/meminfo)
+size=$(awk '/MemTotal:/ {l=5242880;mt=($2*1024);print((s=mt/2)<l)?mt-l:s}' 
/proc/meminfo)      # needs rewrite, do it without AWK
 mount tmpfs /tmp -t tmpfs -o size=$size,nosuid,nodev,mode=1777
 
 if grep devfs /proc/filesystems > /dev/null; then

Attachment: signature.asc
Description: Digital signature

_______________________________________________
openwrt-devel mailing list
[email protected]
http://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel

Reply via email to