lib/update.operations
changeset 62 65bf391fd2f3
parent 61 22b58b938fd0
child 63 a88766722d18
equal deleted inserted replaced
61:22b58b938fd0 62:65bf391fd2f3
     1 #!/bin/bash
     1 #!/bin/bash
     2 ## vim: set ft=sh :
     2 ## vim: set ft=sh :
     3 #
     3 #
     4 # Operations on zonefiles/hosts/whatever
     4 # Operations on zonefiles/hosts/whatever
       
     5 
       
     6 function link_generic {
       
     7     local out=$1
       
     8     local tgt=$2
       
     9 
       
    10     if check_link $out $tgt; then
       
    11         log_update "Linking $out -> $tgt..."
       
    12 
       
    13         do_link $out $tgt
       
    14 
       
    15     else
       
    16         log_skip "Linking $out -> $tgt: not changed"
       
    17     fi
       
    18 }
       
    19 
     5 
    20 
     6 ## Hosts
    21 ## Hosts
     7 ## Update hosts from verbatim from input zone data:
    22 ## Update hosts from verbatim from input zone data:
     8 #
    23 #
     9 #   copy_hosts      $ZONES/$zone    $DATA/$base
    24 #   copy_hosts      $ZONES/$zone    $DATA/$base
    98 #   link_serial $zone $base
   113 #   link_serial $zone $base
    99 function link_serial {
   114 function link_serial {
   100     local zone=$1
   115     local zone=$1
   101     local base=$2
   116     local base=$2
   102 
   117 
   103     local lnk=$SERIALS/$zone.serial
   118     local out=$SERIALS/$zone.serial
   104     local tgt=$SERIALS/$base.serial
   119     local tgt=$SERIALS/$base.serial
   105 
   120 
   106     if check_link $lnk $tgt; then
   121 
   107         log_update "Linking $lnk -> $tgt..."
   122     link_generic $out $tgt
   108 
       
   109         do_link $lnk $tgt
       
   110 
       
   111     else
       
   112         log_skip "Linking $lnk -> $tgt: not changed"
       
   113     fi
       
   114 }
   123 }
   115 
   124 
   116 ## Update zone file verbatim from source:
   125 ## Update zone file verbatim from source:
   117 #
   126 #
   118 #   copy_zone   $view   $zone   [$base]
   127 #   copy_zone   $view   $zone   [$base]
   178     local base=${3:-$zone}
   187     local base=${3:-$zone}
   179 
   188 
   180     local out=$ZONES/$view/$zone
   189     local out=$ZONES/$view/$zone
   181     local tgt=$(choose_link $out $ZONES/$view/$base $ZONES/common/$base)
   190     local tgt=$(choose_link $out $ZONES/$view/$base $ZONES/common/$base)
   182 
   191 
   183     if check_link $out $tgt; then
   192     link_generic $out $tgt
   184         log_update "Linking $out -> $tgt..."
   193 }
   185 
   194 
   186         do_link $out $tgt
   195 ## Link dhcp file directly from data to hosts
   187 
   196 function link_dhcp_hosts {
   188     else
   197     local hosts=$1
   189         log_skip "Linking $out -> $tgt: not changed"
   198     local base=${2:-$hosts}
   190     fi
   199 
       
   200     local out=$DHCP/$hosts.conf
       
   201     local tgt=$(choose_link $out $DHCP/$base.conf $DHCP_DATA/$base.conf)
       
   202 
       
   203     link_generic $out $tgt
   191 }
   204 }
   192 
   205 
   193 ## Test hosts zone for validity:
   206 ## Test hosts zone for validity:
   194 #
   207 #
   195 #   check_hosts     $DATA/$hosts    --check-exempt ...
   208 #   check_hosts     $DATA/$hosts    --check-exempt ...
   237         
   250         
   238         exit 1
   251         exit 1
   239     fi
   252     fi
   240 }
   253 }
   241 
   254 
       
   255 ## Test DHCP configuration for validity using dhcpd -t:
       
   256 #
       
   257 #   check_dhcp      [$conf]
       
   258 #
       
   259 # Defaults to the global $DHCPD_CONF.
       
   260 # Fails if the check fails.
       
   261 function check_dhcp {
       
   262     local conf=${1:-$DHCPD_CONF}
       
   263 
       
   264     local cmd=($DHCPD -cf $conf -t)
       
   265 
       
   266     if "${cmd[@]}" -q; then
       
   267         log_skip    "Check $conf: OK"
       
   268 
       
   269     else
       
   270         log_error   "  Check $conf: Failed"
       
   271 
       
   272         indent "    " "${cmd[@]}"
       
   273 
       
   274         exit 1
       
   275     fi
       
   276 }
       
   277 
       
   278 ## Test DHCP configuration of given hosts file using check_dhcp $DHCP/$host.conf:
       
   279 #
       
   280 #   check_dhcp_hosts    $host
       
   281 #
       
   282 function check_dhcp_hosts {
       
   283     local host=$1
       
   284 
       
   285     check_dhcp $DHCP/$host.conf
       
   286 }
       
   287 
   242 # Run rndc reload
   288 # Run rndc reload
   243 function do_reload {
   289 function do_reload {
   244     # run
   290     # run
   245     indent "        rndc: " \
   291     indent "        rndc: " \
   246         $RNDC reload
   292         $RNDC reload