From 7cb6247bcdf23ebb9058529a2a3eae67731e968d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Mon, 24 Oct 2022 01:30:25 +0200 Subject: [PATCH] run_webhook into own script --- libexec/kiwi-backup/run_command | 25 ++++++------------------- libexec/kiwi-backup/run_webhook | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 19 deletions(-) create mode 100755 libexec/kiwi-backup/run_webhook diff --git a/libexec/kiwi-backup/run_command b/libexec/kiwi-backup/run_command index 0586850..120f91b 100755 --- a/libexec/kiwi-backup/run_command +++ b/libexec/kiwi-backup/run_command @@ -6,22 +6,6 @@ this_dir="${this_script%/*}" # files duplicity_secrets_file="/root/duplicity_secrets" -run_webhook() { #url #message - if [ -z "${WEBHOOK_URL}" ]; then - return 1 - fi - - _rw_message="$(echo "${2}" | sed "s,\s,%20,g" )" - _rw_webhook_url="$(echo "${1}" | sed "s,%%MSG%%,${_rw_message},g" )" - - _rw_curl_args="" - if [ "${WEBHOOK_INSECURE}" = "1" ]; then - _rw_curl_args="--insecure" - fi - - curl ${_rw_curl_args} "${_rw_webhook_url}" 1>/dev/null 2>/dev/null -} - # load secrets file if [ -f "${duplicity_secrets_file}" ]; then # shellcheck disable=SC1090 @@ -36,7 +20,8 @@ if [ -n "${GPG_PASSPHRASE}" ]; then fi # run start webhook -run_webhook "${WEBHOOK_URL}" "running task ${*}" +/usr/local/libexec/kiwi-cron/run_webhook \ + "${WEBHOOK_URL}" "running task ${*}" "${WEBHOOK_INSECURE}" # hand over set -ex @@ -48,9 +33,11 @@ exit_status="${?}" # run finish webhook if [ "${exit_status}" -eq "0" ]; then - run_webhook "${WEBHOOK_URL}" "task ${*} successful" + /usr/local/libexec/kiwi-cron/run_webhook \ + "${WEBHOOK_URL}" "task ${*} successful" "${WEBHOOK_INSECURE}" else - run_webhook "${WEBHOOK_FAIL_URL:-${WEBHOOK_URL}}" "task ${*} failed, status ${exit_status}" + /usr/local/libexec/kiwi-cron/run_webhook \ + "${WEBHOOK_FAIL_URL:-${WEBHOOK_URL}}" "task ${*} failed, status ${exit_status}" "${WEBHOOK_INSECURE}" fi diff --git a/libexec/kiwi-backup/run_webhook b/libexec/kiwi-backup/run_webhook new file mode 100755 index 0000000..0447046 --- /dev/null +++ b/libexec/kiwi-backup/run_webhook @@ -0,0 +1,18 @@ +#!/bin/sh + +message="$(echo "${2}" | sed "s,\s,%20,g" )" +webhook_url="$(echo "${1}" | sed "s,%%MSG%%,${message},g" )" +webhook_insecure="${3:-0}" + + +if [ -z "${webhook_url}" ]; then + return 1 +fi + + +curl_args="" +if [ "${webhook_insecure}" = "1" ]; then + curl_args="--insecure" +fi + +curl ${curl_args} "${webhook_url}" 1>/dev/null 2>/dev/null