|
|
|
@ -4,7 +4,7 @@ |
|
|
|
# Returns 0 when success. |
|
|
|
# |
|
|
|
# Written by Mihkail Zyablickiy <mikeaggy91@gmail.com> |
|
|
|
# 2018 |
|
|
|
# 2018-2019 |
|
|
|
# |
|
|
|
####### Variables ############################## |
|
|
|
#export RANCHER_ACCESS_KEY=7E6F529DAAFE771A5 |
|
|
|
@ -12,6 +12,21 @@ |
|
|
|
#export RANCHER_ENVIRONMENT=1a5 |
|
|
|
#export RANCHER_SERVER=http://rancher-server.example.com |
|
|
|
|
|
|
|
REQ_SOFT="curl awk grep" |
|
|
|
REQ_ENV_VARS="RANCHER_ACCESS_KEY RANCHER_SECRET_KEY RANCHER_ENVIRONMENT RANCHER_SERVER" |
|
|
|
|
|
|
|
######## Private functions ##################### |
|
|
|
|
|
|
|
_getconfigvar() { |
|
|
|
_var="$1" |
|
|
|
case "${_var}" in |
|
|
|
"RANCHER_ACCESS_KEY" ) get_result="Le_rancher_access_key" ;; |
|
|
|
"RANCHER_SECRET_KEY" ) get_result="Le_rancher_secret_key" ;; |
|
|
|
"RANCHER_ENVIRONMENT" ) get_result="Le_rancher_environment" ;; |
|
|
|
"RANCHER_SERVER" ) get_result="Le_rancher_server" ;; |
|
|
|
esac |
|
|
|
} |
|
|
|
|
|
|
|
######## Public functions ##################### |
|
|
|
|
|
|
|
#domain keyfile certfile cafile fullchain |
|
|
|
@ -32,62 +47,30 @@ rancher_deploy() { |
|
|
|
_debug _cfullchain "$_cfullchain" |
|
|
|
|
|
|
|
# Check software needed |
|
|
|
if ! _exists curl; then |
|
|
|
_err "The command curl is not found." |
|
|
|
return 1 |
|
|
|
fi |
|
|
|
|
|
|
|
if ! _exists awk; then |
|
|
|
_err "The command awk is not found." |
|
|
|
return 1 |
|
|
|
fi |
|
|
|
|
|
|
|
if ! _exists grep; then |
|
|
|
_err "The command grep is not found." |
|
|
|
return 1 |
|
|
|
fi |
|
|
|
|
|
|
|
# Check environment variables and config |
|
|
|
|
|
|
|
if [ -z "$RANCHER_ACCESS_KEY" ]; then |
|
|
|
if [ -z "$Le_rancher_access_key" ]; then |
|
|
|
_err "RANCHER_ACCESS_KEY not defined." |
|
|
|
for PROGRAMM in $REQ_SOFT |
|
|
|
do |
|
|
|
if ! _exists $PROGRAMM; then |
|
|
|
_err "The command $PROGRAMM is not found." |
|
|
|
return 1 |
|
|
|
fi |
|
|
|
else |
|
|
|
Le_rancher_access_key="$RANCHER_ACCESS_KEY" |
|
|
|
_savedomainconf Le_rancher_access_key "$Le_rancher_access_key" |
|
|
|
fi |
|
|
|
|
|
|
|
if [ -z "$RANCHER_SECRET_KEY" ]; then |
|
|
|
if [ -z "$Le_rancher_secret_key" ]; then |
|
|
|
_err "RANCHER_SECRET_KEY not defined." |
|
|
|
return 1 |
|
|
|
fi |
|
|
|
else |
|
|
|
Le_rancher_secret_key="$RANCHER_SECRET_KEY" |
|
|
|
_savedomainconf Le_rancher_secret_key "$Le_rancher_secret_key" |
|
|
|
fi |
|
|
|
|
|
|
|
if [ -z "$RANCHER_ENVIRONMENT" ]; then |
|
|
|
if [ -z "$Le_rancher_environment" ]; then |
|
|
|
_err "RANCHER_ENVIRONMENT not defined." |
|
|
|
return 1 |
|
|
|
fi |
|
|
|
else |
|
|
|
Le_rancher_environment="$RANCHER_ENVIRONMENT" |
|
|
|
_savedomainconf Le_rancher_environment "$Le_rancher_environment" |
|
|
|
fi |
|
|
|
done |
|
|
|
|
|
|
|
if [ -z "$RANCHER_SERVER" ]; then |
|
|
|
if [ -z "$Le_rancher_server" ]; then |
|
|
|
_err "RANCHER_SERVER not defined." |
|
|
|
# Check environment variables and config variables |
|
|
|
for ENV_VAR in $REQ_ENV_VARS |
|
|
|
do |
|
|
|
_getconfigvar $ENV_VAR |
|
|
|
eval _var='$'$ENV_VAR |
|
|
|
eval _result='$'$get_result |
|
|
|
if [ -z "$_var" ]; then |
|
|
|
if [ -z "$_result" ]; then |
|
|
|
_err "$ENV_VAR variable not defined." |
|
|
|
return 1 |
|
|
|
fi |
|
|
|
else |
|
|
|
Le_rancher_server="$RANCHER_SERVER" |
|
|
|
_savedomainconf Le_rancher_server "$Le_rancher_server" |
|
|
|
$get_result="$_var" |
|
|
|
_savedomainconf $get_result "_result" |
|
|
|
fi |
|
|
|
done |
|
|
|
|
|
|
|
# Check api connection |
|
|
|
response=$( |
|
|
|
|