X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=src%2Ffunctions%2Ffunctions.settings;fp=src%2Ffunctions%2Ffunctions.settings;h=2f2821ff0e1a7f168b721b4a38f65010c185c64c;hb=1e6f187eb4eb2990f26b2f54ddaaf993e9285718;hp=8b5ac98ec74efa636aadd1a1d5f1bdbd211af40d;hpb=fa0eb21fe367f80abbe9624634be06e80f21b112;p=people%2Fstevee%2Fnetwork.git diff --git a/src/functions/functions.settings b/src/functions/functions.settings index 8b5ac98e..2f2821ff 100644 --- a/src/functions/functions.settings +++ b/src/functions/functions.settings @@ -132,13 +132,30 @@ function settings_strip() { } function settings_write() { - local settings_file=${1} + local settings_file="${1}" assert isset settings_file shift + local check_func + + local arg + while read arg; do + case "${arg}" in + --check=*) + check_func="$(cli_get_val "${arg}")" + ;; + + # Stop argument processing when reaching the first + # configuration parameter + *) + break + ;; + esac + shift + done <<< "$(args $@)" + # Check if all values to be written are sane - if ! settings_check; then - log CRITICAL "Configuration check failed. No settings have been written." + if isset check_func && ! settings_check "${check_func}"; then return ${EXIT_ERROR} fi @@ -174,13 +191,34 @@ function settings_print() { } function settings_check() { - # If there is a function defined that is called __check - # we call that function - if [ -n "$(type -t hook_check)" ]; then - hook_check || return $? - fi - - return ${EXIT_OK} + local check_func="${1}" + + # Execute the check function + "${check_func}" + local ret="${?}" + + case "${ret}" in + # OK + ${EXIT_OK}|${EXIT_TRUE}) + log DEBUG "Configuration check succeeded." + return ${EXIT_TRUE} + ;; + + # Error + ${EXIT_ERROR}|${EXIT_FALSE}) + log CRITICAL "Configuration check failed. No settings have been written." + return ${EXIT_FALSE} + ;; + + # Command not found + ${EXIT_COMMAND_NOT_FOUND}) + log CRITICAL "Configuration check function '${check_func}' was not found." + return ${EXIT_FALSE} + ;; + esac + + log CRITICAL "Unhandled exit code for '${check_func}': ${ret}" + return ${EXIT_ERROR} } function settings_set() {