]> mj.ucw.cz Git - nsc-5.git/blob - bin/genzone
Most directory names are now fixed
[nsc-5.git] / bin / genzone
1 #!/bin/bash
2 # NSC -- Zone file generator
3 # (c) 1997--2019 Martin Mares <mj@ucw.cz>
4
5 set -e
6 . bin/shell-env
7
8 if [ $# -lt 2 ] ; then
9         echo >&2 "Usage: $0 <domain> <source files>"
10         exit 1
11 fi
12 Z=$1
13 shift
14
15 CURRENT_HASH=$($M4 -DHASHING m4/nsc.m4 "$@" | md5sum | cut -d " " -f1)
16 if [ -f keys/$Z.hash ] ; then
17         CURRENT_HASH=$CURRENT_HASH:$(cat keys/$Z.hash)
18         if [ -f keys/resign-stamp ] ; then
19                 CURRENT_HASH=$CURRENT_HASH:$(stat -c '%Y' keys/resign-stamp)
20         fi
21 fi
22
23 PREV_HASH=$(if [ -s hash/$Z ] ; then cat hash/$Z ; fi)
24 if [ "X$CURRENT_HASH" = "X$PREV_HASH" ] ; then
25         echo "-- $Z: No changes"
26         touch zone/$Z hash/$Z
27 else
28         $M4 -DVERS=ver/$Z m4/nsc.m4 "$@" >zone/$Z.new
29         NEWVER="$(sed -e "s/^;;; VERSION: //; t; d" zone/$Z.new)"
30         if [ -f keys/$Z.hash ] ; then
31                 if ! dnssec-signzone -a -d dss -g -K keys/$Z $SIGNZONE_OPTIONS -f zone/$Z.signed -o $Z -S -3 - zone/$Z.new &>zone/$Z.tmp ; then
32                         cat zone/$Z.tmp
33                         echo >&2 "FATAL: Signing failed"
34                         exit 1
35                 fi
36                 rm -f zone/$Z.tmp
37                 mv zone/$Z.signed zone/$Z
38                 SIGNED=" (signed)"
39         else
40                 mv zone/$Z.new zone/$Z
41                 SIGNED=
42         fi
43         echo "** $Z: New version $NEWVER$SIGNED"
44         echo $CURRENT_HASH >hash/$Z
45 fi