1
0
Fork 0
mirror of https://github.com/yavook/kiwi-backup.git synced 2024-11-22 06:53:00 +00:00

run_webhook into own script

This commit is contained in:
Jörn-Michael Miehe 2022-10-24 01:30:25 +02:00
parent 069287989f
commit 7cb6247bcd
2 changed files with 24 additions and 19 deletions

View file

@ -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

18
libexec/kiwi-backup/run_webhook Executable file
View file

@ -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