#!/bin/bash
# vim: set ft=sh :
#
# Command-line options
# use color output?
IS_TTY=
## Options
LOG_ERROR=y
LOG_WARN=y
LOG=y
LOG_FORCE=y
LOG_UPDATE=y
LOG_NOOP=y
LOG_SKIP=
LOG_DEBUG=
LOG_CMD=
LOG_DIFF=y
UPDATE_FORCE=
UPDATE_NOOP=
UPDATE_DIFF=
SERIAL_NOOP=
SERIAL_FORCE=
COMMIT_SKIP=
COMMIT_FORCE=
COMMIT_MSG=' '
RELOAD_NOOP=
RELOAD_FORCE=
## Output command-line argument help.
function help_args {
local prog=$1
cat <<END
Usage: $prog [options]
General:
-h display this help text
-d DIR datadir
Logging:
-q quiet
-v verbose
-D debug
-V debug commands
Updates:
-p show changes
-F force-updates without checking src mtime
-S do not update serial
-s update serials
-n no-op/mock-update; don't actually change/deploy anything; implies -SpC
Commit:
-C do not commit changes
-c commit changes
-m MSG commit message
Deploy:
-R do not reload zones/dhcp
-r force reload zones/dhcp
END
}
## Parse any command-line arguments, setting the global options vars.
function parse_args {
# test tty
[ -t 1 ] && IS_TTY=y
OPTIND=1
while getopts 'hd:qvDVpFSsnCcm:Rr' opt "$@"; do
case $opt in
h)
help_args $0
exit 0
;;
d) SRV="$OPTARG" ;;
q)
LOG=
LOG_WARN=
LOG_UPDATE=
LOG_FORCE=
LOG_NOOP=
LOG_DIFF=
;;
v) LOG_SKIP=y ;;
D)
LOG_DEBUG=y
LOG_INFO=y
;;
V) LOG_CMD=y ;;
p) UPDATE_DIFF=y ;;
F) UPDATE_FORCE=y ;;
S) SERIAL_NOOP=y ;;
s) SERIAL_FORCE=y ;;
n)
UPDATE_NOOP=y
# implies -Sp
UPDATE_DIFF=y
SERIAL_NOOP=y
COMMIT_SKIP=y
RELOAD_NOOP=y
;;
C) COMMIT_SKIP=y ;;
c) COMMIT_FORCE=y ;;
m) COMMIT_MSG="$OPTARG" ;;
R) RELOAD_NOOP=y ;;
r) RELOAD_FORCE=y ;;
?)
die
;;
esac
done
}