#!/bin/bash # # /usr/local/sbin/nsupdate-ddns.sh # # Update DDNS server with current public IP. # # Copyright 2012 - Jean-Sebastien Morisset - http://surniaulula.com/ # # This script is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation; either version 3 of the License, or (at your option) any later # version. # # This script is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details at http://www.gnu.org/licenses/. ddns_domain="ddns.MY_DOMAIN_NAME.com" my_fqdn="`hostname -s`.$ddns_domain" key_file="`echo /etc/named.d/K$my_fqdn.+157+*.private`" if_active="`/sbin/ifconfig -a|egrep '(status: active|inet addr:.*Bcast:.*Mask:)'`" ip_check_url="http://checkip.dyndns.org/" # website that displays our IP (see regex bellow) # read command line opts (works better than getopt) while : do for arg in "$@" do case $arg in -f|--force) force="1" shift 1 ;; -h|--help) echo "purpose: update $my_fqdn ddns entry with current public ip." echo " syntax: $0 [--help|--force|--visual|--keygen]" exit 0 ;; -k|--keygen) if [ -f "$key_file" ] then echo " error: $key_file already exists!" exit 1 fi mkdir -p /etc/named.d # just in case cd /etc/named.d && dnssec-keygen -a HMAC-MD5 -b 512 -n USER $my_fqdn. key_file="`echo /etc/named.d/K$my_fqdn.+157+*.private`" if [ ! -f "$key_file" ] then echo " error: $key_file file not found!" exit 1 fi chmod 600 $key_file # just to make sure secret="`sed -n 's/^Key: //p' $key_file`" if [ -z "$secret" ] then echo " error: secret key not found in $Key_file!" exit 1 fi cat <