script: Fix whiptail cancel behavior

set -e causes the script to exit when whiptail exit with 1 (meaning user picked cancel)
This commit is contained in:
Yifei Ding
2021-11-10 18:19:15 -08:00
parent 0b737e46b4
commit fa1fe33fe1
2 changed files with 74 additions and 68 deletions

View File

@@ -43,77 +43,82 @@ Do you want to update now?" \
fi
}
main_menu(){
#print KIAUH update msg if update available
if [ "$KIAUH_UPDATE_AVAIL" = "true" ]; then
kiauh_update_dialog
fi
main_menu() {
#print KIAUH update msg if update available
if [ "$KIAUH_UPDATE_AVAIL" = "true" ]; then
kiauh_update_dialog
fi
#check install status
print_kiauh_version
klipper_status
moonraker_status
dwc2_status
fluidd_status
mainsail_status
octoprint_status
klipperscreen_status
MoonrakerTelegramBot_status
print_branch
print_kiauh_version
klipper_status
moonraker_status
dwc2_status
fluidd_status
mainsail_status
octoprint_status
klipperscreen_status
MoonrakerTelegramBot_status
print_branch
print_msg && clear_msg
while true; do
MAIN_MENU=$(whiptail --title "$KIAUH_TITLE" --cancel-button "Quit" --menu "Choose an option:"\
"$KIAUH_WHIPTAIL_NORMAL_HEIGHT" "$KIAUH_WHIPTAIL_NORMAL_WIDTH" 8\
"0 Upload Log" "Upload Log For Bug Report"\
"1 Status" "Status Page"\
"2 Install" "Install Instances"\
"3 Update" "Update Instances"\
"4 Remove" "Remove Instances"\
"5 Advanced" "Advanced Settings"\
"6 Backup" "Backup"\
"7 Settings" "Configure KIAUH" 3>&1 1>&2 2>&3)
case "$MAIN_MENU" in
1\ *) echo "Current status" ;;
2\ *) install_menu ;;
3\ *) update_menu ;;
4\ *) remove_menu ;;
5\ *) advanced_menu ;;
6\ *) backup_menu ;;
7\ *) settings_menu ;;
0\ *) do_action "upload_selection" && break;;
*) echo "Unknown Command";;
esac
local menu_str="Klipper: $KLIPPER_STATUS Branch: $PRINT_BRANCH\n
Moonraker: $MOONRAKER_STATUS\n
Mainsail: $MAINSAIL_STATUS Fluidd: $FLUIDD_STATUS
KlipperScreen: $KLIPPERSCREEN_STATUS Telegram Bot: $MOONRAKER_TELEGRAM_BOT_STATUS
DWC2: $DWC2_STATUS Octoprint: $OCTOPRINT_STATUS"
local menu_choices=("1" "Install" "2" "Update" "3" "Remove" "4" "Advanced Settings" "5" "Backup" "6" "Settings" "7" "Upload Log")
local menu
menu=$(whiptail --title "$KIAUH_TITLE $KIAUH_VER" --cancel-button "Finish" --notags --menu "$menu_str\n\nChoose an option:" \
"$KIAUH_WHIPTAIL_NORMAL_HEIGHT" "$KIAUH_WHIPTAIL_NORMAL_WIDTH" 8 "${menu_choices[@]}" 3>&1 1>&2 2>&3)
local out=$?
if [ $out -eq 1 ]; then
break
elif [ $out -eq 1 ]; then
case "$menu" in
1) install_menu ;;
2) update_menu ;;
3) remove_menu ;;
4) advanced_menu ;;
5) backup_menu ;;
6) settings_menu ;;
7) upload_selection ;;
esac
else
exit 1
fi
done
echo -e "${green}###### Happy printing! ######${default}"; echo
# while true; do
# read -p "${cyan}Perform action:${default} " action; echo
# case "$action" in
# "start klipper") do_action_service "start" "klipper"; main_ui;;
# "stop klipper") do_action_service "stop" "klipper"; main_ui;;
# "restart klipper") do_action_service "restart" "klipper"; main_ui;;
# "start moonraker") do_action_service "start" "moonraker"; main_ui;;
# "stop moonraker") do_action_service "stop" "moonraker"; main_ui;;
# "restart moonraker")do_action_service "restart" "moonraker"; main_ui;;
# "start dwc") do_action_service "start" "dwc"; main_ui;;
# "stop dwc") do_action_service "stop" "dwc"; main_ui;;
# "restart dwc") do_action_service "restart" "dwc"; main_ui;;
# "start octoprint") do_action_service "start" "octoprint"; main_ui;;
# "stop octoprint") do_action_service "stop" "octoprint"; main_ui;;
# "restart octoprint") do_action_service "restart" "octoprint"; main_ui;;
# update) do_action "update_kiauh" "main_ui";;
# 0) do_action "upload_selection" "main_ui";;
# 1) clear && install_menu && break;;
# 2) clear && update_menu && break;;
# 3) clear && remove_menu && break;;
# 4) clear && advanced_menu && break;;
# 5) clear && backup_menu && break;;
# 6) clear && settings_menu && break;;
# Q|q)
# echo -e "${green}###### Happy printing! ######${default}"; echo
# exit -1;;
# *)
# deny_action "main_ui";;
# esac
# done
# clear; main_menu
# while true; do
# read -p "${cyan}Perform action:${default} " action; echo
# case "$action" in
# "start klipper") do_action_service "start" "klipper"; main_ui;;
# "stop klipper") do_action_service "stop" "klipper"; main_ui;;
# "restart klipper") do_action_service "restart" "klipper"; main_ui;;
# "start moonraker") do_action_service "start" "moonraker"; main_ui;;
# "stop moonraker") do_action_service "stop" "moonraker"; main_ui;;
# "restart moonraker")do_action_service "restart" "moonraker"; main_ui;;
# "start dwc") do_action_service "start" "dwc"; main_ui;;
# "stop dwc") do_action_service "stop" "dwc"; main_ui;;
# "restart dwc") do_action_service "restart" "dwc"; main_ui;;
# "start octoprint") do_action_service "start" "octoprint"; main_ui;;
# "stop octoprint") do_action_service "stop" "octoprint"; main_ui;;
# "restart octoprint") do_action_service "restart" "octoprint"; main_ui;;
# update) do_action "update_kiauh" "main_ui";;
# 0) do_action "upload_selection" "main_ui";;
# 1) clear && install_menu && break;;
# 2) clear && update_menu && break;;
# 3) clear && remove_menu && break;;
# 4) clear && advanced_menu && break;;
# 5) clear && backup_menu && break;;
# 6) clear && settings_menu && break;;
# Q|q)
# echo -e "${green}###### Happy printing! ######${default}"; echo
# exit -1;;
# *)
# deny_action "main_ui";;
# esac
# done
# clear; main_menu
}