Skip to content

Commit ea94477

Browse files
authored
Merge pull request #5229 from tomo2403/master
Update bark.sh
2 parents f86ee84 + 522c953 commit ea94477

File tree

1 file changed

+90
-13
lines changed

1 file changed

+90
-13
lines changed

notify/bark.sh

+90-13
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,40 @@
11
#!/usr/bin/env sh
22

3-
#Support iOS Bark Notification
3+
# Support iOS Bark Notification
44

5-
#BARK_API_URL="https://api.day.app/xxxx"
6-
#BARK_SOUND="yyyy"
7-
#BARK_GROUP="zzzz"
5+
# Every parameter explained: https://github.com/Finb/bark-server/blob/master/docs/API_V2.md#push
86

9-
# subject content statusCode
7+
# BARK_API_URL="https://api.day.app/xxxx" (required)
8+
# BARK_GROUP="ACME" (optional)
9+
# BARK_SOUND="alarm" (optional)
10+
# BARK_LEVEL="active" (optional)
11+
# BARK_BADGE=0 (optional)
12+
# BARK_AUTOMATICALLYCOPY="1" (optional)
13+
# BARK_COPY="My clipboard Content" (optional)
14+
# BARK_ICON="https://example.com/icon.png" (optional)
15+
# BARK_ISARCHIVE="1" (optional)
16+
# BARK_URL="https://example.com" (optional)
17+
18+
# subject content statusCode
1019
bark_send() {
1120
_subject="$1"
1221
_content="$2"
13-
_statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
22+
_statusCode="$3" # 0: success, 1: error, 2: skipped
1423
_debug "_subject" "$_subject"
1524
_debug "_content" "$_content"
1625
_debug "_statusCode" "$_statusCode"
1726

27+
_content=$(echo "$_content" | _url_encode)
28+
_subject=$(echo "$_subject" | _url_encode)
29+
1830
BARK_API_URL="${BARK_API_URL:-$(_readaccountconf_mutable BARK_API_URL)}"
1931
if [ -z "$BARK_API_URL" ]; then
20-
BARK_API_URL=""
2132
_err "You didn't specify a Bark API URL BARK_API_URL yet."
2233
_err "You can download Bark from App Store and get yours."
2334
return 1
2435
fi
2536
_saveaccountconf_mutable BARK_API_URL "$BARK_API_URL"
2637

27-
BARK_SOUND="${BARK_SOUND:-$(_readaccountconf_mutable BARK_SOUND)}"
28-
_saveaccountconf_mutable BARK_SOUND "$BARK_SOUND"
29-
3038
BARK_GROUP="${BARK_GROUP:-$(_readaccountconf_mutable BARK_GROUP)}"
3139
if [ -z "$BARK_GROUP" ]; then
3240
BARK_GROUP="ACME"
@@ -35,10 +43,79 @@ bark_send() {
3543
_saveaccountconf_mutable BARK_GROUP "$BARK_GROUP"
3644
fi
3745

38-
_content=$(echo "$_content" | _url_encode)
39-
_subject=$(echo "$_subject" | _url_encode)
46+
BARK_SOUND="${BARK_SOUND:-$(_readaccountconf_mutable BARK_SOUND)}"
47+
if [ -n "$BARK_SOUND" ]; then
48+
_saveaccountconf_mutable BARK_SOUND "$BARK_SOUND"
49+
fi
50+
51+
BARK_LEVEL="${BARK_LEVEL:-$(_readaccountconf_mutable BARK_LEVEL)}"
52+
if [ -n "$BARK_LEVEL" ]; then
53+
_saveaccountconf_mutable BARK_LEVEL "$BARK_LEVEL"
54+
fi
55+
56+
BARK_BADGE="${BARK_BADGE:-$(_readaccountconf_mutable BARK_BADGE)}"
57+
if [ -n "$BARK_BADGE" ]; then
58+
_saveaccountconf_mutable BARK_BADGE "$BARK_BADGE"
59+
fi
60+
61+
BARK_AUTOMATICALLYCOPY="${BARK_AUTOMATICALLYCOPY:-$(_readaccountconf_mutable BARK_AUTOMATICALLYCOPY)}"
62+
if [ -n "$BARK_AUTOMATICALLYCOPY" ]; then
63+
_saveaccountconf_mutable BARK_AUTOMATICALLYCOPY "$BARK_AUTOMATICALLYCOPY"
64+
fi
65+
66+
BARK_COPY="${BARK_COPY:-$(_readaccountconf_mutable BARK_COPY)}"
67+
if [ -n "$BARK_COPY" ]; then
68+
_saveaccountconf_mutable BARK_COPY "$BARK_COPY"
69+
fi
70+
71+
BARK_ICON="${BARK_ICON:-$(_readaccountconf_mutable BARK_ICON)}"
72+
if [ -n "$BARK_ICON" ]; then
73+
_saveaccountconf_mutable BARK_ICON "$BARK_ICON"
74+
fi
75+
76+
BARK_ISARCHIVE="${BARK_ISARCHIVE:-$(_readaccountconf_mutable BARK_ISARCHIVE)}"
77+
if [ -n "$BARK_ISARCHIVE" ]; then
78+
_saveaccountconf_mutable BARK_ISARCHIVE "$BARK_ISARCHIVE"
79+
fi
80+
81+
BARK_URL="${BARK_URL:-$(_readaccountconf_mutable BARK_URL)}"
82+
if [ -n "$BARK_URL" ]; then
83+
_saveaccountconf_mutable BARK_URL "$BARK_URL"
84+
fi
85+
86+
_params=""
87+
88+
if [ -n "$BARK_SOUND" ]; then
89+
_params="$_params&sound=$BARK_SOUND"
90+
fi
91+
if [ -n "$BARK_GROUP" ]; then
92+
_params="$_params&group=$BARK_GROUP"
93+
fi
94+
if [ -n "$BARK_LEVEL" ]; then
95+
_params="$_params&level=$BARK_LEVEL"
96+
fi
97+
if [ -n "$BARK_BADGE" ]; then
98+
_params="$_params&badge=$BARK_BADGE"
99+
fi
100+
if [ -n "$BARK_AUTOMATICALLYCOPY" ]; then
101+
_params="$_params&automaticallyCopy=$BARK_AUTOMATICALLYCOPY"
102+
fi
103+
if [ -n "$BARK_COPY" ]; then
104+
_params="$_params&copy=$BARK_COPY"
105+
fi
106+
if [ -n "$BARK_ICON" ]; then
107+
_params="$_params&icon=$BARK_ICON"
108+
fi
109+
if [ -n "$BARK_ISARCHIVE" ]; then
110+
_params="$_params&isArchive=$BARK_ISARCHIVE"
111+
fi
112+
if [ -n "$BARK_URL" ]; then
113+
_params="$_params&url=$BARK_URL"
114+
fi
115+
116+
_params=$(echo "$_params" | sed 's/^&//') # remove leading '&' if exists
40117

41-
response="$(_get "$BARK_API_URL/$_subject/$_content?sound=$BARK_SOUND&group=$BARK_GROUP")"
118+
response="$(_get "$BARK_API_URL/$_subject/$_content?$_params")"
42119

43120
if [ "$?" = "0" ] && _contains "$response" "success"; then
44121
_info "Bark API fired success."

0 commit comments

Comments
 (0)