pushover.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env sh
  2. #Support for pushover.net's api. Push notification platform for multiple platforms
  3. #PUSHOVER_TOKEN="" Required, pushover application token
  4. #PUSHOVER_USER="" Required, pushover userkey
  5. #PUSHOVER_DEVICE="" Optional, Specific device or devices by hostnames, joining multiples with a comma (such as device=iphone,nexus5)
  6. #PUSHOVER_PRIORITY="" Optional, Lowest Priority (-2), Low Priority (-1), Normal Priority (0), High Priority (1)
  7. PUSHOVER_URI="https://api.pushover.net/1/messages.json"
  8. pushover_send() {
  9. _subject="$1"
  10. _content="$2"
  11. _statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
  12. _debug "_statusCode" "$_statusCode"
  13. PUSHOVER_TOKEN="${PUSHOVER_TOKEN:-$(_readaccountconf_mutable PUSHOVER_TOKEN)}"
  14. if [ -z "$PUSHOVER_TOKEN" ]; then
  15. PUSHOVER_TOKEN=""
  16. _err "You didn't specify a PushOver application token yet."
  17. return 1
  18. fi
  19. _saveaccountconf_mutable PUSHOVER_TOKEN "$PUSHOVER_TOKEN"
  20. PUSHOVER_USER="${PUSHOVER_USER:-$(_readaccountconf_mutable PUSHOVER_USER)}"
  21. if [ -z "$PUSHOVER_USER" ]; then
  22. PUSHOVER_USER=""
  23. _err "You didn't specify a PushOver UserKey yet."
  24. return 1
  25. fi
  26. _saveaccountconf_mutable PUSHOVER_USER "$PUSHOVER_USER"
  27. PUSHOVER_DEVICE="${PUSHOVER_DEVICE:-$(_readaccountconf_mutable PUSHOVER_DEVICE)}"
  28. if [ "$PUSHOVER_DEVICE" ]; then
  29. _saveaccountconf_mutable PUSHOVER_DEVICE "$PUSHOVER_DEVICE"
  30. fi
  31. PUSHOVER_PRIORITY="${PUSHOVER_PRIORITY:-$(_readaccountconf_mutable PUSHOVER_PRIORITY)}"
  32. if [ "$PUSHOVER_PRIORITY" ]; then
  33. _saveaccountconf_mutable PUSHOVER_PRIORITY "$PUSHOVER_PRIORITY"
  34. fi
  35. PUSHOVER_SOUND="${PUSHOVER_SOUND:-$(_readaccountconf_mutable PUSHOVER_SOUND)}"
  36. if [ "$PUSHOVER_SOUND" ]; then
  37. _saveaccountconf_mutable PUSHOVER_SOUND "$PUSHOVER_SOUND"
  38. fi
  39. export _H1="Content-Type: application/json"
  40. _content="$(printf "*%s*\n" "$_content" | _json_encode)"
  41. _subject="$(printf "*%s*\n" "$_subject" | _json_encode)"
  42. _data="{\"token\": \"$PUSHOVER_TOKEN\",\"user\": \"$PUSHOVER_USER\",\"title\": \"$_subject\",\"message\": \"$_content\",\"sound\": \"$PUSHOVER_SOUND\", \"device\": \"$PUSHOVER_DEVICE\", \"priority\": \"$PUSHOVER_PRIORITY\"}"
  43. response="$(_post "$_data" "$PUSHOVER_URI")"
  44. if [ "$?" = "0" ] && _contains "$response" "{\"status\":1"; then
  45. _info "PUSHOVER send success."
  46. return 0
  47. fi
  48. _err "PUSHOVER send error."
  49. _err "$response"
  50. return 1
  51. }