acme.sh/dnsapi/dns_nsd.sh

81 lines
2.0 KiB
Bash
Raw Normal View History

#!/bin/bash
2019-04-30 23:53:51 +00:00
#Nsd_ZoneFile="/etc/nsd/zones/example.com.zone"
#Nsd_Command="sudo nsd-control reload"
#Nsd_ZonesDir="/etc/nsd/zones"
2019-04-30 23:53:51 +00:00
# args: fulldomain txtvalue
2019-05-01 10:17:54 +00:00
dns_nsd_add() {
2019-04-30 23:53:51 +00:00
fulldomain=$1
txtvalue=$2
ttlvalue=300
Nsd_ZoneFile="${Nsd_ZoneFile:-$(_readdomainconf Nsd_ZoneFile)}"
Nsd_Command="${Nsd_Command:-$(_readdomainconf Nsd_Command)}"
Nsd_ZonesDir="${Nsd_ZonesDir:-$(_readdomainconf Nsd_ZonesDir)}"
2019-04-30 23:53:51 +00:00
# Arg checks
if [ -n "$Nsd_ZonesDir" ]; then
Nsd_ZoneFile="$Nsd_ZonesDir/$fulldomain.zone"
fi
2019-04-30 23:53:51 +00:00
if [ -z "$Nsd_ZoneFile" ] || [ -z "$Nsd_Command" ]; then
Nsd_ZoneFile=""
Nsd_Command=""
_err "Specify ENV vars Nsd_ZoneFile and Nsd_Command"
return 1
fi
if [ ! -f "$Nsd_ZoneFile" ]; then
Nsd_ZoneFile=""
Nsd_Command=""
_err "No such file: $Nsd_ZoneFile"
return 1
fi
if [ -n "$Nsd_ZonesDir" ]; then
Nsd_ZoneFile="$Nsd_ZonesDir/$fulldomain.zone"
_cleardomainconf Nsd_ZoneFile
_savedomainconf Nsd_Command "$Nsd_Command"
_savedomainconf Nsd_ZonesDir "$Nsd_ZonesDir"
else
_cleardomainconf Nsd_ZonesDir
_savedomainconf Nsd_ZoneFile "$Nsd_ZoneFile"
_savedomainconf Nsd_Command "$Nsd_Command"
fi
2019-04-30 23:53:51 +00:00
2019-05-01 10:17:54 +00:00
echo "$fulldomain. $ttlvalue IN TXT \"$txtvalue\"" >>"$Nsd_ZoneFile"
2019-04-30 23:53:51 +00:00
_info "Added TXT record for $fulldomain"
_debug "Running $Nsd_Command"
if eval "$Nsd_Command"; then
_info "Successfully updated the zone"
return 0
else
_err "Problem updating the zone"
return 1
fi
}
# args: fulldomain txtvalue
2019-05-01 10:17:54 +00:00
dns_nsd_rm() {
2019-04-30 23:53:51 +00:00
fulldomain=$1
txtvalue=$2
ttlvalue=300
Nsd_ZoneFile="${Nsd_ZoneFile:-$(_readdomainconf Nsd_ZoneFile)}"
Nsd_Command="${Nsd_Command:-$(_readdomainconf Nsd_Command)}"
Nsd_ZonesDir="${Nsd_ZonesDir:-$(_readdomainconf Nsd_ZonesDir)}"
2019-04-30 23:53:51 +00:00
sed -i "/$fulldomain. $ttlvalue IN TXT \"$txtvalue\"/d" "$Nsd_ZoneFile"
2019-04-30 23:53:51 +00:00
_info "Removed TXT record for $fulldomain"
_debug "Running $Nsd_Command"
if eval "$Nsd_Command"; then
_info "Successfully reloaded NSD "
return 0
else
_err "Problem reloading NSD"
return 1
fi
}