From bf6615b0345d43b5c2c3234a1717dbe900950bfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Sch=C3=A4ferdiek?= Date: Sun, 10 Jul 2022 18:29:44 +0200 Subject: [PATCH] Make scripts work for global user --- usr/local/bin/check_updates | 52 +++++++++++++-------- usr/local/bin/disk_space_alert | 52 +++++++++++++-------- usr/local/bin/docker_check | 68 +++++++++++++++++++--------- usr/local/bin/docker_compose_update | 54 ++++++++++++++-------- usr/local/bin/dynv6 | 37 +++++++++++---- usr/local/bin/memory_usage_alert | 53 ++++++++++++++-------- usr/local/bin/smartctl_tests_long | 52 +++++++++++++-------- usr/local/bin/systemd_check | 68 +++++++++++++++++++--------- usr/local/bin/systemd_failure_notify | 52 +++++++++++++-------- 9 files changed, 326 insertions(+), 162 deletions(-) mode change 100644 => 100755 usr/local/bin/dynv6 diff --git a/usr/local/bin/check_updates b/usr/local/bin/check_updates index fedd88d..210c4ee 100755 --- a/usr/local/bin/check_updates +++ b/usr/local/bin/check_updates @@ -5,7 +5,7 @@ usage() { USAGE=$(cat < Found $line"; -done < "$DOCKER_CHECK_LIST_FILE" +done < "$listFileToUse" # check if current status is in array of DOCKER_CHECK_NOTIFY_LEVELS function shouldLog() { diff --git a/usr/local/bin/docker_compose_update b/usr/local/bin/docker_compose_update index cebd83a..3f2c565 100755 --- a/usr/local/bin/docker_compose_update +++ b/usr/local/bin/docker_compose_update @@ -5,7 +5,7 @@ usage() { USAGE=$(cat < Found $line"; -done < "$SYSTEMD_CHECK_LIST_FILE" +done < "$listFileToUse" # get status for a service function checkService() { diff --git a/usr/local/bin/systemd_failure_notify b/usr/local/bin/systemd_failure_notify index 91aac9d..b4ff7e0 100755 --- a/usr/local/bin/systemd_failure_notify +++ b/usr/local/bin/systemd_failure_notify @@ -14,7 +14,7 @@ OnFailure=systemd_failure_notify@%n.service You should place the 's service into systemd's user and systemd's system folder so it can be used by global and user services. -If no CONFIG_FILE is given, HOME/.systemd_failure_notify.conf is used. This fallback option +If no CONFIG_FILE is given, HOME/.systemd_failure_notify.conf or /etc/systemd_failure_notify.conf is used. This fallback option has to exist or the script will exit. Configuration can be done in any file and any pre-defined variable can be overwritten. @@ -43,26 +43,42 @@ SYSTEMD_FAILURE_NOTFY_USER=$(whoami) SYSTEMD_FAILURE_NOTIFY_MAIL_ADDRESS=""; # check for config file -source_config() { - local config=$1; - local configFallback=$2; +apply_config() { + local config=$1; - if [[ ! -f "$config" ]]; then - if [[ ! -f "$configFallback" ]]; then - echo "No config file specified and could not find default in '$configFallback'!"; - echo ""; - usage; - exit 1; - else - config=$configFallback; - fi - fi + if [[ ! -f "$config" ]]; then + echo "No config file specified"; + echo ""; + usage; + exit 1; + fi - set -a; - source "$config"; - set +a; + set -a; + source "$config"; + set +a; } -source_config "$2" "$HOME/.systemd_failure_notify.conf" + +source_config() { + local config=$1; + local configFallback=$2; + local configGlobalFallback=$3; + + if [[ -f "$config" ]]; then + apply_config "$config"; + exit 0; + fi + + if [[ -f "$configFallback" ]]; then + apply_config "$configFallback"; + exit 0; + fi + + if [[ -f "$configGlobalFallback" ]]; then + apply_config "$configGlobalFallback"; + exit 0; + fi +} +source_config "$2" "$HOME/.systemd_failure_notify.conf" "/etc/systemd_failure_notify.conf" SUBJECT="[systemd $SYSTEMD_FAILURE_NOTFY_HOSTNAME for $SYSTEMD_FAILURE_NOTFY_USER] $SYSTEMD_FAILURE_NOTFY_SERVICE RUN FAILED" MESSAGE="$SYSTEMD_FAILURE_NOTFY_SERVICE run failed"