From 8fc04ac46b0566ed9e2f41d4543ae1242ddda17e Mon Sep 17 00:00:00 2001
From: Christian Busch <chris@debilux.org>
Date: Sun, 2 Feb 2014 10:49:00 +0100
Subject: [PATCH] Small bugfixes an new compatibility with FreeBSD10

- Changed default IP check site to ifconfig.me
- Added a switch to use _drill_ instead of _nslookup_ because FreeBSD
10 switched from _bind_ to _unbound_
- Renamed _$HOSTNAME_ to _$DOMAIN_ to work around potential conflicts
with _$HOSTNAME_ that's set by the host itself
---
 README.md              | 11 +++++++++++
 nsupdate.config.sample |  8 +++++++-
 nsupdate.sh            | 14 ++++++++------
 3 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/README.md b/README.md
index 3b999be..a388e91 100644
--- a/README.md
+++ b/README.md
@@ -8,6 +8,17 @@ You have to configurue it in the file nsupdate.config.
 
 ## Changelog
 
+**2014-01-2-02**
+
+- Changed default IP check site to ifconfig.me
+- Added a switch to use _drill_ instead of _nslookup_ because FreeBSD 10 switched from _bind_ to _unbound_ 
+- Renamed _$HOSTNAME_ to _$DOMAIN_ to work around potential conflicts with _$HOSTNAME_ that's set by the host itself
+
+**2014-01-06**
+
+- Config files are sourced relative to the script folder now
+
+
 **2013-07-12**
 
 - First commit
diff --git a/nsupdate.config.sample b/nsupdate.config.sample
index 67ee124..e626028 100644
--- a/nsupdate.config.sample
+++ b/nsupdate.config.sample
@@ -1,10 +1,16 @@
 # nsupdate.config
 
+# from which site should we get your wan ip?
+IP_CHECK_SITE="http://ifconfig.me/ip"
+
+# use drill instead of nslookup for hostname lookup
+USE_DRILL="NO"
+
 # Login credentials for the inwx admin interface
 INWX_USER="USERNAME"
 INWX_PASS="PASSWORD"
 
 # The hostname that you want to update and it's ID from the inwx interface
 # You get the ID when you edit the given nameserver entry and hover the save button.
-HOSTNAME="subdomain.example.com"
+DOMAIN="subdomain.example.com"
 INWX_DOMAIN_ID="123456789"
\ No newline at end of file
diff --git a/nsupdate.sh b/nsupdate.sh
index a0f3f9e..24de756 100755
--- a/nsupdate.sh
+++ b/nsupdate.sh
@@ -24,14 +24,16 @@
 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
-# from which site should we get your wan ip?
-IP_CHECK_SITE=http://checkip.dyndns.org
-
 source $(dirname $0)/nsupdate.config
 
 LOG=$0.log
 
-NSLOOKUP=$(nslookup -sil $HOSTNAME - ns.inwx.de | tail -2 | head -1 | cut -d' ' -f2)
+if [[ "$USE_DRILL" == "YES" ]]; then
+   NSLOOKUP=$(drill $DOMAIN @ns.inwx.de | head -7 | tail -1 | awk '{print $5}')   
+else
+   NSLOOKUP=$(nslookup -sil $DOMAIN - ns.inwx.de | tail -2 | head -1 | cut -d' ' -f2)
+fi
+
 WAN_IP=`curl -s ${IP_CHECK_SITE}| grep -Eo '\<[[:digit:]]{1,3}(\.[[:digit:]]{1,3}){3}\>'`
 
 API_XML="<?xml version=\"1.0\"?>
@@ -73,7 +75,7 @@ API_XML="<?xml version=\"1.0\"?>
 
 if [ ! "$NSLOOKUP" == "$WAN_IP" ]; then
 	curl -silent -v -XPOST -H"Content-Type: application/xml" -d "$API_XML" https://api.domrobot.com/xmlrpc/
-	echo "$(date) - $HOSTNAME updated. Old IP: "$NSLOOKUP "New IP: "$WAN_IP >> $LOG
+	echo "$(date) - $DOMAIN updated. Old IP: "$NSLOOKUP "New IP: "$WAN_IP >> $LOG
 else
-	echo "$(date) - No update needed for $HOSTNAME. Current IP: "$NSLOOKUP >> $LOG
+	echo "$(date) - No update needed for $DOMAIN. Current IP: "$NSLOOKUP >> $LOG
 fi
\ No newline at end of file