-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcleanup.sh
executable file
·57 lines (50 loc) · 1.78 KB
/
cleanup.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
#!/bin/bash
# NameSileCertbot-DNS-01 0.2.2
## https://stackoverflow.com/questions/59895
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
echo "Received request for" "${CERTBOT_DOMAIN}"
cd ${DIR}
source config.sh
DOMAIN=${CERTBOT_DOMAIN}
## Get current list (updating may alter rrid, etc)
curl -s "https://www.namesilo.com/api/dnsListRecords?version=1&type=xml&key=$APIKEY&domain=$DOMAIN" > $CACHE$DOMAIN.xml
## Check for existing ACME record
if grep -q "_acme-challenge" $CACHE$DOMAIN.xml ; then
## Get record ID
RECORD_ID=`xmllint --xpath "//namesilo/reply/resource_record/record_id[../host/text() = '_acme-challenge.$DOMAIN' ]" $CACHE$DOMAIN.xml | grep -oP '(?<=<record_id>).*?(?=</record_id>)'`
## Update DNS record in Namesilo:
curl -s "https://www.namesilo.com/api/dnsDeleteRecord?version=1&type=xml&key=$APIKEY&domain=$DOMAIN&rrid=$RECORD_ID" > $RESPONSE
RESPONSE_CODE=`xmllint --xpath "//namesilo/reply/code/text()" $RESPONSE`
## Process response, maybe wait
case $RESPONSE_CODE in
300)
echo "ACME challenge record successfully removed"
;;
280)
RESPONSE_DETAIL=`xmllint --xpath "//namesilo/reply/detail/text()" $RESPONSE`
echo "Record removal failed."
echo "Domain: $DOMAIN"
echo "rrid: $RECORD_ID"
echo "reason: $RESPONSE_DETAIL"
;;
*)
RESPONSE_DETAIL=`xmllint --xpath "//namesilo/reply/detail/text()" $RESPONSE`
echo "Namesilo returned code: $RESPONSE_CODE"
echo "Reason: $RESPONSE_DETAIL"
echo "Domain: $DOMAIN"
echo "rrid: $RECORD_ID"
;;
esac
fi
if [ -f $RESPONSE ] ; then
rm $RESPONSE
fi
if [ -f $CACHE$DOMAIN.xml ] ; then
rm $CACHE$DOMAIN.xml
fi