fix shellcheck warnings

This commit is contained in:
neilpang 2016-11-11 23:30:14 +08:00
parent 031e885e4d
commit c7b16249b8
10 changed files with 108 additions and 108 deletions

10
acme.sh
View File

@ -411,7 +411,7 @@ _digest() {
outputhex="$2" outputhex="$2"
if [ "$alg" = "sha256" ] || [ "$alg" = "sha1" ]; then if [ "$alg" = "sha256" ] || [ "$alg" = "sha1" ] || [ "$alg" = "md5" ]; then
if [ "$outputhex" ]; then if [ "$outputhex" ]; then
openssl dgst -"$alg" -hex | cut -d = -f 2 | tr -d ' ' openssl dgst -"$alg" -hex | cut -d = -f 2 | tr -d ' '
else else
@ -2290,10 +2290,10 @@ _findHook() {
_hookcat="$2" _hookcat="$2"
_hookname="$3" _hookname="$3"
if [ -f "$_SCRIPT_HOME/$_hookdomain/$_hookname" ]; then if [ -f "$_SCRIPT_HOME/$_hookcat/$_hookname" ]; then
d_api="$_SCRIPT_HOME/$_hookdomain/$_hookname" d_api="$_SCRIPT_HOME/$_hookcat/$_hookname"
elif [ -f "$_SCRIPT_HOME/$_hookdomain/$_hookname.sh" ]; then elif [ -f "$_SCRIPT_HOME/$_hookcat/$_hookname.sh" ]; then
d_api="$_SCRIPT_HOME/$_hookdomain/$_hookname.sh" d_api="$_SCRIPT_HOME/$_hookcat/$_hookname.sh"
elif [ -f "$LE_WORKING_DIR/$_hookdomain/$_hookname" ]; then elif [ -f "$LE_WORKING_DIR/$_hookdomain/$_hookname" ]; then
d_api="$LE_WORKING_DIR/$_hookdomain/$_hookname" d_api="$LE_WORKING_DIR/$_hookdomain/$_hookname"
elif [ -f "$LE_WORKING_DIR/$_hookdomain/$_hookname.sh" ]; then elif [ -f "$LE_WORKING_DIR/$_hookdomain/$_hookname.sh" ]; then

View File

@ -25,7 +25,7 @@ dns_cf_add() {
_saveaccountconf CF_Email "$CF_Email" _saveaccountconf CF_Email "$CF_Email"
_debug "First detect the root zone" _debug "First detect the root zone"
if ! _get_root $fulldomain; then if ! _get_root "$fulldomain"; then
_err "invalid domain" _err "invalid domain"
return 1 return 1
fi fi
@ -36,7 +36,7 @@ dns_cf_add() {
_debug "Getting txt records" _debug "Getting txt records"
_cf_rest GET "zones/${_domain_id}/dns_records?type=TXT&name=$fulldomain" _cf_rest GET "zones/${_domain_id}/dns_records?type=TXT&name=$fulldomain"
if ! printf "$response" | grep \"success\":true >/dev/null; then if ! printf "%s" "$response" | grep \"success\":true >/dev/null; then
_err "Error" _err "Error"
return 1 return 1
fi fi
@ -46,7 +46,7 @@ dns_cf_add() {
if [ "$count" = "0" ]; then if [ "$count" = "0" ]; then
_info "Adding record" _info "Adding record"
if _cf_rest POST "zones/$_domain_id/dns_records" "{\"type\":\"TXT\",\"name\":\"$fulldomain\",\"content\":\"$txtvalue\",\"ttl\":120}"; then if _cf_rest POST "zones/$_domain_id/dns_records" "{\"type\":\"TXT\",\"name\":\"$fulldomain\",\"content\":\"$txtvalue\",\"ttl\":120}"; then
if printf -- "%s" "$response" | grep $fulldomain >/dev/null; then if printf -- "%s" "$response" | grep "$fulldomain" >/dev/null; then
_info "Added, sleeping 10 seconds" _info "Added, sleeping 10 seconds"
sleep 10 sleep 10
#todo: check if the record takes effect #todo: check if the record takes effect
@ -60,7 +60,7 @@ dns_cf_add() {
else else
_info "Updating record" _info "Updating record"
record_id=$(printf "%s\n" "$response" | _egrep_o \"id\":\"[^\"]*\" | cut -d : -f 2 | tr -d \" | head -n 1) record_id=$(printf "%s\n" "$response" | _egrep_o \"id\":\"[^\"]*\" | cut -d : -f 2 | tr -d \" | head -n 1)
_debug "record_id" $record_id _debug "record_id" "$record_id"
_cf_rest PUT "zones/$_domain_id/dns_records/$record_id" "{\"id\":\"$record_id\",\"type\":\"TXT\",\"name\":\"$fulldomain\",\"content\":\"$txtvalue\",\"zone_id\":\"$_domain_id\",\"zone_name\":\"$_domain\"}" _cf_rest PUT "zones/$_domain_id/dns_records/$record_id" "{\"id\":\"$record_id\",\"type\":\"TXT\",\"name\":\"$fulldomain\",\"content\":\"$txtvalue\",\"zone_id\":\"$_domain_id\",\"zone_name\":\"$_domain\"}"
if [ "$?" = "0" ]; then if [ "$?" = "0" ]; then
@ -91,8 +91,8 @@ _get_root() {
domain=$1 domain=$1
i=2 i=2
p=1 p=1
while [ '1' ]; do while true; do
h=$(printf $domain | cut -d . -f $i-100) h=$(printf "%s" "$domain" | cut -d . -f $i-100)
if [ -z "$h" ]; then if [ -z "$h" ]; then
#not valid #not valid
return 1 return 1
@ -102,17 +102,17 @@ _get_root() {
return 1 return 1
fi fi
if printf $response | grep \"name\":\"$h\" >/dev/null; then if printf "%s" "$response" | grep "\"name\":\"$h\"" >/dev/null; then
_domain_id=$(printf "%s\n" "$response" | _egrep_o \"id\":\"[^\"]*\" | head -n 1 | cut -d : -f 2 | tr -d \") _domain_id=$(printf "%s\n" "$response" | _egrep_o \"id\":\"[^\"]*\" | head -n 1 | cut -d : -f 2 | tr -d \")
if [ "$_domain_id" ]; then if [ "$_domain_id" ]; then
_sub_domain=$(printf $domain | cut -d . -f 1-$p) _sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p)
_domain=$h _domain=$h
return 0 return 0
fi fi
return 1 return 1
fi fi
p=$i p=$i
i=$(expr $i + 1) i=$(_math "$i" + 1)
done done
return 1 return 1
} }
@ -121,7 +121,7 @@ _cf_rest() {
m=$1 m=$1
ep="$2" ep="$2"
data="$3" data="$3"
_debug $ep _debug "$ep"
_H1="X-Auth-Email: $CF_Email" _H1="X-Auth-Email: $CF_Email"
_H2="X-Auth-Key: $CF_Key" _H2="X-Auth-Key: $CF_Key"
@ -129,7 +129,7 @@ _cf_rest() {
if [ "$data" ]; then if [ "$data" ]; then
_debug data "$data" _debug data "$data"
response="$(_post "$data" "$CF_Api/$ep" "" $m)" response="$(_post "$data" "$CF_Api/$ep" "" "$m")"
else else
response="$(_get "$CF_Api/$ep")" response="$(_get "$CF_Api/$ep")"
fi fi

View File

@ -22,19 +22,19 @@ dns_cx_add() {
return 1 return 1
fi fi
REST_API=$CX_Api REST_API="$CX_Api"
#save the api key and email to the account conf file. #save the api key and email to the account conf file.
_saveaccountconf CX_Key "$CX_Key" _saveaccountconf CX_Key "$CX_Key"
_saveaccountconf CX_Secret "$CX_Secret" _saveaccountconf CX_Secret "$CX_Secret"
_debug "First detect the root zone" _debug "First detect the root zone"
if ! _get_root $fulldomain; then if ! _get_root "$fulldomain"; then
_err "invalid domain" _err "invalid domain"
return 1 return 1
fi fi
existing_records $_domain $_sub_domain existing_records "$_domain" "$_sub_domain"
_debug count "$count" _debug count "$count"
if [ "$?" != "0" ]; then if [ "$?" != "0" ]; then
_err "Error get existing records." _err "Error get existing records."
@ -42,9 +42,9 @@ dns_cx_add() {
fi fi
if [ "$count" = "0" ]; then if [ "$count" = "0" ]; then
add_record $_domain $_sub_domain $txtvalue add_record "$_domain" "$_sub_domain" "$txtvalue"
else else
update_record $_domain $_sub_domain $txtvalue update_record "$_domain" "$_sub_domain" "$txtvalue"
fi fi
if [ "$?" = "0" ]; then if [ "$?" = "0" ]; then
@ -78,7 +78,7 @@ existing_records() {
return 0 return 0
fi fi
if printf "$response" | grep '"type":"TXT"' >/dev/null; then if printf "%s" "$response" | grep '"type":"TXT"' >/dev/null; then
count=1 count=1
record_id=$(printf "%s\n" "$seg" | _egrep_o \"record_id\":\"[^\"]*\" | cut -d : -f 2 | tr -d \") record_id=$(printf "%s\n" "$seg" | _egrep_o \"record_id\":\"[^\"]*\" | cut -d : -f 2 | tr -d \")
_debug record_id "$record_id" _debug record_id "$record_id"
@ -93,7 +93,7 @@ add_record() {
root=$1 root=$1
sub=$2 sub=$2
txtvalue=$3 txtvalue=$3
fulldomain=$sub.$root fulldomain="$sub.$root"
_info "Adding record" _info "Adding record"
@ -110,7 +110,7 @@ update_record() {
root=$1 root=$1
sub=$2 sub=$2
txtvalue=$3 txtvalue=$3
fulldomain=$sub.$root fulldomain="$sub.$root"
_info "Updating record" _info "Updating record"
@ -136,30 +136,30 @@ _get_root() {
return 1 return 1
fi fi
while [ '1' ]; do while true; do
h=$(printf $domain | cut -d . -f $i-100) h=$(printf "%s" "$domain" | cut -d . -f $i-100)
_debug h "$h" _debug h "$h"
if [ -z "$h" ]; then if [ -z "$h" ]; then
#not valid #not valid
return 1 return 1
fi fi
if printf "$response" | grep "$h." >/dev/null; then if _contains "$response" "$h."; then
seg=$(printf "%s" "$response" | _egrep_o "\{[^\{]*\"$h\.\"[^\}]*\}") seg=$(printf "%s" "$response" | _egrep_o "\{[^\{]*\"$h\.\"[^\}]*\}")
_debug seg "$seg" _debug seg "$seg"
_domain_id=$(printf "%s" "$seg" | _egrep_o \"id\":\"[^\"]*\" | cut -d : -f 2 | tr -d \") _domain_id=$(printf "%s" "$seg" | _egrep_o \"id\":\"[^\"]*\" | cut -d : -f 2 | tr -d \")
_debug _domain_id "$_domain_id" _debug _domain_id "$_domain_id"
if [ "$_domain_id" ]; then if [ "$_domain_id" ]; then
_sub_domain=$(printf $domain | cut -d . -f 1-$p) _sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p)
_debug _sub_domain $_sub_domain _debug _sub_domain "$_sub_domain"
_domain=$h _domain="$h"
_debug _domain $_domain _debug _domain "$_domain"
return 0 return 0
fi fi
return 1 return 1
fi fi
p=$i p="$i"
i=$(expr $i + 1) i=$(_math "$i" + 1)
done done
return 1 return 1
} }
@ -168,7 +168,7 @@ _get_root() {
_rest() { _rest() {
m=$1 m=$1
ep="$2" ep="$2"
_debug $ep _debug "$ep"
url="$REST_API/$ep" url="$REST_API/$ep"
_debug url "$url" _debug url "$url"
@ -180,7 +180,7 @@ _rest() {
sec="$CX_Key$url$data$cdate$CX_Secret" sec="$CX_Key$url$data$cdate$CX_Secret"
_debug sec "$sec" _debug sec "$sec"
hmac=$(printf "$sec" | openssl md5 | cut -d " " -f 2) hmac=$(printf "%s" "$sec" | _digest md5 hex)
_debug hmac "$hmac" _debug hmac "$hmac"
_H1="API-KEY: $CX_Key" _H1="API-KEY: $CX_Key"
@ -199,7 +199,7 @@ _rest() {
return 1 return 1
fi fi
_debug2 response "$response" _debug2 response "$response"
if ! printf "$response" | grep '"message":"success"' >/dev/null; then if ! _contains "$response" '"message":"success"'; then
return 1 return 1
fi fi
return 0 return 0

View File

@ -22,19 +22,19 @@ dns_dp_add() {
return 1 return 1
fi fi
REST_API=$DP_Api REST_API="$DP_Api"
#save the api key and email to the account conf file. #save the api key and email to the account conf file.
_saveaccountconf DP_Id "$DP_Id" _saveaccountconf DP_Id "$DP_Id"
_saveaccountconf DP_Key "$DP_Key" _saveaccountconf DP_Key "$DP_Key"
_debug "First detect the root zone" _debug "First detect the root zone"
if ! _get_root $fulldomain; then if ! _get_root "$fulldomain"; then
_err "invalid domain" _err "invalid domain"
return 1 return 1
fi fi
existing_records $_domain $_sub_domain existing_records "$_domain" "$_sub_domain"
_debug count "$count" _debug count "$count"
if [ "$?" != "0" ]; then if [ "$?" != "0" ]; then
_err "Error get existing records." _err "Error get existing records."
@ -42,9 +42,9 @@ dns_dp_add() {
fi fi
if [ "$count" = "0" ]; then if [ "$count" = "0" ]; then
add_record $_domain $_sub_domain $txtvalue add_record "$_domain" "$_sub_domain" "$txtvalue"
else else
update_record $_domain $_sub_domain $txtvalue update_record "$_domain" "$_sub_domain" "$txtvalue"
fi fi
} }
@ -67,14 +67,14 @@ existing_records() {
return 1 return 1
fi fi
if printf "$response" | grep 'No records'; then if _contains "$response" 'No records'; then
count=0 count=0
return 0 return 0
fi fi
if printf "$response" | grep "Action completed successful" >/dev/null; then if _contains "$response" "Action completed successful"; then
count=$(printf "$response" | grep '<type>TXT</type>' | wc -l) count=$(printf "%s" "$response" | grep '<type>TXT</type>' | wc -l)
record_id=$(printf "$response" | grep '^<id>' | tail -1 | cut -d '>' -f 2 | cut -d '<' -f 1) record_id=$(printf "%s" "$response" | grep '^<id>' | tail -1 | cut -d '>' -f 2 | cut -d '<' -f 1)
return 0 return 0
else else
_err "get existing records error." _err "get existing records error."
@ -90,7 +90,7 @@ add_record() {
root=$1 root=$1
sub=$2 sub=$2
txtvalue=$3 txtvalue=$3
fulldomain=$sub.$root fulldomain="$sub.$root"
_info "Adding record" _info "Adding record"
@ -98,7 +98,7 @@ add_record() {
return 1 return 1
fi fi
if printf "$response" | grep "Action completed successful"; then if _contains "$response" "Action completed successful"; then
return 0 return 0
fi fi
@ -112,7 +112,7 @@ update_record() {
root=$1 root=$1
sub=$2 sub=$2
txtvalue=$3 txtvalue=$3
fulldomain=$sub.$root fulldomain="$sub.$root"
_info "Updating record" _info "Updating record"
@ -120,7 +120,7 @@ update_record() {
return 1 return 1
fi fi
if printf "$response" | grep "Action completed successful"; then if _contains "$response" "Action completed successful"; then
return 0 return 0
fi fi
@ -138,8 +138,8 @@ _get_root() {
domain=$1 domain=$1
i=2 i=2
p=1 p=1
while [ '1' ]; do while true; do
h=$(printf $domain | cut -d . -f $i-100) h=$(printf "%s" "$domain" | cut -d . -f $i-100)
if [ -z "$h" ]; then if [ -z "$h" ]; then
#not valid #not valid
return 1 return 1
@ -149,20 +149,20 @@ _get_root() {
return 1 return 1
fi fi
if printf "$response" | grep "Action completed successful" >/dev/null; then if _contains "$response" "Action completed successful"; then
_domain_id=$(printf "%s\n" "$response" | _egrep_o \"id\":\"[^\"]*\" | cut -d : -f 2 | tr -d \") _domain_id=$(printf "%s\n" "$response" | _egrep_o \"id\":\"[^\"]*\" | cut -d : -f 2 | tr -d \")
_debug _domain_id "$_domain_id" _debug _domain_id "$_domain_id"
if [ "$_domain_id" ]; then if [ "$_domain_id" ]; then
_sub_domain=$(printf $domain | cut -d . -f 1-$p) _sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p)
_debug _sub_domain $_sub_domain _debug _sub_domain "$_sub_domain"
_domain=$h _domain="$h"
_debug _domain $_domain _debug _domain "$_domain"
return 0 return 0
fi fi
return 1 return 1
fi fi
p=$i p="$i"
i=$(expr $i + 1) i=$(_math "$i" + 1)
done done
return 1 return 1
} }
@ -172,14 +172,14 @@ _rest() {
m=$1 m=$1
ep="$2" ep="$2"
data="$3" data="$3"
_debug $ep _debug "$ep"
url="$REST_API/$ep" url="$REST_API/$ep"
_debug url "$url" _debug url "$url"
if [ "$data" ]; then if [ "$data" ]; then
_debug2 data "$data" _debug2 data "$data"
response="$(_post $data "$url")" response="$(_post "$data" "$url")"
else else
response="$(_get "$url")" response="$(_get "$url")"
fi fi

View File

@ -26,7 +26,7 @@ dns_gd_add() {
_saveaccountconf GD_Secret "$GD_Secret" _saveaccountconf GD_Secret "$GD_Secret"
_debug "First detect the root zone" _debug "First detect the root zone"
if ! _get_root $fulldomain; then if ! _get_root "$fulldomain"; then
_err "invalid domain" _err "invalid domain"
return 1 return 1
fi fi
@ -67,8 +67,8 @@ _get_root() {
domain=$1 domain=$1
i=2 i=2
p=1 p=1
while [ '1' ]; do while true; do
h=$(printf $domain | cut -d . -f $i-100) h=$(printf "%s" "$domain" | cut -d . -f $i-100)
if [ -z "$h" ]; then if [ -z "$h" ]; then
#not valid #not valid
return 1 return 1
@ -78,11 +78,11 @@ _get_root() {
return 1 return 1
fi fi
if printf "$response" | grep '"code":"NOT_FOUND"' >/dev/null; then if _contains "$response" '"code":"NOT_FOUND"'; then
_debug "$h not found" _debug "$h not found"
else else
_sub_domain=$(printf $domain | cut -d . -f 1-$p) _sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p)
_domain=$h _domain="$h"
return 0 return 0
fi fi
p=$i p=$i
@ -95,7 +95,7 @@ _gd_rest() {
m=$1 m=$1
ep="$2" ep="$2"
data="$3" data="$3"
_debug $ep _debug "$ep"
_H1="Authorization: sso-key $GD_Key:$GD_Secret" _H1="Authorization: sso-key $GD_Key:$GD_Secret"
_H2="Content-Type: application/json" _H2="Content-Type: application/json"

View File

@ -14,9 +14,9 @@ dns_lexicon_add() {
fulldomain=$1 fulldomain=$1
txtvalue=$2 txtvalue=$2
domain=$(printf "$fulldomain" | cut -d . -f 2-999) domain=$(printf "%s" "$fulldomain" | cut -d . -f 2-999)
if ! _exists $lexicon_cmd; then if ! _exists "$lexicon_cmd"; then
_err "Please install $lexicon_cmd first: $wiki" _err "Please install $lexicon_cmd first: $wiki"
return 1 return 1
fi fi
@ -33,7 +33,7 @@ dns_lexicon_add() {
eval Lx_name_v="\$$Lx_name" eval Lx_name_v="\$$Lx_name"
_debug "$Lx_name" "$Lx_name_v" _debug "$Lx_name" "$Lx_name_v"
if [ "$Lx_name_v" ]; then if [ "$Lx_name_v" ]; then
_saveaccountconf $Lx_name "$Lx_name_v" _saveaccountconf "$Lx_name" "$Lx_name_v"
export "$Lx_name" export "$Lx_name"
fi fi
@ -41,7 +41,7 @@ dns_lexicon_add() {
eval Lx_token_v="\$$Lx_token" eval Lx_token_v="\$$Lx_token"
_debug "$Lx_token" "$Lx_token_v" _debug "$Lx_token" "$Lx_token_v"
if [ "$Lx_token_v" ]; then if [ "$Lx_token_v" ]; then
_saveaccountconf $Lx_token "$Lx_token_v" _saveaccountconf "$Lx_token" "$Lx_token_v"
export "$Lx_token" export "$Lx_token"
fi fi
@ -49,7 +49,7 @@ dns_lexicon_add() {
eval Lx_password_v="\$$Lx_password" eval Lx_password_v="\$$Lx_password"
_debug "$Lx_password" "$Lx_password_v" _debug "$Lx_password" "$Lx_password_v"
if [ "$Lx_password_v" ]; then if [ "$Lx_password_v" ]; then
_saveaccountconf $Lx_password "$Lx_password_v" _saveaccountconf "$Lx_password" "$Lx_password_v"
export "$Lx_password" export "$Lx_password"
fi fi
@ -58,7 +58,7 @@ dns_lexicon_add() {
_debug "$Lx_domaintoken" "$Lx_domaintoken_v" _debug "$Lx_domaintoken" "$Lx_domaintoken_v"
if [ "$Lx_domaintoken_v" ]; then if [ "$Lx_domaintoken_v" ]; then
export "$Lx_domaintoken" export "$Lx_domaintoken"
_saveaccountconf $Lx_domaintoken "$Lx_domaintoken_v" _saveaccountconf "$Lx_domaintoken" "$Lx_domaintoken_v"
fi fi
$lexicon_cmd "$PROVIDER" create ${domain} TXT --name="_acme-challenge.${domain}." --content="${txtvalue}" $lexicon_cmd "$PROVIDER" create ${domain} TXT --name="_acme-challenge.${domain}." --content="${txtvalue}"

View File

@ -28,7 +28,7 @@ dns_lua_add() {
_saveaccountconf LUA_Email "$LUA_Email" _saveaccountconf LUA_Email "$LUA_Email"
_debug "First detect the root zone" _debug "First detect the root zone"
if ! _get_root $fulldomain; then if ! _get_root "$fulldomain"; then
_err "invalid domain" _err "invalid domain"
return 1 return 1
fi fi
@ -49,7 +49,7 @@ dns_lua_add() {
if [ "$count" = "0" ]; then if [ "$count" = "0" ]; then
_info "Adding record" _info "Adding record"
if _LUA_rest POST "zones/$_domain_id/records" "{\"type\":\"TXT\",\"name\":\"$fulldomain.\",\"content\":\"$txtvalue\",\"ttl\":120}"; then if _LUA_rest POST "zones/$_domain_id/records" "{\"type\":\"TXT\",\"name\":\"$fulldomain.\",\"content\":\"$txtvalue\",\"ttl\":120}"; then
if printf -- "%s" "$response" | grep $fulldomain >/dev/null; then if printf -- "%s" "$response" | grep "$fulldomain" >/dev/null; then
_info "Added" _info "Added"
#todo: check if the record takes effect #todo: check if the record takes effect
return 0 return 0
@ -62,7 +62,7 @@ dns_lua_add() {
else else
_info "Updating record" _info "Updating record"
record_id=$(printf "%s\n" "$response" | _egrep_o \"id\":[^,]*,\"name\":\"$fulldomain.\",\"type\":\"TXT\" | cut -d: -f2 | cut -d, -f1) record_id=$(printf "%s\n" "$response" | _egrep_o \"id\":[^,]*,\"name\":\"$fulldomain.\",\"type\":\"TXT\" | cut -d: -f2 | cut -d, -f1)
_debug "record_id" $record_id _debug "record_id" "$record_id"
_LUA_rest PUT "zones/$_domain_id/records/$record_id" "{\"id\":\"$record_id\",\"type\":\"TXT\",\"name\":\"$fulldomain.\",\"content\":\"$txtvalue\",\"zone_id\":\"$_domain_id\",\"ttl\":120}" _LUA_rest PUT "zones/$_domain_id/records/$record_id" "{\"id\":\"$record_id\",\"type\":\"TXT\",\"name\":\"$fulldomain.\",\"content\":\"$txtvalue\",\"zone_id\":\"$_domain_id\",\"ttl\":120}"
if [ "$?" = "0" ]; then if [ "$?" = "0" ]; then
@ -95,24 +95,24 @@ _get_root() {
if ! _LUA_rest GET "zones"; then if ! _LUA_rest GET "zones"; then
return 1 return 1
fi fi
while [ '1' ]; do while true; do
h=$(printf $domain | cut -d . -f $i-100) h=$(printf "%s" "$domain" | cut -d . -f $i-100)
if [ -z "$h" ]; then if [ -z "$h" ]; then
#not valid #not valid
return 1 return 1
fi fi
if printf $response | grep \"name\":\"$h\" >/dev/null; then if _contains "$response" "\"name\":\"$h\""; then
_domain_id=$(printf "%s\n" "$response" | _egrep_o \"id\":[^,]*,\"name\":\"$h\" | cut -d : -f 2 | cut -d , -f 1) _domain_id=$(printf "%s\n" "$response" | _egrep_o \"id\":[^,]*,\"name\":\"$h\" | cut -d : -f 2 | cut -d , -f 1)
if [ "$_domain_id" ]; then if [ "$_domain_id" ]; then
_sub_domain=$(printf $domain | cut -d . -f 1-$p) _sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p)
_domain=$h _domain="$h"
return 0 return 0
fi fi
return 1 return 1
fi fi
p=$i p=$i
i=$(expr $i + 1) i=$(_math "$i" + 1)
done done
return 1 return 1
} }
@ -121,7 +121,7 @@ _LUA_rest() {
m=$1 m=$1
ep="$2" ep="$2"
data="$3" data="$3"
_debug $ep _debug "$ep"
_H1="Accept: application/json" _H1="Accept: application/json"
_H2="Authorization: Basic $LUA_auth" _H2="Authorization: Basic $LUA_auth"

View File

@ -25,7 +25,7 @@ dns_me_add() {
_saveaccountconf ME_Secret "$ME_Secret" _saveaccountconf ME_Secret "$ME_Secret"
_debug "First detect the root zone" _debug "First detect the root zone"
if ! _get_root $fulldomain; then if ! _get_root "$fulldomain"; then
_err "invalid domain" _err "invalid domain"
return 1 return 1
fi fi
@ -36,7 +36,7 @@ dns_me_add() {
_debug "Getting txt records" _debug "Getting txt records"
_me_rest GET "${_domain_id}/records?recordName=$_sub_domain&type=TXT" _me_rest GET "${_domain_id}/records?recordName=$_sub_domain&type=TXT"
if ! printf "$response" | grep \"totalRecords\": >/dev/null; then if ! _contains "$response" "\"totalRecords\":"; then
_err "Error" _err "Error"
return 1 return 1
fi fi
@ -59,7 +59,7 @@ dns_me_add() {
else else
_info "Updating record" _info "Updating record"
record_id=$(printf "%s\n" "$response" | _egrep_o \"id\":[^,]* | cut -d : -f 2 | head -n 1) record_id=$(printf "%s\n" "$response" | _egrep_o \"id\":[^,]* | cut -d : -f 2 | head -n 1)
_debug "record_id" $record_id _debug "record_id" "$record_id"
_me_rest PUT "$_domain_id/records/$record_id/" "{\"id\":\"$record_id\",\"type\":\"TXT\",\"name\":\"$_sub_domain\",\"value\":\"$txtvalue\",\"gtdLocation\":\"DEFAULT\",\"ttl\":120}" _me_rest PUT "$_domain_id/records/$record_id/" "{\"id\":\"$record_id\",\"type\":\"TXT\",\"name\":\"$_sub_domain\",\"value\":\"$txtvalue\",\"gtdLocation\":\"DEFAULT\",\"ttl\":120}"
if [ "$?" = "0" ]; then if [ "$?" = "0" ]; then
@ -89,8 +89,8 @@ _get_root() {
domain=$1 domain=$1
i=2 i=2
p=1 p=1
while [ '1' ]; do while true; do
h=$(printf $domain | cut -d . -f $i-100) h=$(printf "%s" "$domain" | cut -d . -f $i-100)
if [ -z "$h" ]; then if [ -z "$h" ]; then
#not valid #not valid
return 1 return 1
@ -100,17 +100,17 @@ _get_root() {
return 1 return 1
fi fi
if printf $response | grep \"name\":\"$h\" >/dev/null; then if _contains "$response" "\"name\":\"$h\""; then
_domain_id=$(printf "%s\n" "$response" | _egrep_o \"id\":[^,]* | head -n 1 | cut -d : -f 2) _domain_id=$(printf "%s\n" "$response" | _egrep_o \"id\":[^,]* | head -n 1 | cut -d : -f 2)
if [ "$_domain_id" ]; then if [ "$_domain_id" ]; then
_sub_domain=$(printf $domain | cut -d . -f 1-$p) _sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p)
_domain=$h _domain="$h"
return 0 return 0
fi fi
return 1 return 1
fi fi
p=$i p=$i
i=$(expr $i + 1) i=$(_math "$i" + 1)
done done
return 1 return 1
} }
@ -119,10 +119,10 @@ _me_rest() {
m=$1 m=$1
ep="$2" ep="$2"
data="$3" data="$3"
_debug $ep _debug "$ep"
cdate=$(date -u +"%a, %d %b %Y %T %Z") cdate=$(date -u +"%a, %d %b %Y %T %Z")
hmac=$(printf "$cdate" | _hmac sha1 "$ME_Secret" 1) hmac=$(printf "%s" "$cdate" | _hmac sha1 "$ME_Secret" 1)
_H1="x-dnsme-apiKey: $ME_Key" _H1="x-dnsme-apiKey: $ME_Key"
_H2="x-dnsme-requestDate: $cdate" _H2="x-dnsme-requestDate: $cdate"

View File

@ -226,8 +226,8 @@ _get_root() {
domain=$1 domain=$1
i=2 i=2
p=1 p=1
while [ '1' ]; do while true; do
h=$(printf $domain | cut -d . -f $i-100) h=$(printf "%s" "$domain" | cut -d . -f $i-100)
if [ -z "$h" ]; then if [ -z "$h" ]; then
#not valid #not valid
return 1 return 1
@ -238,12 +238,12 @@ _get_root() {
fi fi
if ! _contains "$response" "This service does not exist" >/dev/null; then if ! _contains "$response" "This service does not exist" >/dev/null; then
_sub_domain=$(printf $domain | cut -d . -f 1-$p) _sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p)
_domain=$h _domain="$h"
return 0 return 0
fi fi
p=$i p=$i
i=$(expr $i + 1) i=$(_math "$i" + 1)
done done
return 1 return 1
} }
@ -261,7 +261,7 @@ _ovh_rest() {
m=$1 m=$1
ep="$2" ep="$2"
data="$3" data="$3"
_debug $ep _debug "$ep"
_ovh_url="$OVH_API/$ep" _ovh_url="$OVH_API/$ep"
_debug2 _ovh_url "$_ovh_url" _debug2 _ovh_url "$_ovh_url"

View File

@ -35,7 +35,7 @@ dns_pdns_add() {
fi fi
if [ -z "$PDNS_Ttl" ]; then if [ -z "$PDNS_Ttl" ]; then
PDNS_Ttl=$DEFAULT_PDNS_TTL PDNS_Ttl="$DEFAULT_PDNS_TTL"
fi fi
#save the api addr and key to the account conf file. #save the api addr and key to the account conf file.
@ -48,7 +48,7 @@ dns_pdns_add() {
fi fi
_debug "First detect the root zone" _debug "First detect the root zone"
if ! _get_root $fulldomain; then if ! _get_root "$fulldomain"; then
_err "invalid domain" _err "invalid domain"
return 1 return 1
fi fi
@ -94,22 +94,22 @@ _get_root() {
p=1 p=1
if _pdns_rest "GET" "/api/v1/servers/$PDNS_ServerId/zones"; then if _pdns_rest "GET" "/api/v1/servers/$PDNS_ServerId/zones"; then
_zones_response=$response _zones_response="$response"
fi fi
while [ '1' ]; do while true; do
h=$(printf $domain | cut -d . -f $i-100) h=$(printf "%s" "$domain" | cut -d . -f $i-100)
if [ -z "$h" ]; then if [ -z "$h" ]; then
return 1 return 1
fi fi
if printf "$_zones_response" | grep "\"name\": \"$h.\"" >/dev/null; then if _contains "$_zones_response" "\"name\": \"$h.\""; then
_domain=$h _domain="$h"
return 0 return 0
fi fi
p=$i p=$i
i=$(expr $i + 1) i=$(_math $i + 1)
done done
_debug "$domain not found" _debug "$domain not found"
return 1 return 1