Annotation of ze/zefwd, revision 1.1

1.1     ! snw         1: #!/usr/bin/env bash
        !             2: 
        !             3: #
        !             4: #   $Id$
        !             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$
        !            28: #
        !            29: # SPDX-FileCopyrightText:  (C) 2025 Coherent Logic Development LLC
        !            30: # SPDX-License-Identifier: AGPL-3.0-or-later
        !            31: #
        !            32: 
        !            33: source /etc/defaults/ze.conf
        !            34: 
        !            35: [[ -z "${EDITOR}" ]] && EDITOR="emacs -nw"
        !            36: 
        !            37: SHNAME=`basename $0`
        !            38: 
        !            39: if [ ${EUID} -ne 0 ]
        !            40: then
        !            41:     echo "${SHNAME} must be run as root."
        !            42:     exit
        !            43: fi
        !            44: 
        !            45: if [ $1 = "" ]
        !            46: then
        !            47:     echo "usage: $0 zone"
        !            48:     exit
        !            49: fi
        !            50: 
        !            51: 
        !            52: if [ ${SHNAME} = "zefwd" ]
        !            53: then
        !            54:     ZONEFILE="/etc/namedb/$1.db"
        !            55:     ZONEBASE="$1.db"
        !            56:     RNDC_DOMAIN=$1
        !            57: elif [ ${SHNAME} = "zerev" ]
        !            58: then
        !            59:     ZONEFILE="/etc/namedb/rev.${1}.in-addr.arpa"
        !            60:     ZONEBASE="rev.${1}.in-addr.arpa"
        !            61:     RNDC_DOMAIN="${1}.IN-ADDR.ARPA"
        !            62: fi
        !            63: 
        !            64: TMPFILE="/tmp/${ZONEBASE}"
        !            65: 
        !            66: if [ ! -f ${ZONEFILE} ]
        !            67: then
        !            68:     echo "${ZONEFILE} does not exist."
        !            69:     exit
        !            70: fi
        !            71: 
        !            72: if [ -f ${TMPFILE} ]
        !            73: then
        !            74:     echo "${ZONEFILE} already being edited."
        !            75:     exit
        !            76: fi
        !            77: 
        !            78: ORIG_SERIAL=`cat ${ZONEFILE} | sed '3q;d' | tr -d '[[:space:]]'`
        !            79: cp ${ZONEFILE} ${TMPFILE}
        !            80: cd /etc/namedb
        !            81: ${EDITOR} ${TMPFILE}
        !            82: 
        !            83: NEW_SERIAL=`cat ${TMPFILE} | sed '3q;d' | tr -d '[[:space:]]'`
        !            84: 
        !            85: if [ ${NEW_SERIAL} -le ${ORIG_SERIAL} ]
        !            86: then
        !            87:     echo "Serial number in zonefile ${ZONEFILE} must be greater than ${ORIG_SERIAL}."
        !            88:     rm -f ${TMPFILE}
        !            89:     exit
        !            90: else
        !            91:     echo "Serial number changed:  ${ORIG_SERIAL} -> ${NEW_SERIAL}"
        !            92: fi
        !            93: 
        !            94: mv ${TMPFILE} ${ZONEFILE}
        !            95: rm -f ${TMPFILE}
        !            96: 
        !            97: git add ${ZONEFILE}
        !            98: read -p "Enter a comment explaining this edit: " COMMIT_CMNT
        !            99: LOGIN_NAME=`logname`
        !           100: echo "Committing to version control..."
        !           101: git commit -m "${LOGIN_NAME}: ${COMMIT_CMNT}"
        !           102: git push origin master
        !           103: echo "Reloading BIND configuration..."
        !           104: /etc/rc.d/named reload
        !           105: echo "Requesting retransfer from ${SLAVE_SERVER}..."
        !           106: ssh ${SLAVE_USER}@${SLAVE_SERVER} "sudo /usr/sbin/rndc retransfer ${RNDC_DOMAIN}"

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>