From 4a277f7432d863641a8f1bfcd399dd7e8758a290 Mon Sep 17 00:00:00 2001 From: Jesse Young Date: Sun, 24 Oct 2010 21:31:21 -0500 Subject: [PATCH] Use resolvconf for static ethernet if available Signed-off-by: Jesse Young --- docs/ethernet | 8 +++++--- src/connections/ethernet | 41 ++++++++++++++++++++++++++++------------- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/docs/ethernet b/docs/ethernet index 5df810a..dd9594b 100644 --- a/docs/ethernet +++ b/docs/ethernet @@ -23,16 +23,18 @@ IPCFG IFOPTS (deprecated, requires IP of 'static') : Arguments to pass to 'ifconfig'. This allows you to use the syntax for the older 'ifconfig' tool. Retained for compatability. ### DNS +RESOLV_CONF +: Path to resolver configuration. Defaults to /etc/resolv.conf DNS : Array of DNS nameservers. Simply specify the IP's of each of the DNS nameservers. SEARCH -: "search" line for /etc/resolv.conf +: "search" line for RESOLV_CONF DOMAIN -: "domain" line for /etc/resolv.conf +: "domain" line for RESOLV_CONF HOSTNAME : Set the system hostname. Ensure any hostname is correctly referenced in /etc/hosts. DNS1, DNS2 (deprecated) -: First and second DNS servers for /etc/resolv.conf +: First and second DNS servers for RESOLV_CONF ### DHCP DHCP_OPTIONS : String. Any extra arguments to pass to the dhcp client, presently dhcpcd. diff --git a/src/connections/ethernet b/src/connections/ethernet index 36f6b93..2bd065b 100644 --- a/src/connections/ethernet +++ b/src/connections/ethernet @@ -72,7 +72,7 @@ ethernet_up() { static) if [[ -n "$ADDR" ]]; then [[ -z $NETMASK ]] && NETMASK=24 - report_debug ethernet_iproute_up ip addr add "$ADDR/$NETMASK" brd + dev "$INTERFACE" + report_debug ethernet_iproute_up ip addr add "$ADDR/$NETMASK" brd + dev "$INTERFACE" if ! ip addr add "$ADDR/$NETMASK" brd + dev "$INTERFACE"; then report_iproute "Could not configure interface" fi @@ -114,20 +114,28 @@ ethernet_up() { fi # Generate a new resolv.conf + local resolv_conf="" if [[ -n "$DNS" ]]; then - : >/etc/resolv.conf - [[ -n "$DOMAIN" ]] && echo "domain $DOMAIN" >>/etc/resolv.conf - [[ -n "$SEARCH" ]] && echo "search $SEARCH" >>/etc/resolv.conf + [[ -n "$DOMAIN" ]] && resolv_conf="${resolv_conf}domain $DOMANIN\n" + [[ -n "$SEARCH" ]] && resolv_conf="${resolv_conf}search $SEARCH\n" for dns in "${DNS[@]}"; do - echo "nameserver $dns" >>/etc/resolv.conf + resolv_conf="${resolv_conf}nameserver $dns\n" done elif [[ -n "$DNS1" ]]; then # support older 'ethernet' syntax. - : >/etc/resolv.conf - [[ -n "$DOMAIN" ]] && echo "domain $DOMAIN" >>/etc/resolv.conf - [[ -n "$SEARCH" ]] && echo "search $SEARCH" >>/etc/resolv.conf - [[ -n "$DNS1" ]] && echo "nameserver $DNS1" >>/etc/resolv.conf - [[ -n "$DNS2" ]] && echo "nameserver $DNS2" >>/etc/resolv.conf + [[ -n "$DOMAIN" ]] && resolv_conf="${resolv_conf}domain $DOMANIN\n" + [[ -n "$SEARCH" ]] && resolv_conf="${resolv_conf}search $SEARCH\n" + [[ -n "$DNS1" ]] && resolv_conf="${resolv_conf}nameserver $DNS1\n" + [[ -n "$DNS2" ]] && resolv_conf="${resolv_conf}nameserver $DNS2\n" + fi + + if [[ -n "$resolv_conf" ]]; then + if which resolvconf > /dev/null 2>&1; then + printf "$resolv_conf" | resolvconf -a "$INTERFACE" + else + [[ -z "$RESOLV_CONF" ]] && RESOLV_CONF="/etc/resolv.conf" + printf "$resolv_conf" > "$RESOLV_CONF" + fi fi return 0 @@ -136,12 +144,19 @@ ethernet_up() { ethernet_down() { load_profile "$1" - if [[ "$IP" == "dhcp" ]]; then + case "$IP" in + dhcp) if [[ -f "/var/run/dhcpcd-${INTERFACE}.pid" ]]; then report_debug ethernet_down dhcpcd -qx "$INTERFACE" dhcpcd -qx "$INTERFACE" &>/dev/null fi - fi + ;; + static) + if which resolvconf > /dev/null 2>&1; then + resolvconf -d "$INTERFACE" -f + fi + ;; + esac report_debug ethernet_down if_down if [[ "$CONNECTION" == "wireless" ]]; then @@ -149,7 +164,7 @@ ethernet_down() { else bring_interface down "$INTERFACE" fi - return 0 + return 0 } # Returns status of profile - is it still functional? -- 1.7.2.3