new: [send] first step, send to ntfy using curl and use config /etc/ntfy file #4

Closed
bgallet wants to merge 1 commits from bgallet:send_ntfy into master
  1. 49
      bin/send

49
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"
Loading…
Cancel
Save