#!/bin/sh PREFIX= . "$PREFIX/lib/libalpine.sh" usage() { cat <<__EOF__ usage: setup-dns [-h] [-d domain name] [IPADDR...] Setup ${ROOT}etc/resolv.conf DNS settings options: -h Show this help -d specify search domain name The optional IPADDR are a list of DNS servers to use. __EOF__ exit 1 } while getopts "d:n:h" opt; do case $opt in d) DOMAINNAME="$OPTARG";; h) usage;; n) NAMESERVERS="$OPTARG";; esac done shift $(($OPTIND - 1)) conf="${ROOT}etc/resolv.conf" if [ -f "$conf" ] ; then domain=`awk '/^domain/ {print $2}' $conf` dns=`awk '/^nameserver/ {print $2}' $conf` fi if [ -n "$DOMAINNAME" ];then domain="$DOMAINNAME" else echon "DNS domain name? (e.g 'bar.com') [$domain] " default_read domain $domain fi if [ -n "$NAMESERVERS" ] || [ $# -gt 0 ];then dns="$NAMESERVERS" else echon "DNS nameserver(s)? [" for i in $dns ; do echon "$i " done echon "] " default_read dns "$dns" fi if [ "$domain" != "" ]; then mkdir -p "${conf%/*}" echo "search $domain" > $conf fi 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