--- a/bin/update Thu Dec 19 02:30:00 2013 +0200
+++ b/bin/update Thu Dec 19 02:38:03 2013 +0200
@@ -40,13 +40,13 @@
REVERSE_DOMAIN=paivola.fi
## Do things
-function run_hosts {
- # test
+function update {
log "Testing hosts..."
for hosts in $(list_files etc/hosts); do
log_warn "TODO: check_hosts $hosts"
done
+ ## Hosts
log "Updating forward host zones..."
for hosts in $(list_files etc/hosts); do
update_hosts_forward "var/zones/hosts/$hosts" "$hosts" \
@@ -64,18 +64,8 @@
update_hosts_reverse "var/zones/hosts/$zone" "$zone" \
etc/reverse-zones-hosts/$zone/*
done
-# for zone in $(list_files etc/zones); do
-# for reverse_hosts in $(zone_includes_grep var/include-cache/$zone etc/zones/$zone reverse-hosts/); do
-# prefix="${reverse_hosts%_*}"
-# hosts="${reverse_hosts#*_}"
-#
-# update_hosts_reverse "var/zones/reverse-hosts/${prefix}_${hosts}" "$prefix" \
-# "etc/hosts/$hosts"
-# done
-# done
-}
-function run_zones {
+ ## Zones
log "Copying zone includes..."
for zone in $(list_files etc/zones/includes); do
copy "var/zones/includes/$zone" "etc/zones/includes/$zone"
@@ -85,7 +75,6 @@
for zone in $(list_files etc/zones); do
update_serial "var/serials/$zone" "etc/zones/$zone" \
$(zone_includes var/include-cache/$zone etc/zones/$zone var/zones/)
-
done
log "Updating zones..."
@@ -98,17 +87,16 @@
# check_zone var/zones/$zone $zone
log_warn "TODO: check_zone $zone"
done
-}
-function run_deploy {
+ ## Deploy
log "Reload zones..."
reload_zones
log "Reload dhcp..."
reload_dhcp
- log "Commit etc..."
- commit_data etc
+ log "Commit..."
+ commit etc
}
## Main entry point
@@ -131,9 +119,7 @@
done
## Go
- run_hosts
- run_zones
- run_deploy
+ update
}
main "$@"
--- a/lib/update.hg Thu Dec 19 02:30:00 2013 +0200
+++ b/lib/update.hg Thu Dec 19 02:38:03 2013 +0200
@@ -4,12 +4,13 @@
## Run `hg ...` within $REPO.
function hg {
- cmd $HG "${HG_ARGS[@]}" "$@"
+ local repo=$1; shift
+ cmd $HG -R "$repo" "${HG_ARGS[@]}" "$@"
}
## Does the repo have local modifications?
function hg_modified {
- hg id | grep -q '+'
+ hg $1 id | grep -q '+'
}
## Output possible -u flag for commit.
@@ -29,7 +30,8 @@
## Show changes in repo
# hg_diff [path ...]
function hg_diff {
- hg diff "$@"
+ local repo=$1; shift
+ hg $repo diff "$@"
}
## Commit changes in repo, with given message:
@@ -38,14 +40,13 @@
#
# Automatically determines possible -u to use when running with sudo.
function hg_commit {
- local msg=$1; shift
+ local repo=$1
+ local msg=$2
local user_opt=$(hg_user)
local msg_opt=
[ $msg ] && msg_opt=('-m' "$msg")
debug "$user_opt: $msg"
- hg commit ${user_opt[@]} ${msg_opt[@]}
+ hg $repo commit ${user_opt[@]} ${msg_opt[@]}
}
-
-
--- a/lib/update.operations Thu Dec 19 02:30:00 2013 +0200
+++ b/lib/update.operations Thu Dec 19 02:38:03 2013 +0200
@@ -323,11 +323,12 @@
### Commit
## Perform `hg commit`
function do_commit {
+ local repo=$1
local msg=$1
- [ $LOG_DIFF ] && indent " " hg_diff
+ [ $LOG_DIFF ] && indent " " hg_diff $repo
- hg_commit "$msg"
+ hg_commit $repo "$msg"
}
@@ -336,7 +337,8 @@
# commit_data
#
# Invokes `hg commit`, first showing the diff.
-function commit_data {
+function commit {
+ local repo=$1
local commit_msg="$COMMIT_MSG"
local msg="Commit changes"
@@ -347,17 +349,17 @@
do_commit "$commit_msg"
- elif ! hg_modified; then
- log_skip "$msg: no changes"
+ elif ! hg_modified $repo; then
+ log_warn "$msg: no changes"
elif [ $COMMIT_SKIP ]; then
log_noop "$msg: skipped"
# still show diff, though
- [ $LOG_DIFF ] && indent " " hg_diff
+ [ $LOG_DIFF ] && indent " " hg_diff $repo
else
log_update "$msg..."
- do_commit "$commit_msg"
+ do_commit $repo "$commit_msg"
fi
}