Created
March 15, 2015 22:01
-
-
Save stargieg/60c9494c0058aeee3de5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#run with crontab | |
#0 8 * * * /etc/named.d/update-olsrv6.sh | |
export MAILTO="" | |
SERVER="127.0.0.1" | |
ZONENAME=".pberg.freifunk.net." | |
#ZONENET_1="2001:470:5038" | |
#ZONENET_1="2001:bf7:760" | |
ZONENET_1="2001:bf7" | |
# 2001:bf7:760::/48 | |
HOSTS_1="hosts.olsr.ipv6" | |
TTL="3600" | |
KEYFILE="/etc/named.d/Kpberg.freifunk.net.+157+33698" | |
IPV6_REGEX='^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))(\/(1[0-1][0-9]|12[0-8]|[2-9][0-9]|1[6-9]))?$' | |
IPV4_REGEX='[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}' | |
updatedns() { | |
SERVER="$1" | |
ENTRY="$2" | |
RECORD="$3" | |
NAME="$4" | |
DATE="$(date)" | |
echo "$SERVER $ENTRY $RECORD $NAME" | |
/usr/bin/nsupdate -v -k "$KEYFILE" <<EOF | |
server $SERVER | |
update delete $ENTRY $RECORD | |
update delete $ENTRY TXT | |
update add $ENTRY $TTL $RECORD $NAME | |
update add $ENTRY $TTL TXT $DATE | |
show | |
send | |
EOF | |
} | |
main() { | |
IP6ADDR="" | |
IP6ADDR=$(echo "$1" | egrep $IPV6_REGEX) | |
TYPE="NONE" | |
if [ ! -z "${IP6ADDR}" ] ; then | |
TYPE="AAAA" | |
IPADDR=$IP6ADDR | |
fi | |
if [ "$TYPE" == "NONE" ] ; then | |
echo "No IP Adresstype found" | |
#exit 1 | |
fi | |
#eval HOSTNAME=$(echo "$2" | egrep '^([0-9A-Za-z\-\.])*$') | |
eval HOSTNAME=$(echo "$2" | sed -e 's/\.olsr.*//') | |
if [ ! -z "${HOSTNAME}" ] && [ ! -z "${IPADDR}" ] && [ ! "${HOSTNAME}" == "localhost" ]; then | |
if [ "$TYPE" == "AAAA" ] ; then | |
FQDN="$HOSTNAME""$ZONENAME" | |
echo "HOSTNAME: $FQDN IPADDR: $IPADDR" | |
updatedns "$SERVER" "$FQDN" "$TYPE" "$IPADDR" | |
IPADDR=$(ipv6calc --in ipv6addr --out revnibbles.arpa $IPADDR) | |
updatedns "$SERVER" "$IPADDR" "PTR" "$FQDN" | |
fi | |
fi | |
} | |
ssh root@2001:bf7:780:1018::1 "cat /var/etc/$HOSTS_1" | grep "$ZONENET_1" | while read line ; do | |
set $line >/dev/null | |
main $1 $2 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment