various
This commit is contained in:
parent
2948a24fe8
commit
d218f3b102
3 changed files with 48 additions and 23 deletions
|
@ -3,7 +3,7 @@
|
|||
_PLUG_TITLE="ntfy Helper"
|
||||
_PLUG_DESCRIPTION=""
|
||||
_PLUG_ARGS=(
|
||||
"message;m;;string;(No Message)"
|
||||
"message;m;;string"
|
||||
"title;t;;string;(No Title)"
|
||||
"file;f;;path"
|
||||
"level;l;;string;info"
|
||||
|
@ -52,42 +52,43 @@ function main() {
|
|||
hostname="$(hostname -s)"
|
||||
invoked_by="$_invoked_by"
|
||||
level_emoji="$(get_level_emoji "$_level")"
|
||||
topic="$(get_topic "$_invoked_by")"
|
||||
|
||||
n_message="$_message"
|
||||
n_priority="$(get_level_priority "$_level")"
|
||||
n_title="$level_emoji [$hostname] $_title"
|
||||
n_topic="$(get_topic "$_invoked_by")"
|
||||
curl_command="curl"
|
||||
|
||||
body='{
|
||||
"message": "'$n_message'",
|
||||
"priority": '$n_priority',
|
||||
"tags": ["'$hostname'", "'$invoked_by'"],
|
||||
"title": "'$n_title'",
|
||||
"topic": "'$n_topic'"
|
||||
}'
|
||||
|
||||
curl_command="curl -d \"$body\""
|
||||
curl_command+=" -H \"Authorization: Bearer $token\""
|
||||
curl_command+=" -H \"Markdown: yes\""
|
||||
curl_command+=" -H \"Priority: $(get_level_priority "$_level")\""
|
||||
curl_command+=" -H \"Tags: $hostname,$invoked_by\""
|
||||
curl_command+=" -H \"Title: $level_emoji [$hostname] $_title\""
|
||||
|
||||
if [[ "$n_topic" == "zio_test" ]]; then
|
||||
curl_command+=" -H \"Cache: no\""
|
||||
fi
|
||||
if [[ "$_message" != "true" ]]; then
|
||||
curl_command+=" -H \"Message: $_message\""
|
||||
fi
|
||||
|
||||
if [[ "$_file" != "" ]]; then
|
||||
if [[ ! -f "$_file" ]]; then
|
||||
die "Cannot attach '$_file': file does not exist"
|
||||
fi
|
||||
|
||||
if [[ "$n_message" != "" ]]; then
|
||||
say warning "Cannot send --message/-m with --file/-f. Only sending file"
|
||||
fi
|
||||
|
||||
full_file="$(realpath -s "$_file")"
|
||||
|
||||
curl_command+=" -T \"$full_file\""
|
||||
curl_command+=" -H \"Filename: $(basename "$full_file")\""
|
||||
else
|
||||
# HACK: Attachments don't work if you use "Cache: no"
|
||||
if [[ "$topic" == "zio_test" ]]; then
|
||||
curl_command+=" -H \"Cache: no\""
|
||||
fi
|
||||
fi
|
||||
|
||||
curl_command+=" https://ntfy.zio.sh/"
|
||||
curl_command+=" https://ntfy.zio.sh/$topic"
|
||||
|
||||
echo $curl_command
|
||||
echo "$curl_command" | bash
|
||||
}
|
||||
|
||||
if [[ $_PLUG_INVOKED != "true" ]]; then
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue