Initial commit of source
This commit is contained in:
85
dns-record
Executable file
85
dns-record
Executable file
@@ -0,0 +1,85 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
SCRIPT_PATH=$(realpath -s "$0")
|
||||
SCRIPT_DIR=$(dirname "$SCRIPT_PATH")
|
||||
SCRIPT=$(basename "$SCRIPT_PATH")
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Usage: $SCRIPT [OPTIONS]... COMMAND [COMMAND OPTIONS]
|
||||
|
||||
Manage DNS records.
|
||||
|
||||
Commands:
|
||||
* help [COMMAND] show help message of commands
|
||||
* add add record to zone
|
||||
* delete delete record from zone
|
||||
|
||||
Options:
|
||||
-c, --config path to config file
|
||||
-h, --help print this help message
|
||||
|
||||
EOF
|
||||
exit
|
||||
}
|
||||
|
||||
config_file="$SCRIPT_DIR"/config.sh
|
||||
cmd=""
|
||||
|
||||
while [ -n "$1" ]; do
|
||||
opt=$1
|
||||
shift
|
||||
case "$opt" in
|
||||
-c|--config)
|
||||
if [ -z "$1" ]; then
|
||||
echo "$SCRIPT: missing argument to option -- '$opt'" >&2
|
||||
exit 1
|
||||
fi
|
||||
config_file=$1
|
||||
shift
|
||||
;;
|
||||
-h|--help)
|
||||
usage
|
||||
;;
|
||||
-*)
|
||||
echo "$SCRIPT: invalid option -- '$opt'" >&2
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
cmd=$opt
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
cmd=${cmd,,:-help}
|
||||
|
||||
source "$config_file" || exit 1
|
||||
|
||||
LIB_DIR=${LIB_DIR:-$SCRIPT_DIR/lib}
|
||||
source "$LIB_DIR"/dns.sh || exit 1
|
||||
source "$LIB_DIR"/output.sh || exit 1
|
||||
|
||||
params="--interactive"
|
||||
|
||||
if [ "$cmd" == "help" ]; then
|
||||
params="--help"
|
||||
cmd=${1,,}
|
||||
shift
|
||||
fi
|
||||
|
||||
case "$cmd" in
|
||||
add)
|
||||
"$SCRIPT_DIR"/dns-record-add $params "$@"
|
||||
;;
|
||||
del|delete)
|
||||
"$SCRIPT_DIR"/dns-record-delete $params "$@"
|
||||
;;
|
||||
"")
|
||||
usage
|
||||
;;
|
||||
*)
|
||||
echo "$SCRIPT: invalid command -- '$cmd'" >&2
|
||||
exit 5
|
||||
;;
|
||||
esac
|
||||
Reference in New Issue
Block a user