Skip to content

Commit

Permalink
Update the formula to use globals
Browse files Browse the repository at this point in the history
  • Loading branch information
jpeedroza committed Sep 8, 2021
1 parent 68c70f7 commit 31bc48e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
14 changes: 2 additions & 12 deletions vkpr/init/src/unix/formula/formula.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down
33 changes: 21 additions & 12 deletions vkpr/init/src/utils/helper.sh
Original file line number Diff line number Diff line change
@@ -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]*//'
}
1 change: 0 additions & 1 deletion vkpr/init/src/utils/var.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 31bc48e

Please sign in to comment.