scale-catalog/functions/menu.sh

286 lines
12 KiB
Bash
Raw Normal View History

2022-07-26 19:08:33 +00:00
#!/bin/bash
menu(){
2022-07-27 01:04:27 +00:00
clear -x
title
echo "1) Help"
echo "2) List DNS Names"
echo "3) Mount and Unmount PVC storage"
echo "4) Create a Backup"
echo "5) Restore a Backup"
echo "6) Delete a Backup"
echo "7) Update HeavyScript"
echo "8) Update Applications"
2022-08-09 02:12:09 +00:00
echo "9) Command to Container"
2022-07-27 01:04:27 +00:00
echo
echo "0) Exit"
2022-07-30 22:12:45 +00:00
read -rt 120 -p "Please select an option by number: " selection
2022-07-27 00:21:45 +00:00
2022-07-27 01:04:27 +00:00
case $selection in
2022-07-27 00:21:45 +00:00
0)
exit
;;
1)
help="true"
;;
2)
dns="true"
;;
3)
mount="true"
;;
4)
2022-07-30 22:43:42 +00:00
read -rt 120 -p "What is the maximun number of backups you would like?: " number_of_backups || echo "Failed to make a selection"
2022-07-27 02:21:48 +00:00
backup="true"
2022-07-27 04:45:12 +00:00
;;
2022-07-27 00:21:45 +00:00
5)
restore="true"
;;
6)
2022-07-27 00:40:07 +00:00
deleteBackup="true"
2022-07-27 00:21:45 +00:00
;;
7)
self_update="true"
;;
8)
while true
do
clear -x
title
echo "Choose Your Update Type"
echo "-----------------------"
echo "1) -U | Update all applications, ignores versions"
echo "2) -u | Update all applications, does not update Major releases"
echo
echo "0) Exit"
echo
2022-07-30 22:43:42 +00:00
read -rt 120 -p "Type the Number or Flag: " current_selection || { echo -e "\nFailed to make a selection in time" ; exit; }
case $current_selection in
0 | [Ee][Xx][Ii][Tt])
echo "Exiting.."
exit
;;
1 | -U)
while true
do
echo -e "\nHow many applications do you want updating at the same time?"
read -rt 120 -p "Please type an integer greater than 0: " up_async || { echo -e "\nFailed to make a selection in time" ; exit; }
if [[ $up_async == 0 ]]; then
echo "Error: \"$up_async\" is less than 1"
echo "NOT adding it to the list"
sleep 3
continue
elif ! [[ $up_async =~ ^[0-9]+$ ]]; then
echo "Error: \"$up_async\" is invalid, it needs to be an integer"
echo "NOT adding it to the list"
sleep 3
continue
else
update_selection+=("-U" "$up_async")
break
fi
done
break
;;
2 | -u)
while true
do
echo -e "\nHow many applications do you want updating at the same time?"
read -rt 120 -p "Please type an integer greater than 0: " up_async || { echo -e "\nFailed to make a selection in time" ; exit; }
if [[ $up_async == 0 ]]; then
echo "Error: \"$up_async\" is less than 1"
echo "NOT adding it to the list"
sleep 3
continue
elif ! [[ $up_async =~ ^[0-9]+$ ]]; then
echo "Error: \"$up_async\" is invalid, it needs to be an integer"
echo "NOT adding it to the list"
sleep 3
continue
else
update_selection+=("-u" "$up_async")
break
fi
done
break
;;
*)
echo "$current_selection was not an option, try again" && sleep 3
continue
;;
esac
2022-07-27 00:21:45 +00:00
done
while true
do
clear -x
title
2022-08-01 01:01:16 +00:00
echo "Update Options"
echo "--------------"
echo "1) -r | Roll-back applications if they fail to update"
2022-08-01 20:16:54 +00:00
echo "2) -i | Add application to ignore list"
2022-08-01 01:01:16 +00:00
echo "3) -S | Shutdown applications prior to updating"
echo "4) -v | verbose output"
echo "5) -t | Set a custom timeout in seconds when checking if either an App or Mountpoint correctly Started, Stopped or (un)Mounted. Defaults to 500 seconds"
echo
echo "Additional Options"
echo "------------------"
echo "6) -b | Back-up your ix-applications dataset, specify a number after -b"
2022-07-27 00:21:45 +00:00
echo "7) -s | sync catalog"
echo "8) -p | Prune unused/old docker images"
2022-07-28 22:04:41 +00:00
echo "9) --self-update | Updates HeavyScript prior to running any other commands"
2022-07-27 00:21:45 +00:00
echo
2022-07-27 05:25:08 +00:00
echo "99) Remove Update Options, Restart"
echo "00) Done making selections, proceed with update"
2022-07-27 00:21:45 +00:00
echo
2022-07-29 07:26:47 +00:00
echo "0) Exit"
echo
2022-07-27 00:21:45 +00:00
echo "Current Choices"
echo "---------------"
echo "bash heavy_script.sh ${update_selection[*]}"
echo
2022-07-30 22:43:42 +00:00
read -rt 600 -p "Type the Number or Flag: " current_selection || { echo -e "\nFailed to make a selection in time" ; exit; }
2022-07-27 04:45:12 +00:00
case $current_selection in
2022-07-30 22:43:42 +00:00
0 | [Ee][Xx][Ii][Tt])
2022-07-29 07:26:47 +00:00
echo "Exiting.."
exit
;;
2022-07-27 05:25:08 +00:00
00)
2022-07-27 04:45:12 +00:00
clear -x
echo "Running \"bash heavy_script.sh ${update_selection[*]}\""
echo
exec bash "$script_name" "${update_selection[@]}"
exit
;;
2022-08-01 01:01:16 +00:00
1 | -r)
printf '%s\0' "${update_selection[@]}" | grep -Fxqz -- "-r" && echo -e "\"-r\" is already on here, skipping" && sleep 3 && continue #If option is already on there, skip it
update_selection+=("-r")
2022-07-27 04:45:12 +00:00
;;
2022-07-27 05:40:48 +00:00
2 | -i)
2022-07-30 22:43:42 +00:00
read -rt 120 -p "What is the name of the application we should ignore?: " up_ignore || { echo -e "\nFailed to make a selection in time" ; exit; }
2022-07-29 22:13:01 +00:00
! [[ $up_ignore =~ ^[a-zA-Z]([-a-zA-Z0-9]*[a-zA-Z0-9])?$ ]] && echo -e "Error: \"$up_ignore\" is not a possible option for an application name" && sleep 3 && continue
2022-07-27 04:45:12 +00:00
update_selection+=("-i" "$up_ignore")
;;
2022-08-01 01:01:16 +00:00
3 | -S)
2022-07-29 22:13:01 +00:00
printf '%s\0' "${update_selection[@]}" | grep -Fxqz -- "-S" && echo -e "\"-S\" is already on here, skipping" && sleep 3 && continue #If option is already on there, skip it
2022-07-27 04:45:12 +00:00
update_selection+=("-S")
;;
2022-08-01 01:01:16 +00:00
4 | -v)
2022-07-29 22:13:01 +00:00
printf '%s\0' "${update_selection[@]}" | grep -Fxqz -- "-v" && echo -e "\"-v\" is already on here, skipping" && sleep 3 && continue #If option is already on there, skip it
2022-07-27 04:45:12 +00:00
update_selection+=("-v")
;;
2022-08-01 01:01:16 +00:00
5 | -t)
2022-07-29 22:13:01 +00:00
printf '%s\0' "${update_selection[@]}" | grep -Fxqz -- "-t" && echo -e "\"-t\" is already on here, skipping" && sleep 3 && continue #If option is already on there, skip it
2022-07-27 04:45:12 +00:00
echo "What do you want your timeout to be?"
2022-07-30 22:43:42 +00:00
read -rt 120 -p "Please type an integer: " up_timeout || { echo -e "\nFailed to make a selection in time" ; exit; }
2022-07-29 22:13:01 +00:00
! [[ $up_timeout =~ ^[0-9]+$ ]] && echo -e "Error: \"$up_timeout\" is invalid, it needs to be an integer\nNOT adding it to the list" && sleep 3 && continue
2022-07-27 04:54:14 +00:00
update_selection+=("-t" "$up_timeout")
2022-07-27 04:45:12 +00:00
;;
2022-08-01 01:01:16 +00:00
6 | -b)
printf '%s\0' "${update_selection[@]}" | grep -Fxqz -- "-b" && echo -e "\"-b\" is already on here, skipping" && sleep 3 && continue #If option is already on there, skip it
echo "Up to how many backups should we keep?"
read -rt 120 -p "Please type an integer: " up_backups || { echo -e "\nFailed to make a selection in time" ; exit; }
! [[ $up_backups =~ ^[0-9]+$ ]] && echo -e "Error: \"$up_backups\" is invalid, it needs to be an integer\nNOT adding it to the list" && sleep 3 && continue
[[ $up_backups == 0 ]] && echo -e "Error: Number of backups cannot be 0\nNOT adding it to the list" && sleep 3 && continue
update_selection+=("-b" "$up_backups")
;;
2022-07-27 05:40:48 +00:00
7 | -s)
2022-07-29 22:13:01 +00:00
printf '%s\0' "${update_selection[@]}" | grep -Fxqz -- "-s" && echo -e "\"-s\" is already on here, skipping" && sleep 3 && continue #If option is already on there, skip it
2022-07-27 04:45:12 +00:00
update_selection+=("-s")
;;
2022-07-27 05:40:48 +00:00
8 | -p)
2022-07-29 22:13:01 +00:00
printf '%s\0' "${update_selection[@]}" | grep -Fxqz -- "-p" && echo -e "\"-p\" is already on here, skipping" && sleep 3 && continue #If option is already on there, skip it
2022-07-27 04:45:12 +00:00
update_selection+=("-p")
;;
2022-07-28 22:04:41 +00:00
9 | --self-update )
2022-07-29 22:13:01 +00:00
printf '%s\0' "${update_selection[@]}" | grep -Fxqz -- "--self-update" && echo -e "\"--self-update\" is already on here, skipping" && sleep 3 && continue #If option is already on there, skip it
2022-07-28 22:04:41 +00:00
update_selection+=("--self-update")
;;
2022-07-27 05:21:10 +00:00
99)
2022-07-27 05:22:55 +00:00
count=2
2022-07-27 05:21:10 +00:00
echo "restarting"
2022-07-27 05:22:55 +00:00
for i in "${update_selection[@]:2}"
2022-07-27 05:21:10 +00:00
do
unset "update_selection[$count]"
echo "$i removed"
2022-07-27 05:22:55 +00:00
((count++))
2022-07-27 05:21:10 +00:00
done
2022-07-29 22:13:01 +00:00
sleep 3
2022-07-27 05:21:10 +00:00
continue
;;
2022-07-27 04:45:12 +00:00
*)
2022-07-29 22:13:01 +00:00
echo "\"$current_selection\" was not an option, try again" && sleep 3 && continue
2022-07-27 04:45:12 +00:00
;;
esac
2022-07-27 00:21:45 +00:00
done
;;
2022-08-09 02:12:09 +00:00
9)
app_name=$(k3s kubectl get pods -A | awk '{print $1}' | sort -u | grep -v "system" | sed '1d' | sed 's/^[^-]*-//' | nl -s ") " | column -t)
2022-08-09 02:28:36 +00:00
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
2022-08-09 02:29:58 +00:00
echo "Exiting.."
2022-08-09 02:28:36 +00:00
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
2022-08-09 02:12:09 +00:00
app_name=$(echo -e "$app_name" | grep ^"$selection)" | awk '{print $2}')
search=$(k3s crictl ps -a -s running)
2022-08-09 02:43:07 +00:00
mapfile -t pod_id < <(echo "$search" | grep -E " $app_name( |-)?" | awk '{print $9}')
2022-08-09 02:12:09 +00:00
containers=$(
for pod in "${pod_id[@]}"
do
echo "$search" | grep "$pod" | awk '{print $7}'
done | nl -s ") " | column -t)
2022-08-09 02:28:36 +00:00
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
2022-08-09 02:29:58 +00:00
echo "Exiting.."
2022-08-09 02:28:36 +00:00
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}')
2022-08-09 02:12:09 +00:00
clear -x
title
2022-08-09 02:28:36 +00:00
echo "App Name: $app_name"
echo "Container $container"
2022-08-09 02:12:09 +00:00
echo
echo "0) Exit"
2022-08-09 02:28:36 +00:00
read -rt 120 -p "What command would you like to run?: " command || { echo -e "\nFailed to make a selection in time" ; exit; }
2022-08-09 02:29:58 +00:00
[[ $command == 0 ]] && echo "Exiting.." && exit
2022-08-09 02:12:09 +00:00
k3s crictl exec "$container_id" $command
container=$(echo -e "$app_name" | grep ^"$selection)" | awk '{print $2}')
;;
2022-07-27 00:21:45 +00:00
*)
2022-07-29 22:13:01 +00:00
echo "\"$selection\" was not an option, please try agian" && sleep 3 && menu
2022-07-27 00:21:45 +00:00
;;
2022-07-27 01:04:27 +00:00
esac
echo
2022-07-26 19:08:33 +00:00
}
2022-08-01 20:16:54 +00:00
export -f menu