From c05f8afeea71c3a2aac36d5080a0ad4b774aab3d Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Wed, 23 Apr 2014 13:35:05 +0200 Subject: setup-dns: improve $ROOT support We also remove the -n option (but accept it for compat) --- setup-dns.in | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/setup-dns.in b/setup-dns.in index 8982b2a..fbcce70 100644 --- a/setup-dns.in +++ b/setup-dns.in @@ -5,14 +5,15 @@ PREFIX= usage() { cat <<__EOF__ -usage: setup-dns [-h] [-d domain name] [-n name server(s)] +usage: setup-dns [-h] [-d domain name] [IPADDR...] -Setup /etc/resolv.conf DNS settings +Setup ${ROOT}etc/resolv.conf DNS settings options: -h Show this help -d specify search domain name - -n DNS server(s) to use. For multiple servers, surround in quotes and space-seperate the list + +The optional IPADDR are a list of DNS servers to use. __EOF__ exit 1 } @@ -24,8 +25,10 @@ while getopts "d:n:h" opt; do n) NAMESERVERS="$OPTARG";; esac done +shift $(($OPTIND - 1)) + -conf="$ROOT/etc/resolv.conf" +conf="${ROOT}etc/resolv.conf" if [ -f "$conf" ] ; then domain=`awk '/^domain/ {print $2}' $conf` @@ -39,7 +42,7 @@ else default_read domain $domain fi -if [ -n "$NAMESERVERS" ];then +if [ -n "$NAMESERVERS" ] || [ $# -gt 0 ];then dns="$NAMESERVERS" else echon "DNS nameserver(s)? [" @@ -51,9 +54,15 @@ else fi if [ "$domain" != "" ]; then + mkdir -p "${conf%/*}" echo "search $domain" > $conf fi -for i in $dns ; do + +if [ -n "$dns" ] || [ $# -gt 0 ]; then + sed -i -e '/^nameserver/d' $conf +fi +for i in $dns $@; do + mkdir -p "${conf%/*}" echo "nameserver $i" >> $conf done -- cgit v1.2.3