Commit c05f8afe authored by Natanael Copa's avatar Natanael Copa
Browse files

setup-dns: improve $ROOT support

We also remove the -n option (but accept it for compat)
parent 291d078e
...@@ -5,14 +5,15 @@ PREFIX= ...@@ -5,14 +5,15 @@ PREFIX=
usage() { usage() {
cat <<__EOF__ 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: options:
-h Show this help -h Show this help
-d specify search domain name -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__ __EOF__
exit 1 exit 1
} }
...@@ -24,8 +25,10 @@ while getopts "d:n:h" opt; do ...@@ -24,8 +25,10 @@ while getopts "d:n:h" opt; do
n) NAMESERVERS="$OPTARG";; n) NAMESERVERS="$OPTARG";;
esac esac
done done
shift $(($OPTIND - 1))
conf="$ROOT/etc/resolv.conf" conf="${ROOT}etc/resolv.conf"
if [ -f "$conf" ] ; then if [ -f "$conf" ] ; then
domain=`awk '/^domain/ {print $2}' $conf` domain=`awk '/^domain/ {print $2}' $conf`
...@@ -39,7 +42,7 @@ else ...@@ -39,7 +42,7 @@ else
default_read domain $domain default_read domain $domain
fi fi
if [ -n "$NAMESERVERS" ];then if [ -n "$NAMESERVERS" ] || [ $# -gt 0 ];then
dns="$NAMESERVERS" dns="$NAMESERVERS"
else else
echon "DNS nameserver(s)? [" echon "DNS nameserver(s)? ["
...@@ -51,9 +54,15 @@ else ...@@ -51,9 +54,15 @@ else
fi fi
if [ "$domain" != "" ]; then if [ "$domain" != "" ]; then
mkdir -p "${conf%/*}"
echo "search $domain" > $conf echo "search $domain" > $conf
fi 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 echo "nameserver $i" >> $conf
done done
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment