diff --git a/vkpr/init/src/unix/formula/formula.sh b/vkpr/init/src/unix/formula/formula.sh index 17d37ea0..710a7d21 100755 --- a/vkpr/init/src/unix/formula/formula.sh +++ b/vkpr/init/src/unix/formula/formula.sh @@ -17,10 +17,8 @@ runFormula() { echo "VKPR initialization" - # VKPR home is "~/.vkpr" VKPR_HOME=~/.vkpr VKPR_GLOBALS=$VKPR_HOME/global - # required paths mkdir -p $VKPR_HOME/bin mkdir -p $VKPR_HOME/config mkdir -p $VKPR_HOME/bats @@ -34,14 +32,6 @@ runFormula() { installTool "k9s" installGlobals installBats - # if [ "$RIT_INPUT_BOOLEAN" = "true" ]; then - # echoColor "blue" "I've already created formulas using Ritchie." - # else - # echoColor "red" "I'm excited in creating new formulas using Ritchie." - # fi - - # echoColor "yellow" "Today, I want to automate $RIT_INPUT_LIST." - # echoColor "cyan" "My secret is $RIT_INPUT_PASSWORD." } installTool() { @@ -91,8 +81,8 @@ installBats(){ } createPackagesFiles() { - touch $VKPR_GLOBALS/.env - cp $(dirname "$0")/utils/* $VKPR_GLOBALS + touch global-values.yaml + cp $(dirname "$0")/utils/*.sh $VKPR_GLOBALS } echoColor() { diff --git a/vkpr/init/src/utils/helper.sh b/vkpr/init/src/utils/helper.sh index 57bdb274..a1d4f45c 100644 --- a/vkpr/init/src/utils/helper.sh +++ b/vkpr/init/src/utils/helper.sh @@ -1,24 +1,33 @@ #!/bin/bash -verifyExistingEnv(){ - aux=0 - for i in "$@" - do - if [ -z $(cat $VKPR_GLOBALS/.env | grep $i) ]; then - if (( $aux % 2 == 0 )); then - printf "VKPR_ENV_${i}=" >> $VKPR_GLOBALS/.env - else - printf "${i}\n" >> $VKPR_GLOBALS/.env - fi - let "aux++" +# Create a variable by Global Scope +# $1: Global variable / $2: Default value of the global variable / $3: Label from config file / $4: Name of env +checkGlobalConfig(){ + CONFIG_FILE=~/.vkpr/global-config.yaml + FILE_LABEL=".global.$3" + local NAME_ENV=VKPR_ENV_$4 + if [ -f "$CONFIG_FILE" ] && [ $1 == $2 ] && [ $($VKPR_YQ eval $FILE_LABEL $CONFIG_FILE) != "null" ]; then + echoColor "yellow" "Setting value from config file" + eval $NAME_ENV=$($VKPR_YQ eval $FILE_LABEL $CONFIG_FILE) + else + if [ $1 == $2 ]; then + echoColor "yellow" "Setting value from default value" + eval $NAME_ENV=$1 + else + echoColor "yellow" "Setting value from user input" + eval $NAME_ENV=$1 fi - done + fi } +# Create a new instance of DB in Postgres; +# $1: Postgres User / $2: Postgres Password / $3: Name of DB to create createDatabase(){ $VKPR_KUBECTL run init-db --rm -it --restart="Never" --image docker.io/bitnami/postgresql:11.13.0-debian-10-r0 --env="PGUSER=$1" --env="PGPASSWORD=$2" --env="PGHOST=postgres-postgresql" --env="PGPORT=5432" --env="PGDATABASE=postgres" --command -- psql --command="CREATE DATABASE $3" } +# Check if exist some instace of DB with specified name in Postgres +# $1: Postgres User / $2: Postgres Password / $3: Name of DB to search checkExistingDatabase(){ $VKPR_KUBECTL run check-db --rm -it --restart='Never' --image docker.io/bitnami/postgresql:11.13.0-debian-10-r12 --env="PGUSER=$1" --env="PGPASSWORD=$2" --env="PGHOST=postgres-postgresql" --env="PGPORT=5432" --env="PGDATABASE=postgres" --command -- psql -lqt | cut -d \| -f 1 | grep $3 | sed -e 's/^[ \t]*//' } \ No newline at end of file diff --git a/vkpr/init/src/utils/var.sh b/vkpr/init/src/utils/var.sh index 1198661c..e6831282 100644 --- a/vkpr/init/src/utils/var.sh +++ b/vkpr/init/src/utils/var.sh @@ -1,7 +1,6 @@ #!/bin/bash VKPR_HOME=~/.vkpr -VKPR_GLOBALS=$VKPR_HOME/global VKPR_K3D=$VKPR_HOME/bin/k3d VKPR_ARKADE=$VKPR_HOME/bin/arkade