From f233ecfb88d7cd9c5323a660b45d32bd913dd5de Mon Sep 17 00:00:00 2001 From: Boris Gallet Date: Wed, 24 Jan 2024 16:08:29 +0100 Subject: [PATCH] new: [send] first step, send to ntfy using curl and use config /etc/ntfy file --- bin/send | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 bin/send diff --git a/bin/send b/bin/send new file mode 100755 index 0000000..2f6b0c9 --- /dev/null +++ b/bin/send @@ -0,0 +1,49 @@ +#!/bin/bash + +# Send a notification with NTFY and check if the config file is complete + +NTFY_FILE="$(pwd)/etc/ntfy" + +if [ ! -e "$NTFY_FILE" ]; then + + # default option to change if needed + echo 'SERVER="https://ntfy.0k.io/"' > "$NTFY_FILE" + +else + source "$NTFY_FILE" + + if [ -z "$TOKEN" ] || [ -z "$SERVER" ]; then + echo "Config file $NTFY_FILE is not complete" + + if [ -z "$TOKEN" ]; then + read -p "NTFY access TOKEN : " USER_TOKEN + echo "TOKEN=\"$USER_TOKEN\"" >> "$NTFY_FILE" + fi + + if [ -z "$SERVER" ]; then + read -p "NTFY server adress () : " USER_SERVER + echo "SERVER=\"$USER_SERVER\"" >> "$NTFY_FILE" + fi + fi +fi + +# We send the notification using curl +send() { + local CHANNEL="$1" + local MESSAGE="$2" + + + RESPONSE=$(curl -s -H "Authorization: Bearer $TOKEN" -d "$MESSAGE" "$SERVER/$CHANNEL") + + echo "$RESPONSE" +} + +if [ "$#" -ne 2 ]; then + echo "Usage to send info with NTFY : send CANAL \"Message\"" + exit 1 +fi + +USER_CHANNEL="$1" +USER_MESSAGE="$2" + +send "$USER_CHANNEL" "$USER_MESSAGE" \ No newline at end of file -- 2.30.2