ntfy.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env sh
  2. # support ntfy
  3. #NTFY_URL="https://ntfy.sh"
  4. #NTFY_TOPIC="xxxxxxxxxxxxx"
  5. #NTFY_TOKEN="xxxxxxxxxxxxx"
  6. ntfy_send() {
  7. _subject="$1"
  8. _content="$2"
  9. _statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
  10. _debug "_subject" "$_subject"
  11. _debug "_content" "$_content"
  12. _debug "_statusCode" "$_statusCode"
  13. NTFY_URL="${NTFY_URL:-$(_readaccountconf_mutable NTFY_URL)}"
  14. if [ "$NTFY_URL" ]; then
  15. _saveaccountconf_mutable NTFY_URL "$NTFY_URL"
  16. fi
  17. NTFY_TOPIC="${NTFY_TOPIC:-$(_readaccountconf_mutable NTFY_TOPIC)}"
  18. if [ "$NTFY_TOPIC" ]; then
  19. _saveaccountconf_mutable NTFY_TOPIC "$NTFY_TOPIC"
  20. fi
  21. NTFY_TOKEN="${NTFY_TOKEN:-$(_readaccountconf_mutable NTFY_TOKEN)}"
  22. if [ "$NTFY_TOKEN" ]; then
  23. _saveaccountconf_mutable NTFY_TOKEN "$NTFY_TOKEN"
  24. export _H1="Authorization: Bearer $NTFY_TOKEN"
  25. fi
  26. _data="${_subject}. $_content"
  27. response="$(_post "$_data" "$NTFY_URL/$NTFY_TOPIC" "" "POST" "")"
  28. if [ "$?" = "0" ] && _contains "$response" "expires"; then
  29. _info "ntfy event fired success."
  30. return 0
  31. fi
  32. _err "ntfy event fired error."
  33. _err "$response"
  34. return 1
  35. }