Browse Source

Fix formatting

pull/1895/head
Mikhail Zyablitskiy 7 years ago
parent
commit
6408c702d4
  1. 46
      deploy/rancher.sh

46
deploy/rancher.sh

@ -18,12 +18,12 @@
rancher_deploy() { rancher_deploy() {
_cdomain="$1" _cdomain="$1"
# Further $(cat $1 | sed 's/$/\\n/' | tr -d '\n')
# Further $(echo "$1" | sed 's/$/\\n/' | tr -d '\n')
# Made for iclude cert in var in one line with \n # Made for iclude cert in var in one line with \n
_ckey=$(cat $2 | sed 's/$/\\n/' | tr -d '\n')
_ccert=$(cat $3 | sed 's/$/\\n/' | tr -d '\n')
_cca=$(cat $4 | sed 's/$/\\n/' | tr -d '\n')
_cfullchain=$(cat $5 | sed 's/$/\\n/' | tr -d '\n')
_ckey=$(echo "$2" | sed 's/$/\\n/' | tr -d '\n')
_ccert=$(echo "$3" | sed 's/$/\\n/' | tr -d '\n')
_cca=$(echo "$4" | sed 's/$/\\n/' | tr -d '\n')
_cfullchain=$(echo "$5" | sed 's/$/\\n/' | tr -d '\n')
_debug _cdomain "$_cdomain" _debug _cdomain "$_cdomain"
_debug _ckey "$_ckey" _debug _ckey "$_ckey"
@ -31,7 +31,7 @@ rancher_deploy() {
_debug _cca "$_cca" _debug _cca "$_cca"
_debug _cfullchain "$_cfullchain" _debug _cfullchain "$_cfullchain"
# Check software needed
# Check software needed
if ! _exists curl; then if ! _exists curl; then
_err "The command curl is not found." _err "The command curl is not found."
return 1 return 1
@ -47,7 +47,7 @@ rancher_deploy() {
return 1 return 1
fi fi
# Check environment variables and config
# Check environment variables and config
if [ -z "$RANCHER_ACCESS_KEY" ]; then if [ -z "$RANCHER_ACCESS_KEY" ]; then
if [ -z "$Le_rancher_access_key" ]; then if [ -z "$Le_rancher_access_key" ]; then
@ -89,36 +89,36 @@ rancher_deploy() {
_savedomainconf Le_rancher_server "$Le_rancher_server" _savedomainconf Le_rancher_server "$Le_rancher_server"
fi fi
# Check api connection
# Check api connection
response=$( response=$(
curl $Le_rancher_server/v2-beta/ \
--write-out %{http_code} \
curl "$Le_rancher_server/v2-beta/" \
--write-out "%{http_code}" \
--silent \ --silent \
--output /dev/null --output /dev/null
) )
if [[ "$response" -ge 200 && "$response" -le 299 ]]; then
if [ "$response" -ge 200 ] && [ "$response" -le 299 ]; then
_err "Curl failed to connect to $Le_rancher_server v2-beta API" _err "Curl failed to connect to $Le_rancher_server v2-beta API"
return 1 return 1
else else
_info "API connected!" _info "API connected!"
fi fi
# Check if certificate already exist in rancher
# Check if certificate already exist in rancher
id_raw_json=`curl -s -u "$Le_rancher_access_key:$Le_rancher_secret_key" \
id_raw_json=$(curl -s -u "$Le_rancher_access_key:$Le_rancher_secret_key" \
-X GET \ -X GET \
-H 'Accept: application/json' \ -H 'Accept: application/json' \
-H 'Content-Type: application/json' \ -H 'Content-Type: application/json' \
"$Le_rancher_server/v2-beta/projects/$Le_rancher_environment/certificates?name=$_cdomain"`
cert_state=$(echo $id_raw_json | awk -F='\:' -v RS='\,' "\$id_raw_json~/\"state\"/ {print}" | tr -d "\n\t" | sed -e 's/^"//' -e 's/"$//' | grep -o active)
"$Le_rancher_server/v2-beta/projects/$Le_rancher_environment/certificates?name=$_cdomain")
cert_state=$(echo "$id_raw_json" | awk -F='\:' -v RS='\,' "\$id_raw_json~/\"state\"/ {print}" | tr -d "\n\t" | sed -e 's/^"//' -e 's/"$//' | grep -o "active")
_info "Cert state is $cert_state" _info "Cert state is $cert_state"
if [ -z $cert_state ]; then
if [ -z "$cert_state" ]; then
# Add new certificate # Add new certificate
_info "Adding new cert to rancher" _info "Adding new cert to rancher"
response=$( response=$(
curl -u "$Le_rancher_access_key:$Le_rancher_secret_key" \ curl -u "$Le_rancher_access_key:$Le_rancher_secret_key" \
-X POST \ -X POST \
--write-out %{http_code} \
--write-out "%{http_code}" \
--silent \ --silent \
--output /dev/null \ --output /dev/null \
-H 'Accept: application/json' \ -H 'Accept: application/json' \
@ -127,25 +127,25 @@ rancher_deploy() {
"$Le_rancher_server/v2-beta/projects/$Le_rancher_environment/certificates/" "$Le_rancher_server/v2-beta/projects/$Le_rancher_environment/certificates/"
) )
_info "Update status code: $response" _info "Update status code: $response"
if [[ $response -lt 199 || $response -gt 300 ]]; then
if [ "$response" -lt 199 ] || [ "$response" -gt 300 ]; then
_err "Curl failed to create new cert" _err "Curl failed to create new cert"
return 1 return 1
fi fi
else else
# Get certificate ID # Get certificate ID
id_raw_json=`curl -s -u "$Le_rancher_access_key:$Le_rancher_secret_key" \
id_raw_json=$(curl -s -u "$Le_rancher_access_key:$Le_rancher_secret_key" \
-X GET \ -X GET \
-H 'Accept: application/json' \ -H 'Accept: application/json' \
-H 'Content-Type: application/json' \ -H 'Content-Type: application/json' \
"$Le_rancher_server/v2-beta/projects/$Le_rancher_environment/certificates?name=$_cdomain"`
cert_id=$(echo $id_raw_json | awk -F='\:' -v RS='\,' "\$id_raw_json~/\"data\"/ {print}" | tr -d "\n\t" | sed -e 's/^"//' -e 's/"$//' | sed -e 's/data.*"//')
"$Le_rancher_server/v2-beta/projects/$Le_rancher_environment/certificates?name=$_cdomain")
cert_id=$(echo "$id_raw_json" | awk -F='\:' -v RS='\,' "\$id_raw_json~/\"data\"/ {print}" | tr -d "\n\t" | sed -e 's/^"//' -e 's/"$//' | sed -e 's/data.*"//')
_info "Cert already exist ID is: $cert_id" _info "Cert already exist ID is: $cert_id"
# Update existing certificate # Update existing certificate
_info "Updating..." _info "Updating..."
response=$( response=$(
curl -u "$Le_rancher_access_key:$Le_rancher_secret_key" \ curl -u "$Le_rancher_access_key:$Le_rancher_secret_key" \
-X PUT \ -X PUT \
--write-out %{http_code} \
--write-out "%{http_code}" \
--silent \ --silent \
--output /dev/null \ --output /dev/null \
-H 'Accept: application/json' \ -H 'Accept: application/json' \
@ -154,7 +154,7 @@ rancher_deploy() {
"$Le_rancher_server/v2-beta/projects/$Le_rancher_environment/certificates/$cert_id" "$Le_rancher_server/v2-beta/projects/$Le_rancher_environment/certificates/$cert_id"
) )
_info "Update status code: $response" _info "Update status code: $response"
if [[ $response -lt 199 || $response -gt 300 ]]; then
if [ "$response" -lt 199 ] || [ "$response" -gt 300 ]; then
_err "Curl failed to update cert with id=$cert_id" _err "Curl failed to update cert with id=$cert_id"
return 1 return 1
fi fi

Loading…
Cancel
Save