This repository was archived by the owner on Oct 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathadd-host-record.sh
More file actions
executable file
·73 lines (60 loc) · 1.66 KB
/
Copy pathadd-host-record.sh
File metadata and controls
executable file
·73 lines (60 loc) · 1.66 KB
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
64
65
66
67
68
69
70
71
72
73
#!/bin/sh
set -e
. $(dirname "$0")/common.sh
host=
ip=
ipVersion=v4
regNonQual=true
usage() {
echo "Usage $0 {-f} {-v 4|6} hostname ipaddress\n\n -f FQDN only. Sets registerNonQualified=false on the host record. Defaults to true.\n -v 4 or 6. Defaults to 4. Ignored by UDM firmware < 1.9.\n"
}
setIpVersion() {
if echo "$1" | grep -q "^v\?4$"; then
ipVersion=v4
elif echo "$1" | grep -q "^v\?6$"; then
ipVersion=v6
else
echo "Invalid IP version option. Must be 4 or 6."
usage
fi
}
handleArgument() {
if [ "${host}" = "" ]; then
host=$(echo "$1")
elif [ "${ip}" = "" ]; then
ip=$(echo "$1")
else
echo "Invalid number of arguments.\n"
usage
exit 1
fi
}
while [ "$#" -gt 0 ]; do
case "$1" in
-f) regNonQual=false; shift 1;;
-v) setIpVersion "$2"; shift 2;;
-*) echo "unknown option: $1" >&2; exit 1;;
*) handleArgument "$1"; shift 1;;
esac
done
if [ "${host}" = "" ]; then
echo "Host not specified\n"
usage
exit 1
fi
if [ "${ip}" = "" ]; then
echo "IP not specified\n"
usage
exit 1
fi
echo host=${host}
echo ip=${ip}
echo ipVersion=${ipVersion}
echo regNonQual=${regNonQual}
export host
export ip
export regNonQual
export ipVersion
updateServices '.dnsForwarder.hostRecords |= (. | map(. + { key: (.hostName | ascii_downcase), value: (.)}) | from_entries | . + ({ (env.host | ascii_downcase):{address:{address: (env.ip), origin: null, version: (env.ipVersion)}, hostName: (env.host), registerNonQualified: ("true" == env.regNonQual)}}) | to_entries | map(.value))'
echo "\nCurrent host records"
./list-host-records.sh