]> git.proxmox.com Git - mirror_acme.sh.git/blob - dnsapi/dns_nsd.sh
Merge pull request #4531 from NCDGHA/bugfix/issue_4530_fix_http_status_503
[mirror_acme.sh.git] / dnsapi / dns_nsd.sh
1 #!/usr/bin/env sh
2
3 #Nsd_ZoneFile="/etc/nsd/zones/example.com.zone"
4 #Nsd_Command="sudo nsd-control reload"
5
6 # args: fulldomain txtvalue
7 dns_nsd_add() {
8 fulldomain=$1
9 txtvalue=$2
10 ttlvalue=300
11
12 Nsd_ZoneFile="${Nsd_ZoneFile:-$(_readdomainconf Nsd_ZoneFile)}"
13 Nsd_Command="${Nsd_Command:-$(_readdomainconf Nsd_Command)}"
14
15 # Arg checks
16 if [ -z "$Nsd_ZoneFile" ] || [ -z "$Nsd_Command" ]; then
17 Nsd_ZoneFile=""
18 Nsd_Command=""
19 _err "Specify ENV vars Nsd_ZoneFile and Nsd_Command"
20 return 1
21 fi
22
23 if [ ! -f "$Nsd_ZoneFile" ]; then
24 Nsd_ZoneFile=""
25 Nsd_Command=""
26 _err "No such file: $Nsd_ZoneFile"
27 return 1
28 fi
29
30 _savedomainconf Nsd_ZoneFile "$Nsd_ZoneFile"
31 _savedomainconf Nsd_Command "$Nsd_Command"
32
33 echo "$fulldomain. $ttlvalue IN TXT \"$txtvalue\"" >>"$Nsd_ZoneFile"
34 _info "Added TXT record for $fulldomain"
35 _debug "Running $Nsd_Command"
36 if eval "$Nsd_Command"; then
37 _info "Successfully updated the zone"
38 return 0
39 else
40 _err "Problem updating the zone"
41 return 1
42 fi
43 }
44
45 # args: fulldomain txtvalue
46 dns_nsd_rm() {
47 fulldomain=$1
48 txtvalue=$2
49 ttlvalue=300
50
51 Nsd_ZoneFile="${Nsd_ZoneFile:-$(_readdomainconf Nsd_ZoneFile)}"
52 Nsd_Command="${Nsd_Command:-$(_readdomainconf Nsd_Command)}"
53
54 _sed_i "/$fulldomain. $ttlvalue IN TXT \"$txtvalue\"/d" "$Nsd_ZoneFile"
55 _info "Removed TXT record for $fulldomain"
56 _debug "Running $Nsd_Command"
57 if eval "$Nsd_Command"; then
58 _info "Successfully reloaded NSD "
59 return 0
60 else
61 _err "Problem reloading NSD"
62 return 1
63 fi
64 }