-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathntfy_hook
43 lines (41 loc) · 1.2 KB
/
ntfy_hook
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/ash
hit_ntfy ()
{
# source configuration
. /etc/ntfy/mkinitcpio-ntfy.conf
# allow X seconds for passphrase entry before notifying
sleep ${NTFY_DELAY}
# wait for network connectivity
while ! ping -c 1 -w 1 one.one.one.one &> /dev/null
do
# if networking is set up via the net module of mkinitcpio-nfs-utils, the dns won't be working due to missing resolv.conf
# first check if resolv.conf exists
if [ ! -f /etc/resolv.conf ]; then
# if not, check if ipconfig got the dns from dhcp
for ethconf in $(find /tmp -name net-*.conf); do
. ${ethconf}
if [ "${IPV4DNS0}" != "0.0.0.0" ]; then
echo "nameserver ${IPV4DNS0}" > /etc/resolv.conf
break
elif [ "${IPV4DNS1}" != "0.0.0.0" ]; then
echo "nameserver ${IPV4DNS1}" > /etc/resolv.conf
break
fi
done
# if not, set the nameserver to Cloudflare
if [ ! -f /etc/resolv.conf ]; then
echo "nameserver 1.1.1.1" > /etc/resolv.conf
fi
fi
sleep 1
done
# send message
curl -s \
-H "Authorization: Bearer ${NTFY_AUTH_TOKEN}" \
-d "${NTFY_MESSAGE}" \
${NTFY_SERVER_URL} >/dev/null
}
run_hook ()
{
( hit_ntfy & )
}