From 7c39d7d91fb6f6f1226bac1b9225018fe1153d6d Mon Sep 17 00:00:00 2001 From: Yifei Ding Date: Mon, 8 Nov 2021 16:38:39 -0800 Subject: [PATCH 01/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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/26] 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