4 # Description: Edit a dynamic dns zone with an editor, then update it by
7 # Copyright (C) 2008 Emmanuel Lacour <elacour@home-dn.net>
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301,
31 echo "Usage: `basename $0` SERVER ZONE_NAME"
37 echo "Missing zone name!"
43 echo "Missing server!"
49 if [ `echo "$ZONE" | grep -c '\.$'` -eq 0 ]
54 FILE_O=`mktemp /tmp/nsedit_o.XXXXXX`
55 FILE_N=`mktemp /tmp/nsedit_n.XXXXXX`
56 FILE_D=`mktemp /tmp/nsedit_d.XXXXXX`
57 FILE_U=`mktemp /tmp/nsedit_u.XXXXXX`
58 FILE_ERR=`mktemp /tmp/nsedit_err.XXXXXX`
60 # Get the current zone
61 # (skip SOA wich cannot be updated by nsupdate)
62 dig @$SERVER $ZONE AXFR | grep -Ev '^;|^$' | grep -v 'IN SOA ' > $FILE_O
71 # Diff between old and new file
72 diff -au $FILE_O $FILE_N | grep -E '^-|^\+' | grep -Ev '^--- |^\+\+\+ ' > $FILE_D
76 echo "Empty changes, exiting!"
80 # Prepare nsupdate file
81 echo "server $SERVER" > $FILE_U
83 sed 's/^-/update delete /g;s/^+/update add /g' $FILE_D >> $FILE_U
84 echo 'send' >> $FILE_U
86 echo "Do you really wan't to send the following updates?"
88 echo -n "Answer (y/n):"
93 nsupdate $FILE_U > $FILE_ERR 2>&1
96 echo "Update failed: "
98 echo -n "Do you wan't to edit back you're file (y/n): "
104 echo "Ok, exiting..."
107 echo "Update succeded!"
111 echo "Ok, exiting..."
117 rm -f $FILE_O $FILE_N $FILE_D $FILE_U $FILE_ERR