various
parent
3b677d0816
commit
bbdc4eaa42
|
@ -48,6 +48,7 @@
|
|||
!/usr/local/bin/sh.zio.backup
|
||||
!/usr/local/bin/sh.zio.github-runner-wrapper
|
||||
!/usr/local/bin/sh.zio.install-package
|
||||
!/usr/local/bin/sh.zio.notify
|
||||
!/usr/local/bin/sh.zio.pod-exec
|
||||
!/usr/local/bin/sh.zio.pod-systemd
|
||||
!/usr/local/bin/sh.zio.update-rootfs
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
_PLUG_TITLE="ntfy Helper"
|
||||
_PLUG_DESCRIPTION=""
|
||||
_PLUG_ARGS=(
|
||||
"message;m;;string;(No Message)"
|
||||
"title;t;;string;(No Title)"
|
||||
"level;l;;string;info"
|
||||
"invoker;i;;string"
|
||||
)
|
||||
|
||||
function get_level_emoji() {
|
||||
case "$1" in
|
||||
"critical"|"error") echo "⛔" ;;
|
||||
"warning") echo "⚠️" ;;
|
||||
"success") echo "✅" ;;
|
||||
"info") echo "ℹ️" ;;
|
||||
"debug"|*) echo "🔧" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
function get_level_priority() {
|
||||
case "$1" in
|
||||
"critical") echo "5" ;;
|
||||
"error") echo "4" ;;
|
||||
"warning") echo "4" ;;
|
||||
"success") echo "3" ;;
|
||||
"info") echo "2" ;;
|
||||
"debug"|*) echo "1" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
function main() {
|
||||
token_path="$(get_config_dir "sh.zio.notify")/token"
|
||||
[[ ! -f "$token_path" ]] && die "'$token_path' does not exist"
|
||||
|
||||
token="$(cat "$token_path")"
|
||||
|
||||
hostname="$(hostname -s)"
|
||||
invoker="$_invoker"
|
||||
level_emoji="$(get_level_emoji "$_level")"
|
||||
triggered_by="sh.zio.backup"
|
||||
|
||||
n_message="$_message"
|
||||
n_priority="$(get_level_priority "$_level")"
|
||||
n_title="$level_emoji [$hostname] $_title"
|
||||
n_topic="zio_backup_a123"
|
||||
|
||||
body='{
|
||||
"message": "'$n_message'",
|
||||
"priority": '$n_priority',
|
||||
"tags": ["'$hostname'", "'$invoker'"],
|
||||
"title": "'$n_title'",
|
||||
"topic": "'$n_topic'"
|
||||
}'
|
||||
|
||||
curl -d "$body" -H "Authorization: Bearer $token" -H "Cache: no" "https://ntfy.zio.sh/"
|
||||
}
|
||||
|
||||
if [[ $_PLUG_INVOKED != "true" ]]; then
|
||||
base_dir="$(dirname "$(realpath -s "$0")")"
|
||||
git_dir="$base_dir/../../.."
|
||||
|
||||
if [[ -d "$git_dir/.git" ]]; then
|
||||
. "$git_dir/usr/local/libexec/zio/helpers/bash.sh"
|
||||
else
|
||||
. "/usr/local/libexec/zio/helpers/bash.sh"
|
||||
fi
|
||||
|
||||
export -f get_config_dir
|
||||
|
||||
if [[ -d "$git_dir/.git" ]]; then
|
||||
"$git_dir/usr/local/libexec/sodalite/invoker/src/invoke.sh" "$0" $@
|
||||
else
|
||||
"/usr/local/libexec/sodalite/invoker/src/invoke.sh" "$0" $@
|
||||
fi
|
||||
fi
|
Loading…
Reference in New Issue