1
0
Fork 0
mirror of https://github.com/yavook/kiwi-backup.git synced 2025-04-11 16:03:01 +00:00
kiwi-backup/libexec/kiwi-backup/run_command

63 lines
1.7 KiB
Bash
Executable file

#!/bin/sh
this_script="$( readlink -f "${0}" )"
this_dir="${this_script%/*}"
# files
duplicity_secrets_file="/root/duplicity_secrets"
# load secrets file
if [ -f "${duplicity_secrets_file}" ]; then
# shellcheck disable=SC1090
. "${duplicity_secrets_file}"
fi
# handle more verbose "GPG_PASSPHRASE" env var
if [ -n "${GPG_PASSPHRASE}" ]; then
PASSPHRASE="${GPG_PASSPHRASE:-${PASSPHRASE}}"
export PASSPHRASE
unset GPG_PASSPHRASE
fi
run_webhook() {
_rw_webhook_url="${1}"
_rw_message="${2}"
_rw_curl_args=""
if [ "${WEBHOOK_INSECURE}" = "1" ]; then
_rw_curl_args="--insecure"
fi
_rw_webhook_url="$(echo "${_rw_webhook_url}" | sed "s,%%MSG%%,,g" )"
curl ${_rw_curl_args} "${_rw_webhook_url}" 1>/dev/null 2>/dev/null
}
# run start webhook
curl_args=""
if [ "${WEBHOOK_INSECURE}" = "1" ]; then
curl_args="--insecure"
fi
if [ -n "${WEBHOOK_URL}" ]; then
webhook_url="$(echo "${WEBHOOK_URL}" | sed "s,%%MSG%%,running%20task%20${*},g" )"
curl ${curl_args} "${webhook_url}" 1>/dev/null 2>/dev/null
fi
# hand over
set -ex
eval "$( \
"${this_dir}/build_command" \
"${@}" \
)"
exit_code="${?}"
# run finish webhook
if [ "${exit_code}" -eq "0" ] && [ -n "${WEBHOOK_URL}" ]; then
webhook_url="$(echo "${WEBHOOK_URL}" | sed "s,%%MSG%%,task%20${*}%20finished%20successfully,g" )"
curl ${curl_args} "${webhook_url}" 1>/dev/null 2>/dev/null
elif [ "${exit_code}" -ne "0" ] && [ -n "${WEBHOOK_URL}" ]; then
webhook_fail_url="$(echo "${WEBHOOK_FAIL_URL:-${WEBHOOK_URL}}" | sed "s,%%MSG%%,task%20${*}%20finished%20with%20status%20${exit_code},g" )"
curl ${curl_args} "${webhook_fail_url}" 1>/dev/null 2>/dev/null
fi