simplify nameserver logic and use simple grep options

This commit is contained in:
Matthew Mosesohn 2013-08-02 19:19:22 +04:00
parent 9fdf39b3aa
commit 43615fb124
1 changed files with 7 additions and 10 deletions

View File

@ -94,16 +94,13 @@ enable_outbound_network_for_product_vm() {
# Check host nameserver configuration
echo -n "Checking local DNS configuration... "
if [ -f /etc/resolv.conf ]; then
nameserver="$(egrep '^nameserver' /etc/resolv.conf | grep -P -v 'nameserver[ \t]+127.' | head -3)"
if [ -z "$nameserver" ]; then
echo "/etc/resolv.conf does not contain a nameserver. Using 8.8.8.8 for DNS."
nameserver="nameserver 8.8.8.8"
else
echo "OK"
fi
else
echo "Could not find /etc/resolv.conf. Using 8.8.8.8 for DNS"
nameserver="$(grep '^nameserver' /etc/resolv.conf | grep -v 'nameserver\s\s*127.' | head -3)"
fi
if [ -z "$nameserver" ]; then
echo "/etc/resolv.conf does not contain a nameserver. Using 8.8.8.8 for DNS."
nameserver="nameserver 8.8.8.8"
else
echo "OK"
fi
# Enable internet access on inside the VMs
@ -128,7 +125,7 @@ enable_outbound_network_for_product_vm() {
expect "$prompt"
send "sed \"s/GATEWAY=.*/GATEWAY=\"$gateway_ip\"/g\" -i /etc/sysconfig/network\r"
expect "$prompt"
send "echo -e \"$nameserver\\nnameserver 8.8.8.8\" > /etc/dnsmasq.upstream\r"
send "echo -e \"$nameserver\" > /etc/dnsmasq.upstream\r"
expect "$prompt"
send "service network restart >/dev/null 2>&1\r"
expect "$prompt"