lib/pvl/hosts/zone.sh
author Tero Marttila <tero.marttila@aalto.fi>
Thu, 26 Feb 2015 22:53:26 +0200
changeset 629 7214fe5c6fac
parent 628 b10ad946d01d
child 632 711be783d0a1
permissions -rw-r--r--
lib/pvl: fixfix
628
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     1
#HOSTS_CHARSET='utf-8'
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     2
HOSTS_INCLUDE="$ETC/hosts"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     3
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     4
NAMED_CHECKZONE=/usr/sbin/named-checkzone
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     5
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     6
RNDC=/usr/sbin/rndc
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     7
RNDC_KEY=/etc/bind/rndc.key
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     8
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     9
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    10
## Generate forward zone from hosts hosts using pvl.hosts-forward
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    11
#
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    12
#   update_hosts_forward $out $src
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    13
function update_hosts_forward {
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    14
    local out="$1"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    15
    local src="$2"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    16
    local srcs=($src/*)
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    17
    local msg="$out: Generating forward hosts zone: $src"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    18
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    19
    if apply_check "$out" "${srcs[@]}"; then
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    20
        log_skip "$msg"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    21
    else
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    22
        log_apply "$msg"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    23
    
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    24
        apply_cmd "$out" $OPT/bin/pvl.hosts-forward \
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    25
            --hosts-include="$HOSTS_INCLUDE" \
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    26
             "$src"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    27
    fi
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    28
}
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    29
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    30
## Generate reverse zone from hosts hosts using pvl.hosts-reverse
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    31
#
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    32
#   update_hosts_reverse $out $src
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    33
function update_hosts_reverse {
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    34
    local out="$1"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    35
    local src="$2"
629
7214fe5c6fac lib/pvl: fixfix
Tero Marttila <tero.marttila@aalto.fi>
parents: 628
diff changeset
    36
    local srcs=$src/*
628
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    37
    local msg="$out: Generating reverse hosts zone: $src"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    38
629
7214fe5c6fac lib/pvl: fixfix
Tero Marttila <tero.marttila@aalto.fi>
parents: 628
diff changeset
    39
    if apply_check "$out" $srcs; then
628
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    40
        log_skip "$msg"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    41
    else
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    42
        log_apply "$msg"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    43
    
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    44
        apply_cmd "$out" $OPT/bin/pvl.hosts-reverse \
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    45
            --hosts-include="$HOSTS_INCLUDE" \
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    46
             "$src"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    47
    fi
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    48
}
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    49
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    50
function update_zone_include {
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    51
    local out="$1"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    52
    local src="$2"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    53
    local msg="$out: Copy zone include: $src"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    54
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    55
    if apply_check "$out" "${srcs[@]}"; then
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    56
        log_skip "$msg"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    57
    else
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    58
        log_apply "$msg"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    59
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    60
        apply_cmd "$out" cat \
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    61
            "$src"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    62
    fi
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    63
}
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    64
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    65
## Read include paths from file
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    66
function read_zone_includes {
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    67
    cmd sed -n -E 's/^\$INCLUDE\s+"(.+)"/\1/p' "$@"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    68
}
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    69
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    70
## (cached) include paths for zone file
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    71
function zone_includes {
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    72
    local cache="$1"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    73
    local src="$2"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    74
    local prefix="${3:-}"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    75
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    76
    if [ ! -e "$cache" -o "$cache" -ot "$src" ]; then
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    77
        read_zone_includes "$src" > "$cache"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    78
    fi
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    79
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    80
    while read include; do
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    81
        echo -n "$prefix$include "
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    82
    done < "$cache"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    83
}
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    84
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    85
## Search for prefix-matching includes in zone file
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    86
function zone_includes_grep {
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    87
    local cache="$1"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    88
    local src="$2"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    89
    local prefix="$3"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    90
    
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    91
    for include in $(zone_includes $cache $src); do
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    92
        if [ "${include#$prefix}" != "$include" ]; then
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    93
            echo -n " ${include#$prefix}"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    94
        fi
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    95
    done
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    96
}
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    97
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    98
## Generate new serial for zone using pvl.dns-serial, if the zone data has changed:
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    99
#
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   100
#   update_serial   .../serials/$zone   $serial     $deps...
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   101
#
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   102
# Supports SERIAL_FORCE/NOOP.
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   103
# Updates $SERIALS/$zone.serial.
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   104
function update_zone_serial {
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   105
    local out="$1"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   106
    local serial="$2"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   107
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   108
    local old=$(test -e "$out" && cat "$out" || echo '')
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   109
    
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   110
    # test
629
7214fe5c6fac lib/pvl: fixfix
Tero Marttila <tero.marttila@aalto.fi>
parents: 628
diff changeset
   111
    if [ "$UPDATE_SERIAL" = 1 ]; then
628
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   112
        log_force "$out: Force serial $old <- $serial"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   113
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   114
    elif apply_check "$out" "${@:3}"; then
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   115
        log_skip "$out: Skip serial: $old <- $serial"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   116
        
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   117
        return
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   118
629
7214fe5c6fac lib/pvl: fixfix
Tero Marttila <tero.marttila@aalto.fi>
parents: 628
diff changeset
   119
    elif [ "$UPDATE_SERIAL" = 0 ]; then
628
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   120
        log_noop "$out: Noop serial: $old <- $serial"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   121
        
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   122
        return
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   123
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   124
    else
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   125
        log_apply "$out: Update serial: $old <- $serial"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   126
    fi
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   127
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   128
    echo "$serial" > $out
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   129
}
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   130
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   131
## Generate zone file from source using pvl.dns-zone:
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   132
#
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   133
#   update_zone out/zones/$zone in/zones/$zone var/serials/$zone
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   134
function update_zone {
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   135
    local out="$1"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   136
    local src="$2"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   137
    local serial="$3"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   138
    local serial_opt=
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   139
    local msg="$out: Generate zone: $src"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   140
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   141
    if [ -n "$serial" -a -f "$serial" ]; then
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   142
        serial_opt="--serial=$(cat "$serial")"
629
7214fe5c6fac lib/pvl: fixfix
Tero Marttila <tero.marttila@aalto.fi>
parents: 628
diff changeset
   143
    elif [ "$UPDATE_SERIAL" = 0 ]; then
628
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   144
        warn "$out: noop'd serial, omitting"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   145
    else
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   146
        fail "$out: missing serial: $serial"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   147
    fi
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   148
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   149
    if apply_check "$@"; then
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   150
        log_skip "$msg"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   151
    else
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   152
        log_apply "$msg"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   153
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   154
        apply_cmd "$out" $OPT/bin/pvl.dns-zone \
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   155
                --include-path=$VAR/zones  \
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   156
                $serial_opt \
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   157
                "$src"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   158
    fi
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   159
}
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   160
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   161
## Test zone file for validity using named-checkzone:
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   162
#
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   163
#   check_zone      ..../$zone $origin
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   164
function test_zone {
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   165
    local zone=$1
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   166
    local origin=$2
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   167
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   168
    log_check "$zone: Checking zone @$origin..." 
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   169
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   170
    # checkzone is very specific about the order of arguments, -q must be first
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   171
    test_cmd $zone \
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   172
        $NAMED_CHECKZONE $origin $zone
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   173
}
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   174
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   175
# set by do_reload_zone if zone data has actually been reloaded
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   176
RELOAD_ZONES=
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   177
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   178
## Load update zonefiles into bind:
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   179
#
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   180
#   reload_zones    
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   181
#
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   182
# Invokes `rndc reload`, showing its output.
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   183
function reload_zones {
629
7214fe5c6fac lib/pvl: fixfix
Tero Marttila <tero.marttila@aalto.fi>
parents: 628
diff changeset
   184
    if [ "$UPDATE_RELOAD" = 1 ]; then
628
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   185
        log_force "Reload zones"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   186
        
629
7214fe5c6fac lib/pvl: fixfix
Tero Marttila <tero.marttila@aalto.fi>
parents: 628
diff changeset
   187
    elif [ "$UPDATE_RELOAD" = 0 ]; then
628
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   188
        log_noop "Skip reload zones"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   189
        
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   190
        return
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   191
    
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   192
    elif [ ! -e "$RNDC" ]; then
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   193
        warn "Skip with missing RNDC: $RNDC"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   194
        
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   195
        return
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   196
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   197
    elif [ ! -e "$RNDC_KEY" ]; then
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   198
        warn "Skip with missing RNDC_KEY: $RNDC_KEY"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   199
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   200
        return
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   201
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   202
    elif [ ! -r $RNDC_KEY ]; then
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   203
        error "Permission denied for RNDC_KEY: $RNDC_KEY"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   204
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   205
        return 1
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   206
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   207
    else
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   208
        log_apply "Reload zones"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   209
    fi
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   210
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   211
    indent "        rndc: " \
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   212
        $RNDC reload
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   213
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   214
    # set flag for dhcp
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   215
    RELOAD_ZONES=1
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   216
}