feature/config-file #3

Merged
manuel merged 5 commits from feature/config-file into master 2020-11-24 21:35:13 +01:00
Showing only changes of commit 11ad1b471a - Show all commits

View file

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