Skip to content

Instantly share code, notes, and snippets.

@biblia19
Last active August 15, 2022 06:35
Show Gist options
  • Select an option

  • Save biblia19/e9f3c8db39e271e0100fa146002bfb4f to your computer and use it in GitHub Desktop.

Select an option

Save biblia19/e9f3c8db39e271e0100fa146002bfb4f to your computer and use it in GitHub Desktop.
acme.sh DNS manaul mode semi automation issue
#!/bin/sh
DOMAIN=<your_domain_name>
VULTR_API_KEY=<vultr_DNS_only_API_Key>
file1="/tmp/acme.sh.tmp.log"
[ -f $file1 ] && rm $file1
file2="/tmp/TXT.tmp"
[ -f $file2 ] && rm $file2
# https://github.com/acmesh-official/acme.sh/wiki/DNS-manual-mode
acme.sh --issue --dns -d $DOMAIN -d "*.$DOMAIN" --yes-I-know-dns-manual-mode-enough-go-ahead-please >> /tmp/acme.sh.tmp.log
STATUS=$?
# https://github.com/acmesh-official/acme.sh/wiki/Exit-Codes
if [ $STATUS -eq 2 ]; then
# 2: certificate still valid, request skipped
exit 0
else
grep -o "'.*'" /tmp/acme.sh.tmp.log | sed "s/'//g" | grep -v $DOMAIN > /tmp/TXT.tmp
NAME1=$(grep -o "'.*" /tmp/acme.sh.tmp.log | sed "s/'//g" | grep $DOMAIN | grep -v '[*]' | tail -n2 | sed 's/[.].*$//' | head -n 1)
NAME2=$(grep -o "'.*" /tmp/acme.sh.tmp.log | sed "s/'//g" | grep $DOMAIN | grep -v '[*]' | tail -n2 | sed 's/[.].*$//' | tail -n 1)
DATA1=$(head -n1 /tmp/TXT.tmp)
DATA2=$(tail -n1 /tmp/TXT.tmp)
i=1
#rm /tmp/acme.sh.tmp.log
rm /tmp/TXT.tmp
NAME=$NAME1
# https://www.vultr.com/api/#operation/create-dns-domain-record
for DATA in "$DATA1" "$DATA2"; do
eval "ID$i='$(\
curl "https://api.vultr.com/v2/domains/${DOMAIN}/records" \
-X POST \
-H "Authorization: Bearer ${VULTR_API_KEY}" \
-H "Content-Type: application/json" \
--data '{
"name" : "'"${NAME}"'",
"type" : "TXT",
"data" : "'"${DATA}"'",
"ttl" : 300,
"priority" : 0
}' | jq -r '.record.id')'"
i=$((i+1))
NAME=$NAME2
done
echo 'Wait for 20 seconds'
sleep 20
acme.sh --issue --dns -d $DOMAIN -d "*.$DOMAIN" --yes-I-know-dns-manual-mode-enough-go-ahead-please --renew
# https://www.vultr.com/api/#operation/delete-dns-domain-record
for ID in "$ID1" "$ID2"; do
curl "https://api.vultr.com/v2/domains/${DOMAIN}/records/${ID}" \
-X DELETE \
-H "Authorization: Bearer ${VULTR_API_KEY}"
done
# Deploy Hook
# Any deploy hook you want
exit 0
fi
@biblia19

biblia19 commented Aug 14, 2022 •

Copy link
Copy Markdown
Author

It works in acme.sh docker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment