1: #!/usr/bin/env bash
2:
3: #
4: # $Id: zefwd,v 1.1.1.1 2025/06/15 23:36:24 snw Exp $
5: # ChivaNet BIND zone edit script
6: #
7: #
8: # Author: Serena Willis <snw@coherent-logic.com>
9: # Copyright (C) 2013, 2025 Coherent Logic Development LLC
10: #
11: #
12: # This file is part of ze.
13: #
14: # ze is free software: you can redistribute it and/or modify
15: # it under the terms of the GNU Affero General Public License as published by
16: # the Free Software Foundation, either version 3 of the License, or
17: # (at your option) any later version.
18: #
19: # ze is distributed in the hope that it will be useful,
20: # but WITHOUT ANY WARRANTY; without even the implied warranty of
21: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22: # GNU Affero Public License for more details.
23: #
24: # You should have received a copy of the GNU Affero General Public License
25: # along with ze. If not, see <https://www.gnu.org/licenses/>.
26: #
27: # $Log: zefwd,v $
28: # Revision 1.1.1.1 2025/06/15 23:36:24 snw
29: # Initial commit
30: #
31: #
32: # SPDX-FileCopyrightText: (C) 2025 Coherent Logic Development LLC
33: # SPDX-License-Identifier: AGPL-3.0-or-later
34: #
35:
36: source /etc/defaults/ze.conf
37:
38: [[ -z "${EDITOR}" ]] && EDITOR="emacs -nw"
39:
40: SHNAME=`basename $0`
41:
42: if [ ${EUID} -ne 0 ]
43: then
44: echo "${SHNAME} must be run as root."
45: exit
46: fi
47:
48: if [ $1 = "" ]
49: then
50: echo "usage: $0 zone"
51: exit
52: fi
53:
54:
55: if [ ${SHNAME} = "zefwd" ]
56: then
57: ZONEFILE="/etc/namedb/$1.db"
58: ZONEBASE="$1.db"
59: RNDC_DOMAIN=$1
60: elif [ ${SHNAME} = "zerev" ]
61: then
62: ZONEFILE="/etc/namedb/rev.${1}.in-addr.arpa"
63: ZONEBASE="rev.${1}.in-addr.arpa"
64: RNDC_DOMAIN="${1}.IN-ADDR.ARPA"
65: fi
66:
67: TMPFILE="/tmp/${ZONEBASE}"
68:
69: if [ ! -f ${ZONEFILE} ]
70: then
71: echo "${ZONEFILE} does not exist."
72: exit
73: fi
74:
75: if [ -f ${TMPFILE} ]
76: then
77: echo "${ZONEFILE} already being edited."
78: exit
79: fi
80:
81: ORIG_SERIAL=`cat ${ZONEFILE} | sed '3q;d' | tr -d '[[:space:]]'`
82: cp ${ZONEFILE} ${TMPFILE}
83: cd /etc/namedb
84: ${EDITOR} ${TMPFILE}
85:
86: NEW_SERIAL=`cat ${TMPFILE} | sed '3q;d' | tr -d '[[:space:]]'`
87:
88: if [ ${NEW_SERIAL} -le ${ORIG_SERIAL} ]
89: then
90: echo "Serial number in zonefile ${ZONEFILE} must be greater than ${ORIG_SERIAL}."
91: rm -f ${TMPFILE}
92: exit
93: else
94: echo "Serial number changed: ${ORIG_SERIAL} -> ${NEW_SERIAL}"
95: fi
96:
97: mv ${TMPFILE} ${ZONEFILE}
98: rm -f ${TMPFILE}
99:
100: git add ${ZONEFILE}
101: read -p "Enter a comment explaining this edit: " COMMIT_CMNT
102: LOGIN_NAME=`logname`
103: echo "Committing to version control..."
104: git commit -m "${LOGIN_NAME}: ${COMMIT_CMNT}"
105: git push origin master
106: echo "Reloading BIND configuration..."
107: /etc/rc.d/named reload
108: echo "Requesting retransfer from ${SLAVE_SERVER}..."
109: ssh ${SLAVE_USER}@${SLAVE_SERVER} "sudo /usr/sbin/rndc retransfer ${RNDC_DOMAIN}"
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>