script: Move functions

hove print_kiauh_version and kiauh_update_dialog to general_ui and functions

main_menu performance improvements
This commit is contained in:
Yifei Ding
2021-11-12 14:44:05 -08:00
parent 980f6d5ddd
commit 90208f6480
4 changed files with 80 additions and 50 deletions

View File

@@ -1,9 +1,11 @@
#!/bin/bash
# setting up some frequently used functions
check_euid(){
if [ "$EUID" -eq 0 ]
then
whiptail --title "$KIAUH_TITLE" --msgbox "!!! THIS SCRIPT MUST NOT RAN AS ROOT !!!"\
"$KIAUH_WHIPTAIL_HEIGHT" "$KIAUH_WHIPTAIL_WIDTH"
"$KIAUH_WHIPTAIL_SINGLE_LINE_HEIGHT" "$KIAUH_WHIPTAIL_NORMAL_WIDTH"
exit 1
fi
}
@@ -453,3 +455,9 @@ init_ini(){
fi
fetch_webui_ports
}
print_kiauh_version() {
cd ${SRCDIR}/kiauh
KIAUH_VER=$(git describe HEAD --always --tags | cut -d "-" -f 1,2)
KIAUH_VER="$(printf "%-20s" "$KIAUH_VER")"
}

View File

@@ -61,3 +61,31 @@ deny_action(){
print_msg && clear_msg
$1
}
#######################################
# description Advise user to update KIAUH
# Globals:
# KIAUH_WHIPTAIL_NORMAL_HEIGHT
# KIAUH_WHIPTAIL_NORMAL_WIDTH
# RET
# Arguments:
# None
#######################################
kiauh_update_dialog() {
whiptail --title "New KIAUH update available!" \
--yesno \
"View Changelog: https://git.io/JnmlX
It is recommended to keep KIAUH up to date. Updates usually contain bugfixes, \
important changes or new features. Please consider updating!
Do you want to update now?" \
"$KIAUH_WHIPTAIL_NORMAL_HEIGHT" "$KIAUH_WHIPTAIL_NORMAL_WIDTH"
local out=$?
if [ $out -eq 0 ]; then
do_action "update_kiauh"
else
deny_action "kiauh_update_dialog"
fi
}

View File

@@ -1,67 +1,43 @@
#!/bin/bash
print_kiauh_version() {
cd ${SRCDIR}/kiauh
KIAUH_VER=$(git describe HEAD --always --tags | cut -d "-" -f 1,2)
KIAUH_VER="$(printf "%-20s" "$KIAUH_VER")"
}
#######################################
# description Advise user to update KIAUH
# Globals:
# KIAUH_WHIPTAIL_NORMAL_HEIGHT
# KIAUH_WHIPTAIL_NORMAL_WIDTH
# RET
# Arguments:
# None
#######################################
kiauh_update_dialog() {
whiptail --title "New KIAUH update available!" \
--yesno \
"View Changelog: https://git.io/JnmlX
It is recommended to keep KIAUH up to date. Updates usually contain bugfixes, \
important changes or new features. Please consider updating!
Do you want to update now?" \
"$KIAUH_WHIPTAIL_NORMAL_HEIGHT" "$KIAUH_WHIPTAIL_NORMAL_WIDTH"
local out=$?
if [ $out -eq 0 ]; then
do_action "update_kiauh"
else
deny_action "kiauh_update_dialog"
fi
}
main_menu() {
#print KIAUH update msg if update available
local menu_options=(
"1" "Install"\
"2" "Update"\
"3" "Remove"\
"4" "Advanced Settings"\
"5" "Backup"\
"6" "Settings"\
"7" "Upload Log"\
"8" "Service")
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_msg && clear_msg
while true; do
while true; do
#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_msg && clear_msg
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" "8" "Service")
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)
"$KIAUH_WHIPTAIL_NORMAL_HEIGHT" "$KIAUH_WHIPTAIL_NORMAL_WIDTH" 8 "${menu_options[@]}" 3>&1 1>&2 2>&3)
local out=$?
if [ $out -eq 1 ]; then
break

View File

@@ -0,0 +1,18 @@
#!/bin/bash
# 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";;