diff --git a/README.md b/README.md index 71297d3..c300c69 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,9 @@ echo "arDdnsCheck test.org subdomain" >> ./ardnspod # 最近更新 +2025/3/19 +- 支持删除记录,方便管理 + 2025/2/21 - 支持创建记录,当记录不存在时创建 diff --git a/ardnspod b/ardnspod index e3ed56a..9b4d38a 100644 --- a/ardnspod +++ b/ardnspod @@ -469,4 +469,50 @@ arDdnsCreate() { } +# Delete Record +# Args: domain subdomain recordType + +arDdnsDelete() { + + local errCode + local recordId + local recordType + local recordCd + local recordRs + + arLog "=== Delete $2.$1 ===" + + if [ "$3" = "6" ]; then + recordType=AAAA + else + recordType=A + fi + + arLog "> Record Type: $recordType" + + arLog "Fetching RecordId" + recordId=$(arDdnsLookup "$1" "$2" "$recordType") + + errCode=$? + if [ $errCode -eq 0 ]; then + arLog "> Record Id: $recordId" + else + return $errCode + fi + + arLog "Deleting Record" + recordRs=$(arDdnsApi "Record.Remove" "domain=$1&record_id=$recordId") + + # check result + recordCd=$(echo $recordRs | sed 's/.*{"code":"\([0-9]*\)".*/\1/') + if [ "$recordCd" != "1" ]; then + errMsg=$(echo $recordRs | sed 's/.*,"message":"\([^"]*\)".*/\1/') + arLog "> arDdnsDelete - error: $errMsg" + return 1 + fi + + arLog "> arDdnsDelete - successful" + +} + ################################################################### end ##