acme.sh/notify/pushbullet.sh

45 lines
1.6 KiB
Bash
Raw Permalink Normal View History

2021-07-11 23:29:44 +00:00
#!/usr/bin/env sh
#Support for pushbullet.com's api. Push notification, notification sync and message platform for multiple platforms
#PUSHBULLET_TOKEN="" Required, pushbullet application token
#PUSHBULLET_DEVICE="" Optional, Specific device, ignore to send to all devices
PUSHBULLET_URI="https://api.pushbullet.com/v2/pushes"
pushbullet_send() {
2021-07-16 01:55:35 +00:00
_subject="$1"
_content="$2"
_statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
_debug "_statusCode" "$_statusCode"
2021-07-11 23:29:44 +00:00
2021-07-16 01:55:35 +00:00
PUSHBULLET_TOKEN="${PUSHBULLET_TOKEN:-$(_readaccountconf_mutable PUSHBULLET_TOKEN)}"
if [ -z "$PUSHBULLET_TOKEN" ]; then
PUSHBULLET_TOKEN=""
_err "You didn't specify a Pushbullet application token yet."
return 1
fi
_saveaccountconf_mutable PUSHBULLET_TOKEN "$PUSHBULLET_TOKEN"
2021-07-11 23:29:44 +00:00
2021-07-16 01:55:35 +00:00
PUSHBULLET_DEVICE="${PUSHBULLET_DEVICE:-$(_readaccountconf_mutable PUSHBULLET_DEVICE)}"
2021-10-03 14:33:41 +00:00
if [ -z "$PUSHBULLET_DEVICE" ]; then
2021-10-03 14:31:56 +00:00
_clearaccountconf_mutable PUSHBULLET_DEVICE
else
2021-07-17 16:50:45 +00:00
_saveaccountconf_mutable PUSHBULLET_DEVICE "$PUSHBULLET_DEVICE"
2021-07-16 01:55:35 +00:00
fi
2021-07-11 23:29:44 +00:00
2021-07-16 01:55:35 +00:00
export _H1="Content-Type: application/json"
export _H2="Access-Token: ${PUSHBULLET_TOKEN}"
_content="$(printf "*%s*\n" "$_content" | _json_encode)"
_subject="$(printf "*%s*\n" "$_subject" | _json_encode)"
_data="{\"type\": \"note\",\"title\": \"${_subject}\",\"body\": \"${_content}\",\"device_iden\": \"${PUSHBULLET_DEVICE}\"}"
response="$(_post "$_data" "$PUSHBULLET_URI")"
2021-07-11 23:29:44 +00:00
2021-07-16 01:55:35 +00:00
if [ "$?" != "0" ] || _contains "$response" "\"error_code\""; then
_err "PUSHBULLET send error."
_err "$response"
return 1
fi
2021-07-11 23:29:44 +00:00
2021-07-16 01:55:35 +00:00
_info "PUSHBULLET send success."
return 0
2021-07-11 23:29:44 +00:00
}