Change the way default parameters are set.

This commit is contained in:
Manuel Friedli 2020-11-24 21:28:28 +01:00
parent 8e0f22da8f
commit 11ad1b471a

View file

@ -256,10 +256,10 @@ function parse_command_line_args() {
'')
autopilot=1
;;
*[!0-9]*)
echo "Invalid argument for parameter 'auto': '${2}'. Invoke with --help for help." >&2
exit 1
;;
# *[!0-9]*)
# echo "Invalid argument for parameter 'auto': '${2}'. Invoke with --help for help." >&2
# exit 1
# ;;
*)
autopilot="$2"
;;
@ -268,10 +268,10 @@ function parse_command_line_args() {
;;
'-c' | '--country')
IFS=',' read -ra bancountries <<<"${2}"
if [[ -z ${bancountries[@]// /} ]]; then
echo "Invalid argument for parameter 'country': '${2}'. Invoke with --help for help." >&2
exit 1
fi
# if [[ -z ${bancountries[@]// /} ]]; then
# echo "Invalid argument for parameter 'country': '${2}'. Invoke with --help for help." >&2
# exit 1
# fi
shift
;;
'-d' | '--database')
@ -284,10 +284,6 @@ function parse_command_line_args() {
;;
'-f' | '--config-file')
configfile="${2}"
if [[ ! -f "${configfile}" || ! -r "${configfile}" ]]; then
echo "Can not read configuration file '${2}'. Invoke with --help for help." >&2
exit 1
fi
shift
;;
'-j' | '--jail')
@ -296,21 +292,20 @@ function parse_command_line_args() {
;;
'-n' | '--netmask')
case "${2}" in
'1' | '8')
'1')
netmask=8
;;
'2' | '16')
'2')
netmask=16
;;
'3' | '24')
'3')
netmask=24
;;
'4' | '32')
'4')
netmask=32
;;
*)
echo "Invalid argument for parameter 'netmask': '${2}'. Invoke with --help for help." >&2
exit 1
netmask="${2}"
;;
esac
shift
@ -337,21 +332,57 @@ function parse_command_line_args() {
# If the config file option is set, parse the config file.
if [[ ! -z ${configfile+x} ]]; then
if [[ ! -f "${configfile}" || ! -r "${configfile}" ]]; then
echo "Can not read configuration file '${2}'. Invoke with --help for help." >&2
exit 1
fi
parse_config_file
fi
# Here, we set the default values for all options that have not been set yet.
set_default_values
}
function validate_parameter_values() {
# Autopilot
case "${autopilot}" in
*[!0-9]*)
echo "Invalid value argument for parameter 'auto' / 'AUTOPILOT': '${autopilot}'." >&2
echo "Invoke with --help for help." >&2
exit 1
;;
esac
# Countries
if [[ -z ${bancountries[@]// /} ]]; then
echo "Invalid argument for parameter 'country' / 'COUNTRIES': '${bancountries[*]}'." >&2
echo "Invoke with --help for help." >&2
exit 1
fi
# Netmask
case "${netmask}" in
'8' | '16' | '24' | '32')
# Everything OK.
;;
*)
echo "Invalid argument for parameter 'netmask': '${2}'." >&2
echo "Invoke with --help for help." >&2
exit 1
;;
esac
# GeoIP-Database
if [[ -z "${database}" ]]; then
echo "No GeoIP database specified. Invoke with --help for more information." >&2
exit 1
fi
if [[ ! -r "${database}" ]]; then
if [[ ! -f "${database}" || ! -r "${database}" ]]; then
echo "Database '${database}' is not accessible." >&2
exit 1
fi
# Here, we set the default values for all options that have not been set yet.
set_default_values
}
################################################################################
@ -512,6 +543,7 @@ database=
port=
parse_command_line_args "$@"
validate_parameter_values
check_dependencies
dependencies_ok=$?