commit by to_remotes 2023-10-10 14:02:50 +0200 from vmdevac
parent
7e0717ce53
commit
2f57784dd5
81
init.sh
81
init.sh
|
|
@ -9,7 +9,40 @@ echo "################################################"
|
||||||
echo " basic init of wiseadvice node "
|
echo " basic init of wiseadvice node "
|
||||||
echo "################################################"
|
echo "################################################"
|
||||||
|
|
||||||
|
function choose_from_menu() {
|
||||||
|
local prompt="$1" outvar="$2"
|
||||||
|
shift
|
||||||
|
shift
|
||||||
|
local options=("$@") cur=0 count=${#options[@]} index=0
|
||||||
|
local esc=$(echo -en "\e") # cache ESC as test doesn't allow esc codes
|
||||||
|
printf "$prompt\n"
|
||||||
|
while true
|
||||||
|
do
|
||||||
|
# list all options (option list is zero-based)
|
||||||
|
index=0
|
||||||
|
for o in "${options[@]}"
|
||||||
|
do
|
||||||
|
if [ "$index" == "$cur" ]
|
||||||
|
then echo -e " >\e[7m$o\e[0m" # mark & highlight the current option
|
||||||
|
else echo " $o"
|
||||||
|
fi
|
||||||
|
index=$(( $index + 1 ))
|
||||||
|
done
|
||||||
|
read -s -n3 key # wait for user to key in arrows or ENTER
|
||||||
|
if [[ $key == $esc[A ]] # up arrow
|
||||||
|
then cur=$(( $cur - 1 ))
|
||||||
|
[ "$cur" -lt 0 ] && cur=0
|
||||||
|
elif [[ $key == $esc[B ]] # down arrow
|
||||||
|
then cur=$(( $cur + 1 ))
|
||||||
|
[ "$cur" -ge $count ] && cur=$(( $count - 1 ))
|
||||||
|
elif [[ $key == "" ]] # nothing, i.e the read delimiter - ENTER
|
||||||
|
then break
|
||||||
|
fi
|
||||||
|
echo -en "\e[${count}A" # go up to the beginning to re-render
|
||||||
|
done
|
||||||
|
# export the selection to the requested output variable
|
||||||
|
printf -v $outvar "${options[$cur]}"
|
||||||
|
}
|
||||||
function clone_repo_with_retry(){
|
function clone_repo_with_retry(){
|
||||||
REPO_NAME=$1
|
REPO_NAME=$1
|
||||||
echo "starting to pull into $(pwd)"
|
echo "starting to pull into $(pwd)"
|
||||||
|
|
@ -156,45 +189,23 @@ fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if [ -f $WA_REPO/node_type.sh ]; then
|
selections=(
|
||||||
source $WA_REPO/node_type.sh
|
"Init Master"
|
||||||
else
|
"Join Worker"
|
||||||
echo " "
|
"Stop Setup"
|
||||||
echo -n "init as master? type yes: "
|
)
|
||||||
read -r init_as_master
|
|
||||||
|
|
||||||
|
choose_from_menu "Please make a choice:" selected_choice "${selections[@]}"
|
||||||
|
|
||||||
if [ "$init_as_master" = "yes" ]; then
|
if [ "$selected_choice" = "Init Master" ]; then
|
||||||
echo "node type set to master"
|
echo "<=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=>"
|
||||||
echo -n "export NODE_TYPE=master" | tee $WA_REPO/node_type.sh
|
echo "initializing K8s Master Set-Up"
|
||||||
NODE_TYPE=master
|
source $WA_REPO/shared_resources_k8s/k8s/init_master.sh
|
||||||
else
|
else if [ "$selected_choice" = "Join Worker" ]; then
|
||||||
echo "node type set to master"
|
|
||||||
echo -n "export NODE_TYPE=worker" | tee $WA_REPO/node_type.sh
|
|
||||||
NODE_TYPE=worker
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
echo " "
|
|
||||||
echo -n "ready to set-up K8s? type yes: "
|
|
||||||
read -r ready_to_setup_k8s
|
|
||||||
|
|
||||||
if [ "$ready_to_setup_k8s" = "yes" ]; then
|
|
||||||
|
|
||||||
if [ "$NODE_TYPE" = "master" ]; then
|
|
||||||
echo "<=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=>"
|
echo "<=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=>"
|
||||||
echo "initializing K8s Master Set-Up"
|
echo "initializing K8s Master Set-Up"
|
||||||
source $WA_REPO/shared_resources_k8s/k8s/init_master.sh
|
source $WA_REPO/shared_resources_k8s/k8s/init_master.sh
|
||||||
else
|
|
||||||
echo "<=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=>"
|
|
||||||
echo "initializing K8s Worker Set-Up"
|
|
||||||
source $WA_REPO/shared_resources_k8s/k8s/setup_worker.sh
|
|
||||||
fi
|
|
||||||
|
|
||||||
else
|
else
|
||||||
echo "Aborting"
|
echo "Aborting"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
if
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue