script: whiptail Octoprint dialog

This commit is contained in:
Yifei Ding
2021-11-13 12:56:26 -08:00
parent 68bedd7218
commit 9915f00ceb
2 changed files with 31 additions and 43 deletions

View File

@@ -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=(

View File

@@ -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
}