-
Notifications
You must be signed in to change notification settings - Fork 31
/
updateIpv4.sh
executable file
·63 lines (55 loc) · 1.43 KB
/
updateIpv4.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
53
54
55
56
57
58
59
60
61
62
63
#!/bin/sh
#title :updateIpv4.sh
#description :
#author :[email protected]
#date :2022-05-03
#==============================================================================
if [ -n "$BASH_SOURCE" ]; then
workDir=$(
cd $(dirname "$BASH_SOURCE")
pwd
)
else
workDir=$(
cd $(dirname $0)
pwd
)
fi
. "$workDir"/base.sh
checkConfValid
if [ $? -eq 1 ]; then
echo "Missing param, please check config.conf "
exit
fi
externalIpv4Add=$(getIpv4Address)
echo "Get external ipv4 address: $externalIpv4Add"
currentStat=$(listRecord "$zoneId" "$recordName" "$apiKey")
if [ $? -eq 1 ]; then
echo "listRecord failed"
exit
fi
resourceId=$(echo "$currentStat" | sed -n '1p')
currentValue=$(echo "$currentStat" | sed -n '2p')
printf 'Get currentStat:
resourceId=%s
currentValue=%s\n' "$resourceId" "$currentValue"
if [ -z "$resourceId" ]; then
echo "record not exist, will create first"
createdRecordResourceId=$(createRecord "$zoneId" "$recordName" "$apiKey" "A" "$externalIpv4Add")
if [ $? -eq 0 ]; then
resourceId=$createdRecordResourceId
else
echo "Create record failed. Exit"
exit 1
fi
fi
if [ "$currentValue" = "$externalIpv4Add" ]; then
echo "DNS value already same as external address, will not update, exit."
exit 0
fi
updateRecord "$zoneId" "$recordName" "$apiKey" "$resourceId" "A" "$externalIpv4Add"
if [ $? -eq 0 ]; then
echo "update success"
else
echo "update failed"
fi