xref: /netbsd-src/external/mpl/bind/dist/contrib/scripts/zone-edit.sh.in (revision e670fd5c413e99c2f6a37901bb21c537fcd322d2)
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 https://mozilla.org/MPL/2.0/.
8#
9# See the COPYRIGHT file distributed with this work for additional
10# information regarding copyright ownership.
11
12dir=/tmp/zone-edit.$$
13mkdir ${dir} || exit 1
14trap "/bin/rm -rf ${dir}" 0
15
16prefix=@prefix@
17exec_prefix=@exec_prefix@
18bindir=@bindir@
19sbindir=@sbindir@
20
21dig=${bindir}/dig
22checkzone=${sbindir}/named-checkzone
23nsupdate=${bindir}/nsupdate
24
25case $# in
260) echo "Usage: zone-edit <zone> [dig options] [ -- nsupdate options ]"; exit 0 ;;
27esac
28
29# What kind of echo are we using?
30try=`echo -n ""`
31if test "X$try" = "X-n "
32then
33    echo_arg=""
34    bsc="\\c"
35else
36    echo_arg="-n"
37    bsc=""
38fi
39
40zone="${1}"
41shift
42digopts=
43while test $# -ne 0
44do
45    case "${1}" in
46    --)
47	shift
48	break
49	;;
50    *)
51	digopts="$digopts $1"
52	shift
53	;;
54    esac
55done
56
57${dig} axfr "$zone" $digopts |
58awk '$4 == "RRSIG" || $4 == "NSEC" || $4 == "NSEC3" || $4 == "NSEC3PARAM" { next; } { print; }' > ${dir}/old
59
60if test -s ${dir}/old
61then
62    ${checkzone} -q -D "$zone" ${dir}/old > ${dir}/ooo
63fi
64
65if test -s ${dir}/ooo
66then
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
151fi
152