summaryrefslogtreecommitdiff
path: root/templates/system
diff options
context:
space:
mode:
authorMohit Mehta <mohit.mehta@vyatta.com>2008-09-11 09:20:18 -0700
committerMohit Mehta <mohit.mehta@vyatta.com>2008-09-11 09:20:18 -0700
commitd1f63951a35159a4cc659a4119482f7882a48c76 (patch)
treefe7fe5a5132bf8cc8a0f9c449d5e657d09528744 /templates/system
parent15c89f4d2123bd5c52f6dffbe251ce16b7a17b49 (diff)
downloadvyatta-cfg-system-d1f63951a35159a4cc659a4119482f7882a48c76.tar.gz
vyatta-cfg-system-d1f63951a35159a4cc659a4119482f7882a48c76.zip
preserve system name-servers order in /etc/resolv.conf as configured in CLI
Diffstat (limited to 'templates/system')
-rw-r--r--templates/system/name-server/node.def29
1 files changed, 20 insertions, 9 deletions
diff --git a/templates/system/name-server/node.def b/templates/system/name-server/node.def
index fce5cac9..d2ce0c30 100644
--- a/templates/system/name-server/node.def
+++ b/templates/system/name-server/node.def
@@ -1,20 +1,31 @@
multi:
type: ipv4
help: Set Domain Name Server (DNS)
-update: sudo sh -c "touch /etc/resolv.conf &&
-if grep -q \"$VAR(@)\($\|[[:space:]]\)\" /etc/resolv.conf; then
- exit 0;
+update: touch /etc/resolv.conf
+if grep -q "$VAR(@)\($\|[[:space:]]\)" /etc/resolv.conf; then
+ exit 0
else
- mv -f /etc/resolv.conf /etc/old_resolv.conf &&
- echo \"nameserver $VAR(@)\" >> /etc/resolv.conf &&
- cat /etc/old_resolv.conf >> /etc/resolv.conf;
+ cli_ns_array=($(awk '{if (!$3) print $2}' /etc/resolv.conf))
+ cli_ns_array_len=${#cli_ns_array[*]}
+ line_num=0
+ if [ $cli_ns_array_len -gt 0 ]; then
+ grepped_ns_line=`grep "${cli_ns_array[$cli_ns_array_len-1]}$" -n /etc/resolv.conf`
+ echo ${grepped_ns_line%%:*} > /etc/resolv_tmp.conf
+ line_num=`cat /etc/resolv_tmp.conf`
+ fi
+ head -$line_num /etc/resolv.conf > /etc/resolv_tmp.conf
+ echo "nameserver $VAR(@)" >> /etc/resolv_tmp.conf
+ total_lines=`cat /etc/resolv.conf | wc -l`
+ rest_lines=`expr $total_lines - $line_num`
+ tail -$rest_lines /etc/resolv.conf >> /etc/resolv_tmp.conf
+ mv -f /etc/resolv_tmp.conf /etc/resolv.conf
fi &&
if [ -d /opt/vyatta/config/active/service/dns/forwarding ]; then
- /opt/vyatta/sbin/vyatta-dns-forwarding.pl --update-dnsforwarding >&/dev/null;
+ /opt/vyatta/sbin/vyatta-dns-forwarding.pl --update-dnsforwarding >&/dev/null
fi &&
if [ -f /etc/ntp.conf ] && grep -q 'server' /etc/ntp.conf; then
- /usr/sbin/invoke-rc.d ntp restart >&/dev/null;
-fi"
+ /usr/sbin/invoke-rc.d ntp restart >&/dev/null
+fi
delete:expression: "sudo sh -c \"touch /etc/resolv.conf && \
sed -i '/$VAR(@)$/d' /etc/resolv.conf && \
if [ -f /etc/ntp.conf ] && grep -q 'server' /etc/ntp.conf; then \