From 4cdd393d95db283f49f45b509ef03c97f3f7676a Mon Sep 17 00:00:00 2001 From: Stanislav Baiduzhyi Date: Tue, 19 Jul 2016 13:09:35 +0200 Subject: [PATCH 1/2] Passing host DNS to corectld. --- src/functions.sh | 12 ++++++++++++ src/start_corectld.command | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/functions.sh b/src/functions.sh index 41b158d..04e5452 100755 --- a/src/functions.sh +++ b/src/functions.sh @@ -6,3 +6,15 @@ DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) function pause(){ read -p "$*" } + +function printLocalDns(){ + local ALL_DNS='8.8.8.8:53,8.8.4.4:53' + if [[ -r '/etc/resolv.conf' ]] + then + for dns in $( grep '^nameserver' '/etc/resolv.conf' | awk '{ print $2 }' ) + do + ALL_DNS="$dns:53,$ALL_DNS" + done + fi + echo "$ALL_DNS" +} diff --git a/src/start_corectld.command b/src/start_corectld.command index 82d48e5..69e9791 100755 --- a/src/start_corectld.command +++ b/src/start_corectld.command @@ -13,5 +13,5 @@ sudo -k > /dev/null 2>&1 printf '%s\n' "$my_password" | sudo -Sv > /dev/null 2>&1 # start corectld -sudo nohup /usr/local/sbin/corectld start --user $(whoami) +sudo nohup /usr/local/sbin/corectld start --user $(whoami) --recursive-nameservers "$( printLocalDns )" From 89908018083d3243087e974f1e941b520272e720 Mon Sep 17 00:00:00 2001 From: Stanislav Baiduzhyi Date: Wed, 20 Jul 2016 10:02:56 +0200 Subject: [PATCH 2/2] Checking for port 53 being busy before printing any values --- src/functions.sh | 5 +++++ src/start_corectld.command | 9 +++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/functions.sh b/src/functions.sh index 04e5452..4a4b8c1 100755 --- a/src/functions.sh +++ b/src/functions.sh @@ -8,6 +8,11 @@ function pause(){ } function printLocalDns(){ + if nc -z localhost 53 1>/dev/null 2>&1 + then + # port 53 is already bound, do not proceed: + return + fi local ALL_DNS='8.8.8.8:53,8.8.4.4:53' if [[ -r '/etc/resolv.conf' ]] then diff --git a/src/start_corectld.command b/src/start_corectld.command index 69e9791..99a0d98 100755 --- a/src/start_corectld.command +++ b/src/start_corectld.command @@ -13,5 +13,10 @@ sudo -k > /dev/null 2>&1 printf '%s\n' "$my_password" | sudo -Sv > /dev/null 2>&1 # start corectld -sudo nohup /usr/local/sbin/corectld start --user $(whoami) --recursive-nameservers "$( printLocalDns )" - +NAMESERVERS="" +DNS="$( printLocalDns )" +if [[ -n "$DNS" ]] +then + NAMESERVERS="--recursive-nameservers '$DNS'" +fi +sudo nohup /usr/local/sbin/corectld start --user $(whoami) $NAMESERVERS