fix: dialog allowed a higher option than actually possible

Signed-off-by: Dominik Willner th33xitus@gmail.com
This commit is contained in:
th33xitus
2022-04-17 18:59:11 +02:00
parent 02d0ce8a78
commit f362cdce8f

View File

@@ -13,7 +13,7 @@ set -e
function change_klipper_repo_menu(){ function change_klipper_repo_menu(){
local repo_file="${SRCDIR}/kiauh/klipper_repos.txt" local repo_file="${SRCDIR}/kiauh/klipper_repos.txt"
local url branch i=0 local url branch
top_border top_border
echo -e "| ~~~~~~~~ [ Set custom Klipper repo ] ~~~~~~~~ | " echo -e "| ~~~~~~~~ [ Set custom Klipper repo ] ~~~~~~~~ | "
@@ -27,52 +27,51 @@ function change_klipper_repo_menu(){
while IFS="," read -r col1 col2; do while IFS="," read -r col1 col2; do
url+=("${col1}") url+=("${col1}")
branch+=("${col2}") branch+=("${col2}")
i=$((i+1)) done < <(grep "" "${repo_file}" | tail -n "+11")
done < <(grep "" "${repo_file}" | tail -n "+12")
while true; do while true; do
read -p "${cyan}Select Klipper repo:${white} " option read -p "${cyan}Perform action:${white} " option
if [ "${option}" = "b" ] || [ "${option}" = "B" ]; then case "${option}" in
clear && print_header 0 | "$((option < ${#url[@]}))")
settings_menu if [ -d "${KLIPPER_DIR}" ]; then
break top_border
elif [ "${option}" = "h" ] || [ "${option}" = "H" ]; then echo -e "| ${red}!!! ATTENTION !!!${white} |"
clear && print_header echo -e "| Existing Klipper folder found! Proceeding will remove | "
show_custom_klipper_repo_help echo -e "| the existing Klipper folder and replace it with a | "
elif [ "${option}" -le ${#url[@]} ]; then echo -e "| clean copy of the previously selected source repo! | "
if [ -d "${KLIPPER_DIR}" ]; then bottom_border
top_border while true; do
echo -e "| ${red}!!! ATTENTION !!!${white} |" read -p "${cyan}###### Proceed? (Y/n):${white} " yn
echo -e "| Existing Klipper folder found! Proceeding will remove | " case "${yn}" in
echo -e "| the existing Klipper folder and replace it with a | " Y|y|Yes|yes|"")
echo -e "| clean copy of the previously selected source repo! | " select_msg "Yes"
bottom_border switch_klipper_repo "${url[${option}]}" "${branch[${option}]}"
while true; do set_custom_klipper_repo "${url[${option}]}" "${branch[${option}]}"
read -p "${cyan}###### Proceed? (Y/n):${white} " yn break;;
case "${yn}" in N|n|No|no)
Y|y|Yes|yes|"") select_msg "No"
select_msg "Yes" break;;
switch_klipper_repo "${url[${option}]}" "${branch[${option}]}" *)
set_custom_klipper_repo "${url[${option}]}" "${branch[${option}]}" error_msg "Invalid command!";;
break;; esac
N|n|No|no) done
select_msg "No" else
break;; status_msg "Set custom Klipper repository to:\n ● Repository URL: ${url[${option}]}\n ● Branch: ${branch[${option}]}"
*) set_custom_klipper_repo "${url[${option}]}" "${branch[${option}]}"
error_msg "Invalid command!";; ok_msg "This repo will now be used for new Klipper installations!\n"
esac fi
done break;;
else B|b)
status_msg "Set custom Klipper repository to:\n ● Repository URL: ${url[${option}]}\n ● Branch: ${branch[${option}]}" clear && print_header
set_custom_klipper_repo "${url[${option}]}" "${branch[${option}]}" settings_menu
ok_msg "This repo will now be used for new Klipper installations!\n" break;;
fi H|h)
break clear && print_header
else show_custom_klipper_repo_help
clear && print_header break;;
print_error "Invalid command!" *)
change_klipper_repo_menu error_msg "Invalid command!";;
fi esac
done done
} }
@@ -95,9 +94,10 @@ function switch_klipper_repo(){
url=${1} branch=${2} url=${1} branch=${2}
status_msg "Switching Klipper repository..." status_msg "Switching Klipper repository..."
do_action_service "stop" "klipper" do_action_service "stop" "klipper"
cd ~ && rm -rf "${KLIPPER_DIR}" cd "${HOME}"
git clone "${url}" && cd "${KLIPPER_DIR}" [ -d "${KLIPPER_DIR}" ] && rm -rf "${KLIPPER_DIR}"
git checkout "${branch}" && cd ~ git clone "${url}" "klipper" && cd "${KLIPPER_DIR}"
git checkout "${branch}" && cd "${HOME}"
do_action_service "start" "klipper" do_action_service "start" "klipper"
} }