From 7e6b2eeccae3c7b7d21ea2554a9453f4a8994472 Mon Sep 17 00:00:00 2001 From: Zhong Lufan Date: Fri, 10 Jan 2020 12:43:35 +0800 Subject: [PATCH] Update --- AliyunOpenApiSDK.sh | 3 ++- example/UpdateSSLCert.sh | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/AliyunOpenApiSDK.sh b/AliyunOpenApiSDK.sh index 1324a68..e40a0e1 100644 --- a/AliyunOpenApiSDK.sh +++ b/AliyunOpenApiSDK.sh @@ -57,11 +57,12 @@ aliapi_rpc() { local _http_host=$1 _http_method=$2 local _query_str="" local _key _value + local i for (( i = 0; i < ${#_ali_key[@]}; ++i )); do _key=${_ali_key[$i]} _value=${_ali_value[$i]} # 参数值如果是以 () 结束,代表需要执行函数获取值,如果函数不存在,使用原始值。 - [[ ($(grep -E "^.+\(\)$" <<< "$_value") == "$_value" && $(type -t ${_value//()/}) == "function") ]] && _value=$(${_value//()/}) + [[ ($(grep -E "^.+\(\)$" <<< "$_value") == "$_value" && $(type -t "${_value//()/}") == "function") ]] && _value=$(${_value//()/}) _value=$(_urlencode "$_value") _query_str+="$_key=$_value&" done diff --git a/example/UpdateSSLCert.sh b/example/UpdateSSLCert.sh index cec8bf3..2cab99b 100644 --- a/example/UpdateSSLCert.sh +++ b/example/UpdateSSLCert.sh @@ -1,12 +1,12 @@ #!/usr/bin/env bash -# CAS https://help.aliyun.com/document_detail/126507.html -# CDN https://help.aliyun.com/document_detail/106661.html +# 使用的 OpenAPI +# CAS: https://help.aliyun.com/document_detail/126507.html +# CDN:https://help.aliyun.com/document_detail/106661.html # 可配合 acme.sh 使用的 renewHook 脚本:自动将新证书上传至阿里云并更新对应 CDN 域名,然后删除对应域名的旧证书。 # 每次 API 执行都会检测是否失败,如果失败,会中断脚本执行并返回自定义错误代码。 -# 导出 AliAccessKeyId 和 AliAccessKeySecret export AliAccessKeyId="" export AliAccessKeySecret="" # shellcheck disable=SC1091 @@ -24,6 +24,7 @@ ACME_ENV_LIST=( for value in "${ACME_ENV_LIST[@]}" ; do printenv "$value" > /dev/null || exit 1 done +unset value # 获取证书自定义函数 get_cert() { @@ -85,6 +86,8 @@ for domain in "${DOMAIN_LIST[@]}"; do ) aliapi_rpc "cdn.aliyuncs.com" "GET" "2018-05-10" "SetDomainServerCertificate" "${api_custom_key[*]}" "${api_custom_value[*]}" || exit 103 done +unset domain + # 删除旧的证书 for id in ${cert_list}; do api_custom_key=( @@ -95,3 +98,4 @@ for id in ${cert_list}; do ) aliapi_rpc "cas.aliyuncs.com" "GET" "2018-07-13" "DeleteUserCertificate" "${api_custom_key[*]}" "${api_custom_value[*]}" || exit 104 done +unset id