forked from alambrec/validation-hooks-certbot-godaddy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleanup_godaddy.sh
executable file
·76 lines (62 loc) · 1.5 KB
/
cleanup_godaddy.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
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
LOG_DIR="/tmp"
LOG_FILE="$LOG_DIR/cleanup.$CERTBOT_DOMAIN.log"
echo "" > $LOG_FILE
function log {
DATE=$(date)
echo "$DATE: $1" >> $LOG_FILE
}
log "[BEGIN]"
# Get your API key from https://developer.godaddy.com
API_KEY="your_api_key_here"
API_SECRET="your_api_secret_here"
# Init variables
DOMAIN=""
SUBDOMAIN=""
# Detection of root domain or subdomain
if [ "$(uname -s)" == "Darwin" ]
then
DOMAIN=$(expr "$CERTBOT_DOMAIN" : '.*\.\(.*\..*\)')
if [[ ! -z "${DOMAIN// }" ]]
then
log "SUBDOMAIN DETECTED"
SUBDOMAIN=$(echo "$CERTBOT_DOMAIN" | awk -F"." '{print $1}')
else
DOMAIN=$CERTBOT_DOMAIN
fi
else
DOMAIN=$(expr match "$CERTBOT_DOMAIN" '.*\.\(.*\..*\)')
if [[ ! -z "${DOMAIN// }" ]]
then
log "SUBDOMAIN DETECTED"
SUBDOMAIN=$(echo "$CERTBOT_DOMAIN" | awk -F"." '{print $1}')
else
DOMAIN=$CERTBOT_DOMAIN
fi
fi
log "DOMAIN $DOMAIN"
log "SUBDOMAIN $SUBDOMAIN"
# Update TXT record
RECORD_TYPE="TXT"
RECORD_VALUE="none"
if [[ ! -z "${SUBDOMAIN// }" ]]
then
RECORD_NAME="_acme-challenge.$SUBDOMAIN"
else
RECORD_NAME="_acme-challenge"
fi
log "RECORD_NAME $RECORD_NAME"
# Update the previous record to default value
JSON_RESPONSE=$(curl -s -X PUT \
-H "Authorization: sso-key $API_KEY:$API_SECRET" \
-H "Content-Type: application/json" \
-d "[{\"data\": \"$RECORD_VALUE\", \"ttl\": 600}]" \
"https://api.godaddy.com/v1/domains/$DOMAIN/records/$RECORD_TYPE/$RECORD_NAME")
if [ $JSON_RESPONSE == "{}" ]
then
log "OK"
else
log "KO"
log $JSON_RESPONSE
fi
log "[END]"