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.

51 lines
1.4 KiB

  1. #!/usr/bin/env sh
  2. #Support iOS Bark Notification
  3. #BARK_API_URL="https://api.day.app/xxxx"
  4. #BARK_SOUND="yyyy"
  5. #BARK_GROUP="zzzz"
  6. # subject content statusCode
  7. bark_send() {
  8. _subject="$1"
  9. _content="$2"
  10. _statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
  11. _debug "_subject" "$_subject"
  12. _debug "_content" "$_content"
  13. _debug "_statusCode" "$_statusCode"
  14. BARK_API_URL="${BARK_API_URL:-$(_readaccountconf_mutable BARK_API_URL)}"
  15. if [ -z "$BARK_API_URL" ]; then
  16. BARK_API_URL=""
  17. _err "You didn't specify a Bark API URL BARK_API_URL yet."
  18. _err "You can download Bark from App Store and get yours."
  19. return 1
  20. fi
  21. _saveaccountconf_mutable BARK_API_URL "$BARK_API_URL"
  22. BARK_SOUND="${BARK_SOUND:-$(_readaccountconf_mutable BARK_SOUND)}"
  23. _saveaccountconf_mutable BARK_SOUND "$BARK_SOUND"
  24. BARK_GROUP="${BARK_GROUP:-$(_readaccountconf_mutable BARK_GROUP)}"
  25. if [ -z "$BARK_GROUP" ]; then
  26. BARK_GROUP="ACME"
  27. _info "The BARK_GROUP is not set, so use the default ACME as group name."
  28. else
  29. _saveaccountconf_mutable BARK_GROUP "$BARK_GROUP"
  30. fi
  31. _content=$(echo "$_content" | _url_encode)
  32. _subject=$(echo "$_subject" | _url_encode)
  33. response="$(_get "$BARK_API_URL/$_subject/$_content?sound=$BARK_SOUND&group=$BARK_GROUP")"
  34. if [ "$?" = "0" ] && _contains "$response" "success"; then
  35. _info "Bark API fired success."
  36. return 0
  37. fi
  38. _err "Bark API fired error."
  39. _err "$response"
  40. return 1
  41. }