#!/bin/sh
# Written by John Newbigin
# jn@it.swin.edu.au
# Copyright (c) 2003 John Newbigin
# Covered by the terms of the GPL.
# $Header: /home/cso/jnewbigin/cvsroot/ndu/src/dnsedit,v 1.8 2005/07/16 04:56:07 jnewbigin Exp $

# part of ndu

if [ -z "$1" ] ; then
	echo "usage: $0 zone_file"
	exit 1
fi

if [ ! -x "$VISUAL" ] ; then
   if [ -x /usr/bin/vim ] ; then
      VISUAL=/usr/bin/vim
   else
      VISUAL=/bin/vi
   fi
fi;

umask 027
if [ -f "$1" ] ; then
	tempfile=`mktemp /tmp/dnsedit.XXXXXX`
	if [ -z "$tempfile" ]; then
	   echo "$0: Can't create temp file, exiting..."
	   exit 1
	fi
	/bin/cp $1 $tempfile
	$VISUAL $1
	if /usr/bin/diff $1 $tempfile >> /dev/null ; then
	  echo No changes made
	else
		/usr/sbin/dnstouch $1
		/usr/sbin/ndu
		echo updated
		echo 'remember to run "/etc/rc.d/init.d/named restart"'
	fi
else
	echo file does not exist
fi

