99 lines
2.7 KiB
Bash
Executable File
99 lines
2.7 KiB
Bash
Executable File
#!/bin/bash
|
|
#=========================================
|
|
# Author : Colben
|
|
# Create : 2025-11-01 20:10
|
|
#=========================================
|
|
|
|
set -euo pipefail
|
|
umask 022
|
|
export LANG=en_US.UTF-8
|
|
export TENCENTCLOUD_SECRET_ID='tencent secret id'
|
|
export TENCENTCLOUD_SECRET_KEY='tencent secret key'
|
|
|
|
DOMAIN=$CERTBOT_DOMAIN
|
|
SUB_DOMAIN=_acme-challenge
|
|
RECORD_ID=
|
|
RECORD_VA=$CERTBOT_VALIDATION
|
|
RECORD="txt record: $SUB_DOMAIN.$DOMAIN"
|
|
|
|
if [ -t 0 ]; then
|
|
function Print { echo -e "\033[36;1m$(date +'[%F %T]')\033[32;1m $*\033[0m"; }
|
|
function Warn { echo -e "\033[36;1m$(date +'[%F %T]')\033[33;1m $*\033[0m"; }
|
|
function Error { echo -e "\033[36;1m$(date +'[%F %T]')\033[31;1m $*\033[0m"; exit 1; }
|
|
else
|
|
#exec &> /var/log/$(basename ${0%.sh}).out
|
|
function Print { echo -e "$(date +'[%F %T INFO]') $*"; }
|
|
function Warn { echo -e "$(date +'[%F %T WARN]') $*"; }
|
|
function Error { echo -e "$(date +'[%F %T ERROR]') $*"; exit 1; }
|
|
fi
|
|
|
|
function Quit {
|
|
local exitCode=$?
|
|
[ 0 -ne $exitCode ] && Error Failed to request tencent api!
|
|
[ -z "${END:-}" ] && echo && Error Interrupted manually!
|
|
Print Succeeded to request tencent api and wait 30 seconds.
|
|
sleep 30
|
|
}
|
|
|
|
function GetTxtRecord {
|
|
local resp=
|
|
Warn Getting $RECORD ...
|
|
if resp=$(tccli dnspod DescribeRecordList \
|
|
--Domain $DOMAIN \
|
|
--Subdomain $SUB_DOMAIN \
|
|
--RecordType TXT); then
|
|
RECORD_ID=$(echo $resp | jq -rM ".RecordList[0].RecordId")
|
|
else
|
|
[ '255' == "$?" ] && Warn Not found $RECORD! && return 0
|
|
echo "$resp"
|
|
Error Failed to get $RECORD!
|
|
fi
|
|
}
|
|
|
|
function CreateTxtRecord {
|
|
Warn Creating $RECORD ...
|
|
tccli dnspod CreateTXTRecord \
|
|
--Domain $DOMAIN \
|
|
--SubDomain $SUB_DOMAIN \
|
|
--RecordLine '默认' \
|
|
--Value $RECORD_VA \
|
|
&& Print Succeeded to create $RECORD. \
|
|
&& return 0
|
|
Error Failed to create $RECORD!
|
|
}
|
|
|
|
function ModifyTxtRecord {
|
|
Warn Modifying $RECORD ...
|
|
tccli dnspod ModifyTXTRecord \
|
|
--Domain $DOMAIN \
|
|
--SubDomain $SUB_DOMAIN \
|
|
--RecordId $RECORD_ID \
|
|
--RecordLine '默认' \
|
|
--Value $RECORD_VA \
|
|
&& Print Succeeded to modify $RECORD. \
|
|
&& return 0
|
|
Error Failed to modify $RECORD!
|
|
}
|
|
|
|
function DeleteRecord {
|
|
Warn Deleting $RECORD ...
|
|
tccli dnspod DeleteRecord \
|
|
--Domain $DOMAIN \
|
|
--RecordId $RECORD_ID \
|
|
&& Print Succeeded to delete $RECORD. \
|
|
&& return 0
|
|
Error Failed to delete $RECORD!
|
|
}
|
|
|
|
function Main {
|
|
trap Quit EXIT
|
|
GetTxtRecord
|
|
[ -z "$RECORD_ID" ] && CreateTxtRecord
|
|
[ -z "$RECORD_ID" ] || ModifyTxtRecord
|
|
END=1
|
|
}
|
|
|
|
# Start here
|
|
Main
|
|
|