You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.1 KiB
49 lines
1.1 KiB
#!/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"
|