diff --git a/README.md b/README.md index 4dee8e4..0f85e4d 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ **usage** -bash <(curl -sk https://git.service.wiseadvice.eu/wiseadvice_public_repos/wa_public_init_repo/raw/branch/main/init.sh) \ No newline at end of file +zsh <(curl -sk https://git.service.wiseadvice.eu/wiseadvice_public_repos/wa_public_init_repo/raw/branch/main/init.sh) \ No newline at end of file diff --git a/init.sh b/init.sh index 7b85b18..de62ec2 100755 --- a/init.sh +++ b/init.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/zsh WA_REPO=$HOME/wa_repos @@ -9,40 +9,6 @@ echo "################################################" echo " basic init of wiseadvice node " 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(){ REPO_NAME=$1 @@ -188,25 +154,34 @@ EOT fi fi +mainmenu() { + echo -ne " +MAIN MENU +1) Init Master +2) Join Worker +0) Exit +Choose an option: " + read -r ans + case $ans in + 1) + echo "<=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=>" + echo "initializing K8s Master Set-Up" + source $WA_REPO/shared_resources_k8s/k8s/init_master.sh + ;; + 2) + echo "<=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=>" + echo "initializing K8s Master Set-Up" + source $WA_REPO/shared_resources_k8s/k8s/init_master.sh + ;; + 0) + echo "Bye bye." + exit 0 + ;; + *) + echo "Wrong option." + mainmenu + ;; + esac +} - -selections=( -"Init Master" -"Join Worker" -"Stop Setup" -) -choose_from_menu "Please make a choice:" selected_choice "${selections[@]}" - - -if [ "$selected_choice" = "Init Master" ]; then - echo "<=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=>" - echo "initializing K8s Master Set-Up" - zsh $WA_REPO/shared_resources_k8s/k8s/init_master.sh -else if [ "$selected_choice" = "Join Worker" ]; then - echo "<=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=>" - echo "initializing K8s Master Set-Up" - zsh $WA_REPO/shared_resources_k8s/k8s/init_master.sh -else - echo "Aborting" - exit 0 -if \ No newline at end of file +mainmenu