aboutsummaryrefslogtreecommitdiff
path: root/utils/common.sh
diff options
context:
space:
mode:
authorToni <matzeton@googlemail.com>2023-05-28 12:45:44 +0200
committerGitHub <noreply@github.com>2023-05-28 12:45:44 +0200
commit6da3474203fc2ff5981f6c73f7ad02fa81138166 (patch)
treebe8d74931f416143291ffaa1707cfa2f2103c82b /utils/common.sh
parentb11e6a453b0b870957663d214d9f1a0fdf49af90 (diff)
Improved helper scripts. (#1986)
* added additional (more restrictive) checks Signed-off-by: lns <matzeton@googlemail.com>
Diffstat (limited to 'utils/common.sh')
-rwxr-xr-xutils/common.sh39
1 files changed, 39 insertions, 0 deletions
diff --git a/utils/common.sh b/utils/common.sh
new file mode 100755
index 000000000..415d6fe87
--- /dev/null
+++ b/utils/common.sh
@@ -0,0 +1,39 @@
+#!/usr/bin/env sh
+
+printf 'Running script: %s\n' "$(basename ${0})" >&2
+
+function check_http_response()
+{
+ http_response="${1}"
+
+ if [ "${http_response}" != "200" ]; then
+ printf '%s error: %s\n' "${0}" "HTTP Response code ${http_response}; you probably need to update the list url!" >&2
+ exit 1
+ fi
+}
+
+function is_file_empty()
+{
+ file="${1}"
+
+ if [ ! -r "${file}" ]; then
+ printf '%s error: %s\n' "${0}" "file ${file} not found or not readable!" >&2
+ exit 1
+ fi
+
+ if [ `cat "${file}" | wc -l` -eq 0 ]; then
+ printf '%s error: %s\n' "${0}" "file ${file} empty!" >&2
+ exit 1
+ fi
+}
+
+function is_str_empty()
+{
+ str="${1}"
+ errmsg="${2}"
+
+ if [ -z "${str}" ]; then
+ printf '%s error: %s\n' "${0}" "${errmsg}" >&2
+ exit 1
+ fi
+}