setup-dns.in 1.09 KB
Newer Older
Natanael Copa's avatar
Natanael Copa committed
1 2 3 4 5
#!/bin/sh

PREFIX=
. "$PREFIX/lib/libalpine.sh"

6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
usage() {
        cat <<__EOF__
usage: setup-dns [-h] [-d domain name] [-n name server(s)]

Setup /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
__EOF__
        exit 1
}

while getopts "d:n:h" opt; do
        case $opt in
                d) DOMAINNAME="$OPTARG";;
                h) usage;;
                n) NAMESERVERS="$OPTARG";;
        esac
done

Jeff Bilyk's avatar
Jeff Bilyk committed
28
conf="$ROOT/etc/resolv.conf"
29

Natanael Copa's avatar
Natanael Copa committed
30 31 32 33 34
if [ -f "$conf" ] ; then
	domain=`awk '/^domain/ {print $2}' $conf`
	dns=`awk '/^nameserver/ {print $2}' $conf`
fi

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
if [ -n "$DOMAINNAME" ];then
	domain="$DOMAINNAME"
else
	echon "DNS domain name? (e.g 'bar.com') [$domain] "
	default_read domain $domain
fi

if [ -n "$NAMESERVERS" ];then
	dns="$NAMESERVERS"
else
	echon "DNS nameserver(s)? ["
	for i in $dns ; do
		echon "$i "
	done
	echon "] "
	default_read dns "$dns"
fi
Natanael Copa's avatar
Natanael Copa committed
52

53 54 55
if [ "$domain" != "" ]; then
	echo "search $domain" > $conf
fi
Natanael Copa's avatar
Natanael Copa committed
56 57 58 59
for i in $dns ; do
	echo "nameserver $i" >> $conf
done