From 7c39d7d91fb6f6f1226bac1b9225018fe1153d6d Mon Sep 17 00:00:00 2001 From: Yifei Ding Date: Mon, 8 Nov 2021 16:38:39 -0800 Subject: [PATCH 01/28] script: add Gettext support --- kiauh.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kiauh.sh b/kiauh.sh index ea50a51..b0bb55f 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -1,4 +1,8 @@ #!/bin/bash + +### Gettext Configuration +alias GETTEXT='gettext "KIAUH"' + clear set -e -- 2.39.5 From c7ce5ad36c03c224e4be82ad6391924bd44c2df3 Mon Sep 17 00:00:00 2001 From: Yifei Ding Date: Mon, 8 Nov 2021 17:05:14 -0800 Subject: [PATCH 02/28] script: move constants to dedicated files --- kiauh.sh | 43 +--------------------------- scripts/constants/constants.sh | 52 ++++++++++++++++++++++++++++++++++ scripts/constants/strings.sh | 7 +++++ scripts/functions.sh | 3 -- 4 files changed, 60 insertions(+), 45 deletions(-) create mode 100755 scripts/constants/constants.sh create mode 100644 scripts/constants/strings.sh diff --git a/kiauh.sh b/kiauh.sh index b0bb55f..0ca7ea7 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -15,51 +15,10 @@ default=$(echo -en "\e[39m") ### sourcing all additional scripts SRCDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. && pwd )" +for script in "${SRCDIR}/kiauh/scripts/constants/"*.sh; do . $script; done for script in "${SRCDIR}/kiauh/scripts/"*.sh; do . $script; done for script in "${SRCDIR}/kiauh/scripts/ui/"*.sh; do . $script; done -### set important directories -#klipper -KLIPPER_DIR=${HOME}/klipper -KLIPPY_ENV=${HOME}/klippy-env -#nginx -NGINX_SA=/etc/nginx/sites-available -NGINX_SE=/etc/nginx/sites-enabled -NGINX_CONFD=/etc/nginx/conf.d -#moonraker -MOONRAKER_DIR=${HOME}/moonraker -MOONRAKER_ENV=${HOME}/moonraker-env -#mainsail -MAINSAIL_DIR=${HOME}/mainsail -#fluidd -FLUIDD_DIR=${HOME}/fluidd -#dwc2 -DWC2FK_DIR=${HOME}/dwc2-for-klipper-socket -DWC_ENV_DIR=${HOME}/dwc-env -DWC2_DIR=${HOME}/duetwebcontrol -#octoprint -OCTOPRINT_DIR=${HOME}/OctoPrint -#KlipperScreen -KLIPPERSCREEN_DIR=${HOME}/KlipperScreen -KLIPPERSCREEN_ENV_DIR=${HOME}/.KlipperScreen-env -#MoonrakerTelegramBot -MOONRAKER_TELEGRAM_BOT_DIR=${HOME}/moonraker-telegram-bot -MOONRAKER_TELEGRAM_BOT_ENV_DIR=${HOME}/moonraker-telegram-bot-env -#misc -INI_FILE=${HOME}/.kiauh.ini -BACKUP_DIR=${HOME}/kiauh-backups - -### set github repos -KLIPPER_REPO=https://github.com/Klipper3d/klipper.git -ARKSINE_REPO=https://github.com/Arksine/klipper.git -DMBUTYUGIN_REPO=https://github.com/dmbutyugin/klipper.git -DWC2FK_REPO=https://github.com/Stephan3/dwc2-for-klipper-socket.git -KLIPPERSCREEN_REPO=https://github.com/jordanruthe/KlipperScreen.git -NLEF_REPO=https://github.com/nlef/moonraker-telegram-bot.git -#branches -BRANCH_SCURVE_SMOOTHING=dmbutyugin/scurve-smoothing -BRANCH_SCURVE_SHAPING=dmbutyugin/scurve-shaping - ### set some messages warn_msg(){ echo -e "${red} $1${default}" diff --git a/scripts/constants/constants.sh b/scripts/constants/constants.sh new file mode 100755 index 0000000..68c44ed --- /dev/null +++ b/scripts/constants/constants.sh @@ -0,0 +1,52 @@ +### set important directories + +#kiauh.sh +#klipper +KLIPPER_DIR=${HOME}/klipper +KLIPPY_ENV=${HOME}/klippy-env +#nginx +NGINX_SA=/etc/nginx/sites-available +NGINX_SE=/etc/nginx/sites-enabled +NGINX_CONFD=/etc/nginx/conf.d +#moonraker +MOONRAKER_DIR=${HOME}/moonraker +MOONRAKER_ENV=${HOME}/moonraker-env +#mainsail +MAINSAIL_DIR=${HOME}/mainsail +#fluidd +FLUIDD_DIR=${HOME}/fluidd +#dwc2 +DWC2FK_DIR=${HOME}/dwc2-for-klipper-socket +DWC_ENV_DIR=${HOME}/dwc-env +DWC2_DIR=${HOME}/duetwebcontrol +#octoprint +OCTOPRINT_DIR=${HOME}/OctoPrint +#KlipperScreen +KLIPPERSCREEN_DIR=${HOME}/KlipperScreen +KLIPPERSCREEN_ENV_DIR=${HOME}/.KlipperScreen-env +#MoonrakerTelegramBot +MOONRAKER_TELEGRAM_BOT_DIR=${HOME}/moonraker-telegram-bot +MOONRAKER_TELEGRAM_BOT_ENV_DIR=${HOME}/moonraker-telegram-bot-env +#misc +INI_FILE=${HOME}/.kiauh.ini +BACKUP_DIR=${HOME}/kiauh-backups + +### set github repos +KLIPPER_REPO=https://github.com/Klipper3d/klipper.git +ARKSINE_REPO=https://github.com/Arksine/klipper.git +DMBUTYUGIN_REPO=https://github.com/dmbutyugin/klipper.git +DWC2FK_REPO=https://github.com/Stephan3/dwc2-for-klipper-socket.git +KLIPPERSCREEN_REPO=https://github.com/jordanruthe/KlipperScreen.git +NLEF_REPO=https://github.com/nlef/moonraker-telegram-bot.git +#branches +BRANCH_SCURVE_SMOOTHING=dmbutyugin/scurve-smoothing +BRANCH_SCURVE_SHAPING=dmbutyugin/scurve-shaping + +###Whiptail +KIAUH_WHIPTAIL_WIDTH=64 +KIAUH_WHIPTAIL_HEIGHT=30 + +#functions.sh +### base variables +SYSTEMDDIR="/etc/systemd/system" + diff --git a/scripts/constants/strings.sh b/scripts/constants/strings.sh new file mode 100644 index 0000000..2bb451a --- /dev/null +++ b/scripts/constants/strings.sh @@ -0,0 +1,7 @@ +# shellcheck shell=bash + +### Universal Strings +# Universal +KIAUH_TITLE="KIAUH - Klipper Installation And Update Helper" + + diff --git a/scripts/functions.sh b/scripts/functions.sh index d4fa030..a9535c1 100755 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -1,6 +1,3 @@ -### base variables -SYSTEMDDIR="/etc/systemd/system" - # setting up some frequently used functions check_euid(){ if [ "$EUID" -eq 0 ] -- 2.39.5 From 415d057efe21c4de4e23c3114684195ae54d8944 Mon Sep 17 00:00:00 2001 From: Yifei Ding Date: Mon, 8 Nov 2021 17:33:55 -0800 Subject: [PATCH 03/28] script: use whiptail for check_euid --- scripts/constants/constants.sh | 4 ++-- scripts/functions.sh | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/scripts/constants/constants.sh b/scripts/constants/constants.sh index 68c44ed..b491a28 100755 --- a/scripts/constants/constants.sh +++ b/scripts/constants/constants.sh @@ -43,8 +43,8 @@ BRANCH_SCURVE_SMOOTHING=dmbutyugin/scurve-smoothing BRANCH_SCURVE_SHAPING=dmbutyugin/scurve-shaping ###Whiptail -KIAUH_WHIPTAIL_WIDTH=64 -KIAUH_WHIPTAIL_HEIGHT=30 +KIAUH_WHIPTAIL_WIDTH=96 +KIAUH_WHIPTAIL_HEIGHT=25 #functions.sh ### base variables diff --git a/scripts/functions.sh b/scripts/functions.sh index a9535c1..7697a34 100755 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -2,11 +2,8 @@ check_euid(){ if [ "$EUID" -eq 0 ] then - echo -e "${red}" - top_border - echo -e "| !!! THIS SCRIPT MUST NOT RAN AS ROOT !!! |" - bottom_border - echo -e "${default}" + whiptail --title "$KIAUH_TITLE" --msgbox "!!! THIS SCRIPT MUST NOT RAN AS ROOT !!!"\ + "$KIAUH_WHIPTAIL_HEIGHT" "$KIAUH_WHIPTAIL_WIDTH" exit 1 fi } -- 2.39.5 From e231c6b2d633b5116939f439c8b73210bf235284 Mon Sep 17 00:00:00 2001 From: Yifei Ding Date: Tue, 9 Nov 2021 11:41:56 -0800 Subject: [PATCH 04/28] scripts: switch print_msg and main_menu to whiptail --- kiauh.sh | 16 ++---- scripts/ui/main_menu.sh | 120 ++++++++++++++++++++++++---------------- 2 files changed, 77 insertions(+), 59 deletions(-) diff --git a/kiauh.sh b/kiauh.sh index 0ca7ea7..02b8ef4 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -3,7 +3,7 @@ ### Gettext Configuration alias GETTEXT='gettext "KIAUH"' -clear +#clear set -e ### set color variables @@ -41,18 +41,12 @@ print_unkown_cmd(){ print_msg(){ if [[ "$ERROR_MSG" != "" ]]; then - echo -e "${red}" - echo -e "#########################################################" - echo -e " $ERROR_MSG " - echo -e "#########################################################" - echo -e "${default}" + whiptail --title "$KIAUH_TITLE" --msgbox "$ERROR_MSG"\ + "$KIAUH_WHIPTAIL_SINGLE_LINE_HEIGHT" "$KIAUH_WHIPTAIL_NORMAL_WIDTH" fi if [ "$CONFIRM_MSG" != "" ]; then - echo -e "${green}" - echo -e "#########################################################" - echo -e " $CONFIRM_MSG " - echo -e "#########################################################" - echo -e "${default}" + whiptail --title "$KIAUH_TITLE" --msgbox "$CONFIRM_MSG"\ + "$KIAUH_WHIPTAIL_SINGLE_LINE_HEIGHT" "$KIAUH_WHIPTAIL_NORMAL_WIDTH" fi } diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh index ff991a0..3356b34 100755 --- a/scripts/ui/main_menu.sh +++ b/scripts/ui/main_menu.sh @@ -1,22 +1,22 @@ -main_ui(){ +#main_ui(){ #[ $KIAUH_UPDATE_REMIND="true" ] && kiauh_update_reminder - top_border - echo -e "| $(title_msg "~~~~~~~~~~~~~~~ [ Main Menu ] ~~~~~~~~~~~~~~~") |" - hr - echo -e "| 0) [Upload Log] | Klipper: $KLIPPER_STATUS|" - echo -e "| | Branch: ${cyan}$PRINT_BRANCH${default}|" - echo -e "| 1) [Install] | |" - echo -e "| 2) [Update] | Moonraker: $MOONRAKER_STATUS|" - echo -e "| 3) [Remove] | |" - echo -e "| 4) [Advanced] | Mainsail: $MAINSAIL_STATUS|" - echo -e "| 5) [Backup] | Fluidd: $FLUIDD_STATUS|" - echo -e "| | KlipperScreen: $KLIPPERSCREEN_STATUS|" - echo -e "| 6) [Settings] | Telegram Bot: $MOONRAKER_TELEGRAM_BOT_STATUS|" - echo -e "| | |" - echo -e "| | DWC2: $DWC2_STATUS|" - echo -e "| ${cyan}$KIAUH_VER${default}| Octoprint: $OCTOPRINT_STATUS|" - quit_footer -} +# top_border +# echo -e "| $(title_msg "~~~~~~~~~~~~~~~ [ Main Menu ] ~~~~~~~~~~~~~~~") |" +# hr +# echo -e "| 0) [Upload Log] | Klipper: $KLIPPER_STATUS|" +# echo -e "| | Branch: ${cyan}$PRINT_BRANCH${default}|" +# echo -e "| 1) [Install] | |" +# echo -e "| 2) [Update] | Moonraker: $MOONRAKER_STATUS|" +# echo -e "| 3) [Remove] | |" +# echo -e "| 4) [Advanced] | Mainsail: $MAINSAIL_STATUS|" +# echo -e "| 5) [Backup] | Fluidd: $FLUIDD_STATUS|" +# echo -e "| | KlipperScreen: $KLIPPERSCREEN_STATUS|" +# echo -e "| 6) [Settings] | Telegram Bot: $MOONRAKER_TELEGRAM_BOT_STATUS|" +# echo -e "| | |" +# echo -e "| | DWC2: $DWC2_STATUS|" +# echo -e "| ${cyan}$KIAUH_VER${default}| Octoprint: $OCTOPRINT_STATUS|" +# quit_footer +#} print_kiauh_version(){ cd ${SRCDIR}/kiauh @@ -40,7 +40,7 @@ kiauh_update_dialog(){ } main_menu(){ - print_header +# print_header #print KIAUH update msg if update available if [ "$KIAUH_UPDATE_AVAIL" = "true" ]; then kiauh_update_dialog @@ -57,36 +57,60 @@ main_menu(){ MoonrakerTelegramBot_status print_branch print_msg && clear_msg - main_ui + 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";; + 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\ *) remove_menu ;; + 4\ *) advanced_menu ;; + 5\ *) backup_menu ;; + 6\ *) settings_menu ;; + 7\ *) settings_menu ;; + 0\ *) upload_selection;; + *) echo "Unknown Command";; 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 } -- 2.39.5 From ab81cf500db41ab11ab4b7ee3ad5e1d4fd8770c2 Mon Sep 17 00:00:00 2001 From: Yifei Ding Date: Tue, 9 Nov 2021 12:42:42 -0800 Subject: [PATCH 05/28] script: adjust order --- scripts/ui/main_menu.sh | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh index 3356b34..48569b8 100755 --- a/scripts/ui/main_menu.sh +++ b/scripts/ui/main_menu.sh @@ -40,8 +40,7 @@ kiauh_update_dialog(){ } main_menu(){ -# print_header - #print KIAUH update msg if update available + #print KIAUH update msg if update available if [ "$KIAUH_UPDATE_AVAIL" = "true" ]; then kiauh_update_dialog fi @@ -72,12 +71,12 @@ main_menu(){ case "$MAIN_MENU" in 1\ *) echo "Current status" ;; 2\ *) install_menu ;; - 3\ *) remove_menu ;; - 4\ *) advanced_menu ;; - 5\ *) backup_menu ;; - 6\ *) settings_menu ;; + 3\ *) update_menu ;; + 4\ *) remove_menu ;; + 5\ *) advanced_menu ;; + 6\ *) backup_menu ;; 7\ *) settings_menu ;; - 0\ *) upload_selection;; + 0\ *) do_action "upload_selection" && break;; *) echo "Unknown Command";; esac done -- 2.39.5 From 0b737e46b4d603bcc822048dde2903f5e1a982ad Mon Sep 17 00:00:00 2001 From: Yifei Ding Date: Tue, 9 Nov 2021 12:43:59 -0800 Subject: [PATCH 06/28] script: use whiptail for kiauh_update_dialogue --- scripts/ui/general_ui.sh | 12 ------------ scripts/ui/main_menu.sh | 28 ++++++++++++++++------------ 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/scripts/ui/general_ui.sh b/scripts/ui/general_ui.sh index 459b29f..aaffa84 100755 --- a/scripts/ui/general_ui.sh +++ b/scripts/ui/general_ui.sh @@ -41,18 +41,6 @@ print_header(){ bottom_border } -kiauh_update_msg(){ - top_border - echo -e "|${green} New KIAUH update available! ${default}| " - hr - echo -e "|${green} View Changelog: https://git.io/JnmlX ${default}| " - blank_line - echo -e "|${yellow} It is recommended to keep KIAUH up to date. Updates ${default}| " - echo -e "|${yellow} usually contain bugfixes, important changes or new ${default}| " - echo -e "|${yellow} features. Please consider updating! ${default}| " - bottom_border -} - ################################################################################ #******************************************************************************# ################################################################################ diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh index 48569b8..2fe0ef0 100755 --- a/scripts/ui/main_menu.sh +++ b/scripts/ui/main_menu.sh @@ -25,18 +25,22 @@ print_kiauh_version(){ } kiauh_update_dialog(){ - kiauh_update_msg - read -p "${cyan}Do you want to update now? (Y/n):${default} " yn - while true; do - case "$yn" in - Y|y|Yes|yes|"") - do_action "update_kiauh" - break;; - N|n|No|no) break;; - *) - deny_action "kiauh_update_dialog";; - esac - done + 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 + + RET=$? + if [ $RET -eq 0 ]; then + do_action "update_kiauh" + else + deny_action "kiauh_update_dialog" + fi } main_menu(){ -- 2.39.5 From fa1fe33fe17e4ce3744817c7079423545acc3499 Mon Sep 17 00:00:00 2001 From: Yifei Ding Date: Wed, 10 Nov 2021 18:19:15 -0800 Subject: [PATCH 07/28] script: Fix whiptail cancel behavior set -e causes the script to exit when whiptail exit with 1 (meaning user picked cancel) --- kiauh.sh | 3 +- scripts/ui/main_menu.sh | 139 +++++++++++++++++++++------------------- 2 files changed, 74 insertions(+), 68 deletions(-) diff --git a/kiauh.sh b/kiauh.sh index 02b8ef4..3bda5f5 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -4,7 +4,8 @@ alias GETTEXT='gettext "KIAUH"' #clear -set -e +# TODO set -e cause whiptail to force an exit because it use stderr, need a workaround here +# set -e ### set color variables green=$(echo -en "\e[92m") diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh index 2fe0ef0..d080463 100755 --- a/scripts/ui/main_menu.sh +++ b/scripts/ui/main_menu.sh @@ -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 } -- 2.39.5 From 980f6d5ddd8ac19b93e516a3d403467e98f73a4d Mon Sep 17 00:00:00 2001 From: Yifei Ding Date: Fri, 12 Nov 2021 14:23:47 -0800 Subject: [PATCH 08/28] script: fix main_menu confirm result and refactor --- scripts/ui/main_menu.sh | 85 +++++++++++------------------------------ 1 file changed, 23 insertions(+), 62 deletions(-) diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh index d080463..85f937b 100755 --- a/scripts/ui/main_menu.sh +++ b/scripts/ui/main_menu.sh @@ -1,42 +1,33 @@ -#main_ui(){ - #[ $KIAUH_UPDATE_REMIND="true" ] && kiauh_update_reminder -# top_border -# echo -e "| $(title_msg "~~~~~~~~~~~~~~~ [ Main Menu ] ~~~~~~~~~~~~~~~") |" -# hr -# echo -e "| 0) [Upload Log] | Klipper: $KLIPPER_STATUS|" -# echo -e "| | Branch: ${cyan}$PRINT_BRANCH${default}|" -# echo -e "| 1) [Install] | |" -# echo -e "| 2) [Update] | Moonraker: $MOONRAKER_STATUS|" -# echo -e "| 3) [Remove] | |" -# echo -e "| 4) [Advanced] | Mainsail: $MAINSAIL_STATUS|" -# echo -e "| 5) [Backup] | Fluidd: $FLUIDD_STATUS|" -# echo -e "| | KlipperScreen: $KLIPPERSCREEN_STATUS|" -# echo -e "| 6) [Settings] | Telegram Bot: $MOONRAKER_TELEGRAM_BOT_STATUS|" -# echo -e "| | |" -# echo -e "| | DWC2: $DWC2_STATUS|" -# echo -e "| ${cyan}$KIAUH_VER${default}| Octoprint: $OCTOPRINT_STATUS|" -# quit_footer -#} +#!/bin/bash -print_kiauh_version(){ +print_kiauh_version() { cd ${SRCDIR}/kiauh KIAUH_VER=$(git describe HEAD --always --tags | cut -d "-" -f 1,2) KIAUH_VER="$(printf "%-20s" "$KIAUH_VER")" } -kiauh_update_dialog(){ - whiptail --title "New KIAUH update available!"\ - --yesno \ -"View Changelog: https://git.io/JnmlX +####################################### +# 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 + "$KIAUH_WHIPTAIL_NORMAL_HEIGHT" "$KIAUH_WHIPTAIL_NORMAL_WIDTH" - RET=$? - if [ $RET -eq 0 ]; then + local out=$? + if [ $out -eq 0 ]; then do_action "update_kiauh" else deny_action "kiauh_update_dialog" @@ -66,15 +57,15 @@ main_menu() { 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") +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) local out=$? if [ $out -eq 1 ]; then break - elif [ $out -eq 1 ]; then + elif [ $out -eq 0 ]; then case "$menu" in 1) install_menu ;; 2) update_menu ;; @@ -83,42 +74,12 @@ DWC2: $DWC2_STATUS Octoprint: $OCTOPRINT_STATUS" 5) backup_menu ;; 6) settings_menu ;; 7) upload_selection ;; + 8) service_menu;; esac else + # Unexpected event, no clue what happened 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 } -- 2.39.5 From 90208f64809891f0307d172931b3bafc7923fadd Mon Sep 17 00:00:00 2001 From: Yifei Ding Date: Fri, 12 Nov 2021 14:44:05 -0800 Subject: [PATCH 09/28] script: Move functions hove print_kiauh_version and kiauh_update_dialog to general_ui and functions main_menu performance improvements --- scripts/functions.sh | 10 +++++- scripts/ui/general_ui.sh | 28 +++++++++++++++ scripts/ui/main_menu.sh | 74 +++++++++++++------------------------- scripts/ui/service_menu.sh | 18 ++++++++++ 4 files changed, 80 insertions(+), 50 deletions(-) create mode 100644 scripts/ui/service_menu.sh diff --git a/scripts/functions.sh b/scripts/functions.sh index 7697a34..1a780f5 100755 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -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")" +} \ No newline at end of file diff --git a/scripts/ui/general_ui.sh b/scripts/ui/general_ui.sh index aaffa84..673a701 100755 --- a/scripts/ui/general_ui.sh +++ b/scripts/ui/general_ui.sh @@ -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 +} diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh index 85f937b..e8a1f0d 100755 --- a/scripts/ui/main_menu.sh +++ b/scripts/ui/main_menu.sh @@ -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 diff --git a/scripts/ui/service_menu.sh b/scripts/ui/service_menu.sh new file mode 100644 index 0000000..e02a4e9 --- /dev/null +++ b/scripts/ui/service_menu.sh @@ -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";; -- 2.39.5 From 4121461303d6a8131c385d71fa8e934e1c4e967b Mon Sep 17 00:00:00 2001 From: Yifei Ding Date: Fri, 12 Nov 2021 14:58:19 -0800 Subject: [PATCH 10/28] scripts: whiptail migration menu --- scripts/ui/advanced_menu.sh | 37 ------------------------------------ scripts/ui/migration_menu.sh | 29 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 37 deletions(-) create mode 100644 scripts/ui/migration_menu.sh diff --git a/scripts/ui/advanced_menu.sh b/scripts/ui/advanced_menu.sh index 5f7cf5e..5453386 100755 --- a/scripts/ui/advanced_menu.sh +++ b/scripts/ui/advanced_menu.sh @@ -138,40 +138,3 @@ switch_menu(){ ERROR_MSG="No Klipper directory found! Download Klipper first!" fi } - -############################################################# -############################################################# - -migration_ui(){ - top_border - echo -e "| $(title_msg "~~~~~~~~~ [ CustomPiOS Migration ] ~~~~~~~~~~") | " - hr - echo -e "| This function will help you to migrate a vanilla | " - echo -e "| MainsailOS or FluiddPi image to a newer state. | " - blank_line - echo -e "| Only use this function if you use MainsailOS 0.4.0 | " - echo -e "| or lower, or FluiddPi v1.13.0 or lower. | " - blank_line - echo -e "| Please have a look at the KIAUH changelog for more | " - echo -e "| details on what this function will do. | " - hr - echo -e "| | " - echo -e "| 1) [Migrate MainsailOS] | " - echo -e "| 2) [Migrate FluiddPi] | " - echo -e "| | " - back_footer -} - -migration_menu(){ - print_msg && clear_msg - migration_ui - while true; do - read -p "${cyan}Perform action:${default} " action; echo - case "$action" in - 1) migrate_custompios "mainsail"; migration_menu;; - 2) migrate_custompios "fluiddpi"; migration_menu;; - B|b) clear; advanced_menu; break;; - *) print_unkown_cmd; migration_menu;; - esac - done -} diff --git a/scripts/ui/migration_menu.sh b/scripts/ui/migration_menu.sh new file mode 100644 index 0000000..0618bf6 --- /dev/null +++ b/scripts/ui/migration_menu.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +migration_menu(){ + local menu_options=( + "1" "Migrate MainsailOS" + "2" "Migrate FluiddPi" + ) + local menu_str="This function will help you to migrate a vanilla MainsailOS or FluiddPi image to a newer state. +Only use this function if you use MainsailOS 0.4.0 or lower, or FluiddPi v1.13.0 or lower. +Please have a look at the KIAUH changelog for more details on what this function will do." + + while true; do + local menu + menu=$(whiptail --title "CustomPiOS Migration" --cancel-button "Back" --notags --menu "$menu_str\n\nPerform Action:" \ + "$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 + elif [ $out -eq 0 ]; then + case "$menu" in + 1) migrate_custompios "mainsail";; + 2) migrate_custompios "fluiddpi";; + esac + else + # Unexpected event, no clue what happened + exit 1 + fi + done +} -- 2.39.5 From b1bfe7089a09db2c010fad975444acd8901225c8 Mon Sep 17 00:00:00 2001 From: Yifei Ding Date: Fri, 12 Nov 2021 15:03:05 -0800 Subject: [PATCH 11/28] script: remove unsupported color of statuses --- scripts/ui/remove_menu.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/ui/remove_menu.sh b/scripts/ui/remove_menu.sh index 9df4e9f..b4716a4 100755 --- a/scripts/ui/remove_menu.sh +++ b/scripts/ui/remove_menu.sh @@ -1,3 +1,5 @@ +#!/bin/bash + remove_ui(){ top_border echo -e "| ${red}~~~~~~~~~~~~~~ [ Remove Menu ] ~~~~~~~~~~~~~~${default} | " -- 2.39.5 From 600036059f1dfe7eb5605157acd68aba3d06fb90 Mon Sep 17 00:00:00 2001 From: Yifei Ding Date: Fri, 12 Nov 2021 15:20:39 -0800 Subject: [PATCH 12/28] script: remove redundant systemd constant --- scripts/constants/constants.sh | 66 +++++++++---------- .../install-debian.sh | 1 - scripts/install_dwc2.sh | 1 - scripts/install_klipper.sh | 1 - scripts/install_mjpg-streamer.sh | 1 - scripts/install_moonraker.sh | 1 - scripts/install_octoprint.sh | 1 - scripts/ms_theme_installer.sh | 1 - scripts/remove.sh | 3 - 9 files changed, 32 insertions(+), 44 deletions(-) diff --git a/scripts/constants/constants.sh b/scripts/constants/constants.sh index b491a28..74cc45e 100755 --- a/scripts/constants/constants.sh +++ b/scripts/constants/constants.sh @@ -1,52 +1,50 @@ +#!/bin/bash ### set important directories #kiauh.sh #klipper -KLIPPER_DIR=${HOME}/klipper -KLIPPY_ENV=${HOME}/klippy-env +readonly KLIPPER_DIR=${HOME}/klipper +readonly KLIPPY_ENV=${HOME}/klippy-env #nginx -NGINX_SA=/etc/nginx/sites-available -NGINX_SE=/etc/nginx/sites-enabled -NGINX_CONFD=/etc/nginx/conf.d +readonly NGINX_SA=/etc/nginx/sites-available +readonly NGINX_SE=/etc/nginx/sites-enabled +readonly NGINX_CONFD=/etc/nginx/conf.d #moonraker -MOONRAKER_DIR=${HOME}/moonraker -MOONRAKER_ENV=${HOME}/moonraker-env +readonly MOONRAKER_DIR=${HOME}/moonraker +readonly MOONRAKER_ENV=${HOME}/moonraker-env #mainsail -MAINSAIL_DIR=${HOME}/mainsail +readonly MAINSAIL_DIR=${HOME}/mainsail #fluidd -FLUIDD_DIR=${HOME}/fluidd +readonly FLUIDD_DIR=${HOME}/fluidd #dwc2 -DWC2FK_DIR=${HOME}/dwc2-for-klipper-socket -DWC_ENV_DIR=${HOME}/dwc-env -DWC2_DIR=${HOME}/duetwebcontrol +readonly DWC2FK_DIR=${HOME}/dwc2-for-klipper-socket +readonly DWC_ENV_DIR=${HOME}/dwc-env +readonly DWC2_DIR=${HOME}/duetwebcontrol #octoprint -OCTOPRINT_DIR=${HOME}/OctoPrint +readonly OCTOPRINT_DIR=${HOME}/OctoPrint #KlipperScreen -KLIPPERSCREEN_DIR=${HOME}/KlipperScreen -KLIPPERSCREEN_ENV_DIR=${HOME}/.KlipperScreen-env +readonly KLIPPERSCREEN_DIR=${HOME}/KlipperScreen +readonly KLIPPERSCREEN_ENV_DIR=${HOME}/.KlipperScreen-env #MoonrakerTelegramBot -MOONRAKER_TELEGRAM_BOT_DIR=${HOME}/moonraker-telegram-bot -MOONRAKER_TELEGRAM_BOT_ENV_DIR=${HOME}/moonraker-telegram-bot-env +readonly MOONRAKER_TELEGRAM_BOT_DIR=${HOME}/moonraker-telegram-bot +readonly MOONRAKER_TELEGRAM_BOT_ENV_DIR=${HOME}/moonraker-telegram-bot-env #misc -INI_FILE=${HOME}/.kiauh.ini -BACKUP_DIR=${HOME}/kiauh-backups +readonly INI_FILE=${HOME}/.kiauh.ini +readonly BACKUP_DIR=${HOME}/kiauh-backups +readonly SYSTEMDDIR=/etc/systemd/system ### set github repos -KLIPPER_REPO=https://github.com/Klipper3d/klipper.git -ARKSINE_REPO=https://github.com/Arksine/klipper.git -DMBUTYUGIN_REPO=https://github.com/dmbutyugin/klipper.git -DWC2FK_REPO=https://github.com/Stephan3/dwc2-for-klipper-socket.git -KLIPPERSCREEN_REPO=https://github.com/jordanruthe/KlipperScreen.git -NLEF_REPO=https://github.com/nlef/moonraker-telegram-bot.git +readonly KLIPPER_REPO=https://github.com/Klipper3d/klipper.git +readonly ARKSINE_REPO=https://github.com/Arksine/klipper.git +readonly DMBUTYUGIN_REPO=https://github.com/dmbutyugin/klipper.git +readonly DWC2FK_REPO=https://github.com/Stephan3/dwc2-for-klipper-socket.git +readonly KLIPPERSCREEN_REPO=https://github.com/jordanruthe/KlipperScreen.git +readonly NLEF_REPO=https://github.com/nlef/moonraker-telegram-bot.git #branches -BRANCH_SCURVE_SMOOTHING=dmbutyugin/scurve-smoothing -BRANCH_SCURVE_SHAPING=dmbutyugin/scurve-shaping +readonly BRANCH_SCURVE_SMOOTHING=dmbutyugin/scurve-smoothing +readonly BRANCH_SCURVE_SHAPING=dmbutyugin/scurve-shaping ###Whiptail -KIAUH_WHIPTAIL_WIDTH=96 -KIAUH_WHIPTAIL_HEIGHT=25 - -#functions.sh -### base variables -SYSTEMDDIR="/etc/systemd/system" - +readonly KIAUH_WHIPTAIL_NORMAL_WIDTH=70 +readonly KIAUH_WHIPTAIL_NORMAL_HEIGHT=24 +readonly KIAUH_WHIPTAIL_SINGLE_LINE_HEIGHT=7 diff --git a/scripts/dwc2-for-klipper-socket-installer/install-debian.sh b/scripts/dwc2-for-klipper-socket-installer/install-debian.sh index 8012c58..e71385e 100755 --- a/scripts/dwc2-for-klipper-socket-installer/install-debian.sh +++ b/scripts/dwc2-for-klipper-socket-installer/install-debian.sh @@ -5,7 +5,6 @@ # https://github.com/Stephan3/dwc2-for-klipper-socket.git PYTHONDIR="${HOME}/dwc-env" -SYSTEMDDIR="/etc/systemd/system" DWC_USER=${USER} # Step 1: Verify Klipper has been installed diff --git a/scripts/install_dwc2.sh b/scripts/install_dwc2.sh index f45de5c..65223ce 100755 --- a/scripts/install_dwc2.sh +++ b/scripts/install_dwc2.sh @@ -1,5 +1,4 @@ ### base variables -SYSTEMDDIR="/etc/systemd/system" DWC_ENV="${HOME}/dwc-env" DWC2_DIR="${HOME}/duetwebcontrol" diff --git a/scripts/install_klipper.sh b/scripts/install_klipper.sh index 6ee6dfe..664f6dd 100755 --- a/scripts/install_klipper.sh +++ b/scripts/install_klipper.sh @@ -1,5 +1,4 @@ ### base variables -SYSTEMDDIR="/etc/systemd/system" KLIPPY_ENV="${HOME}/klippy-env" KLIPPER_DIR="${HOME}/klipper" diff --git a/scripts/install_mjpg-streamer.sh b/scripts/install_mjpg-streamer.sh index 8035642..5390f9b 100755 --- a/scripts/install_mjpg-streamer.sh +++ b/scripts/install_mjpg-streamer.sh @@ -1,5 +1,4 @@ ### base variables -SYSTEMDDIR="/etc/systemd/system" WEBCAMD_SRC="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/mjpgstreamer/filesystem/root/usr/local/bin/webcamd" WEBCAM_TXT_SRC="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/mjpgstreamer/filesystem/home/pi/klipper_config/webcam.txt" diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh index b6d2d75..a96c346 100755 --- a/scripts/install_moonraker.sh +++ b/scripts/install_moonraker.sh @@ -1,5 +1,4 @@ ### base variables -SYSTEMDDIR="/etc/systemd/system" MOONRAKER_ENV="${HOME}/moonraker-env" MOONRAKER_DIR="${HOME}/moonraker" MOONRAKER_REPO="https://github.com/Arksine/moonraker.git" diff --git a/scripts/install_octoprint.sh b/scripts/install_octoprint.sh index c48bf57..da89a47 100755 --- a/scripts/install_octoprint.sh +++ b/scripts/install_octoprint.sh @@ -1,5 +1,4 @@ ### base variables -SYSTEMDDIR="/etc/systemd/system" OCTOPRINT_ENV="${HOME}/OctoPrint" octoprint_setup_dialog(){ diff --git a/scripts/ms_theme_installer.sh b/scripts/ms_theme_installer.sh index 424de8e..2a61cb3 100755 --- a/scripts/ms_theme_installer.sh +++ b/scripts/ms_theme_installer.sh @@ -1,5 +1,4 @@ ### base variables -SYSTEMDDIR="/etc/systemd/system" get_theme_list(){ theme_csv_url="https://raw.githubusercontent.com/meteyou/mainsail/develop/docs/_data/themes.csv" diff --git a/scripts/remove.sh b/scripts/remove.sh index 29af7d0..1da6409 100755 --- a/scripts/remove.sh +++ b/scripts/remove.sh @@ -1,6 +1,3 @@ -### base variables -SYSTEMDDIR="/etc/systemd/system" - remove_klipper(){ shopt -s extglob # enable extended globbing ### ask the user if he wants to uninstall moonraker too. -- 2.39.5 From de23b4175930fa8ecd0937f0b199c6ba3e5c9c55 Mon Sep 17 00:00:00 2001 From: Yifei Ding Date: Fri, 12 Nov 2021 15:25:13 -0800 Subject: [PATCH 13/28] Revert "script: remove unsupported color of statuses" This reverts commit b1bfe7089a09db2c010fad975444acd8901225c8. --- scripts/ui/remove_menu.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/ui/remove_menu.sh b/scripts/ui/remove_menu.sh index b4716a4..9df4e9f 100755 --- a/scripts/ui/remove_menu.sh +++ b/scripts/ui/remove_menu.sh @@ -1,5 +1,3 @@ -#!/bin/bash - remove_ui(){ top_border echo -e "| ${red}~~~~~~~~~~~~~~ [ Remove Menu ] ~~~~~~~~~~~~~~${default} | " -- 2.39.5 From 77a768026beafe76dd352aa3d7b1e439bfc13df8 Mon Sep 17 00:00:00 2001 From: Yifei Ding Date: Fri, 12 Nov 2021 15:27:23 -0800 Subject: [PATCH 14/28] refactor: SYSTEMDDIR -> SYSTEMD_DIR --- scripts/constants/constants.sh | 2 +- .../install-debian.sh | 2 +- scripts/functions.sh | 18 +++++++-------- scripts/install_dwc2.sh | 4 ++-- scripts/install_klipper.sh | 4 ++-- scripts/install_mjpg-streamer.sh | 2 +- scripts/install_moonraker.sh | 8 +++---- scripts/install_octoprint.sh | 4 ++-- scripts/remove.sh | 22 +++++++++---------- scripts/update.sh | 2 +- 10 files changed, 34 insertions(+), 34 deletions(-) diff --git a/scripts/constants/constants.sh b/scripts/constants/constants.sh index 74cc45e..05790b6 100755 --- a/scripts/constants/constants.sh +++ b/scripts/constants/constants.sh @@ -31,7 +31,7 @@ readonly MOONRAKER_TELEGRAM_BOT_ENV_DIR=${HOME}/moonraker-telegram-bot-env #misc readonly INI_FILE=${HOME}/.kiauh.ini readonly BACKUP_DIR=${HOME}/kiauh-backups -readonly SYSTEMDDIR=/etc/systemd/system +readonly SYSTEMD_DIR=/etc/systemd/system ### set github repos readonly KLIPPER_REPO=https://github.com/Klipper3d/klipper.git diff --git a/scripts/dwc2-for-klipper-socket-installer/install-debian.sh b/scripts/dwc2-for-klipper-socket-installer/install-debian.sh index e71385e..b608cf2 100755 --- a/scripts/dwc2-for-klipper-socket-installer/install-debian.sh +++ b/scripts/dwc2-for-klipper-socket-installer/install-debian.sh @@ -48,7 +48,7 @@ create_virtualenv() # Step 4: Install startup script install_script(){ report_status "Installing system start script..." - sudo /bin/sh -c "cat > $SYSTEMDDIR/dwc.service" << EOF + sudo /bin/sh -c "cat > $SYSTEMD_DIR/dwc.service" << EOF #Systemd service file for DWC [Unit] Description=dwc_webif diff --git a/scripts/functions.sh b/scripts/functions.sh index 1a780f5..64fee5a 100755 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -93,33 +93,33 @@ set_klipper_cfg_path(){ fi ### handle single klipper instance service file - if [ -f $SYSTEMDDIR/klipper.service ]; then + if [ -f $SYSTEMD_DIR/klipper.service ]; then status_msg "Configuring Klipper for new path ..." - sudo sed -i -r "/ExecStart=/ s| (.+)\/printer.cfg| $new_klipper_cfg_loc/printer.cfg|" $SYSTEMDDIR/klipper.service + sudo sed -i -r "/ExecStart=/ s| (.+)\/printer.cfg| $new_klipper_cfg_loc/printer.cfg|" $SYSTEMD_DIR/klipper.service ok_msg "OK!" fi ### handle multi klipper instance service file - if ls $SYSTEMDDIR/klipper-*.service 2>/dev/null 1>&2; then + if ls $SYSTEMD_DIR/klipper-*.service 2>/dev/null 1>&2; then status_msg "Configuring Klipper for new path ..." - for service in $(find $SYSTEMDDIR/klipper-*.service); do + for service in $(find $SYSTEMD_DIR/klipper-*.service); do sudo sed -i -r "/ExecStart=/ s| (.+)\/printer_| $new_klipper_cfg_loc/printer_|" $service done ok_msg "OK!" fi ### handle single moonraker instance service and moonraker.conf file - if [ -f $SYSTEMDDIR/moonraker.service ]; then + if [ -f $SYSTEMD_DIR/moonraker.service ]; then status_msg "Configuring Moonraker for new path ..." - sudo sed -i -r "/ExecStart=/ s|-c (.+)\/moonraker\.conf|-c $new_klipper_cfg_loc/moonraker.conf|" $SYSTEMDDIR/moonraker.service + sudo sed -i -r "/ExecStart=/ s|-c (.+)\/moonraker\.conf|-c $new_klipper_cfg_loc/moonraker.conf|" $SYSTEMD_DIR/moonraker.service ### replace old file path with new one in moonraker.conf sed -i -r "/config_path:/ s|config_path:.*|config_path: $new_klipper_cfg_loc|" $new_klipper_cfg_loc/moonraker.conf ok_msg "OK!" fi ### handle multi moonraker instance service file - if ls $SYSTEMDDIR/moonraker-*.service 2>/dev/null 1>&2; then + if ls $SYSTEMD_DIR/moonraker-*.service 2>/dev/null 1>&2; then status_msg "Configuring Moonraker for new path ..." - for service in $(find $SYSTEMDDIR/moonraker-*.service); do + for service in $(find $SYSTEMD_DIR/moonraker-*.service); do sudo sed -i -r "/ExecStart=/ s|-c (.+)\/printer_|-c $new_klipper_cfg_loc/printer_|" $service done ### replace old file path with new one in moonraker.conf @@ -144,7 +144,7 @@ source_kiauh_ini(){ do_action_service(){ shopt -s extglob # enable extended globbing - SERVICES="$SYSTEMDDIR/$2?(-*([0-9])).service" + SERVICES="$SYSTEMD_DIR/$2?(-*([0-9])).service" ### set a variable for the ok and status messages [ "$1" == "start" ] && ACTION1="started" && ACTION2="Starting" [ "$1" == "stop" ] && ACTION1="stopped" && ACTION2="Stopping" diff --git a/scripts/install_dwc2.sh b/scripts/install_dwc2.sh index 65223ce..ea289f6 100755 --- a/scripts/install_dwc2.sh +++ b/scripts/install_dwc2.sh @@ -193,7 +193,7 @@ create_dwc_virtualenv() create_single_dwc_startscript(){ ### create systemd service file - sudo /bin/sh -c "cat > ${SYSTEMDDIR}/dwc.service" << DWC + sudo /bin/sh -c "cat > ${SYSTEMD_DIR}/dwc.service" << DWC [Unit] Description=DuetWebControl After=network.target @@ -211,7 +211,7 @@ DWC create_multi_dwc_startscript(){ ### create systemd service file - sudo /bin/sh -c "cat > ${SYSTEMDDIR}/dwc-$INSTANCE.service" << DWC + sudo /bin/sh -c "cat > ${SYSTEMD_DIR}/dwc-$INSTANCE.service" << DWC [Unit] Description=DuetWebControl After=network.target diff --git a/scripts/install_klipper.sh b/scripts/install_klipper.sh index 664f6dd..c9ce73b 100755 --- a/scripts/install_klipper.sh +++ b/scripts/install_klipper.sh @@ -120,7 +120,7 @@ create_klipper_service(){ P_CFG="$CFG_PATH/printer.cfg" P_CFG_SRC="${SRCDIR}/kiauh/resources/printer.cfg" KL_SERV_SRC="${SRCDIR}/kiauh/resources/klipper.service" - KL_SERV_TARGET="$SYSTEMDDIR/klipper.service" + KL_SERV_TARGET="$SYSTEMD_DIR/klipper.service" write_kl_service(){ [ ! -d $CFG_PATH ] && mkdir -p $CFG_PATH @@ -155,7 +155,7 @@ create_klipper_service(){ while [ $i -le $INSTANCE_COUNT ]; do ### rewrite default variables for multi instance cases CFG_PATH="$klipper_cfg_loc/printer_$i" - KL_SERV_TARGET="$SYSTEMDDIR/klipper-$i.service" + KL_SERV_TARGET="$SYSTEMD_DIR/klipper-$i.service" P_TMP="/tmp/printer-$i" P_CFG="$CFG_PATH/printer.cfg" KL_LOG="${HOME}/klipper_logs/klippy-$i.log" diff --git a/scripts/install_mjpg-streamer.sh b/scripts/install_mjpg-streamer.sh index 5390f9b..25fbed1 100755 --- a/scripts/install_mjpg-streamer.sh +++ b/scripts/install_mjpg-streamer.sh @@ -8,7 +8,7 @@ install_mjpg-streamer(){ ### set default values MJPG_SERV_SRC="${SRCDIR}/kiauh/resources/webcamd.service" - MJPG_SERV_TARGET="$SYSTEMDDIR/webcamd.service" + MJPG_SERV_TARGET="$SYSTEMD_DIR/webcamd.service" WEBCAM_TXT="$klipper_cfg_loc/webcam.txt" ### if there is a webcamd.service -> exit diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh index a96c346..24efd66 100755 --- a/scripts/install_moonraker.sh +++ b/scripts/install_moonraker.sh @@ -31,13 +31,13 @@ moonraker_setup_dialog(){ shopt -s extglob # enable extended globbing ### check for existing moonraker service installations - FILE="$SYSTEMDDIR/moonraker?(-*([0-9])).service" + FILE="$SYSTEMD_DIR/moonraker?(-*([0-9])).service" if ls $FILE 2>/dev/null 1>&2; then ERROR_MSG="At least one Moonraker service is already installed!" && return 0 fi ### check for existing klipper service installations - FILE="$SYSTEMDDIR/klipper?(-*([0-9])).service" + FILE="$SYSTEMD_DIR/klipper?(-*([0-9])).service" if ! ls $FILE 2>/dev/null 1>&2; then ERROR_MSG="Klipper service not found, please install Klipper first!" && return 0 fi @@ -167,7 +167,7 @@ create_moonraker_service(){ MR_LOG="${HOME}/klipper_logs/moonraker.log" MR_CONF="$CFG_PATH/moonraker.conf" MR_SERV_SRC="${SRCDIR}/kiauh/resources/moonraker.service" - MR_SERV_TARGET="$SYSTEMDDIR/moonraker.service" + MR_SERV_TARGET="$SYSTEMD_DIR/moonraker.service" write_mr_service(){ if [ ! -f $MR_SERV_TARGET ]; then @@ -196,7 +196,7 @@ create_moonraker_service(){ while [ $i -le $INSTANCE_COUNT ]; do ### rewrite default variables for multi instance cases CFG_PATH="$klipper_cfg_loc/printer_$i" - MR_SERV_TARGET="$SYSTEMDDIR/moonraker-$i.service" + MR_SERV_TARGET="$SYSTEMD_DIR/moonraker-$i.service" MR_CONF="$CFG_PATH/moonraker.conf" MR_LOG="${HOME}/klipper_logs/moonraker-$i.log" ### write multi instance service diff --git a/scripts/install_octoprint.sh b/scripts/install_octoprint.sh index da89a47..488e3b9 100755 --- a/scripts/install_octoprint.sh +++ b/scripts/install_octoprint.sh @@ -102,7 +102,7 @@ add_to_groups(){ create_single_octoprint_startscript(){ ### create single instance systemd service file -sudo /bin/sh -c "cat > ${SYSTEMDDIR}/octoprint.service" << OCTOPRINT +sudo /bin/sh -c "cat > ${SYSTEMD_DIR}/octoprint.service" << OCTOPRINT [Unit] Description=Starts OctoPrint on startup After=network-online.target @@ -122,7 +122,7 @@ OCTOPRINT create_multi_octoprint_startscript(){ ### create multi instance systemd service file -sudo /bin/sh -c "cat > ${SYSTEMDDIR}/octoprint-$INSTANCE.service" << OCTOPRINT +sudo /bin/sh -c "cat > ${SYSTEMD_DIR}/octoprint-$INSTANCE.service" << OCTOPRINT [Unit] Description=Starts OctoPrint instance $INSTANCE on startup After=network-online.target diff --git a/scripts/remove.sh b/scripts/remove.sh index 1da6409..0055b89 100755 --- a/scripts/remove.sh +++ b/scripts/remove.sh @@ -2,7 +2,7 @@ remove_klipper(){ shopt -s extglob # enable extended globbing ### ask the user if he wants to uninstall moonraker too. ###? currently usefull if the user wants to switch from single-instance to multi-instance - FILE="$SYSTEMDDIR/moonraker?(-*([0-9])).service" + FILE="$SYSTEMD_DIR/moonraker?(-*([0-9])).service" if ls $FILE 2>/dev/null 1>&2; then while true; do unset REM_MR @@ -44,7 +44,7 @@ remove_klipper(){ fi ### remove all klipper services - FILE="$SYSTEMDDIR/klipper?(-*([0-9])).service" + FILE="$SYSTEMD_DIR/klipper?(-*([0-9])).service" if ls $FILE 2>/dev/null 1>&2; then status_msg "Removing Klipper Services ..." for service in $(ls $FILE | cut -d"/" -f5) @@ -52,7 +52,7 @@ remove_klipper(){ status_msg "Removing $service ..." sudo systemctl stop $service sudo systemctl disable $service - sudo rm -f $SYSTEMDDIR/$service + sudo rm -f $SYSTEMD_DIR/$service ok_msg "Done!" done ### reloading units @@ -125,7 +125,7 @@ remove_moonraker(){ fi ### remove all moonraker services - FILE="$SYSTEMDDIR/moonraker?(-*([0-9])).service" + FILE="$SYSTEMD_DIR/moonraker?(-*([0-9])).service" if ls $FILE 2>/dev/null 1>&2; then status_msg "Removing Moonraker Services ..." for service in $(ls $FILE | cut -d"/" -f5) @@ -133,7 +133,7 @@ remove_moonraker(){ status_msg "Removing $service ..." sudo systemctl stop $service sudo systemctl disable $service - sudo rm -f $SYSTEMDDIR/$service + sudo rm -f $SYSTEMD_DIR/$service ok_msg "Done!" done ### reloading units @@ -204,7 +204,7 @@ remove_dwc2(){ status_msg "Removing $service ..." sudo systemctl stop $service sudo systemctl disable $service - sudo rm -f $SYSTEMDDIR/$service + sudo rm -f $SYSTEMD_DIR/$service ok_msg "Done!" done ### reloading units @@ -324,7 +324,7 @@ remove_octoprint(){ status_msg "Removing $service ..." sudo systemctl stop $service sudo systemctl disable $service - sudo rm -f $SYSTEMDDIR/$service + sudo rm -f $SYSTEMD_DIR/$service ok_msg "OctoPrint Service removed!" done ### reloading units @@ -396,7 +396,7 @@ remove_klipperscreen(){ status_msg "Removing KlipperScreen service ..." sudo systemctl stop KlipperScreen sudo systemctl disable moonraker - sudo rm -f $SYSTEMDDIR/KlipperScreen.service + sudo rm -f $SYSTEMD_DIR/KlipperScreen.service ###reloading units sudo systemctl daemon-reload sudo systemctl reset-failed @@ -439,7 +439,7 @@ remove_MoonrakerTelegramBot(){ status_msg "Removing MoonrakerTelegramBot service ..." sudo systemctl stop moonraker-telegram-bot sudo systemctl disable moonraker-telegram-bot - sudo rm -f $SYSTEMDDIR/moonraker-telegram-bot.service + sudo rm -f $SYSTEMD_DIR/moonraker-telegram-bot.service ###reloading units sudo systemctl daemon-reload sudo systemctl reset-failed @@ -464,10 +464,10 @@ remove_MoonrakerTelegramBot(){ remove_mjpg-streamer(){ ### remove MJPG-Streamer service - if [ -e $SYSTEMDDIR/webcamd.service ]; then + if [ -e $SYSTEMD_DIR/webcamd.service ]; then status_msg "Removing MJPG-Streamer service ..." sudo systemctl stop webcamd && sudo systemctl disable webcamd - sudo rm -f $SYSTEMDDIR/webcamd.service + sudo rm -f $SYSTEMD_DIR/webcamd.service ###reloading units sudo systemctl daemon-reload sudo systemctl reset-failed diff --git a/scripts/update.sh b/scripts/update.sh index 8a453b3..3222912 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -75,7 +75,7 @@ update_log_paths(){ source_kiauh_ini LPATH="${HOME}/klipper_logs" [ ! -d "$LPATH" ] && mkdir -p "$LPATH" - FILE="$SYSTEMDDIR/$1?(-*([0-9])).service" + FILE="$SYSTEMD_DIR/$1?(-*([0-9])).service" for file in $(ls $FILE); do [ "$1" == "klipper" ] && LOG="klippy" [ "$1" == "moonraker" ] && LOG="moonraker" -- 2.39.5 From ecf4041851dec7538973a3e1a63a90491516080a Mon Sep 17 00:00:00 2001 From: Yifei Ding Date: Fri, 12 Nov 2021 16:14:27 -0800 Subject: [PATCH 15/28] fix: remove redundant global for moonraker --- scripts/constants/constants.sh | 4 ++-- scripts/install_moonraker.sh | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/scripts/constants/constants.sh b/scripts/constants/constants.sh index 05790b6..3b7b351 100755 --- a/scripts/constants/constants.sh +++ b/scripts/constants/constants.sh @@ -1,8 +1,7 @@ #!/bin/bash ### set important directories -#kiauh.sh -#klipper +# klipper readonly KLIPPER_DIR=${HOME}/klipper readonly KLIPPY_ENV=${HOME}/klippy-env #nginx @@ -12,6 +11,7 @@ readonly NGINX_CONFD=/etc/nginx/conf.d #moonraker readonly MOONRAKER_DIR=${HOME}/moonraker readonly MOONRAKER_ENV=${HOME}/moonraker-env +readonly MOONRAKER_REPO="https://github.com/Arksine/moonraker.git" #mainsail readonly MAINSAIL_DIR=${HOME}/mainsail #fluidd diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh index 24efd66..8ca43c0 100755 --- a/scripts/install_moonraker.sh +++ b/scripts/install_moonraker.sh @@ -1,7 +1,4 @@ -### base variables -MOONRAKER_ENV="${HOME}/moonraker-env" -MOONRAKER_DIR="${HOME}/moonraker" -MOONRAKER_REPO="https://github.com/Arksine/moonraker.git" +#!/bin/bash system_check_moonraker(){ ### python 3 check -- 2.39.5 From 4613a85ccf3743a33cd042e75a52cb2c4df29939 Mon Sep 17 00:00:00 2001 From: Yifei Ding Date: Fri, 12 Nov 2021 16:18:03 -0800 Subject: [PATCH 16/28] script: remove unsupported color of status --- scripts/status.sh | 52 ++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/scripts/status.sh b/scripts/status.sh index a9d02d6..bbcffb1 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -1,3 +1,5 @@ +#!/bin/bash + kiauh_status(){ if [ -d "${SRCDIR}/kiauh/.git" ]; then cd ${SRCDIR}/kiauh @@ -50,11 +52,11 @@ klipper_status(){ ### display status if [ "$kcount" == "${#klipper_data[*]}" ]; then - KLIPPER_STATUS="$(printf "${green}Installed: %-5s${default}" $SERVICE_FILE_COUNT)" + KLIPPER_STATUS="$(printf "Installed: %-5s" $SERVICE_FILE_COUNT)" elif [ "$kcount" == 0 ]; then - KLIPPER_STATUS="${red}Not installed!${default} " + KLIPPER_STATUS="Not installed!" else - KLIPPER_STATUS="${yellow}Incomplete!${default} " + KLIPPER_STATUS="Incomplete!" fi } @@ -82,11 +84,11 @@ dwc2_status(){ done if [ "$dcount" == "${#dwc_data[*]}" ]; then - DWC2_STATUS="$(printf "${green}Installed: %-5s${default}" $SERVICE_FILE_COUNT)" + DWC2_STATUS="$(printf "Installed: %-5s" $SERVICE_FILE_COUNT)" elif [ "$dcount" == 0 ]; then - DWC2_STATUS="${red}Not installed!${default} " + DWC2_STATUS="Not installed!" else - DWC2_STATUS="${yellow}Incomplete!${default} " + DWC2_STATUS="Incomplete!" fi } @@ -114,11 +116,11 @@ moonraker_status(){ ### display status if [ "$mrcount" == "${#moonraker_data[*]}" ]; then - MOONRAKER_STATUS="$(printf "${green}Installed: %-5s${default}" $SERVICE_FILE_COUNT)" + MOONRAKER_STATUS="$(printf "Installed: %-5s" $SERVICE_FILE_COUNT)" elif [ "$mrcount" == 0 ]; then - MOONRAKER_STATUS="${red}Not installed!${default} " + MOONRAKER_STATUS="Not installed!" else - MOONRAKER_STATUS="${yellow}Incomplete!${default} " + MOONRAKER_STATUS="Incomplete!" fi } @@ -137,11 +139,11 @@ mainsail_status(){ fi done if [ "$mcount" == "${#mainsail_data[*]}" ]; then - MAINSAIL_STATUS="${green}Installed!${default} " + MAINSAIL_STATUS="Installed!" elif [ "$mcount" == 0 ]; then - MAINSAIL_STATUS="${red}Not installed!${default} " + MAINSAIL_STATUS="Not installed!" else - MAINSAIL_STATUS="${yellow}Incomplete!${default} " + MAINSAIL_STATUS="Incomplete!" fi } @@ -160,11 +162,11 @@ fluidd_status(){ fi done if [ "$fcount" == "${#fluidd_data[*]}" ]; then - FLUIDD_STATUS="${green}Installed!${default} " + FLUIDD_STATUS="Installed!" elif [ "$fcount" == 0 ]; then - FLUIDD_STATUS="${red}Not installed!${default} " + FLUIDD_STATUS="Not installed!" else - FLUIDD_STATUS="${yellow}Incomplete!${default} " + FLUIDD_STATUS="Incomplete!" fi } @@ -190,11 +192,11 @@ octoprint_status(){ ### display status if [ "$ocount" == "${#octoprint_data[*]}" ]; then - OCTOPRINT_STATUS="$(printf "${green}Installed: %-5s${default}" $SERVICE_FILE_COUNT)" + OCTOPRINT_STATUS="$(printf "Installed: %-5s" $SERVICE_FILE_COUNT)" elif [ "$ocount" == 0 ]; then - OCTOPRINT_STATUS="${red}Not installed!${default} " + OCTOPRINT_STATUS="Not installed!" else - OCTOPRINT_STATUS="${yellow}Incomplete!${default} " + OCTOPRINT_STATUS="Incomplete!" fi } @@ -220,11 +222,11 @@ klipperscreen_status(){ fi done if [ "$klsccount" == "${#klipperscreen_data[*]}" ]; then - KLIPPERSCREEN_STATUS="${green}Installed!${default} " + KLIPPERSCREEN_STATUS="Installed!" elif [ "$klsccount" == 0 ]; then - KLIPPERSCREEN_STATUS="${red}Not installed!${default} " + KLIPPERSCREEN_STATUS="Not installed!" else - KLIPPERSCREEN_STATUS="${yellow}Incomplete!${default} " + KLIPPERSCREEN_STATUS="Incomplete!" fi } @@ -250,11 +252,11 @@ MoonrakerTelegramBot_status(){ fi done if [ "$mtbcount" == "${#MoonrakerTelegramBot_data[*]}" ]; then - MOONRAKER_TELEGRAM_BOT_STATUS="${green}Installed!${default} " + MOONRAKER_TELEGRAM_BOT_STATUS="Installed!" elif [ "$mtbcount" == 0 ]; then - MOONRAKER_TELEGRAM_BOT_STATUS="${red}Not installed!${default} " + MOONRAKER_TELEGRAM_BOT_STATUS="Not installed!" else - MOONRAKER_TELEGRAM_BOT_STATUS="${yellow}Incomplete!${default} " + MOONRAKER_TELEGRAM_BOT_STATUS="Incomplete!" fi } @@ -293,7 +295,7 @@ print_branch(){ if [ ! -z "$GET_BRANCH" ]; then PRINT_BRANCH="$(printf "%-16s" "$GET_BRANCH")" else - PRINT_BRANCH="${red}--------------${default} " + PRINT_BRANCH="--------------" fi } -- 2.39.5 From 00fa372e0c694cb071e737e3e0ed14494eed91cb Mon Sep 17 00:00:00 2001 From: Yifei Ding Date: Sat, 13 Nov 2021 00:42:23 -0800 Subject: [PATCH 17/28] script: multi-layer install menu --- scripts/ui/install_interface_menu.sh | 36 +++++++++++++ scripts/ui/install_menu.sh | 76 ++++++++++------------------ scripts/ui/install_other_menu.sh | 33 ++++++++++++ 3 files changed, 95 insertions(+), 50 deletions(-) create mode 100755 scripts/ui/install_interface_menu.sh create mode 100755 scripts/ui/install_other_menu.sh diff --git a/scripts/ui/install_interface_menu.sh b/scripts/ui/install_interface_menu.sh new file mode 100755 index 0000000..d5409ff --- /dev/null +++ b/scripts/ui/install_interface_menu.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# +# Brief description of your script + +install_interface_menu(){ + + local menu_options=( + "1" "Mainsail - lightweight & responsive web interface for Klipper" + "2" "Fluidd - a free and open-source Klipper web interface for managing your 3d printer" + "3" "KlipperScreen - a touchscreen GUI that interfaces with Klipper via Moonraker" + "4" "Duet Web Control - a fully-responsive HTML5-based web interface for RepRapFirmware" + "5" "OctoPrint - a snappy web interface for controlling consumer 3D printers." + ) + local menu_str="Select an interface to install, you can install multiple interfaces." + + while true; do + local menu + menu=$(whiptail --title "Install Interface" --cancel-button "Back" --notags --menu "$menu_str\n\nPerform Action:" \ + "$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 + elif [ $out -eq 0 ]; then + case "$menu" in + 1) do_action "install_webui mainsail";; + 2) do_action "install_webui fluidd";; + 3) do_action "install_klipperscreen";; + 4) do_action "dwc_setup_dialog";; + 5) do_action "octoprint_setup_dialog";; + esac + else + # Unexpected event, no clue what happened + exit 1 + fi + done +} diff --git a/scripts/ui/install_menu.sh b/scripts/ui/install_menu.sh index 5c8fc13..6733b72 100755 --- a/scripts/ui/install_menu.sh +++ b/scripts/ui/install_menu.sh @@ -1,55 +1,31 @@ -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: | Touchscreen GUI: | " - echo -e "| 1) [Klipper] | 5) [KlipperScreen] | " - echo -e "| | | " - echo -e "| Klipper API: | Other: | " - echo -e "| 2) [Moonraker] | 6) [Duet Web Control] | " - echo -e "| | 7) [OctoPrint] | " - echo -e "| Klipper Webinterface: | 8) [PrettyGCode] | " - echo -e "| 3) [Mainsail] | 9) [Telegram Bot] | " - echo -e "| 4) [Fluidd] | | " - echo -e "| | Webcam: | " - echo -e "| | 10) [MJPG-Streamer] | " - back_footer -} +#!/bin/bash install_menu(){ - do_action "" "install_ui" + local menu_options=( + "1" "Klipper" + "2" "Klipper API(Moonraker)" + "3" "Interfaces" + "4" "Other" + ) + local menu_str="You need this menu usually only for installing all necessary dependencies for the various functions on a completely fresh system." + while true; do - read -p "${cyan}Perform action:${default} " action; echo - case "$action" in - 1) - do_action "klipper_setup_dialog" "install_ui";; - 2) - do_action "moonraker_setup_dialog" "install_ui";; - 3) - do_action "install_webui mainsail" "install_ui";; - 4) - do_action "install_webui fluidd" "install_ui";; - 5) - do_action "install_klipperscreen" "install_ui";; - 6) - do_action "dwc_setup_dialog" "install_ui";; - 7) - do_action "octoprint_setup_dialog" "install_ui";; - 8) - do_action "install_pgc_for_klipper" "install_ui";; - 9) - do_action "install_MoonrakerTelegramBot" "install_ui";; - 10) - do_action "install_mjpg-streamer" "install_ui";; - B|b) - clear; main_menu; break;; - *) - deny_action "install_ui";; - esac + local menu + menu=$(whiptail --title "Install" --cancel-button "Back" --notags --menu "$menu_str\n\nPerform Action:" \ + "$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 + elif [ $out -eq 0 ]; then + case "$menu" in + 1) do_action "klipper_setup_dialog";; + 2) do_action "moonraker_setup_dialog";; + 3) install_interface_menu;; + 4) install_other_menu;; + esac + else + # Unexpected event, no clue what happened + exit 1 + fi done - install_menu } diff --git a/scripts/ui/install_other_menu.sh b/scripts/ui/install_other_menu.sh new file mode 100755 index 0000000..da5bc52 --- /dev/null +++ b/scripts/ui/install_other_menu.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# +# Brief description of your script + +install_other_menu(){ + + local menu_options=( + #TODO WIP + "1" "PrettyGCode - " + "2" "Klipper Telegram Bot - " + "3" "Webcam MJPG-Streamer - Use MJPG-Streamer with webcam" + ) + local menu_str="Select an option to install." + + while true; do + local menu + menu=$(whiptail --title "Install Other" --cancel-button "Back" --notags --menu "$menu_str\n\nPerform Action:" \ + "$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 + elif [ $out -eq 0 ]; then + case "$menu" in + 1) do_action "install_pgc_for_klipper";; + 2) do_action "install_MoonrakerTelegramBot";; + 3) do_action "install_mjpg-streamer";; + esac + else + # Unexpected event, no clue what happened + exit 1 + fi + done +} -- 2.39.5 From e7873fd05765ca4584ffa4f1d811a7b7a1459d59 Mon Sep 17 00:00:00 2001 From: Yifei Ding Date: Sat, 13 Nov 2021 00:42:53 -0800 Subject: [PATCH 18/28] script: add service menu --- scripts/ui/service_menu.sh | 62 ++++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 16 deletions(-) mode change 100644 => 100755 scripts/ui/service_menu.sh diff --git a/scripts/ui/service_menu.sh b/scripts/ui/service_menu.sh old mode 100644 new mode 100755 index e02a4e9..9d656de --- a/scripts/ui/service_menu.sh +++ b/scripts/ui/service_menu.sh @@ -1,18 +1,48 @@ #!/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";; +service_menu(){ + local menu_options=( + "1" "Start Klipper" + "2" "Stop Klipper" + "3" "Restart Klipper" + "4" "Start Moonraker" + "5" "Stop Moonraker" + "6" "Restart Moonraker" + "7" "Start Duet Web Control" + "8" "Stop Duet Web Control" + "9" "Restart Duet Web Control" + "10" "Start Octoprint" + "11" "Stop Octoprint" + "12" "Restart Octoprint" + ) + + local menu_str="Start/stop/restart services" + + while true; do + local menu + menu=$(whiptail --title "Service Menu" --cancel-button "Back" --notags --menu "$menu_str\n\nPerform Action:" \ + "$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 + elif [ $out -eq 0 ]; then + case "$menu" in + 1) do_action_service "start" "klipper";; + 2) do_action_service "stop" "klipper";; + 3) do_action_service "restart" "klipper";; + 4) do_action_service "start" "moonraker";; + 5) do_action_service "stop" "moonraker";; + 6) do_action_service "restart" "moonraker";; + 7)do_action_service "start" "dwc";; + 8)do_action_service "stop" "dwc";; + 9)do_action_service "restart" "dwc";; + 10)do_action_service "start" "octoprint";; + 11)do_action_service "stop" "octoprint";; + 12)do_action_service "restart" "octoprint";; + esac + else + # Unexpected event, no clue what happened + exit 1 + fi + done +} \ No newline at end of file -- 2.39.5 From f42ce0f0c5d3e1fd16c0ce38f6024d1f71905f48 Mon Sep 17 00:00:00 2001 From: Yifei Ding Date: Sat, 13 Nov 2021 00:46:17 -0800 Subject: [PATCH 19/28] script: rename general_ui and separate dialog --- ...{general_ui.sh => general_ui_functions.sh} | 30 +------------------ scripts/ui/update_dialog.sh | 27 +++++++++++++++++ 2 files changed, 28 insertions(+), 29 deletions(-) rename scripts/ui/{general_ui.sh => general_ui_functions.sh} (64%) create mode 100644 scripts/ui/update_dialog.sh diff --git a/scripts/ui/general_ui.sh b/scripts/ui/general_ui_functions.sh similarity index 64% rename from scripts/ui/general_ui.sh rename to scripts/ui/general_ui_functions.sh index 673a701..7715e25 100755 --- a/scripts/ui/general_ui.sh +++ b/scripts/ui/general_ui_functions.sh @@ -1,3 +1,4 @@ +#!/bin/bash #ui total width = 57 chars top_border(){ echo -e "/=======================================================\\" @@ -48,11 +49,8 @@ print_header(){ do_action(){ clear && print_header - ### $1 is the action the user wants to fire $1 print_msg && clear_msg - ### $2 is the menu the user usually gets directed back to after an action is completed - $2 } deny_action(){ @@ -62,30 +60,4 @@ deny_action(){ $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 -} diff --git a/scripts/ui/update_dialog.sh b/scripts/ui/update_dialog.sh new file mode 100644 index 0000000..e72d8e6 --- /dev/null +++ b/scripts/ui/update_dialog.sh @@ -0,0 +1,27 @@ +####################################### +# 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 +} \ No newline at end of file -- 2.39.5 From 44966cba2d8993d82d8d6abaf0b14d63c4abf971 Mon Sep 17 00:00:00 2001 From: Yifei Ding Date: Sat, 13 Nov 2021 00:48:25 -0800 Subject: [PATCH 20/28] fix: upload log should not rerun the main_menu --- scripts/upload_log.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/upload_log.sh b/scripts/upload_log.sh index 7c2234b..02d6e81 100755 --- a/scripts/upload_log.sh +++ b/scripts/upload_log.sh @@ -1,3 +1,5 @@ +#!/bin/bash + accept_upload_conditions(){ while true; do top_border @@ -23,7 +25,7 @@ accept_upload_conditions(){ ;; N|n|No|no) clear - main_menu + main_menu #TODO this is the issue causing main menu to not exit break ;; *) -- 2.39.5 From a60223306cef298ae7828f14c9c2677a0fc8cb32 Mon Sep 17 00:00:00 2001 From: Yifei Ding Date: Sat, 13 Nov 2021 01:01:11 -0800 Subject: [PATCH 21/28] scripts: rename update_dialog --- scripts/ui/{update_dialog.sh => kiauh_update_yesno.sh} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename scripts/ui/{update_dialog.sh => kiauh_update_yesno.sh} (91%) diff --git a/scripts/ui/update_dialog.sh b/scripts/ui/kiauh_update_yesno.sh similarity index 91% rename from scripts/ui/update_dialog.sh rename to scripts/ui/kiauh_update_yesno.sh index e72d8e6..c74c9bf 100644 --- a/scripts/ui/update_dialog.sh +++ b/scripts/ui/kiauh_update_yesno.sh @@ -7,7 +7,7 @@ # Arguments: # None ####################################### -kiauh_update_dialog() { +kiauh_update_yesno() { whiptail --title "New KIAUH update available!" \ --yesno \ "View Changelog: https://git.io/JnmlX @@ -22,6 +22,6 @@ Do you want to update now?" \ if [ $out -eq 0 ]; then do_action "update_kiauh" else - deny_action "kiauh_update_dialog" + return fi } \ No newline at end of file -- 2.39.5 From d7ab5dc01700a3d085d3e6f5341b9a2eace8c008 Mon Sep 17 00:00:00 2001 From: Yifei Ding Date: Sat, 13 Nov 2021 01:01:44 -0800 Subject: [PATCH 22/28] script: use whiptail for upload log --- scripts/ui/upload_yesno.sh | 24 +++++++++++++++++++++++ scripts/upload_log.sh | 40 +------------------------------------- 2 files changed, 25 insertions(+), 39 deletions(-) create mode 100644 scripts/ui/upload_yesno.sh diff --git a/scripts/ui/upload_yesno.sh b/scripts/ui/upload_yesno.sh new file mode 100644 index 0000000..eeffade --- /dev/null +++ b/scripts/ui/upload_yesno.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +upload_yesno(){ + whiptail --title "Upload Agreement" \ + --yesno \ + "The following function will help to quickly upload logs for debugging purposes. With confirming this dialog, you agree that during that process your logs will be uploaded to: http://paste.c-net.org/ + +PLEASE NOTE: + +Be aware that logs can contain network information, private data like usernames, filenames, or other information you may not want to make public. + +Do ${red}NOT${default} use this function if you don't agree! + +Do you accept?" \ + "$KIAUH_WHIPTAIL_NORMAL_HEIGHT" "$KIAUH_WHIPTAIL_NORMAL_WIDTH" + + local out=$? + if [ $out -eq 0 ]; then + sed -i "/logupload_accepted=/s/false/true/" $INI_FILE + clear && print_header && upload_selection + else + return + fi +} \ No newline at end of file diff --git a/scripts/upload_log.sh b/scripts/upload_log.sh index 02d6e81..b7e7230 100755 --- a/scripts/upload_log.sh +++ b/scripts/upload_log.sh @@ -1,46 +1,8 @@ #!/bin/bash -accept_upload_conditions(){ - while true; do - top_border - echo -e "| ${red}~~~~~~~~~~~ [ Upload Agreement ] ~~~~~~~~~~~~${default} |" - hr - echo -e "| The following function will help to quickly upload |" - echo -e "| logs for debugging purposes. With confirming this |" - echo -e "| dialog, you agree that during that process your logs |" - echo -e "| will be uploaded to: ${yellow}http://paste.c-net.org/${default} |" - hr - echo -e "| ${red}PLEASE NOTE:${default} |" - echo -e "| Be aware that logs can contain network information, |" - echo -e "| private data like usernames, filenames, or other |" - echo -e "| information you may not want to make public. |" - blank_line - echo -e "| Do ${red}NOT${default} use this function if you don't agree! |" - bottom_border - read -p "${cyan}Do you accept? (Y/n):${default} " yn - case "$yn" in - Y|y|Yes|yes|"") - sed -i "/logupload_accepted=/s/false/true/" $INI_FILE - clear && print_header && upload_selection - ;; - N|n|No|no) - clear - main_menu #TODO this is the issue causing main menu to not exit - break - ;; - *) - clear - print_header - print_unkown_cmd - print_msg && clear_msg - accept_upload_conditions;; - esac - done -} - upload_selection(){ source_kiauh_ini - [ "$logupload_accepted" = "false" ] && accept_upload_conditions + [ "$logupload_accepted" = "false" ] && upload_yesno ### find all suitable logfiles for klipper logfiles=() -- 2.39.5 From a5ae3fb8915bc75697fe68182488cffa71eb9dfe Mon Sep 17 00:00:00 2001 From: Yifei Ding Date: Sat, 13 Nov 2021 01:17:44 -0800 Subject: [PATCH 23/28] script: whiptail remove menu --- scripts/ui/remove_interface_menu.sh | 36 +++++++++++++++++ scripts/ui/remove_menu.sh | 63 +++++++++++++++-------------- scripts/ui/remove_other_menu.sh | 34 ++++++++++++++++ 3 files changed, 102 insertions(+), 31 deletions(-) create mode 100755 scripts/ui/remove_interface_menu.sh create mode 100755 scripts/ui/remove_other_menu.sh diff --git a/scripts/ui/remove_interface_menu.sh b/scripts/ui/remove_interface_menu.sh new file mode 100755 index 0000000..6a8e909 --- /dev/null +++ b/scripts/ui/remove_interface_menu.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# +# Brief description of your script + +remove_interface_menu(){ + + local menu_options=( + "1" "Mainsail - lightweight & responsive web interface for Klipper" + "2" "Fluidd - a free and open-source Klipper web interface for managing your 3d printer" + "3" "KlipperScreen - a touchscreen GUI that interfaces with Klipper via Moonraker" + "4" "Duet Web Control - a fully-responsive HTML5-based web interface for RepRapFirmware" + "5" "OctoPrint - a snappy web interface for controlling consumer 3D printers." + ) + local menu_str="Select an interface to install, you can install multiple interfaces." + + while true; do + local menu + menu=$(whiptail --title "Install Interface" --cancel-button "Back" --notags --menu "$menu_str\n\nPerform Action:" \ + "$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 + elif [ $out -eq 0 ]; then + case "$menu" in + 1) do_action "install_webui mainsail";; + 2) do_action "install_webui fluidd";; + 3) do_action "install_klipperscreen";; + 4) do_action "dwc_setup_dialog";; + 5) do_action "octoprint_setup_dialog";; + esac + else + # Unexpected event, no clue what happened + exit 1 + fi + done +} diff --git a/scripts/ui/remove_menu.sh b/scripts/ui/remove_menu.sh index 9df4e9f..0d5c4d2 100755 --- a/scripts/ui/remove_menu.sh +++ b/scripts/ui/remove_menu.sh @@ -1,3 +1,4 @@ +#!/bin/bash remove_ui(){ top_border echo -e "| ${red}~~~~~~~~~~~~~~ [ Remove Menu ] ~~~~~~~~~~~~~~${default} | " @@ -22,37 +23,37 @@ remove_ui(){ } remove_menu(){ - do_action "" "remove_ui" + #TODO Currently it's a "dumb" remove page, looking for a "smart" one + local menu_options=( + "1" "Klipper" + "2" "Klipper API(Moonraker)" + "3" "Interfaces" + "4" "Other" + ) + local menu_str="Directories which remain untouched: + +Your printer configuration directory +~/kiauh-backups + +You need remove them manually if you wish so." + while true; do - read -p "${cyan}Perform action:${default} " action; echo - case "$action" in - 1) - do_action "remove_klipper" "remove_ui";; - 2) - do_action "remove_moonraker" "remove_ui";; - 3) - do_action "remove_mainsail" "remove_ui";; - 4) - do_action "remove_fluidd" "remove_ui";; - 5) - do_action "remove_klipperscreen" "remove_ui";; - 6) - do_action "remove_dwc2" "remove_ui";; - 7) - do_action "remove_octoprint" "remove_ui";; - 8) - do_action "remove_prettygcode" "remove_ui";; - 9) - do_action "remove_MoonrakerTelegramBot" "remove_ui";; - 10) - do_action "remove_mjpg-streamer" "remove_ui";; - 11) - do_action "remove_nginx" "remove_ui";; - B|b) - clear; main_menu; break;; - *) - deny_action "remove_ui";; - esac + local menu + menu=$(whiptail --title "Remove Menu" --cancel-button "Back" --notags --menu "$menu_str\n\nPerform Action:" \ + "$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 + elif [ $out -eq 0 ]; then + case "$menu" in + 1) do_action "remove_klipper";; + 2) do_action "remove_moonraker";; + 3) remove_interface_menu;; + 4) remove_other_menu;; + esac + else + # Unexpected event, no clue what happened + exit 1 + fi done - remove_menu } diff --git a/scripts/ui/remove_other_menu.sh b/scripts/ui/remove_other_menu.sh new file mode 100755 index 0000000..7f56db8 --- /dev/null +++ b/scripts/ui/remove_other_menu.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# Brief description of your script + +remove_other_menu() { + + local menu_options=( + #TODO WIP + "1" "PrettyGCode - " + "2" "Klipper Telegram Bot - " + "3" "Webcam MJPG-Streamer - Use MJPG-Streamer with webcam" + "4" "Nginx" + ) + local menu_str="Select an option to install." + + while true; do + local menu + menu=$(whiptail --title "Remove Other" --cancel-button "Back" --notags --menu "$menu_str\n\nPerform Action:" \ + "$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 + elif [ $out -eq 0 ]; then + case "$menu" in + 1) do_action "remove_pgc_for_klipper" ;; + 2) do_action "remove_MoonrakerTelegramBot" ;; + 3) do_action "remove_mjpg-streamer" ;; + 4) do_action "remove_nginx" ;; + esac + else + # Unexpected event, no clue what happened + exit 1 + fi + done +} -- 2.39.5 From 17ca9e50a08ae8e35d8fb0cecba1789d53068fb2 Mon Sep 17 00:00:00 2001 From: Yifei Ding Date: Sat, 13 Nov 2021 11:29:38 -0800 Subject: [PATCH 24/28] script: whiptail backup menu --- scripts/ui/backup_menu.sh | 89 ++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 49 deletions(-) diff --git a/scripts/ui/backup_menu.sh b/scripts/ui/backup_menu.sh index 4c612ae..551057a 100755 --- a/scripts/ui/backup_menu.sh +++ b/scripts/ui/backup_menu.sh @@ -1,53 +1,44 @@ -backup_ui(){ - top_border - echo -e "| $(title_msg "~~~~~~~~~~~~~~ [ Backup Menu ] ~~~~~~~~~~~~~~") | " - hr - echo -e "| ${yellow}Backup location: ~/kiauh-backups${default} | " - hr - echo -e "| Configuration folder: | Klipper Webinterface: | " - echo -e "| 0) [Klipper configs] | 4) [Mainsail] | " - echo -e "| | 5) [Fluidd] | " - echo -e "| Firmware: | | " - echo -e "| 1) [Klipper] | HDMI Screen: | " - echo -e "| | 6) [KlipperScreen] | " - echo -e "| Klipper API: | | " - echo -e "| 2) [Moonraker] | Other: | " - echo -e "| 3) [Moonraker DB] | 7) [Duet Web Control] | " - echo -e "| | 8) [OctoPrint] | " - echo -e "| | 9) [MoonrakerTelegramBot] | " - back_footer -} +#!/bin/bash backup_menu(){ - do_action "" "backup_ui" + + local menu_options=( + "1" "Klipper configs" + "2" "Klipper" + "3" "Moonraker" + "4" "Moonraker DB" + "5" "Mainsail" + "6" "KlipperScreen" + "7" "Duet Web Control" + "8" "OctoPrint" + "9" "MoonrakerTelegramBot" + ) + + local menu_str="Backup location: ~/kiauh-backups" while true; do - read -p "${cyan}Perform action:${default} " action; echo - case "$action" in - 0) - do_action "backup_klipper_config_dir" "backup_ui";; - 1) - do_action "backup_klipper" "backup_ui";; - 2) - do_action "backup_moonraker" "backup_ui";; - 3) - do_action "backup_moonraker_database" "backup_ui";; - 4) - do_action "backup_mainsail" "backup_ui";; - 5) - do_action "backup_fluidd" "backup_ui";; - 6) - do_action "backup_klipperscreen" "backup_ui";; - 7) - do_action "backup_dwc2" "backup_ui";; - 8) - do_action "backup_octoprint" "backup_ui";; - 9) - do_action "backup_MoonrakerTelegramBot" "backup_ui";; - B|b) - clear; main_menu; break;; - *) - deny_action "backup_ui";; - esac - done - backup_menu + local menu + menu=$(whiptail --title "Backup Menu" --cancel-button "Back" --notags --menu "$menu_str\n\nPerform Action:"\ + "$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 + elif [ $out -eq 0 ]; then + case "$menu" in + 0) do_action "backup_klipper_config_dir";; + 1) do_action "backup_klipper";; + 2) do_action "backup_moonraker";; + 3) do_action "backup_moonraker_database";; + 4) do_action "backup_mainsail";; + 5) do_action "backup_fluidd";; + 6) do_action "backup_klipperscreen";; + 7) do_action "backup_dwc2";; + 8) do_action "backup_octoprint";; + 9) do_action "backup_MoonrakerTelegramBot";; + esac + else + # Unexpected event, no clue what happened + exit 1 + fi + done } -- 2.39.5 From 68bedd7218fb285c5bbc6279c31f48505fc481b6 Mon Sep 17 00:00:00 2001 From: Yifei Ding Date: Sat, 13 Nov 2021 12:29:34 -0800 Subject: [PATCH 25/28] script: separate moonraker removal with whiptail --- scripts/remove.sh | 31 ++++------------------------ scripts/ui/remove_moonraker_yesno.sh | 17 +++++++++++++++ 2 files changed, 21 insertions(+), 27 deletions(-) create mode 100755 scripts/ui/remove_moonraker_yesno.sh diff --git a/scripts/remove.sh b/scripts/remove.sh index 0055b89..e632635 100755 --- a/scripts/remove.sh +++ b/scripts/remove.sh @@ -1,36 +1,13 @@ +#!/bin/bash + remove_klipper(){ + #TODO The logic to Ask if you want to remove moonraker should be outside of remove_klipper shopt -s extglob # enable extended globbing ### ask the user if he wants to uninstall moonraker too. ###? currently usefull if the user wants to switch from single-instance to multi-instance FILE="$SYSTEMD_DIR/moonraker?(-*([0-9])).service" if ls $FILE 2>/dev/null 1>&2; then - while true; do - unset REM_MR - top_border - echo -e "| Do you want to remove Moonraker afterwards? |" - echo -e "| |" - echo -e "| This is useful in case you want to switch from a |" - echo -e "| single-instance to a multi-instance installation, |" - echo -e "| which makes a re-installation of Moonraker necessary. |" - echo -e "| |" - echo -e "| If for any other reason you only want to uninstall |" - echo -e "| Klipper, please select 'No' and continue. |" - bottom_border - read -p "${cyan}###### Remove Moonraker afterwards? (y/N):${default} " yn - case "$yn" in - Y|y|Yes|yes) - echo -e "###### > Yes" - REM_MR="true" - break;; - N|n|No|no|"") - echo -e "###### > No" - REM_MR="false" - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac - done + remove_moonraker_yesno fi ### remove "legacy" klipper init.d service diff --git a/scripts/ui/remove_moonraker_yesno.sh b/scripts/ui/remove_moonraker_yesno.sh new file mode 100755 index 0000000..80379d0 --- /dev/null +++ b/scripts/ui/remove_moonraker_yesno.sh @@ -0,0 +1,17 @@ +#!/bin/bash +remove_moonraker_yesno(){ + whiptail --title "Remove" \ + --yesno \ + "Do you want to remove Moonraker afterwards? + + This is useful in case you want to switch from a single-instance to a multi-instance installation, which makes a re-installation of Moonraker necessary. + + If for any other reason you only want to uninstall Klipper, please select 'No' and continue." \ + "$KIAUH_WHIPTAIL_NORMAL_HEIGHT" "$KIAUH_WHIPTAIL_NORMAL_WIDTH" + + local out=$? + if [ $out -eq 0 ]; then + REM_MR="true" + else + REM_MR="false" +} \ No newline at end of file -- 2.39.5 From 9915f00ceb91e3aa190e48d24b0d2f22f63f1c01 Mon Sep 17 00:00:00 2001 From: Yifei Ding Date: Sat, 13 Nov 2021 12:56:26 -0800 Subject: [PATCH 26/28] script: whiptail Octoprint dialog --- scripts/install_octoprint.sh | 44 +--------------------------- scripts/ui/octoprint_setup_dialog.sh | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 43 deletions(-) create mode 100755 scripts/ui/octoprint_setup_dialog.sh diff --git a/scripts/install_octoprint.sh b/scripts/install_octoprint.sh index 488e3b9..b485d08 100755 --- a/scripts/install_octoprint.sh +++ b/scripts/install_octoprint.sh @@ -1,46 +1,4 @@ -### base variables -OCTOPRINT_ENV="${HOME}/OctoPrint" - -octoprint_setup_dialog(){ - status_msg "Initializing OctoPrint installation ..." - - ### count amount of klipper services - if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ]; then - INSTANCE_COUNT=1 - else - INSTANCE_COUNT=$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service" | wc -l) - fi - - ### instance confirmation dialog - while true; do - echo - top_border - if [ $INSTANCE_COUNT -gt 1 ]; then - printf "|%-55s|\n" " $INSTANCE_COUNT Klipper instances were found!" - else - echo -e "| 1 Klipper instance was found! | " - fi - echo -e "| You need one OctoPrint instance per Klipper instance. | " - bottom_border - echo - read -p "${cyan}###### Create $INSTANCE_COUNT OctoPrint instances? (Y/n):${default} " yn - case "$yn" in - Y|y|Yes|yes|"") - echo -e "###### > Yes" - status_msg "Creating $INSTANCE_COUNT OctoPrint instances ..." - octoprint_setup - break;; - N|n|No|no) - echo -e "###### > No" - warn_msg "Exiting OctoPrint setup ..." - echo - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac - done -} +#!/bin/bash octoprint_dependencies(){ dep=( diff --git a/scripts/ui/octoprint_setup_dialog.sh b/scripts/ui/octoprint_setup_dialog.sh new file mode 100755 index 0000000..30ffdc3 --- /dev/null +++ b/scripts/ui/octoprint_setup_dialog.sh @@ -0,0 +1,30 @@ +#!/bin/bash +octoprint_setup_dialog(){ + status_msg "Initializing OctoPrint installation ..." + + ### count amount of klipper services + if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ]; then + INSTANCE_COUNT=1 + else + INSTANCE_COUNT=$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service" | wc -l) + fi + + whiptail --title "Install OctoPrint" \ + --yesno \ + "$INSTANCE_COUNT Klipper instances were found! + +You need one OctoPrint instance per Klipper instance. + +Create $INSTANCE_COUNT OctoPrint instances?" \ + "$KIAUH_WHIPTAIL_NORMAL_HEIGHT" "$KIAUH_WHIPTAIL_NORMAL_WIDTH" + + local out=$? + if [ $out -eq 0 ]; then + status_msg "Creating $INSTANCE_COUNT OctoPrint instances ..." + octoprint_setup + else + whiptail --title "$KIAUH_TITLE" --msgbox "Exiting OctoPrint Install" \ + "$KIAUH_WHIPTAIL_SINGLE_LINE_HEIGHT" "$KIAUH_WHIPTAIL_NORMAL_WIDTH" + return + fi +} -- 2.39.5 From 44f41a57bcf6d5d9ed3285a85d4dac7429819689 Mon Sep 17 00:00:00 2001 From: Yifei Ding Date: Sat, 13 Nov 2021 13:41:10 -0800 Subject: [PATCH 27/28] ignore: add idea and iml --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f7de4a4..59edb44 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -kiauh.ini \ No newline at end of file +kiauh.ini +.idea +kiauh.iml \ No newline at end of file -- 2.39.5 From e2262f8aed9e01fec32e789cb1f0fbe85cff42f2 Mon Sep 17 00:00:00 2001 From: Yifei Ding Date: Sat, 13 Nov 2021 13:49:09 -0800 Subject: [PATCH 28/28] script: Fix Broken Git --- kiauh.sh | 104 ++++++---- scripts/backup.sh | 1 + scripts/constants/constants.sh | 5 + scripts/functions.sh | 3 +- scripts/install_klipper.sh | 4 +- ...g-streamer.sh => install_mjpg_streamer.sh} | 8 +- scripts/install_moonraker.sh | 100 ++++----- ...t.sh => install_moonraker_telegram_bot.sh} | 4 +- scripts/install_octoprint.sh | 8 +- scripts/install_pgc_for_klipper.sh | 2 + scripts/ms_theme_installer.sh | 43 +--- scripts/network_functions.sh | 2 + scripts/rollback.sh | 2 +- scripts/status.sh | 4 +- scripts/switch_branch.sh | 2 + scripts/ui/advanced_menu.sh | 191 ++++++------------ scripts/ui/kiauh_update_yesno.sh | 1 + scripts/ui/main_menu.sh | 28 +-- scripts/ui/remove_menu.sh | 22 -- scripts/ui/settings_menu.sh | 2 + scripts/ui/switch_menu.sh | 96 +++++++++ scripts/ui/theme_menu.sh | 69 +++++++ scripts/ui/update_menu.sh | 3 + scripts/ui/upload_yesno.sh | 0 scripts/update.sh | 2 + scripts/upload_log.sh | 1 + 26 files changed, 393 insertions(+), 314 deletions(-) rename scripts/{install_mjpg-streamer.sh => install_mjpg_streamer.sh} (91%) rename scripts/{install_moonraker-telegram-bot.sh => install_moonraker_telegram_bot.sh} (93%) mode change 100644 => 100755 mode change 100644 => 100755 scripts/ui/kiauh_update_yesno.sh create mode 100755 scripts/ui/switch_menu.sh create mode 100755 scripts/ui/theme_menu.sh mode change 100644 => 100755 scripts/ui/upload_yesno.sh diff --git a/kiauh.sh b/kiauh.sh index 3bda5f5..08fa409 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -1,62 +1,88 @@ #!/bin/bash - -### Gettext Configuration -alias GETTEXT='gettext "KIAUH"' - -#clear -# TODO set -e cause whiptail to force an exit because it use stderr, need a workaround here -# set -e - -### set color variables -green=$(echo -en "\e[92m") -yellow=$(echo -en "\e[93m") -red=$(echo -en "\e[91m") -cyan=$(echo -en "\e[96m") -default=$(echo -en "\e[39m") - -### sourcing all additional scripts -SRCDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. && pwd )" -for script in "${SRCDIR}/kiauh/scripts/constants/"*.sh; do . $script; done -for script in "${SRCDIR}/kiauh/scripts/"*.sh; do . $script; done -for script in "${SRCDIR}/kiauh/scripts/ui/"*.sh; do . $script; done - ### set some messages -warn_msg(){ +warn_msg() { echo -e "${red} $1${default}" } -status_msg(){ - echo; echo -e "${yellow}###### $1${default}" +status_msg() { + echo + echo -e "${yellow}###### $1${default}" } -ok_msg(){ +ok_msg() { echo -e "${green}>>>>>> $1${default}" } -title_msg(){ +title_msg() { echo -e "${cyan}$1${default}" } -get_date(){ +get_date() { current_date=$(date +"%y%m%d-%H%M") } -print_unkown_cmd(){ +print_unkown_cmd() { ERROR_MSG="Invalid command!" } -print_msg(){ - if [[ "$ERROR_MSG" != "" ]]; then - whiptail --title "$KIAUH_TITLE" --msgbox "$ERROR_MSG"\ - "$KIAUH_WHIPTAIL_SINGLE_LINE_HEIGHT" "$KIAUH_WHIPTAIL_NORMAL_WIDTH" +####################################### +# description Display an error or a confirmation +# Globals: +# CONFIRM_MSG +# ERROR_MSG +# KIAUH_TITLE +# KIAUH_WHIPTAIL_NORMAL_WIDTH +# KIAUH_WHIPTAIL_SINGLE_LINE_HEIGHT +# Arguments: +# None +####################################### +print_msg() { + if [[ $ERROR_MSG != "" ]]; then + whiptail --title "$KIAUH_TITLE" --msgbox "$ERROR_MSG" \ + "$KIAUH_WHIPTAIL_SINGLE_LINE_HEIGHT" "$KIAUH_WHIPTAIL_NORMAL_WIDTH" fi + # TODO Maybe confirm_msg can be yesno box if [ "$CONFIRM_MSG" != "" ]; then - whiptail --title "$KIAUH_TITLE" --msgbox "$CONFIRM_MSG"\ - "$KIAUH_WHIPTAIL_SINGLE_LINE_HEIGHT" "$KIAUH_WHIPTAIL_NORMAL_WIDTH" + whiptail --title "$KIAUH_TITLE" --msgbox "$CONFIRM_MSG" \ + "$KIAUH_WHIPTAIL_SINGLE_LINE_HEIGHT" "$KIAUH_WHIPTAIL_NORMAL_WIDTH" fi } -clear_msg(){ +clear_msg() { unset CONFIRM_MSG unset ERROR_MSG } -check_euid -init_ini -kiauh_status -main_menu +function main() { + ### Gettext Configuration + alias GETTEXT='gettext "KIAUH"' + + #clear + # TODO set -e cause whiptail to force an exit because it use stderr, need a workaround here + # set -e + ### set color variables + green=$(echo -en "\e[92m") + + yellow=$(echo -en "\e[93m") + + red=$(echo -en "\e[91m") + + cyan=$(echo -en "\e[96m") + + default=$(echo -en "\e[39m") + + ### sourcing all additional scripts + SRCDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)" + + for script in "${SRCDIR}/kiauh/scripts/constants/"*.sh; 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 + + init_ini + + kiauh_status + + main_menu + +} + +main "$@" diff --git a/scripts/backup.sh b/scripts/backup.sh index e0f6901..2228b6c 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -1,3 +1,4 @@ +#!/bin/bash check_for_backup_dir(){ if [ ! -d $BACKUP_DIR ]; then status_msg "Create KIAUH backup directory ..." diff --git a/scripts/constants/constants.sh b/scripts/constants/constants.sh index 3b7b351..d06b9c9 100755 --- a/scripts/constants/constants.sh +++ b/scripts/constants/constants.sh @@ -22,6 +22,7 @@ readonly DWC_ENV_DIR=${HOME}/dwc-env readonly DWC2_DIR=${HOME}/duetwebcontrol #octoprint readonly OCTOPRINT_DIR=${HOME}/OctoPrint +readonly OCTOPRINT_ENV_DIR=${HOME}/OctoPrint/env #KlipperScreen readonly KLIPPERSCREEN_DIR=${HOME}/KlipperScreen readonly KLIPPERSCREEN_ENV_DIR=${HOME}/.KlipperScreen-env @@ -44,6 +45,10 @@ readonly NLEF_REPO=https://github.com/nlef/moonraker-telegram-bot.git readonly BRANCH_SCURVE_SMOOTHING=dmbutyugin/scurve-smoothing readonly BRANCH_SCURVE_SHAPING=dmbutyugin/scurve-shaping +### Webcam +readonly WEBCAMD_SRC="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/mjpgstreamer/filesystem/root/usr/local/bin/webcamd" +readonly WEBCAM_TXT_SRC="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/mjpgstreamer/filesystem/home/pi/klipper_config/webcam.txt" + ###Whiptail readonly KIAUH_WHIPTAIL_NORMAL_WIDTH=70 readonly KIAUH_WHIPTAIL_NORMAL_HEIGHT=24 diff --git a/scripts/functions.sh b/scripts/functions.sh index ad2b812..99749fd 100755 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -1,4 +1,5 @@ #!/bin/bash + # setting up some frequently used functions check_euid(){ @@ -456,7 +457,7 @@ init_ini(){ fetch_webui_ports } -print_kiauh_version() { +check_kiauh_version() { cd ${SRCDIR}/kiauh KIAUH_VER=$(git describe HEAD --always --tags | cut -d "-" -f 1,2) KIAUH_VER="$(printf "%-20s" "$KIAUH_VER")" diff --git a/scripts/install_klipper.sh b/scripts/install_klipper.sh index c9ce73b..30a16c9 100755 --- a/scripts/install_klipper.sh +++ b/scripts/install_klipper.sh @@ -1,6 +1,4 @@ -### base variables -KLIPPY_ENV="${HOME}/klippy-env" -KLIPPER_DIR="${HOME}/klipper" +#!/bin/bash klipper_setup_dialog(){ status_msg "Initializing Klipper installation ..." diff --git a/scripts/install_mjpg-streamer.sh b/scripts/install_mjpg_streamer.sh similarity index 91% rename from scripts/install_mjpg-streamer.sh rename to scripts/install_mjpg_streamer.sh index 25fbed1..4cfa517 100755 --- a/scripts/install_mjpg-streamer.sh +++ b/scripts/install_mjpg_streamer.sh @@ -1,8 +1,6 @@ -### base variables -WEBCAMD_SRC="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/mjpgstreamer/filesystem/root/usr/local/bin/webcamd" -WEBCAM_TXT_SRC="https://raw.githubusercontent.com/raymondh2/MainsailOS/master/src/modules/mjpgstreamer/filesystem/home/pi/klipper_config/webcam.txt" +#!/bin/bash -install_mjpg-streamer(){ +install_mjpg_streamer(){ ### checking dependencies check_klipper_cfg_path @@ -108,4 +106,4 @@ EOF echo -e " ${cyan}● Webcam URL:${default} $WEBCAM_IP" echo -e " ${cyan}● Webcam URL:${default} $WEBCAM_URL" echo -} \ No newline at end of file +} diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh index 747d96e..024a9eb 100755 --- a/scripts/install_moonraker.sh +++ b/scripts/install_moonraker.sh @@ -1,6 +1,6 @@ #!/bin/bash -system_check_moonraker(){ +system_check_moonraker() { ### python 3 check status_msg "Your Python 3 version is: $(python3 --version)" major=$(python3 --version | cut -d" " -f2 | cut -d"." -f1) @@ -14,7 +14,7 @@ system_check_moonraker(){ fi } -moonraker_setup_dialog(){ +moonraker_setup_dialog() { status_msg "Initializing Moonraker installation ..." ### checking system for python3.7+ @@ -52,36 +52,39 @@ moonraker_setup_dialog(){ ### instance confirmation dialog while true; do - echo - top_border - if [ $INSTANCE_COUNT -gt 1 ]; then - printf "|%-55s|\n" " $INSTANCE_COUNT Klipper instances were found!" - else - echo -e "| 1 Klipper instance was found! | " - fi - echo -e "| You need one Moonraker instance per Klipper instance. | " - bottom_border - echo - read -p "${cyan}###### Create $INSTANCE_COUNT Moonraker instances? (Y/n):${default} " yn - case "$yn" in - Y|y|Yes|yes|"") - echo -e "###### > Yes" - status_msg "Creating $INSTANCE_COUNT Moonraker instances ..." - moonraker_setup - break;; - N|n|No|no) - echo -e "###### > No" - warn_msg "Exiting Moonraker setup ..." - echo - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; + echo + top_border + if [ $INSTANCE_COUNT -gt 1 ]; then + printf "|%-55s|\n" " $INSTANCE_COUNT Klipper instances were found!" + else + echo -e "| 1 Klipper instance was found! | " + fi + echo -e "| You need one Moonraker instance per Klipper instance. | " + bottom_border + echo + read -p "${cyan}###### Create $INSTANCE_COUNT Moonraker instances? (Y/n):${default} " yn + case "$yn" in + Y | y | Yes | yes | "") + echo -e "###### > Yes" + status_msg "Creating $INSTANCE_COUNT Moonraker instances ..." + moonraker_setup + break + ;; + N | n | No | no) + echo -e "###### > No" + warn_msg "Exiting Moonraker setup ..." + echo + break + ;; + *) + print_unkown_cmd + print_msg && clear_msg + ;; esac done } -moonraker_setup(){ +moonraker_setup() { ### checking dependencies dep=(wget curl unzip dfu-util virtualenv) ### additional deps for kiauh compatibility for armbian @@ -112,10 +115,11 @@ moonraker_setup(){ print_msg && clear_msg ### display moonraker ips to the user - print_mr_ip_list; echo + print_mr_ip_list + echo } -install_moonraker_packages(){ +install_moonraker_packages() { ### read PKGLIST from official install script status_msg "Reading dependencies..." install_script="${HOME}/moonraker/scripts/install-moonraker.sh" @@ -134,13 +138,13 @@ install_moonraker_packages(){ sudo apt-get install --yes ${PKGARR[@]} } -create_moonraker_virtualenv(){ +create_moonraker_virtualenv() { status_msg "Installing python virtual environment..." ### If venv exists and user prompts a rebuild, then do so - if [ -d ${MOONRAKER_ENV} ] && [ $REBUILD_ENV = "y" ]; then + if [ -d "${MOONRAKER_ENV}" ] && [ $REBUILD_ENV = "y" ]; then status_msg "Removing old virtualenv" - rm -rf ${MOONRAKER_ENV} + rm -rf "${MOONRAKER_ENV}" fi if [ ! -d ${MOONRAKER_ENV} ]; then @@ -152,7 +156,7 @@ create_moonraker_virtualenv(){ ${MOONRAKER_ENV}/bin/pip install -r ${MOONRAKER_DIR}/scripts/moonraker-requirements.txt } -create_moonraker_service(){ +create_moonraker_service() { ### get config directory source_kiauh_ini @@ -166,16 +170,16 @@ create_moonraker_service(){ MR_SERV_SRC="${SRCDIR}/kiauh/resources/moonraker.service" MR_SERV_TARGET="$SYSTEMD_DIR/moonraker.service" - write_mr_service(){ + write_mr_service() { if [ ! -f $MR_SERV_TARGET ]; then status_msg "Creating Moonraker Service $i ..." - sudo cp $MR_SERV_SRC $MR_SERV_TARGET - sudo sed -i "s|%INST%|$i|" $MR_SERV_TARGET - sudo sed -i "s|%USER%|${USER}|" $MR_SERV_TARGET - sudo sed -i "s|%MR_ENV%|$MR_ENV|" $MR_SERV_TARGET - sudo sed -i "s|%MR_DIR%|$MR_DIR|" $MR_SERV_TARGET - sudo sed -i "s|%MR_LOG%|$MR_LOG|" $MR_SERV_TARGET - sudo sed -i "s|%MR_CONF%|$MR_CONF|" $MR_SERV_TARGET + sudo cp $MR_SERV_SRC $MR_SERV_TARGET + sudo sed -i "s|%INST%|$i|" $MR_SERV_TARGET + sudo sed -i "s|%USER%|${USER}|" $MR_SERV_TARGET + sudo sed -i "s|%MR_ENV%|$MR_ENV|" $MR_SERV_TARGET + sudo sed -i "s|%MR_DIR%|$MR_DIR|" $MR_SERV_TARGET + sudo sed -i "s|%MR_LOG%|$MR_LOG|" $MR_SERV_TARGET + sudo sed -i "s|%MR_CONF%|$MR_CONF|" $MR_SERV_TARGET fi } @@ -203,7 +207,7 @@ create_moonraker_service(){ ### launching instance do_action_service "start" "moonraker-$i" ### raise values by 1 - i=$((i+1)) + i=$((i + 1)) done unset i @@ -217,7 +221,7 @@ create_moonraker_service(){ fi } -create_moonraker_conf(){ +create_moonraker_conf() { ### get config directory source_kiauh_ini @@ -234,7 +238,7 @@ create_moonraker_conf(){ IP=$(hostname -I | cut -d" " -f1) LAN="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-2).0.0/16" - write_mr_conf(){ + write_mr_conf() { [ ! -d $CFG_PATH ] && mkdir -p $CFG_PATH if [ ! -f $MR_CONF ]; then status_msg "Creating moonraker.conf in $CFG_PATH ..." @@ -277,14 +281,14 @@ create_moonraker_conf(){ mr_ip_list+=("$IP:$PORT") ### raise values by 1 - PORT=$((PORT+1)) - i=$((i+1)) + PORT=$((PORT + 1)) + i=$((i + 1)) done unset PORT && unset i fi } -print_mr_ip_list(){ +print_mr_ip_list() { i=1 for ip in ${mr_ip_list[@]}; do echo -e " ${cyan}● Instance $i:${default} $ip" diff --git a/scripts/install_moonraker-telegram-bot.sh b/scripts/install_moonraker_telegram_bot.sh old mode 100644 new mode 100755 similarity index 93% rename from scripts/install_moonraker-telegram-bot.sh rename to scripts/install_moonraker_telegram_bot.sh index 13d3e02..501c062 --- a/scripts/install_moonraker-telegram-bot.sh +++ b/scripts/install_moonraker_telegram_bot.sh @@ -1,4 +1,6 @@ -install_MoonrakerTelegramBot(){ +#!/bin/bash + +install_moonraker_telegram_bot(){ source_kiauh_ini #MoonrakerTelegramBot main installation MoonrakerTelegramBot_setup diff --git a/scripts/install_octoprint.sh b/scripts/install_octoprint.sh index b485d08..e50a4a0 100755 --- a/scripts/install_octoprint.sh +++ b/scripts/install_octoprint.sh @@ -23,9 +23,9 @@ octoprint_setup(){ add_reboot_permission ### create and activate the virtualenv - [ ! -d $OCTOPRINT_ENV ] && mkdir -p $OCTOPRINT_ENV + [ ! -d $OCTOPRINT_DIR ] && mkdir -p $OCTOPRINT_DIR status_msg "Set up virtualenv ..." - cd $OCTOPRINT_ENV + cd $OCTOPRINT_DIR virtualenv --python=python3 venv source venv/bin/activate @@ -71,7 +71,7 @@ Environment="LC_ALL=C.UTF-8" Environment="LANG=C.UTF-8" Type=simple User=$USER -ExecStart=${OCTOPRINT_ENV}/venv/bin/octoprint --basedir ${BASEDIR} --config ${CONFIG_YAML} --port=${PORT} serve +ExecStart=${OCTOPRINT_DIR}/venv/bin/octoprint --basedir ${BASEDIR} --config ${CONFIG_YAML} --port=${PORT} serve [Install] WantedBy=multi-user.target @@ -91,7 +91,7 @@ Environment="LC_ALL=C.UTF-8" Environment="LANG=C.UTF-8" Type=simple User=$USER -ExecStart=${OCTOPRINT_ENV}/venv/bin/octoprint --basedir ${BASEDIR} --config ${CONFIG_YAML} --port=${PORT} serve +ExecStart=${OCTOPRINT_DIR}/venv/bin/octoprint --basedir ${BASEDIR} --config ${CONFIG_YAML} --port=${PORT} serve [Install] WantedBy=multi-user.target diff --git a/scripts/install_pgc_for_klipper.sh b/scripts/install_pgc_for_klipper.sh index 36982be..83272f6 100755 --- a/scripts/install_pgc_for_klipper.sh +++ b/scripts/install_pgc_for_klipper.sh @@ -1,3 +1,5 @@ +#!/bin/bash + ### base variables PGC_FOR_KLIPPER_REPO="https://github.com/Kragrathea/pgcode" PGC_DIR="${HOME}/pgcode" diff --git a/scripts/ms_theme_installer.sh b/scripts/ms_theme_installer.sh index 2a61cb3..119b4a6 100755 --- a/scripts/ms_theme_installer.sh +++ b/scripts/ms_theme_installer.sh @@ -1,4 +1,4 @@ -### base variables +#!/bin/bash get_theme_list(){ theme_csv_url="https://raw.githubusercontent.com/meteyou/mainsail/develop/docs/_data/themes.csv" @@ -20,47 +20,6 @@ get_theme_list(){ done <<< $theme_csv } -ms_theme_ui(){ - top_border - echo -e "| ${red}~~~~~~~~ [ Mainsail Theme Installer ] ~~~~~~~${default} | " - hr - echo -e "| ${green}A preview of each Mainsail theme can be found here:${default} | " - echo -e "| https://docs.mainsail.xyz/theming/themes | " - blank_line - echo -e "| ${yellow}Important note:${default} | " - echo -e "| Installing a theme from this menu will overwrite an | " - echo -e "| already installed theme or modified custom.css file! | " - hr - #echo -e "| Theme: | " - # dynamically generate the themelist from a csv file - get_theme_list - echo -e "| | " - echo -e "| R) [Remove Theme] | " - #echo -e "| | " - back_footer -} - -ms_theme_menu(){ - ms_theme_ui - while true; do - read -p "${cyan}Install theme:${default} " a; echo - if [ $a = "b" ] || [ $a = "B" ]; then - clear && advanced_menu && break - elif [ $a = "r" ] || [ $a = "R" ]; then - ms_theme_delete - ms_theme_menu - elif [ $a -le ${#t_url[@]} ]; then - ms_theme_install "${t_auth[$a]}" "${t_url[$a]}" "${t_name[$a]}" "${t_note[$a]}" - ms_theme_menu - else - clear && print_header - ERROR_MSG="Invalid command!" && print_msg && clear_msg - ms_theme_menu - fi - done - ms_theme_menu -} - check_select_printer(){ unset printer_num diff --git a/scripts/network_functions.sh b/scripts/network_functions.sh index 23fb554..18a841f 100755 --- a/scripts/network_functions.sh +++ b/scripts/network_functions.sh @@ -1,3 +1,5 @@ +#!/bin/bash + set_nginx_cfg(){ if [ "$SET_NGINX_CFG" = "true" ]; then #check for dependencies diff --git a/scripts/rollback.sh b/scripts/rollback.sh index a1f74e5..ae2dea2 100755 --- a/scripts/rollback.sh +++ b/scripts/rollback.sh @@ -20,7 +20,7 @@ save_klipper_state(){ load_klipper_state(){ source_kiauh_ini - print_branch + get_branch cd $KLIPPER_DIR CURRENT_COMMIT=$(git rev-parse --short=8 HEAD) if [ "$GET_BRANCH" = "origin/master" ] || [ "$GET_BRANCH" = "master" ]; then diff --git a/scripts/status.sh b/scripts/status.sh index bbcffb1..4757786 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -230,7 +230,7 @@ klipperscreen_status(){ fi } -MoonrakerTelegramBot_status(){ +update_moonraker_telegram_bot_status(){ mtbcount=0 MoonrakerTelegramBot_data=( SERVICE @@ -290,7 +290,7 @@ read_branch(){ } #prints the current klipper branch in the main menu -print_branch(){ +get_branch(){ read_branch if [ ! -z "$GET_BRANCH" ]; then PRINT_BRANCH="$(printf "%-16s" "$GET_BRANCH")" diff --git a/scripts/switch_branch.sh b/scripts/switch_branch.sh index 212c436..4a7e3b3 100755 --- a/scripts/switch_branch.sh +++ b/scripts/switch_branch.sh @@ -1,3 +1,5 @@ +#!/bin/bash + switch_to_master(){ cd $KLIPPER_DIR status_msg "Switching...Please wait ..."; echo diff --git a/scripts/ui/advanced_menu.sh b/scripts/ui/advanced_menu.sh index 5453386..4b5f209 100755 --- a/scripts/ui/advanced_menu.sh +++ b/scripts/ui/advanced_menu.sh @@ -1,140 +1,63 @@ -advanced_ui(){ - top_border - echo -e "| ${yellow}~~~~~~~~~~~~~ [ Advanced Menu ] ~~~~~~~~~~~~~${default} | " - hr - if [ ! "$OPRINT_SERVICE_STATUS" == "" ]; then - echo -e "| 0) $OPRINT_SERVICE_STATUS| " - hr - echo -e "| | | " - fi - echo -e "| Klipper: | Mainsail: | " - echo -e "| 1) [Switch Branch] | 7) [Theme installer] | " - echo -e "| 2) [Rollback] | | " - echo -e "| | System: | " - echo -e "| Firmware: | 8) [Change hostname] | " - echo -e "| 3) [Build only] | | " - echo -e "| 4) [Flash only] | Extensions: | " - echo -e "| 5) [Build + Flash] | 9) [Shell Command] | " - echo -e "| 6) [Get MCU ID] | | " - echo -e "| | CustomPiOS: | " - echo -e "| | 10) [Migration Helper] | " -back_footer -} +#!/bin/bash advanced_menu(){ - read_octoprint_service_status - do_action "" "advanced_ui" + + local menu_options=( + "1" " " + "2" "Switch Klipper Branch" + "3" "Rollback Klipper" + "4" "Build Firmware" + "5" "Flash Firmware" + "6" "Build and Flash Firmware" + "7" "Get MCU ID" + "8" "Install Mainsail Theme" + "9" "Change System Hostname" + "10" "Run Shell Command" + "11" "CustomPiOS Migration Helper" + ) + while true; do - read -p "${cyan}Perform action:${default} " action; echo - case "$action" in - 0) - clear - print_header - toggle_octoprint_service - read_octoprint_service_status - print_msg && clear_msg - advanced_ui;; - 1) - do_action "switch_menu";; - 2) - do_action "load_klipper_state" "advanced_ui";; - 3) - do_action "build_fw" "advanced_ui";; - 4) - do_action "select_flash_method" "advanced_ui";; - 5) - clear && print_header - status_msg "Please wait..." - build_fw - select_flash_method - print_msg && clear_msg - advanced_ui;; - 6) - do_action "select_mcu_connection" "advanced_ui";; - 7) - do_action "ms_theme_menu";; - 8) - clear - print_header - create_custom_hostname && set_hostname - print_msg && clear_msg - advanced_ui;; - 9) - do_action "setup_gcode_shell_command" "advanced_ui";; - 10) - do_action "migration_menu";; - B|b) - clear; main_menu; break;; - *) - deny_action "advanced_ui";; - esac - done - advanced_menu -} + read_octoprint_service_status + menu_options[2]="Current OctoPrint Status: $OPRINT_SERVICE_STATUS" -############################################################# -############################################################# + if [ ! "$OPRINT_SERVICE_STATUS" == "" ]; then + local menu + menu=$(whiptail --title "Advanced Menu" --cancel-button "Back" --notags --menu "Perform Action:"\ + "$KIAUH_WHIPTAIL_NORMAL_HEIGHT" "$KIAUH_WHIPTAIL_NORMAL_WIDTH" 8 "${menu_options[@]}" 3>&1 1>&2 2>&3) + else + local menu + menu=$(whiptail --title "Advanced Menu" --cancel-button "Back" --notags --menu "Perform Action:"\ + "$KIAUH_WHIPTAIL_NORMAL_HEIGHT" "$KIAUH_WHIPTAIL_NORMAL_WIDTH" 8 "${menu_options[@]:2}" 3>&1 1>&2 2>&3) + fi -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 "| | " - echo -e "| KevinOConnor: | " - echo -e "| 1) [--> master] | " - echo -e "| | " - echo -e "| dmbutyugin: | " - echo -e "| 2) [--> scurve-shaping] | " - echo -e "| 3) [--> scurve-smoothing] | " - back_footer -} - -switch_menu(){ - if [ -d $KLIPPER_DIR ]; then - read_branch - do_action "" "switch_ui" - while true; do - read -p "${cyan}Perform action:${default} " action; echo - case "$action" in - 1) - clear - print_header - switch_to_master - 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;; - B|b) - clear; advanced_menu; break;; - *) - deny_action "switch_ui";; - esac - done - else - ERROR_MSG="No Klipper directory found! Download Klipper first!" - fi + local out=$? + if [ $out -eq 1 ]; then + break + elif [ $out -eq 0 ]; then + case "$menu" in + 1) clear + print_header + toggle_octoprint_service + read_octoprint_service_status + print_msg && clear_msg;; + 2) do_action "switch_menu" ;; + 3) do_action "load_klipper_state";; + 4) do_action "build_fw" ;; + 5) do_action "select_flash_method" ;; + 6) clear && print_header + status_msg "Please wait..." + build_fw + select_flash_method + print_msg && clear_msg;; + 7) do_action "select_mcu_connection" ;; + 8) do_action "select_flash_method" ;; + 9) do_action "ms_theme_menu";; + 10) do_action "setup_gcode_shell_command" ;; + 11) migration_menu;; + esac + else + # Unexpected event, no clue what happened + exit 1 + fi + done } diff --git a/scripts/ui/kiauh_update_yesno.sh b/scripts/ui/kiauh_update_yesno.sh old mode 100644 new mode 100755 index c74c9bf..8c49bde --- a/scripts/ui/kiauh_update_yesno.sh +++ b/scripts/ui/kiauh_update_yesno.sh @@ -1,3 +1,4 @@ +#!/bin/bash ####################################### # description Advise user to update KIAUH # Globals: diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh index e8a1f0d..ad4aaa8 100755 --- a/scripts/ui/main_menu.sh +++ b/scripts/ui/main_menu.sh @@ -3,22 +3,25 @@ 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") + "1" "Install" + "2" "Update" + "3" "Remove" + "4" "Advanced Settings" + "5" "Backup" + "6" "Settings" + "7" "Upload Log" + "8" "Service" + ) + # Ask for update only once if [ "$KIAUH_UPDATE_AVAIL" = "true" ]; then - kiauh_update_dialog + kiauh_update_yesno fi while true; do #check install status - print_kiauh_version + #TODO it is install status, introduce a "service status" for service menu is probably a good idea, refactor required + check_kiauh_version klipper_status moonraker_status dwc2_status @@ -26,8 +29,8 @@ main_menu() { mainsail_status octoprint_status klipperscreen_status - MoonrakerTelegramBot_status - print_branch + update_moonraker_telegram_bot_status + get_branch print_msg && clear_msg local menu_str="Klipper: $KLIPPER_STATUS Branch: $PRINT_BRANCH\n @@ -35,6 +38,7 @@ 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 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_options[@]}" 3>&1 1>&2 2>&3) diff --git a/scripts/ui/remove_menu.sh b/scripts/ui/remove_menu.sh index 0d5c4d2..d206d76 100755 --- a/scripts/ui/remove_menu.sh +++ b/scripts/ui/remove_menu.sh @@ -1,26 +1,4 @@ #!/bin/bash -remove_ui(){ - top_border - echo -e "| ${red}~~~~~~~~~~~~~~ [ Remove Menu ] ~~~~~~~~~~~~~~${default} | " - hr - echo -e "| Directories which remain untouched: | " - echo -e "| --> Your printer configuration directory | " - echo -e "| --> ~/kiauh-backups | " - echo -e "| You need remove them manually if you wish so. | " - hr - echo -e "| Firmware: | Touchscreen GUI: | " - echo -e "| 1) [Klipper] | 5) [KlipperScreen] | " - echo -e "| | | " - echo -e "| Klipper API: | Other: | " - echo -e "| 2) [Moonraker] | 6) [Duet Web Control] | " - echo -e "| | 7) [OctoPrint] | " - echo -e "| Klipper Webinterface: | 8) [PrettyGCode] | " - echo -e "| 3) [Mainsail] | 9) [Telegram Bot] | " - echo -e "| 4) [Fluidd] | | " - echo -e "| | 10) [MJPG-Streamer] | " - echo -e "| | 11) [NGINX] | " - back_footer -} remove_menu(){ #TODO Currently it's a "dumb" remove page, looking for a "smart" one diff --git a/scripts/ui/settings_menu.sh b/scripts/ui/settings_menu.sh index 0537941..133bf78 100755 --- a/scripts/ui/settings_menu.sh +++ b/scripts/ui/settings_menu.sh @@ -1,3 +1,5 @@ +#!/bin/bash + settings_ui(){ source_kiauh_ini top_border diff --git a/scripts/ui/switch_menu.sh b/scripts/ui/switch_menu.sh new file mode 100755 index 0000000..453759b --- /dev/null +++ b/scripts/ui/switch_menu.sh @@ -0,0 +1,96 @@ +#!/bin/bash + +switch_ui(){ + SWITCH_MENU_STR="Active Branch: $GET_BRANCH" + SWITCH_MENU=$(whiptail --title "Switch Klipper Branch" --cancel-button "Back" --menu "$SWITCH_MENU_STR\n\nSelect a Branch Owner:"\ + "$KIAUH_WHIPTAIL_NORMAL_HEIGHT" "$KIAUH_WHIPTAIL_NORMAL_WIDTH" 8\ + "1 Klipper3D" "Official Klipper3D"\ + "2 dmbutyugin" "dmbutyugin S-Curve Acceleration"\ + "3 Custom" "Pick a custom branch" 3>&1 1>&2 2>&3) + + OUT=$SWITCH_MENU + case "$OUT" in + 1\ *) Something;; + 2\ *) install_menu ;; + 3\ *) echo "Custom Branch" ;; + esac + + KILPPER3D_MENU_STR="Active Branch: $GET_BRANCH" + KILPPER3D_MENU=$(whiptail --title "Switch Klipper Branch" --cancel-button "Back" --menu "$KILPPER3D_MENU_STR\n\nSelect a Branch:"\ + "$KIAUH_WHIPTAIL_NORMAL_HEIGHT" "$KIAUH_WHIPTAIL_NORMAL_WIDTH" 8\ + "1 master" "Official Klipper with rolling update") + + OUT=$KILPPER3D_MENU + case "$OUT" in + 1\ *) Something;; + esac + + DMBUTYUGIN_MENU_STR="Active Branch: $GET_BRANCH" + DMBUTYUGIN_MENU=$(whiptail --title "Switch Klipper Branch" --cancel-button "Back" --menu "$DMBUTYUGIN_MENU\n\nSelect a Branch:"\ + "$KIAUH_WHIPTAIL_NORMAL_HEIGHT" "$KIAUH_WHIPTAIL_NORMAL_WIDTH" 8\ + "1 scurve-shaping" "Official Klipper with rolling update"\ + "2 scurve-smoothing" "Pick a custom branch/tag" 3>&1 1>&2 2>&3) + + OUT=$DMBUTYUGIN_MENU + case "$OUT" in + 1\ *) Something;; + 2\ *) install_menu ;; + esac + + + CUSTOM_BRANCH_MENU_MENU=$(whiptail --title "Switch Klipper Branch" --cancel-button "Back" --inputbox "Paste the link of a Klipper Git repository:"\ + "$KIAUH_WHIPTAIL_NORMAL_HEIGHT" "$KIAUH_WHIPTAIL_NORMAL_WIDTH" "github.com/Klipper3d/klipper" 3>&1 1>&2 2>&3) + + OUT=$CUSTOM_BRANCH_MENU_MENU + case "$OUT" in + 1\ *) Something;; + 2\ *) install_menu ;; + esac +} +# TODO Automatically list the available branches of an account or allow type in custom + +switch_menu(){ + if [ -d $KLIPPER_DIR ]; then + read_branch + do_action "" "switch_ui" + while true; do + read -p "${cyan}Perform action:${default} " action; echo + case "$action" in + 1) + clear + print_header + switch_to_master + 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;; + B|b) + clear; advanced_menu; break;; + *) + deny_action "switch_ui";; + esac + done + else + ERROR_MSG="No Klipper directory found! Download Klipper first!" + fi +} diff --git a/scripts/ui/theme_menu.sh b/scripts/ui/theme_menu.sh new file mode 100755 index 0000000..9c84de3 --- /dev/null +++ b/scripts/ui/theme_menu.sh @@ -0,0 +1,69 @@ +#!/bin/bash + +ms_theme_ui(){ + top_border + echo -e "| ${red}~~~~~~~~ [ Mainsail Theme Installer ] ~~~~~~~${default} | " + hr + echo -e "| ${green}A preview of each Mainsail theme can be found here:${default} | " + echo -e "| https://docs.mainsail.xyz/theming/themes | " + blank_line + echo -e "| ${yellow}Important note:${default} | " + echo -e "| Installing a theme from this menu will overwrite an | " + echo -e "| already installed theme or modified custom.css file! | " + hr + #echo -e "| Theme: | " + # dynamically generate the themelist from a csv file + get_theme_list + echo -e "| | " + echo -e "| R) [Remove Theme] | " + #echo -e "| | " + back_footer +} + +ms_theme_menu(){ + + local menu_options=( + "1" "Migrate MainsailOS" + "2" "Migrate FluiddPi" + ) + local menu_str="This function will help you to migrate a vanilla MainsailOS or FluiddPi image to a newer state. +Only use this function if you use MainsailOS 0.4.0 or lower, or FluiddPi v1.13.0 or lower. +Please have a look at the KIAUH changelog for more details on what this function will do." + + while true; do + local menu + menu=$(whiptail --title "Mainsail Theme Installer" --cancel-button "Back" --notags --menu "$menu_str\n\nInstall/Remove Theme:" \ + "$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 + elif [ $out -eq 0 ]; then + case "$menu" in + 1) migrate_custompios "mainsail";; + 2) migrate_custompios "fluiddpi";; + esac + else + # Unexpected event, no clue what happened + exit 1 + fi + done + + ms_theme_ui + while true; do + read -p "${cyan}Install theme:${default} " a; echo + if [ $a = "b" ] || [ $a = "B" ]; then + clear && advanced_menu && break + elif [ $a = "r" ] || [ $a = "R" ]; then + ms_theme_delete + ms_theme_menu + elif [ $a -le ${#t_url[@]} ]; then + ms_theme_install "${t_auth[$a]}" "${t_url[$a]}" "${t_name[$a]}" "${t_note[$a]}" + ms_theme_menu + else + clear && print_header + ERROR_MSG="Invalid command!" && print_msg && clear_msg + ms_theme_menu + fi + done + ms_theme_menu +} \ No newline at end of file diff --git a/scripts/ui/update_menu.sh b/scripts/ui/update_menu.sh index 0d23c74..eca7615 100755 --- a/scripts/ui/update_menu.sh +++ b/scripts/ui/update_menu.sh @@ -1,4 +1,7 @@ +#!/bin/bash + update_ui(){ + # TODO Try to match the width so we can use the menu text to show local and remote version ui_print_versions top_border echo -e "| ${green}~~~~~~~~~~~~~~ [ Update Menu ] ~~~~~~~~~~~~~~${default} | " diff --git a/scripts/ui/upload_yesno.sh b/scripts/ui/upload_yesno.sh old mode 100644 new mode 100755 diff --git a/scripts/update.sh b/scripts/update.sh index 3222912..20ef474 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -1,3 +1,5 @@ +#!/bin/bash + update_kiauh(){ if [ "$KIAUH_UPDATE_AVAIL" = "true" ]; then status_msg "Updating KIAUH ..." diff --git a/scripts/upload_log.sh b/scripts/upload_log.sh index b7e7230..56107b1 100755 --- a/scripts/upload_log.sh +++ b/scripts/upload_log.sh @@ -2,6 +2,7 @@ upload_selection(){ source_kiauh_ini + # TODO Whiptail probably changed logic here [ "$logupload_accepted" = "false" ] && upload_yesno ### find all suitable logfiles for klipper -- 2.39.5