add plemininary ultrasparc support
[openwrt.git] / package / base-files / files / usr / share / udhcpc / default.script
index ea0a28b..9acde82 100755 (executable)
@@ -11,11 +11,6 @@ change_state () {
        uci_set_state "$1" "$2" "$3" "$4"
 }
 
-uci_get() {
-       [ -n "$ifc" ] || return
-       uci -P /dev/null get "$1" 2>/dev/null
-}
-
 setup_interface () {
        local old_ip
        local old_broadcast
@@ -24,11 +19,12 @@ setup_interface () {
        local old_dns
        local user_dns
        local user_router
+       local user_metric
 
        [ -n "$ifc" ] && {
-               config_get old_ip        "$ifc" ipaddr
-               config_get old_broadcast "$ifc" broadcast
-               config_get old_subnet    "$ifc" netmask
+               old_ip="$(uci_get_state network "$ifc" ipaddr)"
+               old_broadcast="$(uci_get_state network "$ifc" broadcast)"
+               old_subnet="$(uci_get_state network "$ifc" netmask)"
        }
 
        [ "$ip" != "$old_ip" ] \
@@ -46,8 +42,9 @@ setup_interface () {
        # Default Route
        [ -n "$ifc" ] && {
                change_state network "$ifc" lease_gateway "$router"
-               config_get old_router "$ifc" gateway
-               user_router=$(uci_get "network.$ifc.gateway")
+               old_router="$(uci_get_state network "$ifc" gateway)"
+               user_router="$(uci_get network "$ifc" gateway)"
+               user_metric="$(uci_get network "$ifc" metric)"
                [ -n "$user_router" ] && router="$user_router"
        }
 
@@ -56,7 +53,7 @@ setup_interface () {
 
                local valid_gw=""
                for i in $router ; do
-                       route add default gw $i dev $interface
+                       route add default gw $i ${user_metric:+metric $user_metric} dev $interface
                        valid_gw="${valid_gw:+$valid_gw|}$i"
                done
                
@@ -144,21 +141,21 @@ setup_interface () {
        }
 
        # DNS
-       config_get old_dns "$ifc" dns
+       old_dns=$(uci_get_state network "$ifc" dns)
+       old_domain=$(uci_get_state network "$ifc" dnsdomain)
        user_dns=$(uci_get "network.$ifc.dns")
        [ -n "$user_dns" ] && dns="$user_dns"
 
-       [ -n "$dns" ] && [ ! -s "${RESOLV_CONF}" -o "$dns" != "$old_dns" ] && {
+       [ -n "$dns" ] && [ "$dns" != "$old_dns" -o -n "$user_dns" ] && {
                echo "udhcpc: setting dns servers: $dns"
-               echo -n > "${RESOLV_CONF}.tmp"
-               for i in $dns ; do
-                       echo "nameserver $i" >> "${RESOLV_CONF}.tmp"
-               done
-               ${domain:+echo search $domain} >> "${RESOLV_CONF}.tmp"
-               mv "${RESOLV_CONF}.tmp" "$RESOLV_CONF"
-
-               change_state network "$ifc" dnsdomain "$domain"
-               change_state network "$ifc" dns "$dns"
+               add_dns "$ifc" $dns
+
+               [ -n "$domain" ] && [ "$domain" != "$old_domain" ] && {
+                       echo "udhcpc: setting dns domain: $domain"
+                       sed -i -e "${old_domain:+/^search $old_domain$/d; }/^search $domain$/d" "${RESOLV_CONF}"
+                       echo "search $domain" >> "${RESOLV_CONF}"
+                       change_state network "$ifc" dnsdomain "$domain"
+               }
        }
 
        [ -n "$ifc" ] || return
@@ -203,7 +200,6 @@ for ifc in $interfaces __default; do
                                config_get ifname "$ifc" ifname
                                config_get aliases "$ifc" aliases
                                uci_revert_state network "$ifc"
-                               uci_set_state network "$ifc" started 1
                                [ -n "$device" ] && uci_set_state network "$ifc" device "$device"
                                [ -n "$ifname" ] && uci_set_state network "$ifc" ifname "$ifname"
                                [ -n "$aliases" ] && uci_set_state network "$ifc" aliases "$aliases"
This page took 0.027184 seconds and 4 git commands to generate.