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

10 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. if ! [ -e "$NTFY_CONFIG_FILE" ]; then
  9. mkdir -p "${NTFY_CONFIG_FILE%/*}"
  10. ## default option to change if needed
  11. echo 'SERVER="https://ntfy.0k.io/"' > "$NTFY_CONFIG_FILE"
  12. else
  13. source "$NTFY_CONFIG_FILE"
  14. for var in TOKEN SERVER; do
  15. if ! [ -v "$var" ]; then
  16. echo "Error: missing $var in $NTFY_CONFIG_FILE"
  17. exit 1
  18. fi
  19. done
  20. fi
  21. exname=${0##*/}
  22. usage="Usage: $exname CHANNEL MESSAGE"
  23. if [ "$#" -ne 2 ]; then
  24. echo "$usage" >&2
  25. exit 1
  26. fi
  27. channel="$1"
  28. message="$2"
  29. curl -s -H "Authorization: Bearer $TOKEN" \
  30. -d "$message" "$SERVER/$channel" > /dev/null