-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-ddns.sh
executable file
·52 lines (47 loc) · 1.07 KB
/
update-ddns.sh
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
44
45
46
47
48
49
50
51
52
#!/usr/bin/env bash
source config.sh
get_current_ip() {
curl --retry 5 -s https://ipinfo.io/ip
}
current_IP=$(get_current_ip)
get_last_ip() {
cat ${scriptpath}/lastip.txt
}
last_IP=$(get_last_ip)
update_ip() {
echo "Updating IP..."
echo " "
echo "lastip.txt:"
cat ${scriptpath}/lastip.txt
echo " "
echo "Updating Njalla..."
curl --retry 5 -s "https://njal.la/update/?h=${njalladomain}&k=${njallakey}&auto&quiet"
echo "Njalla is updated."
echo " "
echo "Saving IP address..."
curl --retry 5 -s https://ipinfo.io/ip -o ${scriptpath}/lastip.txt
echo "IP address saved to file"
echo " "
echo "lastip.txt:"
cat ${scriptpath}/lastip.txt
echo " "
curl \
-d "New IP: ${current_IP}" \
-H "Title: New IP for ${hostname}" \
-H "Priority: high" \
https://ntfy.sh/${ntfytopic}
}
if [ "$last_IP" = "$current_IP" ]; then
echo " "
echo "Current IP is ${current_IP}"
echo "Saved IP is ${last_IP}"
echo "IP has not changed."
echo " "
else
echo " "
echo "Current IP is ${current_IP}"
echo "Saved IP is ${last_IP}"
echo "IP has changed."
echo " "
update_ip
fi