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.

128 lines
3.8 KiB

  1. #!/usr/bin/env sh
  2. # Support iOS Bark Notification
  3. # Every parameter explained: https://github.com/Finb/bark-server/blob/master/docs/API_V2.md#push
  4. # BARK_API_URL="https://api.day.app/xxxx" (required)
  5. # BARK_GROUP="ACME" (optional)
  6. # BARK_SOUND="alarm" (optional)
  7. # BARK_LEVEL="active" (optional)
  8. # BARK_BADGE=0 (optional)
  9. # BARK_AUTOMATICALLYCOPY="1" (optional)
  10. # BARK_COPY="My clipboard Content" (optional)
  11. # BARK_ICON="https://example.com/icon.png" (optional)
  12. # BARK_ISARCHIVE="1" (optional)
  13. # BARK_URL="https://example.com" (optional)
  14. # subject content statusCode
  15. bark_send() {
  16. _subject="$1"
  17. _content="$2"
  18. _statusCode="$3" # 0: success, 1: error, 2: skipped
  19. _debug "_subject" "$_subject"
  20. _debug "_content" "$_content"
  21. _debug "_statusCode" "$_statusCode"
  22. _content=$(echo "$_content" | _url_encode)
  23. _subject=$(echo "$_subject" | _url_encode)
  24. BARK_API_URL="${BARK_API_URL:-$(_readaccountconf_mutable BARK_API_URL)}"
  25. if [ -z "$BARK_API_URL" ]; then
  26. _err "You didn't specify a Bark API URL BARK_API_URL yet."
  27. _err "You can download Bark from App Store and get yours."
  28. return 1
  29. fi
  30. _saveaccountconf_mutable BARK_API_URL "$BARK_API_URL"
  31. BARK_GROUP="${BARK_GROUP:-$(_readaccountconf_mutable BARK_GROUP)}"
  32. if [ -z "$BARK_GROUP" ]; then
  33. BARK_GROUP="ACME"
  34. _info "The BARK_GROUP is not set, so use the default ACME as group name."
  35. else
  36. _saveaccountconf_mutable BARK_GROUP "$BARK_GROUP"
  37. fi
  38. BARK_SOUND="${BARK_SOUND:-$(_readaccountconf_mutable BARK_SOUND)}"
  39. if [ -n "$BARK_SOUND" ]; then
  40. _saveaccountconf_mutable BARK_SOUND "$BARK_SOUND"
  41. fi
  42. BARK_LEVEL="${BARK_LEVEL:-$(_readaccountconf_mutable BARK_LEVEL)}"
  43. if [ -n "$BARK_LEVEL" ]; then
  44. _saveaccountconf_mutable BARK_LEVEL "$BARK_LEVEL"
  45. fi
  46. BARK_BADGE="${BARK_BADGE:-$(_readaccountconf_mutable BARK_BADGE)}"
  47. if [ -n "$BARK_BADGE" ]; then
  48. _saveaccountconf_mutable BARK_BADGE "$BARK_BADGE"
  49. fi
  50. BARK_AUTOMATICALLYCOPY="${BARK_AUTOMATICALLYCOPY:-$(_readaccountconf_mutable BARK_AUTOMATICALLYCOPY)}"
  51. if [ -n "$BARK_AUTOMATICALLYCOPY" ]; then
  52. _saveaccountconf_mutable BARK_AUTOMATICALLYCOPY "$BARK_AUTOMATICALLYCOPY"
  53. fi
  54. BARK_COPY="${BARK_COPY:-$(_readaccountconf_mutable BARK_COPY)}"
  55. if [ -n "$BARK_COPY" ]; then
  56. _saveaccountconf_mutable BARK_COPY "$BARK_COPY"
  57. fi
  58. BARK_ICON="${BARK_ICON:-$(_readaccountconf_mutable BARK_ICON)}"
  59. if [ -n "$BARK_ICON" ]; then
  60. _saveaccountconf_mutable BARK_ICON "$BARK_ICON"
  61. fi
  62. BARK_ISARCHIVE="${BARK_ISARCHIVE:-$(_readaccountconf_mutable BARK_ISARCHIVE)}"
  63. if [ -n "$BARK_ISARCHIVE" ]; then
  64. _saveaccountconf_mutable BARK_ISARCHIVE "$BARK_ISARCHIVE"
  65. fi
  66. BARK_URL="${BARK_URL:-$(_readaccountconf_mutable BARK_URL)}"
  67. if [ -n "$BARK_URL" ]; then
  68. _saveaccountconf_mutable BARK_URL "$BARK_URL"
  69. fi
  70. _params=""
  71. if [ -n "$BARK_SOUND" ]; then
  72. _params="$_params&sound=$BARK_SOUND"
  73. fi
  74. if [ -n "$BARK_GROUP" ]; then
  75. _params="$_params&group=$BARK_GROUP"
  76. fi
  77. if [ -n "$BARK_LEVEL" ]; then
  78. _params="$_params&level=$BARK_LEVEL"
  79. fi
  80. if [ -n "$BARK_BADGE" ]; then
  81. _params="$_params&badge=$BARK_BADGE"
  82. fi
  83. if [ -n "$BARK_AUTOMATICALLYCOPY" ]; then
  84. _params="$_params&automaticallyCopy=$BARK_AUTOMATICALLYCOPY"
  85. fi
  86. if [ -n "$BARK_COPY" ]; then
  87. _params="$_params&copy=$BARK_COPY"
  88. fi
  89. if [ -n "$BARK_ICON" ]; then
  90. _params="$_params&icon=$BARK_ICON"
  91. fi
  92. if [ -n "$BARK_ISARCHIVE" ]; then
  93. _params="$_params&isArchive=$BARK_ISARCHIVE"
  94. fi
  95. if [ -n "$BARK_URL" ]; then
  96. _params="$_params&url=$BARK_URL"
  97. fi
  98. _params=$(echo "$_params" | sed 's/^&//') # remove leading '&' if exists
  99. response="$(_get "$BARK_API_URL/$_subject/$_content?$_params")"
  100. if [ "$?" = "0" ] && _contains "$response" "success"; then
  101. _info "Bark API fired success."
  102. return 0
  103. fi
  104. _err "Bark API fired error."
  105. _err "$response"
  106. return 1
  107. }