--- a/bin/update Mon Dec 16 21:53:41 2013 +0200
+++ b/bin/update Tue Dec 17 00:04:00 2013 +0200
@@ -3,280 +3,117 @@
set -ue
-# resolve $0 -> bin/update
-self=$0
-while [ -L $self ]; do
- tgt=$(readlink $self)
-
- if [ "${tgt:0:1}" == "/" ]; then
- self=$tgt
- else
- self=$(dirname $self)/$tgt
- fi
-done
-
-# root dir
-ROOT=$(dirname $(dirname $self))
+if [ $0 == './update' ]; then
+ SRV=$(pwd)
+ OPT=./opt
+else
+ SRV=${SRV:-/srv/dns}
+ OPT=${SRV:-/srv/dns/opt}
+ cd $SRV
+fi
-BIN=$ROOT/bin
-LIB=$ROOT/lib
-VAR=$ROOT/var
-
-## Data paths
-# absolute path to data files; can be changed using -d
-ROOT=$(pwd)
+# charset for files under etc/
+CHARSET='utf-8'
-DATA=settings
-ZONES=$VAR/zones
-SERIALS=$VAR/serials
+# External bins
+NAMED_CHECKZONE=/usr/sbin/named-checkzone
-DHCP=$VAR/dhcp
-DHCP_DATA=$DATA/dhcp
-
-# global DHCP conf to test
DHCPD=/usr/sbin/dhcpd
DHCPD_CONF=/etc/dhcp/dhcpd.conf
DHCPD_INIT=/etc/init.d/isc-dhcp-server
-# hg repo to commit
-REPO=$DATA
-
-## Settings used in lib
-# Hide files under repo in commit diff output..
-REPO_HIDE='*.serial'
-
-# data input charsets; arguments to ./bin/... python scripts
-HOSTS_FILE_ARGS='--input-charset utf-8'
-DHCP_FILE_ARGS='--input-charset utf-8'
-
-# External bins
-NAMED_CHECKZONE=/usr/sbin/named-checkzone
-
HG=/usr/bin/hg
HG_ARGS=(--config trusted.users=root)
RNDC=/usr/sbin/rndc
-
-# Path to rndc key, must be readable to run..
RNDC_KEY=/etc/bind/rndc.key
-## Library includes
-# Command-line argument handling
-source $LIB/update.args
-
-# Logging
-source $LIB/update.logging
-
-# Utility functions
-source $LIB/update.utils
-
-# Dependency-based updates
-source $LIB/update.updates
-
-# Operations; the functions called from run()
-source $LIB/update.operations
+# Library includes
+source lib/update
## Flags
# set by do_reload_zone if zone data has actually been reloaded
RELOAD_ZONES=
## Site settings, used as arguments to scripts
-# MX record to generate in hosts --forward-zone
-FORWARD_MX=mx0
-
-# IP network to generate reverse records for in --reverse-zone
-REVERSE_ZONE=194.197.235
-
# Origin domain to generate reverse records for in --reverse-zone
REVERSE_DOMAIN=paivola.fi
-# Views used
-VIEWS=(internal external)
-
-# Base domain zone for domains
-DOMAIN_BASE=paivola
-
-# List of actual domains used; will be linked to $DOMAIN_BASE
-DOMAINS=(paivola.fi paivola.net paivola.org paivola.info paivola.mobi xn--pivl-load8j.fi)
-
-# Names of dhcp conf file names
-DHCP_CONFS=( $(list_files $DHCP_DATA *.conf) )
-
-## Operate!
-# these functions are all defined in lib/update.operations
-
-# Update $ZONES/$DHCP host-files from $DATA
+## Do things
function run_hosts {
- ## Hosts
# test
log "Testing hosts..."
- # data args...
- check_hosts $DATA/paivola.txt --check-exempt ufc
-
- # update
- log "Generating host zones..."
- # hosts data args...
- update_hosts $ZONES/hosts/paivola:internal $DATA/paivola.txt --forward-zone --forward-txt
- update_hosts $ZONES/hosts/paivola:external $DATA/paivola.txt --forward-zone
- update_hosts $ZONES/hosts/194.197.235 $DATA/paivola.txt --reverse-zone $REVERSE_ZONE --reverse-domain $REVERSE_DOMAIN
+ for hosts in $(list_files etc/hosts); do
+ log_warn "TODO: check_hosts $hosts"
+ done
-
- update_hosts $ZONES/hosts/10 $DATA/pvl.txt --reverse-zone 10 --reverse-domain pvl -q
- update_hosts $ZONES/hosts/10.0 $DATA/test.pvl.txt --reverse-zone 10.0 --reverse-domain test.pvl -q
- update_hosts $ZONES/hosts/fdc4:4cef:395a $DATA/test.pvl.txt --reverse-zone fdc4:4cef:395a --reverse-domain test.pvl -q
- update_hosts $ZONES/hosts/192.168 $DATA/pvl.txt --reverse-zone 192.168 --reverse-domain pvl -q
+ log "Updating host zones..."
+ for hosts in $(list_files etc/hosts); do
+ update_hosts_forward var/zones/hosts/$hosts etc/hosts/$hosts
+ done
- # XXX: unsupported --forward-zone with pvl.txt
- # update_hosts $ZONES/hosts/pvl $DATA/pvl.txt --forward-zone
- copy_hosts $ZONES/hosts/pvl $DATA/pvl.txt
- copy_hosts $ZONES/hosts/test.pvl $DATA/test.pvl.txt
+ log "Updating DHCP hosts..."
+ for hosts in $(list_files etc/hosts); do
+ update_hosts_dhcp var/dhcp/$hosts.conf etc/hosts/$hosts
+ done
}
-# Update $ZONES files
function run_zones {
- ## Includes
log "Copying zone includes..."
- # view zone base
- copy_zone includes paivola:internal paivola.zone.internal
- copy_zone includes paivola:external paivola.zone.external
- copy_zone includes paivola.auto paivola.zone.auto
- copy_zone includes paivola.services paivola.zone.services
- copy_zone includes paivola.aux paivola.zone.aux
-
- ## Serials
- log "Updating serials..."
+ for zone in $(list_files etc/zones/includes); do
+ copy var/zones/includes/$zone etc/zones/includes/$zone
+ done
- # zone deps...
- # includes...
- update_serial pvl $ZONES/hosts/pvl $DATA/pvl.zone
- update_serial test.pvl $ZONES/hosts/test.pvl $DATA/test.pvl.zone
- update_serial 10 $ZONES/hosts/10 $DATA/10.zone
- update_serial 10.0 $ZONES/hosts/10.0 $DATA/10.0.zone
- update_serial fdc4:4cef:395a $ZONES/hosts/fdc4:4cef:395a $DATA/fdc4:4cef:395a.zone
- update_serial 192.168 $ZONES/hosts/192.168 $DATA/192.168.zone
-
- update_serial paivola $ZONES/hosts/paivola:* $DATA/paivola.zone \
- $ZONES/includes/paivola:* \
- $ZONES/includes/paivola.*
-
- update_serial 194.197.235 $ZONES/hosts/194.197.235 $DATA/194.197.235.zone
+ log "Updating zone serials..."
+ for zone in $(list_files etc/zones); do
+ update_serial var/serials/$zone etc/zones/$zone
+ done
- ## Zones
log "Updating zones..."
- # view zone base
- update_zone internal pvl
- update_zone internal test.pvl
+ for zone in $(list_files etc/zones); do
+ update_zone var/zones/$zone etc/zones/$zone var/serials/$zone
+ done
- update_zone internal 10
- update_zone internal 10.0
- update_zone internal fdc4:4cef:395a
- update_zone internal 192.168
-
- update_zone common 194.197.235
- link_zone internal 194.197.235
- link_zone external 194.197.235
-
- ## Test
log "Testing zones..."
- # view zone origin
- check_zone internal 10 10.in-addr.arpa
- check_zone internal 10.0 0.10.in-addr.arpa
- check_zone internal fdc4:4cef:395a a.5.9.3.f.e.c.4.4.c.d.f.ip6.arpa
-
- check_zone internal 192.168 192.168.in-addr.arpa
- check_zone common 194.197.235 235.197.194.in-addr.arpa
-
- ## Domains...
- log "Linking domains..."
- for view in "${VIEWS[@]}"; do
- for zone in "${DOMAINS[@]}"; do
- # choose input .zone to use
- base=$(choose_zone $zone $DOMAIN_BASE)
-
- if [ $base != $DOMAIN_BASE ]; then
- # serial
- # XXX: not all zones use all these includes?
- update_serial $base $DATA/$base.zone \
- $ZONES/hosts/paivola:* \
- $ZONES/includes/paivola:* \
- $ZONES/includes/paivola.*
- fi
-
- # link
- update_zone $view $zone $base
-
- # test
- check_zone $view $zone $zone
- done
- done
-}
-
-# Update $DHCP files from $DATA/dhcp
-function run_dhcp {
- log_debug "DHCP_CONFS: ${DHCP_CONFS[*]}"
-
- log "Copying DHCP configs..."
- for conf in "${DHCP_CONFS[@]}"; do
- # XXX: ei toimi, koska conf:it riippuu toisistaan include:ien takia
- # check_dhcp_conf $conf
-
- # conf base
- copy_dhcp_conf $conf
- done
-
- log "Testing dhcp..."
- # checks the whole dhcpd.conf, with all includes..
- check_dhcp
-}
-
-# Runs DHCP checks, once DNS hosts have been updated
-function run_dhcp_check {
- log "Testing dhcp hosts..."
- for conf in "${DHCP_CONFS[@]}"; do
- check_dhcp_hosts $DHCP/$conf.conf
- done
+ for zone in $(list_files etc/zones); do
+ # check_zone var/zones/$zone $zone
+ log_warn "TODO: check_zone $zone"
+ done
}
function run_deploy {
- ## Reload zones
log "Reload zones..."
reload_zones
- ## DHCP
- run_dhcp_check
-
log "Reload dhcp..."
reload_dhcp
- ## Commit
- log "Commit data..."
- commit_data
+ log "Commit etc..."
+ commit_data etc
}
## Main entry point
function main {
- # test tty
- [ -t 1 ] && IS_TTY=y
-
parse_args "$@"
## Input dirs
- [ -d $ROOT/$DATA ] || die "Missing data: $ROOT/$DATA"
+ for dir in etc etc/dhcp etc/zones; do
+ [ -d $dir ] || die "Missing directory: $dir"
+ done
## Output dirs
- for dir in $VAR $DHCP $ZONES $SERIALS; do
+ for dir in var var/dhcp var/zones var/serials; do
ensure_dir $dir
done
# sub-$ZONES
- for dir in "common" "hosts" "includes" "${VIEWS[@]}"; do
- ensure_dir $ZONES/$dir
+ for dir in var/zones/hosts var/zones/includes; do
+ ensure_dir $dir
done
## Go
run_hosts
run_zones
- run_dhcp
run_deploy
}