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