#!/bin/sh # Copyright (c) 2008..2009 Dirk Jagdmann # # This program 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 2 of the License, or # (at your option) any later version. # # This program 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. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # $Header: /www/llg/tools/edit_zone,v 1.1 2009/06/16 20:55:21 doj Exp $ # Website: http://llg.cubic.org/tools/#dns_inc_serial # you have to compile and install the dns_inc_serial.c file from the # website mentioned above into your path. # # Usage: edit_zone "zone filename" # # your zone filename should be the full domain name. All zone files # must be located in the directory configured by ZONE_DIRECTORY below. ZONE_DIRECTORY=/var/named # check configuration if [ ! -d "$ZONE_DIRECTORY" ] ; then echo "$ZONE_DIRECTORY is no directory! Please configure edit_zone." exit 1 fi # check command line arguments if [ -z "$1" ] ; then echo "usage: edit_zone " exit 1 fi ZONE="$1" ZONEFILE="$ZONE_DIRECTORY/$ZONE" if [ ! -f "$ZONEFILE" ] ; then echo "did not find $ZONEFILE" exit 1 fi # choose an editor if [ -z "$EDITOR" ] ; then EDITOR="$VISUAL" if [ -z "$EDITOR" ] ; then EDITOR=vi fi fi # create backup file TMP=`mktemp` cp -f "$ZONEFILE" $TMP # edit $EDITOR "$ZONEFILE" # check if anything changed cmp -s "$ZONEFILE" $TMP RES=$? rm -f $TMP if [ $RES = 0 ] ; then echo "file not changed." exit 0 fi # check zone for errors named-checkzone "$ZONE" "$ZONEFILE" || exit 1 # increase serial number dns_inc_serial "$ZONEFILE" # load new zone #/etc/init.d/bind9 restart rndc reload "$ZONE"