]> git.ipfire.org Git - people/ms/network.git/blobdiff - src/functions/functions.util
Do not try to start Bird during boot process
[people/ms/network.git] / src / functions / functions.util
index 0201d0286d41224b6275b833319150081428837c..39ad8613b6e4419c5ef97e86c900e63ac9d75383 100644 (file)
@@ -248,6 +248,19 @@ file_get_age() {
        return ${EXIT_ERROR}
 }
 
+file_to_log() {
+       local level="${1}"
+       assert isset level
+
+       local file="${2}"
+       assert file_exists "${file}"
+
+       local line
+       while read line; do
+               log "${level}" "${line}"
+       done < "${file}"
+}
+
 make_directory() {
        local path="${1}"
 
@@ -456,14 +469,27 @@ assert() {
        local assertion="$@"
 
        if ! ${assertion}; then
-               error_log "Assertion '${assertion}' failed."
                backtrace
-               exit ${EXIT_ERROR_ASSERT}
+
+               # End the program here
+               abort "Assertion failed: ${assertion}"
        fi
 
        return ${EXIT_OK}
 }
 
+# Ends the program immediately without cleaning up
+abort() {
+       local msg="$@"
+
+       # Print message
+       if isset msg; then
+               log ERROR "${msg}"
+       fi
+
+       exit ${EXIT_ERROR_ASSERT}
+}
+
 # This function checks, if the given argument is an assert error
 # exit code. If this is the case, the script will halt immediately.
 assert_check_retval() {
@@ -532,11 +558,11 @@ cmd_quiet() {
 }
 
 cmd_exec() {
-       local cmd=$@
+       local cmd=( "$@" )
 
        log DEBUG "Exec'ing command: ${cmd}"
 
-       exec ${cmd}
+       exec "${cmd[@]}"
 
        log ERROR "Could not exec-ute: ${cmd}"
        exit ${EXIT_ERROR}
@@ -732,6 +758,19 @@ contains_spaces() {
        return ${EXIT_FALSE}
 }
 
+contains_non_ascii_characters() {
+       local value="$@"
+
+       # Strip away all ASCII characters
+       local non_ascii="${value//[[:ascii:]]/}"
+
+       if isset non_ascii; then
+               return ${EXIT_TRUE}
+       fi
+
+       return ${EXIT_FALSE}
+}
+
 string_match() {
        local match=${1}
        local string=${2}
@@ -873,6 +912,11 @@ copy() {
                return ${EXIT_ERROR}
        fi
 
+       # Create destination directory if it doesn't exist, yet
+       if ! make_parent_directory "${dst}"; then
+               return ${EXIT_ERROR}
+       fi
+
        if ! fread "${src}" > "${dst}"; then
                log ERROR "Could not copy data from ${src} to ${dst}"
                return ${EXIT_ERROR}