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.
39 lines
845 B
39 lines
845 B
#!/bin/bash
|
|
|
|
## Send a notification with NTFY and check if the config file is complete
|
|
|
|
if [[ "$UID" == "0" ]]; then
|
|
NTFY_CONFIG_FILE="/etc/ntfy/ntfy.conf"
|
|
else
|
|
NTFY_CONFIG_FILE="$HOME/.config/ntfy/ntfy.conf"
|
|
fi
|
|
|
|
if ! [ -e "$NTFY_CONFIG_FILE" ]; then
|
|
mkdir -p "${NTFY_CONFIG_FILE%/*}"
|
|
## default option to change if needed
|
|
echo 'SERVER="https://ntfy.0k.io/"' > "$NTFY_CONFIG_FILE"
|
|
else
|
|
source "$NTFY_CONFIG_FILE"
|
|
|
|
for var in TOKEN SERVER; do
|
|
if ! [ -v "$var" ]; then
|
|
echo "Error: missing $var in $NTFY_CONFIG_FILE"
|
|
exit 1
|
|
fi
|
|
done
|
|
fi
|
|
|
|
exname=${0##*/}
|
|
usage="Usage: $exname CHANNEL MESSAGE"
|
|
|
|
if [ "$#" -ne 2 ]; then
|
|
echo "$usage" >&2
|
|
exit 1
|
|
fi
|
|
|
|
channel="$1"
|
|
message="$2"
|
|
|
|
curl -s -H "Authorization: Bearer $TOKEN" \
|
|
-d "$message" "$SERVER/$channel" > /dev/null
|
|
|