From 9915f00ceb91e3aa190e48d24b0d2f22f63f1c01 Mon Sep 17 00:00:00 2001 From: Yifei Ding Date: Sat, 13 Nov 2021 12:56:26 -0800 Subject: [PATCH] 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 +}