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