cleaner version of the udhcp script
authorMike Baker <mbm@openwrt.org>
Mon, 14 May 2007 08:37:57 +0000 (08:37 +0000)
committerMike Baker <mbm@openwrt.org>
Mon, 14 May 2007 08:37:57 +0000 (08:37 +0000)
SVN-Revision: 7222

package/base-files/files/usr/share/udhcpc/default.script

index f2099204e36a342bbb44c861695a5f70d3dbc0d0..76ba746e28f7c2ff275264d5a8d143067ddf9f62 100755 (executable)
@@ -28,15 +28,17 @@ case "$1" in
                netmask ${subnet:-255.255.255.0} \
                broadcast ${broadcast:-+}
 
-               if [ "$router" != "$(route -n | grep '^0.0.0.0' | grep $interface | awk '{ print $2 }')" ] ; then
-                       echo "deleting routers"
-                       while route del default gw 0.0.0.0 dev $interface >&- 2>&- ; do :; done
-                                       
+               [ "$router"] && {
                        for i in $router ; do
                                echo "adding router $i"
                                route add default gw $i dev $interface
+                               valid="$valid|$i"
+
                        done
-               fi
+
+                       echo "deleting old routes"
+                       $(route -n | awk '/^0.0.0.0\W{9}('$valid')\W/ {next} /^0.0.0.0/ {print "route del -net "$1" gw "$2";"}')
+               }
                
                [ -n "$dns" ] && {
                        echo -n > $RESOLV_CONF