Home | History | Annotate | Line # | Download | only in scripts
zone-edit.sh.in revision 1.1
      1 #!/bin/sh
      2 #
      3 # Copyright (C) Internet Systems Consortium, Inc. ("ISC")
      4 #
      5 # This Source Code Form is subject to the terms of the Mozilla Public
      6 # License, v. 2.0. If a copy of the MPL was not distributed with this
      7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
      8 #
      9 # See the COPYRIGHT file distributed with this work for additional
     10 # information regarding copyright ownership.
     11 
     12 dir=/tmp/zone-edit.$$
     13 mkdir ${dir} || exit 1
     14 trap "/bin/rm -rf ${dir}" 0
     15 
     16 prefix=@prefix@
     17 exec_prefix=@exec_prefix@
     18 bindir=@bindir@
     19 sbindir=@sbindir@
     20 
     21 dig=${bindir}/dig
     22 checkzone=${sbindir}/named-checkzone
     23 nsupdate=${bindir}/nsupdate
     24 
     25 case $# in
     26 0) echo "Usage: zone-edit <zone> [dig options] [ -- nsupdate options ]"; exit 0 ;;
     27 esac
     28 
     29 # What kind of echo are we using?
     30 try=`echo -n ""`
     31 if test "X$try" = "X-n "
     32 then
     33     echo_arg=""
     34     bsc="\\c"
     35 else
     36     echo_arg="-n"
     37     bsc=""
     38 fi
     39 
     40 zone="${1}"
     41 shift
     42 digopts=
     43 while test $# -ne 0
     44 do
     45     case "${1}" in
     46     --)
     47 	shift
     48 	break
     49 	;;
     50     *)
     51 	digopts="$digopts $1"
     52 	shift
     53 	;;
     54     esac
     55 done
     56 
     57 ${dig} axfr "$zone" $digopts |
     58 awk '$4 == "RRSIG" || $4 == "NSEC" || $4 == "NSEC3" || $4 == "NSEC3PARAM" { next; } { print; }' > ${dir}/old
     59 
     60 if test -s ${dir}/old
     61 then
     62     ${checkzone} -q -D "$zone" ${dir}/old > ${dir}/ooo
     63 fi
     64 
     65 if test -s ${dir}/ooo
     66 then
     67     cp ${dir}/ooo ${dir}/new
     68     while :
     69     do
     70         if ${VISUAL:-${EDITOR:-/bin/ed}} ${dir}/new
     71         then
     72 	    if ${checkzone} -q -D "$zone" ${dir}/new > ${dir}/nnn
     73 	    then
     74 	        sort ${dir}/ooo > ${dir}/s1 
     75 	        sort ${dir}/nnn > ${dir}/s2 
     76 	        comm -23 ${dir}/s1 ${dir}/s2 |
     77 		sed 's/^/update delete /' > ${dir}/ccc
     78 	        comm -13 ${dir}/s1 ${dir}/s2 |
     79 		sed 's/^/update add /' >> ${dir}/ccc
     80 	        if test -s ${dir}/ccc
     81 	        then
     82 		    cat ${dir}/ccc | more
     83 		    while :
     84 		    do
     85 		        echo ${echo_arg} "Update (u), Abort (a), Redo (r), Modify (m), Display (d) : $bsc"
     86 			read ans
     87 			case "$ans" in
     88 		        u)
     89 			    (
     90 			    echo zone "$zone"
     91 			    cat ${dir}/ccc
     92 			    echo send
     93 			    ) | ${nsupdate} "$@"
     94 			    break 2
     95 			    ;;
     96 			a)
     97 			    break 2
     98 			    ;;
     99 			d)
    100 			    cat ${dir}/ccc | more
    101 			    ;;
    102 			r)
    103 			    cp ${dir}/ooo ${dir}/new
    104 			    break
    105 			    ;;
    106 			m)
    107 			    break
    108 			    ;;
    109 		        esac
    110 		    done
    111 		else
    112 		    while :
    113 		    do 
    114 		        echo ${echo_arg} "Abort (a), Redo (r), Modify (m) : $bsc"
    115 		        read ans
    116 		        case "$ans" in
    117 		        a)
    118 		            break 2
    119 		            ;;
    120 		        r)
    121 		            cp ${dir}/ooo ${dir}/new
    122 		    	    break
    123 		            ;;
    124 		        m)
    125 			    break
    126 		            ;;
    127 		        esac
    128 		    done
    129 	        fi
    130 	    else
    131 		while :
    132 		do 
    133 		    echo ${echo_arg} "Abort (a), Redo (r), Modify (m) : $bsc"
    134 		    read ans
    135 		    case "$ans" in
    136 		    a)
    137 		        break 2
    138 		        ;;
    139 		    r)
    140 		        cp ${dir}/ooo ${dir}/new
    141 		    	break
    142 		        ;;
    143 		    m)
    144 			break
    145 		        ;;
    146 		    esac
    147 		done
    148 	    fi
    149         fi
    150     done
    151 fi
    152