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.
 
 

45 lines
987 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
SERVER="https://ntfy.0k.io/"
if ! [ -e "$NTFY_CONFIG_FILE" ]; then
mkdir -p "${NTFY_CONFIG_FILE%/*}"
## default option to change if needed
echo "SERVER=$SERVER" > "$NTFY_CONFIG_FILE"
## else if $NTFY_CONFIG_FILE exist but SERVER is not defined
elif ! grep -q "^SERVER=" "$NTFY_CONFIG_FILE"; then
echo "SERVER=$SERVER" >> "$NTFY_CONFIG_FILE"
fi
source "$NTFY_CONFIG_FILE"
for var in SERVER LOGIN PASSWORD; do
if ! [ -v "$var" ]; then
echo "Error: missing $var in $NTFY_CONFIG_FILE"
exit 1
fi
done
exname=${0##*/}
usage="Usage: $exname CHANNEL MESSAGE"
if [ "$#" -ne 2 ]; then
echo "$usage" >&2
exit 1
fi
channel="$1"
message="$2"
curl -s -u $LOGIN:$PASSWORD \
-d "$message" "$SERVER/$channel" > /dev/null