diff --git a/kiauh.sh b/kiauh.sh index 6714d88..f25bfeb 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -10,26 +10,6 @@ red=$(echo -en "\001\033[01;31m\002") cyan=$(echo -en "\001\033[01;36m\002") default=$(echo -en "\001\033[0m\002") -### set some messages -warn_msg(){ - echo -e "${red} $1${default}" -} -status_msg(){ - echo; echo -e "${yellow}###### $1${default}" -} -ok_msg(){ - echo -e "${green}>>>>>> $1${default}" -} -title_msg(){ - echo -e "${cyan}$1${default}" -} -get_date(){ - current_date=$(date +"%Y-%m-%d_%H-%M") -} -print_unkown_cmd(){ - ERROR_MSG=" Sorry i don't know that command!" -} - ### set important directories #klipper KLIPPER_DIR=${HOME}/klipper @@ -40,8 +20,6 @@ KLIPPER_SERVICE2=/etc/default/klipper DWC2FK_DIR=${HOME}/dwc2-for-klipper DWC2_DIR=${HOME}/sdcard/dwc2 WEB_DWC2=${HOME}/klipper/klippy/extras/web_dwc2.py -TORNADO_DIR1=${HOME}/klippy-env/lib/python2.7/site-packages/tornado -TORNADO_DIR2=${HOME}/klippy-env/lib/python2.7/site-packages/tornado-5.1.1.dist-info #mainsail/moonraker MAINSAIL_DIR=${HOME}/mainsail MOONRAKER_DIR=${HOME}/moonraker @@ -69,6 +47,26 @@ BRANCH_MOONRAKER=Arksine/dev-moonraker-testing BRANCH_SCURVE_SMOOTHING=dmbutyugin/scurve-smoothing BRANCH_SCURVE_SHAPING=dmbutyugin/scurve-shaping +### set some messages +warn_msg(){ + echo -e "${red} $1${default}" +} +status_msg(){ + echo; echo -e "${yellow}###### $1${default}" +} +ok_msg(){ + echo -e "${green}>>>>>> $1${default}" +} +title_msg(){ + echo -e "${cyan}$1${default}" +} +get_date(){ + current_date=$(date +"%Y-%m-%d_%H-%M") +} +print_unkown_cmd(){ + ERROR_MSG=" Sorry i don't know that command!" +} + print_msg(){ if [[ "$ERROR_MSG" != "" ]]; then echo -e "${red}" @@ -87,442 +85,14 @@ print_msg(){ } clear_msg(){ - CONFIRM_MSG="" && ERROR_MSG="" -} - -main_menu(){ - print_header - #print KIAUH update msg if update available - if [ "$KIAUH_UPDATE_AVAIL" = "true" ]; then - kiauh_update_msg - fi - #check install status - klipper_status - dwc2_status - mainsail_status - octoprint_status - print_branch - print_msg && clear_msg - main_ui - while true; do - echo -e "${cyan}" - read -p "Perform action: " action; echo - echo -e "${default}" - case "$action" in - update) - clear - print_header - update_kiauh - print_msg && clear_msg - main_ui;; - 0) - clear - print_header - ERROR_MSG="Sorry this function is not implemented yet!" - print_msg && clear_msg - 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;; - Q|q) - echo -e "${green}###### Happy printing! ######${default}"; echo - exit -1;; - *) - clear - print_header - print_unkown_cmd - print_msg && clear_msg - main_ui;; - esac - done - clear; main_menu -} - -install_menu(){ - print_header - install_ui - while true; do - echo -e "${cyan}" - read -p "Perform action: " action; echo - echo -e "${default}" - case "$action" in - 1) - clear - print_header - install_klipper - print_msg && clear_msg - install_ui;; - 2) - clear - print_header - install_moonraker - print_msg && clear_msg - install_ui;; - 3) - clear - print_header - install_dwc2 - print_msg && clear_msg - install_ui;; - 4) - clear - print_header - INST_MAINSAIL="true" && install_mainsail - print_msg && clear_msg - install_ui;; - 5) - clear - print_header - install_octoprint - print_msg && clear_msg - install_ui;; - Q|q) - clear; main_menu; break;; - *) - clear - print_header - print_unkown_cmd - print_msg && clear_msg - install_ui;; - esac - done - install_menu -} - -update_menu(){ - print_header - #compare versions - ui_print_versions - print_msg && clear_msg - read_bb4u_stat - update_ui - while true; do - echo -e "${cyan}" - read -p "Perform action: " action; echo - echo -e "${default}" - case "$action" in - 0) - clear - print_header - toggle_backups - print_msg && clear_msg - update_ui;; - 1) - clear - print_header - update_klipper && ui_print_versions - print_msg && clear_msg - update_ui;; - 2) - clear - print_header - update_dwc2fk && ui_print_versions - print_msg && clear_msg - update_ui;; - 3) - clear - print_header - update_dwc2 && ui_print_versions - print_msg && clear_msg - update_ui;; - 4) - clear - print_header - update_moonraker && ui_print_versions - print_msg && clear_msg - update_ui;; - 5) - clear - print_header - update_mainsail && ui_print_versions - print_msg && clear_msg - update_ui;; - Q|q) - clear; main_menu; break;; - *) - clear - print_header - print_unkown_cmd - print_msg && clear_msg - ui_print_versions - update_ui;; - esac - done - update_menu -} - -remove_menu(){ - print_header - remove_ui - while true; do - echo -e "${cyan}" - read -p "Perform action: " action; echo - echo -e "${default}" - case "$action" in - 1) - clear - print_header - remove_klipper - print_msg && clear_msg - remove_ui;; - 2) - clear - print_header - remove_moonraker - print_msg && clear_msg - remove_ui;; - 3) - clear - print_header - remove_dwc2 - print_msg && clear_msg - remove_ui;; - 4) - clear - print_header - remove_mainsail - print_msg && clear_msg - remove_ui;; - 5) - clear - print_header - remove_octoprint - print_msg && clear_msg - remove_ui;; - 6) - clear - print_header - remove_nginx - print_msg && clear_msg - remove_ui;; - Q|q) - clear; main_menu; break;; - *) - clear - print_header - print_unkown_cmd - print_msg && clear_msg - remove_ui;; - esac - done - remove_menu -} - -advanced_menu(){ - print_header - print_msg && clear_msg - read_octoprint_service_status - advanced_ui - while true; do - echo -e "${cyan}" - read -p "Perform action: " action; echo - echo -e "${default}" - case "$action" in - 0) - clear - print_header - toggle_octoprint_service - read_octoprint_service_status - print_msg && clear_msg - advanced_ui;; - 1) - clear - print_header - switch_menu - print_msg && clear_msg - advanced_ui;; - 2) - clear - print_header - load_klipper_state - print_msg && clear_msg - advanced_ui;; - 3) - clear - print_header - build_fw - print_msg && clear_msg - advanced_ui;; - 4) - clear - print_header - flash_routine - print_msg && clear_msg - advanced_ui;; - 5) - clear - print_header - get_printer_usb - print_msg && clear_msg - advanced_ui;; - 6) - clear - print_header - get_printer_usb && write_printer_usb - print_msg && clear_msg - advanced_ui;; - 7) - clear - print_header - create_dwc2fk_cfg - print_msg && clear_msg - advanced_ui;; - 8) - clear - print_header - create_custom_hostname - print_msg && clear_msg - advanced_ui;; - 9) - clear - print_header - remove_branding - print_msg && clear_msg - advanced_ui;; - Q|q) - clear; main_menu; break;; - *) - clear - print_header - print_unkown_cmd - print_msg && clear_msg - advanced_ui;; - esac - done - advanced_menu -} - -switch_menu(){ - if [ -d $KLIPPER_DIR ]; then - read_branch - print_msg && clear_msg - switch_ui - while true; do - echo -e "${cyan}" - read -p "Perform action: " action; echo - echo -e "${default}" - case "$action" in - 1) - clear - print_header - switch_to_origin - read_branch - print_msg && clear_msg - switch_ui;; - 2) - clear - print_header - switch_to_scurve_shaping - read_branch - print_msg && clear_msg - switch_ui;; - 3) - clear - print_header - switch_to_scurve_smoothing - read_branch - print_msg && clear_msg - switch_ui;; - 4) - clear - print_header - switch_to_moonraker - read_branch - print_msg && clear_msg - switch_ui;; - Q|q) - clear; advanced_menu; break;; - *) - clear - print_header - print_unkown_cmd - print_msg && clear_msg - switch_ui;; - esac - done - else - ERROR_MSG="No Klipper directory found! Download Klipper first!" - fi -} - -#rollback_menu(){ -# load_klipper_state -# print_msg && clear_msg -# advanced_menu -#} - -backup_menu(){ - print_header - print_msg && clear_msg - backup_ui - while true; do - echo -e "${cyan}" - read -p "Perform action: " action; echo - echo -e "${default}" - case "$action" in - 1) - clear - print_header - backup_klipper - print_msg && clear_msg - backup_ui;; - 2) - clear - print_header - backup_dwc2 - print_msg && clear_msg - backup_ui;; - 3) - clear - print_header - backup_mainsail - print_msg && clear_msg - backup_ui;; - 4) - clear - print_header - backup_moonraker - print_msg && clear_msg - backup_ui;; - 5) - clear - print_header - backup_octoprint - print_msg && clear_msg - backup_ui;; - Q|q) - clear; main_menu; break;; - *) - clear - print_header - print_unkown_cmd - print_msg && clear_msg - backup_ui;; - esac - done - backup_menu + unset CONFIRM_MSG + unset ERROR_MSG } ### sourcing all additional scripts SRCDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. && pwd )" -for script in "${SRCDIR}/kiauh/scripts/"*; do . $script; done +for script in "${SRCDIR}/kiauh/scripts/"*.sh; do . $script; done +for script in "${SRCDIR}/kiauh/scripts/ui/"*.sh; do . $script; done check_euid kiauh_status diff --git a/scripts/ui.sh b/scripts/ui.sh deleted file mode 100755 index f8ea188..0000000 --- a/scripts/ui.sh +++ /dev/null @@ -1,190 +0,0 @@ -### set up some UI stuff - -#ui total width = 57 chars -top_border(){ - echo -e "/=======================================================\ " -} - -bottom_border(){ - echo -e "\=======================================================/" -} - -hr(){ - echo -e "|-------------------------------------------------------|" -} - -quit_footer(){ - hr - echo -e "| ${red}Q) Quit${default} | " - bottom_border - echo -e " KIAUH: $CURR_KIAUH_BRANCH" -} - -print_header(){ - top_border - echo -e "| $(title_msg "~~~~~~~~~~~~~~~~~ [ KIAUH ] ~~~~~~~~~~~~~~~~~") |" - echo -e "| $(title_msg " Klipper Installation And Update Helper ") |" - echo -e "| $(title_msg "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") |" - bottom_border -} - -main_ui(){ - top_border - echo -e "| $(title_msg "~~~~~~~~~~~~~~~ [ Main Menu ] ~~~~~~~~~~~~~~~") |" - hr - echo -e "| | |" - echo -e "| 1) [Install] | Klipper: $KLIPPER_STATUS|" - echo -e "| 2) [Update] | Branch: ${cyan}$PRINT_BRANCH${default}|" - echo -e "| 3) [Remove] | |" - echo -e "| | DWC2: $DWC2_STATUS|" - echo -e "| 4) [Advanced] | Mainsail: $MAINSAIL_STATUS|" - echo -e "| 5) [Backup] | Octoprint: $OCTOPRINT_STATUS|" - echo -e "| | |" - quit_footer -} - -install_ui(){ - top_border - echo -e "| ${green}~~~~~~~~~~~ [ Installation Menu ] ~~~~~~~~~~~${default} | " - hr - echo -e "| You need this menu usually only for installing | " - echo -e "| all necessary dependencies for the various | " - echo -e "| functions on a completely fresh system. | " - hr - echo -e "| Firmware: | Webinterface: | " - echo -e "| 1) [Klipper] | 3) [DWC2] | " - echo -e "| | 4) [Mainsail] | " - echo -e "| Klipper API: | 5) [Octoprint] | " - echo -e "| 2) [Moonraker] | | " - quit_footer -} - -update_ui(){ - top_border - echo -e "| ${green}~~~~~~~~~~~~~~ [ Update Menu ] ~~~~~~~~~~~~~~${default} | " - hr - echo -e "| It is a good idea to check the following website | " - echo -e "| for important software changes to the config file | " - echo -e "| >> BEFORE << updating your klipper installation: | " - echo -e "| | " - echo -e "| ${yellow}https://www.klipper3d.org/Config_Changes.html${default} | " - bottom_border - top_border - echo -e "| 0) $BB4U_STATUS| " - hr - echo -e "| | Local Vers: | Remote Vers: | " - echo -e "| Firmware: | | | " - echo -e "| 1) [Klipper] | $(echo "$LOCAL_COMMIT") | $(echo "$REMOTE_COMMIT") | " - echo -e "| | | | " - echo -e "| Webinterface: |---------------|--------------| " - echo -e "| 2) [DWC2-for-Klipper] | $(echo "$LOCAL_DWC2FK_COMMIT") | $(echo "$REMOTE_DWC2FK_COMMIT") | " - echo -e "| 3) [DWC2 Web UI] | $(echo "$DWC2_LOCAL_VER") | $(echo "$DWC2_REMOTE_VER") | " - echo -e "| |---------------|--------------| " - echo -e "| 4) [Moonraker] | $(echo "$LOCAL_MOONRAKER_COMMIT") | $(echo "$REMOTE_MOONRAKER_COMMIT") | " - echo -e "| 5) [Mainsail] | $(echo "$MAINSAIL_LOCAL_VER") | $(echo "$MAINSAIL_REMOTE_VER") | " - quit_footer -} - -remove_ui(){ - top_border - echo -e "| ${red}~~~~~~~~~~~~~~ [ Remove Menu ] ~~~~~~~~~~~~~~${default} | " - hr - echo -e "| Files and directories which remain untouched: | " - echo -e "| --> ~/printer.cfg | " - echo -e "| --> ~/klipper_config | " - echo -e "| --> ~/kiauh-backups | " - echo -e "| You need remove them manually if you wish so. | " - hr - echo -e "| Firmware: | Webinterface: | " - echo -e "| 1) [Klipper] | 3) [DWC2] | " - echo -e "| | 4) [Mainsail] | " - echo -e "| Klipper API: | 5) [Octoprint] | " - echo -e "| 2) [Moonraker] | | " - echo -e "| | Webserver: | " - echo -e "| | 6) [Nginx] | " - quit_footer -} - -advanced_ui(){ - top_border - echo -e "| ${yellow}~~~~~~~~~~~~~ [ Advanced Menu ] ~~~~~~~~~~~~~${default} | " - hr - echo -e "| 0) $OPRINT_SERVICE_STATUS| " - hr - echo -e "| | | " - echo -e "| Klipper: | System: | " - echo -e "| 1) [Switch Version] | 8) [Change hostname] | " - echo -e "| 2) [Rollback] | | " - echo -e "| | Mainsail: | " - echo -e "| Firmware: | 9) [Remove branding] | " - echo -e "| 3) [Build Firmware] | | " - echo -e "| 4) [Flash MCU] | | " - echo -e "| 5) [Get Printer-USB] | | " - echo -e "| 6) [Write Printer-USB] | | " - echo -e "| 7) [Write DWC2 config] | | " - echo -e "| | | " -quit_footer -} - -backup_ui(){ - top_border - echo -e "| $(title_msg "~~~~~~~~~~~~~~ [ Backup Menu ] ~~~~~~~~~~~~~~") | " - hr - echo -e "| ${yellow}Backup location: ~/kiauh-backups${default} | " - hr - echo -e "| Firmware: | " - echo -e "| 1) [Klipper] | " - echo -e "| | " - echo -e "| Webinterface: | " - echo -e "| 2) [DWC2 Web UI] | " - echo -e "| | " - echo -e "| 3) [Mainsail] | " - echo -e "| 4) [Moonraker] | " - echo -e "| | " - echo -e "| 5) [OctoPrint] | " - echo -e "| | " - quit_footer -} - -switch_ui(){ - top_border - echo -e "| $(title_msg "~~~~~~~~~ [ Switch Klipper Branch ] ~~~~~~~~~") |" - bottom_border - echo - echo -e " $(title_msg "Active Branch: ")${green}$GET_BRANCH${default}" - echo - top_border - echo -e "| 1) [--> origin/master] | " - echo -e "| | " - echo -e "| 2) [--> scurve-shaping] | " - echo -e "| 3) [--> scurve-smoothing] | " - echo -e "| | " - echo -e "| 4) [--> moonraker] | " - quit_footer -} - -kiauh_update_msg(){ - top_border - echo -e "| ${yellow}There is a newer version of this script available!${default} | " - echo -e "| ${yellow}Type 'update' if you want to update KIAUH now.${default} | " - bottom_border -} - -rollback_ui(){ - top_border - echo -e "| $(title_msg "~~~~~~~~~~~~~ [ Rollback Menu ] ~~~~~~~~~~~~~") | " - hr - echo -e "| If serious errors occured after updating Klipper, | " - echo -e "| you can use this menu to return to the previously | " - echo -e "| used commit from which you have updated. | " - bottom_border - top_border - echo -e "| Active branch: ${green}$PRINT_BRANCH${default} | " - hr - echo -e "| Currently on commit: | " - echo -e "| $CURR_UI | " - hr - echo -e "| Commit last updated from: | " - echo -e "| $PREV_UI | " - quit_footer -} \ No newline at end of file diff --git a/scripts/ui/advanced_menu.sh b/scripts/ui/advanced_menu.sh new file mode 100755 index 0000000..9508328 --- /dev/null +++ b/scripts/ui/advanced_menu.sh @@ -0,0 +1,205 @@ +advanced_ui(){ + top_border + echo -e "| ${yellow}~~~~~~~~~~~~~ [ Advanced Menu ] ~~~~~~~~~~~~~${default} | " + hr + echo -e "| 0) $OPRINT_SERVICE_STATUS| " + hr + echo -e "| | | " + echo -e "| Klipper: | System: | " + echo -e "| 1) [Switch Version] | 8) [Change hostname] | " + echo -e "| 2) [Rollback] | | " + echo -e "| | Mainsail: | " + echo -e "| Firmware: | 9) [Remove branding] | " + echo -e "| 3) [Build Firmware] | | " + echo -e "| 4) [Flash MCU] | Extensions: | " + echo -e "| 5) [Get Printer-USB] | 10) [Shell Command] | " + echo -e "| 6) [Write Printer-USB] | | " + echo -e "| 7) [Write DWC2 config] | | " + echo -e "| | | " +quit_footer +} + +advanced_menu(){ + print_header + print_msg && clear_msg + read_octoprint_service_status + advanced_ui + while true; do + echo -e "${cyan}" + read -p "Perform action: " action; echo + echo -e "${default}" + case "$action" in + 0) + clear + print_header + toggle_octoprint_service + read_octoprint_service_status + print_msg && clear_msg + advanced_ui;; + 1) + clear + print_header + switch_menu + print_msg && clear_msg + advanced_ui;; + 2) + clear + print_header + load_klipper_state + print_msg && clear_msg + advanced_ui;; + 3) + clear + print_header + build_fw + print_msg && clear_msg + advanced_ui;; + 4) + clear + print_header + flash_routine + print_msg && clear_msg + advanced_ui;; + 5) + clear + print_header + get_printer_usb + print_msg && clear_msg + advanced_ui;; + 6) + clear + print_header + get_printer_usb && write_printer_usb + print_msg && clear_msg + advanced_ui;; + 7) + clear + print_header + create_dwc2fk_cfg + print_msg && clear_msg + advanced_ui;; + 8) + clear + print_header + create_custom_hostname + print_msg && clear_msg + advanced_ui;; + 9) + clear + print_header + remove_branding + print_msg && clear_msg + advanced_ui;; + 10) + clear + print_header + install_extension_shell_command + print_msg && clear_msg + advanced_ui;; + Q|q) + clear; main_menu; break;; + *) + clear + print_header + print_unkown_cmd + print_msg && clear_msg + advanced_ui;; + esac + done + advanced_menu +} + +############################################################# +############################################################# + +switch_ui(){ + top_border + echo -e "| $(title_msg "~~~~~~~~~ [ Switch Klipper Branch ] ~~~~~~~~~") |" + bottom_border + echo + echo -e " $(title_msg "Active Branch: ")${green}$GET_BRANCH${default}" + echo + top_border + echo -e "| 1) [--> origin/master] | " + echo -e "| | " + echo -e "| 2) [--> scurve-shaping] | " + echo -e "| 3) [--> scurve-smoothing] | " + echo -e "| | " + echo -e "| 4) [--> moonraker] | " + quit_footer +} + +switch_menu(){ + if [ -d $KLIPPER_DIR ]; then + read_branch + print_msg && clear_msg + switch_ui + while true; do + echo -e "${cyan}" + read -p "Perform action: " action; echo + echo -e "${default}" + case "$action" in + 1) + clear + print_header + switch_to_origin + read_branch + print_msg && clear_msg + switch_ui;; + 2) + clear + print_header + switch_to_scurve_shaping + read_branch + print_msg && clear_msg + switch_ui;; + 3) + clear + print_header + switch_to_scurve_smoothing + read_branch + print_msg && clear_msg + switch_ui;; + 4) + clear + print_header + switch_to_moonraker + read_branch + print_msg && clear_msg + switch_ui;; + Q|q) + clear; advanced_menu; break;; + *) + clear + print_header + print_unkown_cmd + print_msg && clear_msg + switch_ui;; + esac + done + else + ERROR_MSG="No Klipper directory found! Download Klipper first!" + fi +} + +############################################################# +############################################################# + +rollback_ui(){ + top_border + echo -e "| $(title_msg "~~~~~~~~~~~~~ [ Rollback Menu ] ~~~~~~~~~~~~~") | " + hr + echo -e "| If serious errors occured after updating Klipper, | " + echo -e "| you can use this menu to return to the previously | " + echo -e "| used commit from which you have updated. | " + bottom_border + top_border + echo -e "| Active branch: ${green}$PRINT_BRANCH${default} | " + hr + echo -e "| Currently on commit: | " + echo -e "| $CURR_UI | " + hr + echo -e "| Commit last updated from: | " + echo -e "| $PREV_UI | " + quit_footer +} diff --git a/scripts/ui/backup_menu.sh b/scripts/ui/backup_menu.sh new file mode 100755 index 0000000..5738821 --- /dev/null +++ b/scripts/ui/backup_menu.sh @@ -0,0 +1,71 @@ +backup_ui(){ + top_border + echo -e "| $(title_msg "~~~~~~~~~~~~~~ [ Backup Menu ] ~~~~~~~~~~~~~~") | " + hr + echo -e "| ${yellow}Backup location: ~/kiauh-backups${default} | " + hr + echo -e "| Firmware: | " + echo -e "| 1) [Klipper] | " + echo -e "| | " + echo -e "| Webinterface: | " + echo -e "| 2) [DWC2 Web UI] | " + echo -e "| | " + echo -e "| 3) [Mainsail] | " + echo -e "| 4) [Moonraker] | " + echo -e "| | " + echo -e "| 5) [OctoPrint] | " + echo -e "| | " + quit_footer +} + +backup_menu(){ + print_header + print_msg && clear_msg + backup_ui + while true; do + echo -e "${cyan}" + read -p "Perform action: " action; echo + echo -e "${default}" + case "$action" in + 1) + clear + print_header + backup_klipper + print_msg && clear_msg + backup_ui;; + 2) + clear + print_header + backup_dwc2 + print_msg && clear_msg + backup_ui;; + 3) + clear + print_header + backup_mainsail + print_msg && clear_msg + backup_ui;; + 4) + clear + print_header + backup_moonraker + print_msg && clear_msg + backup_ui;; + 5) + clear + print_header + backup_octoprint + print_msg && clear_msg + backup_ui;; + Q|q) + clear; main_menu; break;; + *) + clear + print_header + print_unkown_cmd + print_msg && clear_msg + backup_ui;; + esac + done + backup_menu +} diff --git a/scripts/ui/general_ui.sh b/scripts/ui/general_ui.sh new file mode 100755 index 0000000..865af8d --- /dev/null +++ b/scripts/ui/general_ui.sh @@ -0,0 +1,34 @@ +#ui total width = 57 chars +top_border(){ + echo -e "/=======================================================\ " +} + +bottom_border(){ + echo -e "\=======================================================/" +} + +hr(){ + echo -e "|-------------------------------------------------------|" +} + +quit_footer(){ + hr + echo -e "| ${red}Q) Quit${default} | " + bottom_border + echo -e " KIAUH: $CURR_KIAUH_BRANCH" +} + +print_header(){ + top_border + echo -e "| $(title_msg "~~~~~~~~~~~~~~~~~ [ KIAUH ] ~~~~~~~~~~~~~~~~~") |" + echo -e "| $(title_msg " Klipper Installation And Update Helper ") |" + echo -e "| $(title_msg "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") |" + bottom_border +} + +kiauh_update_msg(){ + top_border + echo -e "| ${yellow}There is a newer version of this script available!${default} | " + echo -e "| ${yellow}Type 'update' if you want to update KIAUH now.${default} | " + bottom_border +} diff --git a/scripts/ui/install_menu.sh b/scripts/ui/install_menu.sh new file mode 100755 index 0000000..8e0ec75 --- /dev/null +++ b/scripts/ui/install_menu.sh @@ -0,0 +1,66 @@ +install_ui(){ + top_border + echo -e "| ${green}~~~~~~~~~~~ [ Installation Menu ] ~~~~~~~~~~~${default} | " + hr + echo -e "| You need this menu usually only for installing | " + echo -e "| all necessary dependencies for the various | " + echo -e "| functions on a completely fresh system. | " + hr + echo -e "| Firmware: | Webinterface: | " + echo -e "| 1) [Klipper] | 3) [DWC2] | " + echo -e "| | 4) [Mainsail] | " + echo -e "| Klipper API: | 5) [Octoprint] | " + echo -e "| 2) [Moonraker] | | " + quit_footer +} + +install_menu(){ + print_header + install_ui + while true; do + echo -e "${cyan}" + read -p "Perform action: " action; echo + echo -e "${default}" + case "$action" in + 1) + clear + print_header + install_klipper + print_msg && clear_msg + install_ui;; + 2) + clear + print_header + install_moonraker + print_msg && clear_msg + install_ui;; + 3) + clear + print_header + install_dwc2 + print_msg && clear_msg + install_ui;; + 4) + clear + print_header + INST_MAINSAIL="true" && install_mainsail + print_msg && clear_msg + install_ui;; + 5) + clear + print_header + install_octoprint + print_msg && clear_msg + install_ui;; + Q|q) + clear; main_menu; break;; + *) + clear + print_header + print_unkown_cmd + print_msg && clear_msg + install_ui;; + esac + done + install_menu +} diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh new file mode 100755 index 0000000..07d86c4 --- /dev/null +++ b/scripts/ui/main_menu.sh @@ -0,0 +1,79 @@ +main_ui(){ + top_border + echo -e "| $(title_msg "~~~~~~~~~~~~~~~ [ Main Menu ] ~~~~~~~~~~~~~~~") |" + hr + echo -e "| | |" + echo -e "| 1) [Install] | Klipper: $KLIPPER_STATUS|" + echo -e "| 2) [Update] | Branch: ${cyan}$PRINT_BRANCH${default}|" + echo -e "| 3) [Remove] | |" + echo -e "| | DWC2: $DWC2_STATUS|" + echo -e "| 4) [Advanced] | Mainsail: $MAINSAIL_STATUS|" + echo -e "| 5) [Backup] | Octoprint: $OCTOPRINT_STATUS|" + echo -e "| | |" + quit_footer +} + +main_menu(){ + print_header + #print KIAUH update msg if update available + if [ "$KIAUH_UPDATE_AVAIL" = "true" ]; then + kiauh_update_msg + fi + #check install status + klipper_status + dwc2_status + mainsail_status + octoprint_status + print_branch + print_msg && clear_msg + main_ui + while true; do + echo -e "${cyan}" + read -p "Perform action: " action; echo + echo -e "${default}" + case "$action" in + update) + clear + print_header + update_kiauh + print_msg && clear_msg + main_ui;; + 0) + clear + print_header + ERROR_MSG="Sorry this function is not implemented yet!" + print_msg && clear_msg + 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;; + Q|q) + echo -e "${green}###### Happy printing! ######${default}"; echo + exit -1;; + *) + clear + print_header + print_unkown_cmd + print_msg && clear_msg + main_ui;; + esac + done + clear; main_menu +} diff --git a/scripts/ui/remove_menu.sh b/scripts/ui/remove_menu.sh new file mode 100755 index 0000000..f0692b5 --- /dev/null +++ b/scripts/ui/remove_menu.sh @@ -0,0 +1,76 @@ +remove_ui(){ + top_border + echo -e "| ${red}~~~~~~~~~~~~~~ [ Remove Menu ] ~~~~~~~~~~~~~~${default} | " + hr + echo -e "| Files and directories which remain untouched: | " + echo -e "| --> ~/printer.cfg | " + echo -e "| --> ~/klipper_config | " + echo -e "| --> ~/kiauh-backups | " + echo -e "| You need remove them manually if you wish so. | " + hr + echo -e "| Firmware: | Webinterface: | " + echo -e "| 1) [Klipper] | 3) [DWC2] | " + echo -e "| | 4) [Mainsail] | " + echo -e "| Klipper API: | 5) [Octoprint] | " + echo -e "| 2) [Moonraker] | | " + echo -e "| | Webserver: | " + echo -e "| | 6) [Nginx] | " + quit_footer +} + +remove_menu(){ + print_header + remove_ui + while true; do + echo -e "${cyan}" + read -p "Perform action: " action; echo + echo -e "${default}" + case "$action" in + 1) + clear + print_header + remove_klipper + print_msg && clear_msg + remove_ui;; + 2) + clear + print_header + remove_moonraker + print_msg && clear_msg + remove_ui;; + 3) + clear + print_header + remove_dwc2 + print_msg && clear_msg + remove_ui;; + 4) + clear + print_header + remove_mainsail + print_msg && clear_msg + remove_ui;; + 5) + clear + print_header + remove_octoprint + print_msg && clear_msg + remove_ui;; + 6) + clear + print_header + remove_nginx + print_msg && clear_msg + remove_ui;; + Q|q) + clear; main_menu; break;; + *) + clear + print_header + print_unkown_cmd + print_msg && clear_msg + remove_ui;; + esac + done + remove_menu +} diff --git a/scripts/ui/update_menu.sh b/scripts/ui/update_menu.sh new file mode 100755 index 0000000..928311e --- /dev/null +++ b/scripts/ui/update_menu.sh @@ -0,0 +1,87 @@ +update_ui(){ + top_border + echo -e "| ${green}~~~~~~~~~~~~~~ [ Update Menu ] ~~~~~~~~~~~~~~${default} | " + hr + echo -e "| It is a good idea to check the following website | " + echo -e "| for important software changes to the config file | " + echo -e "| >> BEFORE << updating your klipper installation: | " + echo -e "| | " + echo -e "| ${yellow}https://www.klipper3d.org/Config_Changes.html${default} | " + bottom_border + top_border + echo -e "| 0) $BB4U_STATUS| " + hr + echo -e "| | Local Vers: | Remote Vers: | " + echo -e "| Firmware: | | | " + echo -e "| 1) [Klipper] | $(echo "$LOCAL_COMMIT") | $(echo "$REMOTE_COMMIT") | " + echo -e "| | | | " + echo -e "| Webinterface: |---------------|--------------| " + echo -e "| 2) [DWC2-for-Klipper] | $(echo "$LOCAL_DWC2FK_COMMIT") | $(echo "$REMOTE_DWC2FK_COMMIT") | " + echo -e "| 3) [DWC2 Web UI] | $(echo "$DWC2_LOCAL_VER") | $(echo "$DWC2_REMOTE_VER") | " + echo -e "| |---------------|--------------| " + echo -e "| 4) [Moonraker] | $(echo "$LOCAL_MOONRAKER_COMMIT") | $(echo "$REMOTE_MOONRAKER_COMMIT") | " + echo -e "| 5) [Mainsail] | $(echo "$MAINSAIL_LOCAL_VER") | $(echo "$MAINSAIL_REMOTE_VER") | " + quit_footer +} + +update_menu(){ + print_header + #compare versions + ui_print_versions + print_msg && clear_msg + read_bb4u_stat + update_ui + while true; do + echo -e "${cyan}" + read -p "Perform action: " action; echo + echo -e "${default}" + case "$action" in + 0) + clear + print_header + toggle_backups + print_msg && clear_msg + update_ui;; + 1) + clear + print_header + update_klipper && ui_print_versions + print_msg && clear_msg + update_ui;; + 2) + clear + print_header + update_dwc2fk && ui_print_versions + print_msg && clear_msg + update_ui;; + 3) + clear + print_header + update_dwc2 && ui_print_versions + print_msg && clear_msg + update_ui;; + 4) + clear + print_header + update_moonraker && ui_print_versions + print_msg && clear_msg + update_ui;; + 5) + clear + print_header + update_mainsail && ui_print_versions + print_msg && clear_msg + update_ui;; + Q|q) + clear; main_menu; break;; + *) + clear + print_header + print_unkown_cmd + print_msg && clear_msg + ui_print_versions + update_ui;; + esac + done + update_menu +}