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

11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
  1. #!/bin/bash
  2. ## Send a notification with NTFY and check if the config file is complete
  3. if [[ "$UID" == "0" ]]; then
  4. NTFY_CONFIG_FILE="/etc/ntfy/ntfy.conf"
  5. else
  6. NTFY_CONFIG_FILE="$HOME/.config/ntfy/ntfy.conf"
  7. fi
  8. SERVER="https://ntfy.0k.io/"
  9. if ! [ -e "$NTFY_CONFIG_FILE" ]; then
  10. mkdir -p "${NTFY_CONFIG_FILE%/*}"
  11. ## default option to change if needed
  12. echo "SERVER=$SERVER" > "$NTFY_CONFIG_FILE"
  13. ## else if $NTFY_CONFIG_FILE exist but SERVER is not defined
  14. elif ! grep -q "^SERVER=" "$NTFY_CONFIG_FILE"; then
  15. echo "SERVER=$SERVER" >> "$NTFY_CONFIG_FILE"
  16. fi
  17. source "$NTFY_CONFIG_FILE"
  18. for var in SERVER LOGIN PASSWORD; do
  19. if ! [ -v "$var" ]; then
  20. echo "Error: missing $var in $NTFY_CONFIG_FILE"
  21. exit 1
  22. fi
  23. done
  24. exname=${0##*/}
  25. usage="Usage: $exname CHANNEL MESSAGE"
  26. if [ "$#" -ne 2 ]; then
  27. echo "$usage" >&2
  28. exit 1
  29. fi
  30. channel="$1"
  31. message="$2"
  32. curl -s -u $LOGIN:$PASSWORD \
  33. -d "$message" "$SERVER/$channel" > /dev/null