Ignore:
Timestamp:
2010-05-07T03:17:47+02:00 (7 years ago)
Author:
jow
Message:

[package] base-files: add add_dns() and remove_dns() helpers to network config, useful to merge dns entries from multiple interfaces

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/package/base-files/files/lib/network/config.sh

    r21386 r21391  
    6565        } 
    6666        return 1 
     67} 
     68 
     69# add dns entries if they are not in resolv.conf yet 
     70add_dns() { 
     71        local cfg="$1"; shift 
     72 
     73        local dns 
     74        local add 
     75        for dns in "$@"; do 
     76                grep -qsF "nameserver $dns" /tmp/resolv.conf.auto || { 
     77                        add="${add:+$add }$dns" 
     78                        echo "nameserver $dns" >> /tmp/resolv.conf.auto 
     79                } 
     80        done 
     81 
     82        uci_set_state network "$cfg" dns "$add" 
     83} 
     84 
     85# remove dns entries of the given iface 
     86remove_dns() { 
     87        local cfg="$1" 
     88 
     89        local dns 
     90        config_get dns "$cfg" dns 
     91        for dns in $dns; do 
     92                sed -i -e "/^nameserver $dns$/d" /tmp/resolv.conf.auto 
     93        done 
     94 
     95        uci_revert_state network "$cfg" dns 
    6796} 
    6897 
Note: See TracChangeset for help on using the changeset viewer.