From 887e69cb36caac435935acfb81adf0657adbea0e Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Mon, 8 Aug 2022 20:28:36 -0600 Subject: [PATCH] while loops to cmd to cnter --- functions/menu.sh | 63 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 17 deletions(-) diff --git a/functions/menu.sh b/functions/menu.sh index 6d9063c9..b4cd224b 100644 --- a/functions/menu.sh +++ b/functions/menu.sh @@ -215,14 +215,26 @@ case $selection in ;; 9) - title - clear -x app_name=$(k3s kubectl get pods -A | awk '{print $1}' | sort -u | grep -v "system" | sed '1d' | sed 's/^[^-]*-//' | nl -s ") " | column -t) - echo "$app_name" - echo - echo "0) Exit" - [[ $selection == 0 ]] && echo "Exiting.." && exit - read -rt 120 -p "Please type a number: " selection || { echo -e "\nFailed to make a selection in time" ; exit; } + while true + do + clear -x + title + echo "$app_name" + echo + echo "0) Exit" + read -rt 120 -p "Please type a number: " selection || { echo -e "\nFailed to make a selection in time" ; exit; } + if [[ $selection == 0 ]]; then + echo "Exitting.." + exit + elif ! echo -e "$app_name" | grep -qs ^"$selection)" ; then + echo "Error: \"$selection\" was not an option.. Try again" + sleep 3 + continue + else + break + fi + done app_name=$(echo -e "$app_name" | grep ^"$selection)" | awk '{print $2}') search=$(k3s crictl ps -a -s running) mapfile -t pod_id < <(echo "$search" | grep "$app_name" | awk '{print $9}') @@ -232,18 +244,35 @@ case $selection in do echo "$search" | grep "$pod" | awk '{print $7}' done | nl -s ") " | column -t) - clear -x - title - echo "$containers" - echo - echo "0) Exit" - read -rt 120 -p "Choose a container by number: " selection || { echo -e "\nFailed to make a selection in time" ; exit; } - [[ $selection == 0 ]] && echo "Exiting.." && exit - + while true + do + clear -x + title + echo "$containers" + echo + echo "0) Exit" + read -rt 120 -p "Choose a container by number: " selection || { echo -e "\nFailed to make a selection in time" ; exit; } + if [[ $selection == 0 ]]; then + echo "Exitting.." + exit + elif ! echo -e "$containers" | grep -qs ^"$selection)" ; then + echo "Error: \"$selection\" was not an option.. Try again" + sleep 3 + continue + else + break + fi + done container=$(echo "$containers" | grep ^"$selection)" | awk '{print $2}') container_id=$(echo "$search" | grep "$container" | awk '{print $1}') - - read -rt 120 -p "What command would you like to submit to $app_name on $container?: " command || { echo -e "\nFailed to make a selection in time" ; exit; } + clear -x + title + echo "App Name: $app_name" + echo "Container $container" + echo + echo "0) Exit" + read -rt 120 -p "What command would you like to run?: " command || { echo -e "\nFailed to make a selection in time" ; exit; } + [[ $command == 0 ]] && echo "Exitting.." && exit k3s crictl exec "$container_id" $command container=$(echo -e "$app_name" | grep ^"$selection)" | awk '{print $2}') ;;