Skip to content

Instantly share code, notes, and snippets.

@garrydzeng
Last active September 12, 2025 06:39
Show Gist options
  • Select an option

  • Save garrydzeng/0f9282ae74af838c9fad244b0351d831 to your computer and use it in GitHub Desktop.

Select an option

Save garrydzeng/0f9282ae74af838c9fad244b0351d831 to your computer and use it in GitHub Desktop.
Script for alidns + certbot --manual-auth-hook & --manual-cleanup-hook
#!/usr/bin/env bash
set -e
which aliyun &> /dev/null
if [[ $? -eq 0 ]]; then
aliyun alidns AddDomainRecord --DomainName $CERTBOT_DOMAIN --RR _acme-challenge --Type TXT --Value $CERTBOT_VALIDATION
fi
#!/usr/bin/env bash
set -u
which aliyun jq &> /dev/null
if [[ $? -eq 0 ]]; then
set -euo pipefail
PAGE=1
while true; do
LIST=$(aliyun alidns DescribeDomainRecords --DomainName $CERTBOT_DOMAIN --Type TXT --RRKeyWord _acme-challenge --PageNumber $PAGE | jq -r .DomainRecords.Record[].RecordId)
if [[ -z $LIST ]]; then
break
fi
((PAGE++))
echo "$LIST" | while read -r ID; do
aliyun alidns DeleteDomainRecord --RecordId $ID
done
done
fi
certbot certonly -d *.example.com -d example.com --preferred-chain 'ISRG Root X2' --preferred-challenges dns --manual --manual-auth-hook /usr/local/etc/letsencrypt/authenticate.sh --manual-cleanup-hook /usr/local/etc/letsencrypt/clear.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment