mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-24 16:23:36 +05:00
Compare commits
4 Commits
dc87d30770
...
e50ce1fc71
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e50ce1fc71 | ||
|
|
417180f724 | ||
|
|
f2691f33d3 | ||
|
|
39f0bd8b0a |
@@ -154,18 +154,20 @@ prompt and confirm by hitting ENTER.
|
||||
<tr>
|
||||
<th><h3><a href="https://github.com/Clon1998/mobileraker_companion">Mobileraker's Companion</a></h3></th>
|
||||
<th><h3><a href="https://octoeverywhere.com/?source=kiauh_readme">OctoEverywhere For Klipper</a></h3></th>
|
||||
<th><h3><a href="https://github.com/crysxd/OctoPrint-OctoApp">OctoApp For Klipper</a></h3></th>
|
||||
<th><h3></h3></th>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th><a href="https://github.com/Clon1998/mobileraker_companion"><img src="https://raw.githubusercontent.com/Clon1998/mobileraker/master/assets/icon/mr_appicon.png" alt="OctoEverywhere Logo" height="64"></a></th>
|
||||
<th><a href="https://octoeverywhere.com/?source=kiauh_readme"><img src="https://octoeverywhere.com/img/logo.svg" alt="OctoEverywhere Logo" height="64"></a></th>
|
||||
<th></th>
|
||||
<th><a href="https://octoapp.eu/?source=kiauh_readme"><img src="https://octoapp.eu/octoapp.webp" alt="OctoApp Logo" height="64"></a></th>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th>by <a href="https://github.com/Clon1998">Patrick Schmidt</a></th>
|
||||
<th>by <a href="https://github.com/QuinnDamerell">Quinn Damerell</a></th>
|
||||
<th>by <a href="https://github.com/crysxd">Christian Würthner</a></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
|
||||
|
||||
@@ -10,26 +10,27 @@
|
||||
import textwrap
|
||||
|
||||
from components.klipper import klipper_remove
|
||||
from core.menus import BACK_HELP_FOOTER
|
||||
from core.menus import FooterType
|
||||
from core.menus.base_menu import BaseMenu
|
||||
from utils.constants import RESET_FORMAT, COLOR_RED, COLOR_CYAN
|
||||
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
class KlipperRemoveMenu(BaseMenu):
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
header=False,
|
||||
options={
|
||||
"0": self.toggle_all,
|
||||
"1": self.toggle_remove_klipper_service,
|
||||
"2": self.toggle_remove_klipper_dir,
|
||||
"3": self.toggle_remove_klipper_env,
|
||||
"4": self.toggle_delete_klipper_logs,
|
||||
"c": self.run_removal_process,
|
||||
},
|
||||
footer_type=BACK_HELP_FOOTER,
|
||||
)
|
||||
def __init__(self, previous_menu: BaseMenu):
|
||||
super().__init__()
|
||||
|
||||
self.previous_menu: BaseMenu = previous_menu
|
||||
self.options = {
|
||||
"0": self.toggle_all,
|
||||
"1": self.toggle_remove_klipper_service,
|
||||
"2": self.toggle_remove_klipper_dir,
|
||||
"3": self.toggle_remove_klipper_env,
|
||||
"4": self.toggle_delete_klipper_logs,
|
||||
"c": self.run_removal_process,
|
||||
}
|
||||
self.footer_type = FooterType.BACK_HELP
|
||||
|
||||
self.remove_klipper_service = False
|
||||
self.remove_klipper_dir = False
|
||||
self.remove_klipper_env = False
|
||||
|
||||
@@ -21,7 +21,7 @@ from components.klipper_firmware.flash_utils import (
|
||||
find_usb_dfu_device,
|
||||
flash_device,
|
||||
)
|
||||
from core.menus import BACK_HELP_FOOTER, BACK_FOOTER
|
||||
from core.menus import FooterType
|
||||
|
||||
from core.menus.base_menu import BaseMenu
|
||||
from utils.constants import COLOR_CYAN, RESET_FORMAT, COLOR_YELLOW, COLOR_RED
|
||||
@@ -32,18 +32,19 @@ from utils.logger import Logger
|
||||
# noinspection PyUnusedLocal
|
||||
# noinspection PyMethodMayBeStatic
|
||||
class KlipperFlashMethodMenu(BaseMenu):
|
||||
def __init__(self):
|
||||
def __init__(self, previous_menu: BaseMenu):
|
||||
super().__init__()
|
||||
|
||||
self.previous_menu: BaseMenu = previous_menu
|
||||
self.options = {
|
||||
"1": self.select_regular,
|
||||
"2": self.select_sdcard,
|
||||
"h": lambda: KlipperFlashMethodHelpMenu(self).run(),
|
||||
}
|
||||
self.input_label_txt = "Select flash method"
|
||||
self.footer_type = FooterType.BACK_HELP
|
||||
|
||||
self.flash_options = FlashOptions()
|
||||
super().__init__(
|
||||
header=False,
|
||||
options={
|
||||
"1": self.select_regular,
|
||||
"2": self.select_sdcard,
|
||||
"h": KlipperFlashMethodHelpMenu,
|
||||
},
|
||||
input_label_txt="Select flash method",
|
||||
footer_type=BACK_HELP_FOOTER,
|
||||
)
|
||||
|
||||
def print_menu(self) -> None:
|
||||
header = " [ Flash MCU ] "
|
||||
@@ -75,27 +76,26 @@ class KlipperFlashMethodMenu(BaseMenu):
|
||||
self.goto_next_menu()
|
||||
|
||||
def goto_next_menu(self, **kwargs):
|
||||
next_menu = KlipperFlashCommandMenu(previous_menu=self)
|
||||
next_menu.start()
|
||||
KlipperFlashCommandMenu(previous_menu=self).run()
|
||||
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
# noinspection PyMethodMayBeStatic
|
||||
class KlipperFlashCommandMenu(BaseMenu):
|
||||
def __init__(self, previous_menu: BaseMenu):
|
||||
super().__init__()
|
||||
|
||||
self.previous_menu: BaseMenu = previous_menu
|
||||
self.options = {
|
||||
"1": self.select_flash,
|
||||
"2": self.select_serialflash,
|
||||
"h": lambda: KlipperFlashCommandHelpMenu(previous_menu=self).run(),
|
||||
}
|
||||
self.default_option = self.select_flash
|
||||
self.input_label_txt = "Select flash command"
|
||||
self.footer_type = FooterType.BACK_HELP
|
||||
|
||||
self.flash_options = FlashOptions()
|
||||
super().__init__(
|
||||
header=False,
|
||||
options={
|
||||
"1": self.select_flash,
|
||||
"2": self.select_serialflash,
|
||||
"h": KlipperFlashCommandHelpMenu,
|
||||
},
|
||||
default_option="1",
|
||||
input_label_txt="Select flash command",
|
||||
previous_menu=previous_menu,
|
||||
footer_type=BACK_HELP_FOOTER,
|
||||
)
|
||||
|
||||
def print_menu(self) -> None:
|
||||
menu = textwrap.dedent(
|
||||
@@ -119,27 +119,26 @@ class KlipperFlashCommandMenu(BaseMenu):
|
||||
self.goto_next_menu()
|
||||
|
||||
def goto_next_menu(self, **kwargs):
|
||||
next_menu = KlipperSelectMcuConnectionMenu(previous_menu=self)
|
||||
next_menu.start()
|
||||
KlipperSelectMcuConnectionMenu(previous_menu=self).run()
|
||||
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
# noinspection PyMethodMayBeStatic
|
||||
class KlipperSelectMcuConnectionMenu(BaseMenu):
|
||||
def __init__(self, previous_menu: BaseMenu):
|
||||
super().__init__()
|
||||
|
||||
self.previous_menu: BaseMenu = previous_menu
|
||||
self.options = {
|
||||
"1": self.select_usb,
|
||||
"2": self.select_dfu,
|
||||
"3": self.select_usb_dfu,
|
||||
"h": lambda: KlipperMcuConnectionHelpMenu(previous_menu=self).run(),
|
||||
}
|
||||
self.input_label_txt = "Select connection type"
|
||||
self.footer_type = FooterType.BACK_HELP
|
||||
|
||||
self.flash_options = FlashOptions()
|
||||
super().__init__(
|
||||
header=False,
|
||||
options={
|
||||
"1": self.select_usb,
|
||||
"2": self.select_dfu,
|
||||
"3": self.select_usb_dfu,
|
||||
"h": KlipperMcuConnectionHelpMenu,
|
||||
},
|
||||
input_label_txt="Select connection type",
|
||||
previous_menu=previous_menu,
|
||||
footer_type=BACK_HELP_FOOTER,
|
||||
)
|
||||
|
||||
def print_menu(self) -> None:
|
||||
header = "Make sure that the controller board is connected now!"
|
||||
@@ -185,6 +184,8 @@ class KlipperSelectMcuConnectionMenu(BaseMenu):
|
||||
Logger.print_status("Identifying MCU connected via USB in DFU mode ...")
|
||||
self.flash_options.mcu_list = find_usb_dfu_device()
|
||||
|
||||
print(self.flash_options.mcu_list)
|
||||
|
||||
if len(self.flash_options.mcu_list) < 1:
|
||||
Logger.print_warn("No MCUs found!")
|
||||
Logger.print_warn("Make sure they are connected and repeat this step.")
|
||||
@@ -192,24 +193,23 @@ class KlipperSelectMcuConnectionMenu(BaseMenu):
|
||||
self.goto_next_menu()
|
||||
|
||||
def goto_next_menu(self, **kwargs):
|
||||
next_menu = KlipperSelectMcuIdMenu(previous_menu=self)
|
||||
next_menu.start()
|
||||
KlipperSelectMcuIdMenu(previous_menu=self).run()
|
||||
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
# noinspection PyMethodMayBeStatic
|
||||
class KlipperSelectMcuIdMenu(BaseMenu):
|
||||
def __init__(self, previous_menu: BaseMenu):
|
||||
super().__init__()
|
||||
|
||||
self.previous_menu: BaseMenu = previous_menu
|
||||
self.flash_options = FlashOptions()
|
||||
self.mcu_list = self.flash_options.mcu_list
|
||||
print(self.mcu_list)
|
||||
options = {f"{index}": self.flash_mcu for index in range(len(self.mcu_list))}
|
||||
super().__init__(
|
||||
header=False,
|
||||
options=options,
|
||||
input_label_txt="Select MCU to flash",
|
||||
previous_menu=previous_menu,
|
||||
footer_type=BACK_FOOTER,
|
||||
)
|
||||
self.options = options
|
||||
self.input_label_txt = "Select MCU to flash"
|
||||
self.footer_type = FooterType.BACK_HELP
|
||||
|
||||
def print_menu(self) -> None:
|
||||
header = "!!! ATTENTION !!!"
|
||||
@@ -250,23 +250,17 @@ class KlipperSelectMcuIdMenu(BaseMenu):
|
||||
self.goto_next_menu()
|
||||
|
||||
def goto_next_menu(self, **kwargs):
|
||||
pass
|
||||
# TODO: navigate back to advanced menu after flashing
|
||||
from core.menus.main_menu import MainMenu
|
||||
from core.menus.advanced_menu import AdvancedMenu
|
||||
|
||||
# from core.menus.main_menu import MainMenu
|
||||
# from core.menus.advanced_menu import AdvancedMenu
|
||||
#
|
||||
# next_menu = AdvancedMenu()
|
||||
# next_menu.start()
|
||||
AdvancedMenu(previous_menu=MainMenu()).run()
|
||||
|
||||
|
||||
class KlipperFlashMethodHelpMenu(BaseMenu):
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
header=False,
|
||||
options={},
|
||||
footer_type=BACK_FOOTER,
|
||||
)
|
||||
def __init__(self, previous_menu: BaseMenu):
|
||||
super().__init__()
|
||||
|
||||
self.previous_menu: BaseMenu = previous_menu
|
||||
|
||||
def print_menu(self) -> None:
|
||||
header = " < ? > Help: Flash MCU < ? > "
|
||||
@@ -308,12 +302,10 @@ class KlipperFlashMethodHelpMenu(BaseMenu):
|
||||
|
||||
|
||||
class KlipperFlashCommandHelpMenu(BaseMenu):
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
header=False,
|
||||
options={},
|
||||
footer_type=BACK_FOOTER,
|
||||
)
|
||||
def __init__(self, previous_menu: BaseMenu):
|
||||
super().__init__()
|
||||
|
||||
self.previous_menu: BaseMenu = previous_menu
|
||||
|
||||
def print_menu(self) -> None:
|
||||
header = " < ? > Help: Flash MCU < ? > "
|
||||
@@ -342,12 +334,10 @@ class KlipperFlashCommandHelpMenu(BaseMenu):
|
||||
|
||||
|
||||
class KlipperMcuConnectionHelpMenu(BaseMenu):
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
header=False,
|
||||
options={},
|
||||
footer_type=BACK_FOOTER,
|
||||
)
|
||||
def __init__(self, previous_menu: BaseMenu):
|
||||
super().__init__()
|
||||
|
||||
self.previous_menu: BaseMenu = previous_menu
|
||||
|
||||
def print_menu(self) -> None:
|
||||
header = " < ? > Help: Flash MCU < ? > "
|
||||
|
||||
@@ -11,21 +11,19 @@ import textwrap
|
||||
|
||||
from components.log_uploads.log_upload_utils import get_logfile_list
|
||||
from components.log_uploads.log_upload_utils import upload_logfile
|
||||
from core.menus import BACK_FOOTER
|
||||
from core.menus.base_menu import BaseMenu
|
||||
from utils.constants import RESET_FORMAT, COLOR_YELLOW
|
||||
|
||||
|
||||
# noinspection PyMethodMayBeStatic
|
||||
class LogUploadMenu(BaseMenu):
|
||||
def __init__(self):
|
||||
def __init__(self, previous_menu: BaseMenu):
|
||||
super().__init__()
|
||||
|
||||
self.previous_menu: BaseMenu = previous_menu
|
||||
self.logfile_list = get_logfile_list()
|
||||
options = {f"{index}": self.upload for index in range(len(self.logfile_list))}
|
||||
super().__init__(
|
||||
header=True,
|
||||
options=options,
|
||||
footer_type=BACK_FOOTER,
|
||||
)
|
||||
self.options = options
|
||||
|
||||
def print_menu(self):
|
||||
header = " [ Log Upload ] "
|
||||
|
||||
@@ -10,27 +10,26 @@
|
||||
import textwrap
|
||||
|
||||
from components.moonraker import moonraker_remove
|
||||
from core.menus import BACK_HELP_FOOTER
|
||||
from core.menus.base_menu import BaseMenu
|
||||
from utils.constants import RESET_FORMAT, COLOR_RED, COLOR_CYAN
|
||||
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
class MoonrakerRemoveMenu(BaseMenu):
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
header=False,
|
||||
options={
|
||||
"0": self.toggle_all,
|
||||
"1": self.toggle_remove_moonraker_service,
|
||||
"2": self.toggle_remove_moonraker_dir,
|
||||
"3": self.toggle_remove_moonraker_env,
|
||||
"4": self.toggle_remove_moonraker_polkit,
|
||||
"5": self.toggle_delete_moonraker_logs,
|
||||
"c": self.run_removal_process,
|
||||
},
|
||||
footer_type=BACK_HELP_FOOTER,
|
||||
)
|
||||
def __init__(self, previous_menu: BaseMenu):
|
||||
super().__init__()
|
||||
|
||||
self.previous_menu: BaseMenu = previous_menu
|
||||
self.options = {
|
||||
"0": self.toggle_all,
|
||||
"1": self.toggle_remove_moonraker_service,
|
||||
"2": self.toggle_remove_moonraker_dir,
|
||||
"3": self.toggle_remove_moonraker_env,
|
||||
"4": self.toggle_remove_moonraker_polkit,
|
||||
"5": self.toggle_delete_moonraker_logs,
|
||||
"c": self.run_removal_process,
|
||||
}
|
||||
|
||||
self.remove_moonraker_service = False
|
||||
self.remove_moonraker_dir = False
|
||||
self.remove_moonraker_env = False
|
||||
|
||||
@@ -11,33 +11,30 @@ import textwrap
|
||||
from typing import Callable, Dict
|
||||
|
||||
from components.webui_client import client_remove, ClientData
|
||||
from core.menus import BACK_HELP_FOOTER
|
||||
from core.menus.base_menu import BaseMenu
|
||||
from utils.constants import RESET_FORMAT, COLOR_RED, COLOR_CYAN
|
||||
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
class ClientRemoveMenu(BaseMenu):
|
||||
def __init__(self, client: ClientData):
|
||||
def __init__(self, previous_menu: BaseMenu, client: ClientData):
|
||||
super().__init__()
|
||||
self.previous_menu = previous_menu
|
||||
self.options = self.get_options(client)
|
||||
|
||||
self.client = client
|
||||
self.rm_client = False
|
||||
self.rm_client_config = False
|
||||
self.backup_mainsail_config_json = False
|
||||
|
||||
super().__init__(
|
||||
header=False,
|
||||
options=self.get_options(),
|
||||
footer_type=BACK_HELP_FOOTER,
|
||||
)
|
||||
|
||||
def get_options(self) -> Dict[str, Callable]:
|
||||
def get_options(self, client: ClientData) -> Dict[str, Callable]:
|
||||
options = {
|
||||
"0": self.toggle_all,
|
||||
"1": self.toggle_rm_client,
|
||||
"2": self.toggle_rm_client_config,
|
||||
"c": self.run_removal_process,
|
||||
}
|
||||
if self.client.get("name") == "mainsail":
|
||||
if client.get("name") == "mainsail":
|
||||
options["3"] = self.toggle_backup_mainsail_config_json
|
||||
|
||||
return options
|
||||
|
||||
@@ -7,6 +7,25 @@
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
# ======================================================================= #
|
||||
|
||||
QUIT_FOOTER = "quit"
|
||||
BACK_FOOTER = "back"
|
||||
BACK_HELP_FOOTER = "back_help"
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class FooterType(Enum):
|
||||
QUIT = "QUIT"
|
||||
BACK = "BACK"
|
||||
BACK_HELP = "BACK_HELP"
|
||||
|
||||
|
||||
NAVI_OPTIONS = {
|
||||
FooterType.QUIT: ["q"],
|
||||
FooterType.BACK: ["b"],
|
||||
FooterType.BACK_HELP: ["b", "h"],
|
||||
}
|
||||
|
||||
|
||||
class ExitAppException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class GoBackException(Exception):
|
||||
pass
|
||||
|
||||
@@ -9,26 +9,27 @@
|
||||
|
||||
import textwrap
|
||||
|
||||
from components.klipper_firmware.menus.klipper_flash_menu import KlipperFlashMethodMenu
|
||||
from core.menus import BACK_FOOTER
|
||||
from components.klipper_firmware.menus.klipper_flash_menu import (
|
||||
KlipperFlashMethodMenu,
|
||||
KlipperSelectMcuConnectionMenu,
|
||||
)
|
||||
from core.menus.base_menu import BaseMenu
|
||||
from utils.constants import COLOR_YELLOW, RESET_FORMAT
|
||||
|
||||
|
||||
class AdvancedMenu(BaseMenu):
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
header=True,
|
||||
options={
|
||||
"1": None,
|
||||
"2": None,
|
||||
"3": None,
|
||||
"4": KlipperFlashMethodMenu,
|
||||
"5": None,
|
||||
"6": None,
|
||||
},
|
||||
footer_type=BACK_FOOTER,
|
||||
)
|
||||
def __init__(self, previous_menu: BaseMenu):
|
||||
super().__init__()
|
||||
|
||||
self.previous_menu: BaseMenu = previous_menu
|
||||
self.options = {
|
||||
"1": None,
|
||||
"2": None,
|
||||
"3": None,
|
||||
"4": lambda: KlipperFlashMethodMenu(previous_menu=self).run(),
|
||||
"5": None,
|
||||
"6": lambda: KlipperSelectMcuConnectionMenu(previous_menu=self).run(),
|
||||
}
|
||||
|
||||
def print_menu(self):
|
||||
header = " [ Advanced Menu ] "
|
||||
|
||||
@@ -19,7 +19,6 @@ from components.webui_client.client_utils import (
|
||||
load_client_data,
|
||||
backup_client_config_data,
|
||||
)
|
||||
from core.menus import BACK_FOOTER
|
||||
from core.menus.base_menu import BaseMenu
|
||||
from utils.common import backup_printer_config_dir
|
||||
from utils.constants import COLOR_CYAN, RESET_FORMAT, COLOR_YELLOW
|
||||
@@ -28,22 +27,21 @@ from utils.constants import COLOR_CYAN, RESET_FORMAT, COLOR_YELLOW
|
||||
# noinspection PyUnusedLocal
|
||||
# noinspection PyMethodMayBeStatic
|
||||
class BackupMenu(BaseMenu):
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
header=True,
|
||||
options={
|
||||
"1": self.backup_klipper,
|
||||
"2": self.backup_moonraker,
|
||||
"3": self.backup_printer_config,
|
||||
"4": self.backup_moonraker_db,
|
||||
"5": self.backup_mainsail,
|
||||
"6": self.backup_fluidd,
|
||||
"7": self.backup_mainsail_config,
|
||||
"8": self.backup_fluidd_config,
|
||||
"9": self.backup_klipperscreen,
|
||||
},
|
||||
footer_type=BACK_FOOTER,
|
||||
)
|
||||
def __init__(self, previous_menu: BaseMenu):
|
||||
super().__init__()
|
||||
|
||||
self.previous_menu: BaseMenu = previous_menu
|
||||
self.options = {
|
||||
"1": self.backup_klipper,
|
||||
"2": self.backup_moonraker,
|
||||
"3": self.backup_printer_config,
|
||||
"4": self.backup_moonraker_db,
|
||||
"5": self.backup_mainsail,
|
||||
"6": self.backup_fluidd,
|
||||
"7": self.backup_mainsail_config,
|
||||
"8": self.backup_fluidd_config,
|
||||
"9": self.backup_klipperscreen,
|
||||
}
|
||||
|
||||
def print_menu(self):
|
||||
header = " [ Backup Menu ] "
|
||||
|
||||
@@ -13,9 +13,9 @@ import subprocess
|
||||
import sys
|
||||
import textwrap
|
||||
from abc import abstractmethod, ABC
|
||||
from typing import Dict, Any, Literal, Union, Callable
|
||||
from typing import Dict, Union, Callable, Type
|
||||
|
||||
from core.menus import QUIT_FOOTER, BACK_FOOTER, BACK_HELP_FOOTER
|
||||
from core.menus import FooterType, NAVI_OPTIONS, ExitAppException, GoBackException
|
||||
from utils.constants import (
|
||||
COLOR_GREEN,
|
||||
COLOR_YELLOW,
|
||||
@@ -92,108 +92,90 @@ def print_back_help_footer():
|
||||
print(footer, end="")
|
||||
|
||||
|
||||
class BaseMenu(ABC):
|
||||
NAVI_OPTIONS = {"quit": ["q"], "back": ["b"], "back_help": ["b", "h"]}
|
||||
Options = Dict[str, Callable]
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
options: Dict[str, Union[Callable, Any]],
|
||||
options_offset: int = 0,
|
||||
default_option: Union[str, None] = None,
|
||||
input_label_txt: Union[str, None] = None,
|
||||
header: bool = True,
|
||||
previous_menu: BaseMenu = None,
|
||||
footer_type: Literal[
|
||||
"QUIT_FOOTER", "BACK_FOOTER", "BACK_HELP_FOOTER"
|
||||
] = QUIT_FOOTER,
|
||||
):
|
||||
self.previous_menu = previous_menu
|
||||
self.options = options
|
||||
self.default_option = default_option
|
||||
self.options_offset = options_offset
|
||||
self.input_label_txt = input_label_txt
|
||||
self.header = header
|
||||
self.footer_type = footer_type
|
||||
|
||||
class BaseMenu(ABC):
|
||||
options: Options = {}
|
||||
options_offset: int = 0
|
||||
default_option: Union[Callable, None] = None
|
||||
input_label_txt: str = "Perform action"
|
||||
header: bool = False
|
||||
previous_menu: Union[Type[BaseMenu], BaseMenu] = None
|
||||
footer_type: FooterType = FooterType.BACK
|
||||
|
||||
def __init__(self):
|
||||
if type(self) is BaseMenu:
|
||||
raise NotImplementedError("BaseMenu cannot be instantiated directly.")
|
||||
|
||||
@abstractmethod
|
||||
def print_menu(self) -> None:
|
||||
raise NotImplementedError("Subclasses must implement the print_menu method")
|
||||
|
||||
def print_footer(self) -> None:
|
||||
footer_type_map = {
|
||||
QUIT_FOOTER: print_quit_footer,
|
||||
BACK_FOOTER: print_back_footer,
|
||||
BACK_HELP_FOOTER: print_back_help_footer,
|
||||
}
|
||||
footer_function = footer_type_map.get(self.footer_type, print_quit_footer)
|
||||
footer_function()
|
||||
if self.footer_type is FooterType.QUIT:
|
||||
print_quit_footer()
|
||||
elif self.footer_type is FooterType.BACK:
|
||||
print_back_footer()
|
||||
elif self.footer_type is FooterType.BACK_HELP:
|
||||
print_back_help_footer()
|
||||
else:
|
||||
raise NotImplementedError("Method for printing footer not implemented.")
|
||||
|
||||
def display(self) -> None:
|
||||
def display_menu(self) -> None:
|
||||
# clear()
|
||||
if self.header:
|
||||
print_header()
|
||||
self.print_menu()
|
||||
self.print_footer()
|
||||
|
||||
def handle_user_input(self) -> str:
|
||||
def validate_user_input(self, usr_input: str) -> Callable:
|
||||
"""
|
||||
Validate the user input and either return an Option, a string or None
|
||||
:param usr_input: The user input in form of a string
|
||||
:return: Option, str or None
|
||||
"""
|
||||
usr_input = usr_input.lower()
|
||||
option = self.options.get(usr_input, None)
|
||||
|
||||
# check if usr_input contains a character used for basic navigation, e.g. b, h or q
|
||||
# and if the current menu has the appropriate footer to allow for that action
|
||||
is_valid_navigation = self.footer_type in NAVI_OPTIONS
|
||||
user_navigated = usr_input in NAVI_OPTIONS[self.footer_type]
|
||||
if is_valid_navigation and user_navigated:
|
||||
if usr_input == "q":
|
||||
raise ExitAppException()
|
||||
elif usr_input == "b":
|
||||
raise GoBackException()
|
||||
elif usr_input == "h":
|
||||
return option
|
||||
|
||||
# if usr_input is None or an empty string, we execute the menues default option if specified
|
||||
if usr_input == "" and self.default_option is not None:
|
||||
return self.default_option
|
||||
|
||||
# user selected a regular option
|
||||
return option
|
||||
|
||||
def handle_user_input(self) -> Callable:
|
||||
"""Handle the user input, return the validated input or print an error."""
|
||||
while True:
|
||||
label_text = (
|
||||
"Perform action"
|
||||
if self.input_label_txt is None or self.input_label_txt == ""
|
||||
else self.input_label_txt
|
||||
)
|
||||
choice = input(f"{COLOR_CYAN}###### {label_text}: {RESET_FORMAT}").lower()
|
||||
option = self.options.get(choice, None)
|
||||
print(f"{COLOR_CYAN}###### {self.input_label_txt}: {RESET_FORMAT}", end="")
|
||||
usr_input = input().lower()
|
||||
|
||||
has_navi_option = self.footer_type in self.NAVI_OPTIONS
|
||||
user_navigated = choice in self.NAVI_OPTIONS[self.footer_type]
|
||||
if has_navi_option and user_navigated:
|
||||
return choice
|
||||
|
||||
if option is not None:
|
||||
return choice
|
||||
elif option is None and self.default_option is not None:
|
||||
return self.default_option
|
||||
if (validated_input := self.validate_user_input(usr_input)) is not None:
|
||||
return validated_input
|
||||
else:
|
||||
Logger.print_error("Invalid input!", False)
|
||||
|
||||
def start(self) -> None:
|
||||
def run(self) -> None:
|
||||
"""Start the menu lifecycle. When this function returns, the lifecycle of the menu ends."""
|
||||
while True:
|
||||
self.display()
|
||||
choice = self.handle_user_input()
|
||||
|
||||
if choice == "q":
|
||||
try:
|
||||
self.display_menu()
|
||||
self.handle_user_input()()
|
||||
except GoBackException:
|
||||
return
|
||||
except ExitAppException:
|
||||
Logger.print_ok("###### Happy printing!", False)
|
||||
sys.exit(0)
|
||||
elif choice == "b":
|
||||
return
|
||||
else:
|
||||
self.execute_option(choice)
|
||||
|
||||
def execute_option(self, choice: str) -> None:
|
||||
option = self.options.get(choice, None)
|
||||
|
||||
if isinstance(option, type) and issubclass(option, BaseMenu):
|
||||
self.navigate_to_menu(option, True)
|
||||
elif isinstance(option, BaseMenu):
|
||||
self.navigate_to_menu(option, False)
|
||||
elif callable(option):
|
||||
option(opt_index=choice)
|
||||
elif option is None:
|
||||
raise NotImplementedError(f"No implementation for option {choice}")
|
||||
else:
|
||||
raise TypeError(
|
||||
f"Type {type(option)} of option {choice} not of type BaseMenu or Method"
|
||||
)
|
||||
|
||||
def navigate_to_menu(self, menu, instantiate: bool) -> None:
|
||||
"""
|
||||
Method for handling the actual menu switch. Can either take in a menu type or an already
|
||||
instantiated menu class. Use instantiated menu classes only if the menu requires specific input parameters
|
||||
:param menu: A menu type or menu instance
|
||||
:param instantiate: Specify if the menu requires instantiation
|
||||
:return: None
|
||||
"""
|
||||
menu = menu() if instantiate else menu
|
||||
menu.previous_menu = self
|
||||
menu.start()
|
||||
|
||||
@@ -12,24 +12,22 @@ import inspect
|
||||
import json
|
||||
import textwrap
|
||||
from pathlib import Path
|
||||
from typing import List, Dict
|
||||
from typing import List
|
||||
|
||||
from core.base_extension import BaseExtension
|
||||
from core.menus import BACK_FOOTER
|
||||
from core.menus.base_menu import BaseMenu
|
||||
from core.menus.base_menu import BaseMenu, Options
|
||||
from utils.constants import RESET_FORMAT, COLOR_CYAN, COLOR_YELLOW
|
||||
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
# noinspection PyMethodMayBeStatic
|
||||
class ExtensionsMenu(BaseMenu):
|
||||
def __init__(self):
|
||||
def __init__(self, previous_menu: BaseMenu):
|
||||
super().__init__()
|
||||
|
||||
self.previous_menu: BaseMenu = previous_menu
|
||||
self.extensions = self.discover_extensions()
|
||||
super().__init__(
|
||||
header=False,
|
||||
options=self.get_options(),
|
||||
footer_type=BACK_FOOTER,
|
||||
)
|
||||
self.options: Options = self.get_options(self.extensions)
|
||||
|
||||
def discover_extensions(self) -> List[BaseExtension]:
|
||||
extensions = []
|
||||
@@ -58,11 +56,11 @@ class ExtensionsMenu(BaseMenu):
|
||||
|
||||
return sorted(extensions, key=lambda ex: ex.metadata.get("index"))
|
||||
|
||||
def get_options(self) -> Dict[str, BaseMenu]:
|
||||
options = {}
|
||||
for extension in self.extensions:
|
||||
def get_options(self, extensions: List[BaseExtension]) -> Options:
|
||||
options: Options = {}
|
||||
for extension in extensions:
|
||||
index = extension.metadata.get("index")
|
||||
options[f"{index}"] = ExtensionSubmenu(extension)
|
||||
options[f"{index}"] = lambda: ExtensionSubmenu(self, extension).run()
|
||||
|
||||
return options
|
||||
|
||||
@@ -92,18 +90,18 @@ class ExtensionsMenu(BaseMenu):
|
||||
# noinspection PyUnusedLocal
|
||||
# noinspection PyMethodMayBeStatic
|
||||
class ExtensionSubmenu(BaseMenu):
|
||||
def __init__(self, extension: BaseExtension):
|
||||
def __init__(self, previous_menu: BaseMenu, extension: BaseExtension):
|
||||
super().__init__()
|
||||
|
||||
self.previous_menu = previous_menu
|
||||
self.options = {
|
||||
"1": extension.install_extension,
|
||||
"2": extension.remove_extension,
|
||||
}
|
||||
|
||||
self.extension = extension
|
||||
self.extension_name = extension.metadata.get("display_name")
|
||||
self.extension_desc = extension.metadata.get("description")
|
||||
super().__init__(
|
||||
header=False,
|
||||
options={
|
||||
"1": extension.install_extension,
|
||||
"2": extension.remove_extension,
|
||||
},
|
||||
footer_type=BACK_FOOTER,
|
||||
)
|
||||
|
||||
def print_menu(self) -> None:
|
||||
header = f" [ {self.extension_name} ] "
|
||||
|
||||
@@ -13,7 +13,7 @@ from components.klipper import klipper_setup
|
||||
from components.moonraker import moonraker_setup
|
||||
from components.webui_client import client_setup
|
||||
from components.webui_client.client_config import client_config_setup
|
||||
from core.menus import BACK_FOOTER
|
||||
|
||||
from core.menus.base_menu import BaseMenu
|
||||
from utils.constants import COLOR_GREEN, RESET_FORMAT
|
||||
|
||||
@@ -21,22 +21,21 @@ from utils.constants import COLOR_GREEN, RESET_FORMAT
|
||||
# noinspection PyUnusedLocal
|
||||
# noinspection PyMethodMayBeStatic
|
||||
class InstallMenu(BaseMenu):
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
header=True,
|
||||
options={
|
||||
"1": self.install_klipper,
|
||||
"2": self.install_moonraker,
|
||||
"3": self.install_mainsail,
|
||||
"4": self.install_fluidd,
|
||||
"5": self.install_mainsail_config,
|
||||
"6": self.install_fluidd_config,
|
||||
"7": None,
|
||||
"8": None,
|
||||
"9": None,
|
||||
},
|
||||
footer_type=BACK_FOOTER,
|
||||
)
|
||||
def __init__(self, previous_menu: BaseMenu):
|
||||
super().__init__()
|
||||
|
||||
self.previous_menu: BaseMenu = previous_menu
|
||||
self.options = {
|
||||
"1": self.install_klipper,
|
||||
"2": self.install_moonraker,
|
||||
"3": self.install_mainsail,
|
||||
"4": self.install_fluidd,
|
||||
"5": self.install_mainsail_config,
|
||||
"6": self.install_fluidd_config,
|
||||
"7": None,
|
||||
"8": None,
|
||||
"9": None,
|
||||
}
|
||||
|
||||
def print_menu(self):
|
||||
header = " [ Installation Menu ] "
|
||||
|
||||
@@ -17,7 +17,7 @@ from components.webui_client.client_utils import (
|
||||
load_client_data,
|
||||
get_current_client_config,
|
||||
)
|
||||
from core.menus import QUIT_FOOTER
|
||||
from core.menus import FooterType
|
||||
from core.menus.advanced_menu import AdvancedMenu
|
||||
from core.menus.backup_menu import BackupMenu
|
||||
from core.menus.base_menu import BaseMenu
|
||||
@@ -39,20 +39,22 @@ from utils.constants import (
|
||||
# noinspection PyMethodMayBeStatic
|
||||
class MainMenu(BaseMenu):
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
header=True,
|
||||
options={
|
||||
"0": LogUploadMenu,
|
||||
"1": InstallMenu,
|
||||
"2": UpdateMenu,
|
||||
"3": RemoveMenu,
|
||||
"4": AdvancedMenu,
|
||||
"5": BackupMenu,
|
||||
"e": ExtensionsMenu,
|
||||
"s": SettingsMenu,
|
||||
},
|
||||
footer_type=QUIT_FOOTER,
|
||||
)
|
||||
super().__init__()
|
||||
|
||||
self.options = {
|
||||
"0": lambda: LogUploadMenu(previous_menu=self).run(),
|
||||
"1": lambda: InstallMenu(previous_menu=self).run(),
|
||||
"2": lambda: UpdateMenu(previous_menu=self).run(),
|
||||
"3": lambda: RemoveMenu(previous_menu=self).run(),
|
||||
"4": lambda: AdvancedMenu(previous_menu=self).run(),
|
||||
"5": lambda: BackupMenu(previous_menu=self).run(),
|
||||
"6": None,
|
||||
"e": lambda: ExtensionsMenu(previous_menu=self).run(),
|
||||
"s": lambda: SettingsMenu(previous_menu=self).run(),
|
||||
}
|
||||
self.header = True
|
||||
self.footer_type = FooterType.QUIT
|
||||
|
||||
self.kl_status = ""
|
||||
self.kl_repo = ""
|
||||
self.mr_status = ""
|
||||
|
||||
@@ -15,7 +15,6 @@ from components.moonraker.menus.moonraker_remove_menu import (
|
||||
)
|
||||
from components.webui_client.client_utils import load_client_data
|
||||
from components.webui_client.menus.client_remove_menu import ClientRemoveMenu
|
||||
from core.menus import BACK_FOOTER
|
||||
from core.menus.base_menu import BaseMenu
|
||||
from utils.constants import COLOR_RED, RESET_FORMAT
|
||||
|
||||
@@ -23,26 +22,29 @@ from utils.constants import COLOR_RED, RESET_FORMAT
|
||||
# noinspection PyUnusedLocal
|
||||
# noinspection PyMethodMayBeStatic
|
||||
class RemoveMenu(BaseMenu):
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
header=True,
|
||||
options={
|
||||
"1": KlipperRemoveMenu,
|
||||
"2": MoonrakerRemoveMenu,
|
||||
"3": ClientRemoveMenu(client=load_client_data("mainsail")),
|
||||
"4": ClientRemoveMenu(client=load_client_data("fluidd")),
|
||||
"5": None,
|
||||
"6": None,
|
||||
"7": None,
|
||||
"8": None,
|
||||
"9": None,
|
||||
"10": None,
|
||||
"11": None,
|
||||
"12": None,
|
||||
"13": None,
|
||||
},
|
||||
footer_type=BACK_FOOTER,
|
||||
)
|
||||
def __init__(self, previous_menu: BaseMenu):
|
||||
super().__init__()
|
||||
|
||||
self.previous_menu: BaseMenu = previous_menu
|
||||
self.options = {
|
||||
"1": lambda: KlipperRemoveMenu(previous_menu=self).run(),
|
||||
"2": lambda: MoonrakerRemoveMenu(previous_menu=self).run(),
|
||||
"3": lambda: ClientRemoveMenu(
|
||||
previous_menu=self, client=load_client_data("mainsail")
|
||||
).run(),
|
||||
"4": lambda: ClientRemoveMenu(
|
||||
previous_menu=self, client=load_client_data("fluidd")
|
||||
).run(),
|
||||
"5": None,
|
||||
"6": None,
|
||||
"7": None,
|
||||
"8": None,
|
||||
"9": None,
|
||||
"10": None,
|
||||
"11": None,
|
||||
"12": None,
|
||||
"13": None,
|
||||
}
|
||||
|
||||
def print_menu(self):
|
||||
header = " [ Remove Menu ] "
|
||||
|
||||
@@ -12,8 +12,10 @@ from core.menus.base_menu import BaseMenu
|
||||
|
||||
# noinspection PyMethodMayBeStatic
|
||||
class SettingsMenu(BaseMenu):
|
||||
def __init__(self):
|
||||
super().__init__(header=True, options={})
|
||||
def __init__(self, previous_menu: BaseMenu):
|
||||
super().__init__()
|
||||
|
||||
self.previous_menu: BaseMenu = previous_menu
|
||||
|
||||
def print_menu(self):
|
||||
print("self")
|
||||
|
||||
@@ -25,7 +25,6 @@ from components.webui_client.client_utils import (
|
||||
load_client_data,
|
||||
get_client_config_status,
|
||||
)
|
||||
from core.menus import BACK_FOOTER
|
||||
from core.menus.base_menu import BaseMenu
|
||||
from utils.constants import (
|
||||
COLOR_GREEN,
|
||||
@@ -39,24 +38,24 @@ from utils.constants import (
|
||||
# noinspection PyUnusedLocal
|
||||
# noinspection PyMethodMayBeStatic
|
||||
class UpdateMenu(BaseMenu):
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
header=True,
|
||||
options={
|
||||
"0": self.update_all,
|
||||
"1": self.update_klipper,
|
||||
"2": self.update_moonraker,
|
||||
"3": self.update_mainsail,
|
||||
"4": self.update_fluidd,
|
||||
"5": self.update_mainsail_config,
|
||||
"6": self.update_fluidd_config,
|
||||
"7": self.update_klipperscreen,
|
||||
"8": self.update_mobileraker,
|
||||
"9": self.update_crowsnest,
|
||||
"10": self.upgrade_system_packages,
|
||||
},
|
||||
footer_type=BACK_FOOTER,
|
||||
)
|
||||
def __init__(self, previous_menu):
|
||||
super().__init__()
|
||||
|
||||
self.previous_menu: BaseMenu = previous_menu
|
||||
self.options = {
|
||||
"0": self.update_all,
|
||||
"1": self.update_klipper,
|
||||
"2": self.update_moonraker,
|
||||
"3": self.update_mainsail,
|
||||
"4": self.update_fluidd,
|
||||
"5": self.update_mainsail_config,
|
||||
"6": self.update_fluidd_config,
|
||||
"7": self.update_klipperscreen,
|
||||
"8": self.update_mobileraker,
|
||||
"9": self.update_crowsnest,
|
||||
"10": self.upgrade_system_packages,
|
||||
}
|
||||
|
||||
self.kl_local = f"{COLOR_WHITE}{RESET_FORMAT}"
|
||||
self.kl_remote = f"{COLOR_WHITE}{RESET_FORMAT}"
|
||||
self.mr_local = f"{COLOR_WHITE}{RESET_FORMAT}"
|
||||
|
||||
@@ -22,7 +22,6 @@ from components.klipper.klipper_dialogs import (
|
||||
from core.base_extension import BaseExtension
|
||||
from core.instance_manager.base_instance import BaseInstance
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
from core.menus import BACK_FOOTER
|
||||
from core.menus.base_menu import BaseMenu
|
||||
from core.repo_manager.repo_manager import RepoManager
|
||||
from utils.constants import COLOR_YELLOW, COLOR_CYAN, RESET_FORMAT
|
||||
@@ -44,7 +43,7 @@ class MainsailThemeInstallerExtension(BaseExtension):
|
||||
|
||||
def install_extension(self, **kwargs) -> None:
|
||||
install_menu = MainsailThemeInstallMenu(self.instances)
|
||||
install_menu.start()
|
||||
install_menu.run()
|
||||
|
||||
def remove_extension(self, **kwargs) -> None:
|
||||
print_instance_overview(
|
||||
@@ -79,14 +78,12 @@ class MainsailThemeInstallMenu(BaseMenu):
|
||||
)
|
||||
|
||||
def __init__(self, instances: List[Klipper]):
|
||||
self.instances = instances
|
||||
super().__init__()
|
||||
self.themes: List[ThemeData] = self.load_themes()
|
||||
options = {f"{index}": self.install_theme for index in range(len(self.themes))}
|
||||
super().__init__(
|
||||
header=False,
|
||||
options=options,
|
||||
footer_type=BACK_FOOTER,
|
||||
)
|
||||
self.options = options
|
||||
|
||||
self.instances = instances
|
||||
|
||||
def print_menu(self) -> None:
|
||||
header = " [ Mainsail Theme Installer ] "
|
||||
|
||||
@@ -13,6 +13,6 @@ from utils.logger import Logger
|
||||
|
||||
def main():
|
||||
try:
|
||||
MainMenu().start()
|
||||
MainMenu().run()
|
||||
except KeyboardInterrupt:
|
||||
Logger.print_ok("\nHappy printing!\n", prefix=False)
|
||||
|
||||
@@ -83,4 +83,8 @@ function set_globals() {
|
||||
MOBILERAKER_DIR="${HOME}/mobileraker_companion"
|
||||
MOBILERAKER_REPO="https://github.com/Clon1998/mobileraker_companion.git"
|
||||
|
||||
#=============== OCTOAPP ================#
|
||||
OCTOAPP_ENV="${HOME}/octoapp-env"
|
||||
OCTOAPP_DIR="${HOME}/octoapp"
|
||||
OCTOAPP_REPO="https://github.com/crysxd/OctoApp-Plugin.git"
|
||||
}
|
||||
|
||||
369
scripts/octoapp.sh
Normal file
369
scripts/octoapp.sh
Normal file
@@ -0,0 +1,369 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/dw-0/kiauh #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
#=======================================================================#
|
||||
|
||||
#
|
||||
# This file is written and maintained by Christian Würthner from OctoApp
|
||||
# Please contact me if you need any help!
|
||||
# hello@octoapp.eu
|
||||
#
|
||||
|
||||
set -e
|
||||
|
||||
#===================================================#
|
||||
#============== Install ============#
|
||||
#===================================================#
|
||||
|
||||
function octoapp_systemd() {
|
||||
local services
|
||||
services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/octoapp(-[0-9a-zA-Z]+)?.service")
|
||||
echo "${services}"
|
||||
}
|
||||
|
||||
function octoapp_setup_dialog() {
|
||||
status_msg "Initializing OctoApp for Klipper installation ..."
|
||||
|
||||
# First, check for moonraker service instances.
|
||||
local moonraker_count
|
||||
local moonraker_names
|
||||
moonraker_count=$(moonraker_systemd | wc -w)
|
||||
if (( moonraker_count == 0 )); then
|
||||
### return early if moonraker is not installed
|
||||
local error="Moonraker not installed! Please install Moonraker first!"
|
||||
log_error "OctoApp setup started without Moonraker being installed. Aborting setup."
|
||||
print_error "${error}" && return
|
||||
elif (( moonraker_count > 1 )); then
|
||||
# moonraker_names is valid only in case of multi-instance
|
||||
read -r -a moonraker_names <<< "$(get_multi_instance_names)"
|
||||
fi
|
||||
|
||||
# Next, check for any existing OctoApp services.
|
||||
local octoapp_services
|
||||
local existing_octoapp_count
|
||||
octoapp_services=$(octoapp_systemd)
|
||||
existing_octoapp_count=$(echo "${octoapp_services}" | wc -w )
|
||||
|
||||
# We need to make the moonraker instance count to the OctoApp service count.
|
||||
local allowed_octoapp_count=$(( moonraker_count - existing_octoapp_count ))
|
||||
if (( allowed_octoapp_count > 0 )); then
|
||||
local new_octoapp_count
|
||||
|
||||
### Step 1: Ask for the number of OctoApp instances to install
|
||||
if (( moonraker_count == 1 )); then
|
||||
ok_msg "Moonraker installation found!\n"
|
||||
new_octoapp_count=1
|
||||
elif (( moonraker_count > 1 )); then
|
||||
top_border
|
||||
printf "|${green}%-55s${white}|\n" " ${moonraker_count} Moonraker instances found!"
|
||||
for name in "${moonraker_names[@]}"; do
|
||||
printf "|${cyan}%-57s${white}|\n" " ● moonraker-${name}"
|
||||
done
|
||||
blank_line
|
||||
if (( existing_octoapp_count > 0 )); then
|
||||
printf "|${green}%-55s${white}|\n" " ${existing_octoapp_count} OctoApp instances already installed!"
|
||||
for svc in ${octoapp_services}; do
|
||||
printf "|${cyan}%-57s${white}|\n" " ● octoapp-$(get_instance_name "${svc}")"
|
||||
done
|
||||
fi
|
||||
blank_line
|
||||
echo -e "| The setup will apply the same names to OctoApp |"
|
||||
blank_line
|
||||
echo -e "| Please select the number of OctoApp instances to |"
|
||||
echo -e "| install. Usually one OctoApp instance per Moonraker |"
|
||||
echo -e "| instance is required, but you may not install more |"
|
||||
echo -e "| OctoApp instances than available Moonraker instances. |"
|
||||
bottom_border
|
||||
|
||||
### ask for amount of instances
|
||||
local re="^[1-9][0-9]*$"
|
||||
while [[ ! ${new_octoapp_count} =~ ${re} || ${new_octoapp_count} -gt ${allowed_octoapp_count} ]]; do
|
||||
read -p "${cyan}###### Number of new OctoApp instances to set up:${white} " -i "${allowed_octoapp_count}" -e new_octoapp_count
|
||||
### break if input is valid
|
||||
[[ ${new_octoapp_count} =~ ${re} && ${new_octoapp_count} -le ${allowed_octoapp_count} ]] && break
|
||||
### conditional error messages
|
||||
[[ ! ${new_octoapp_count} =~ ${re} ]] && error_msg "Input not a number"
|
||||
(( new_octoapp_count > allowed_octoapp_count )) && error_msg "Number of OctoApp instances larger than installed Moonraker instances"
|
||||
done && select_msg "${new_octoapp_count}"
|
||||
else
|
||||
log_error "Internal error. moonraker_count of '${moonraker_count}' not equal or grater than one!"
|
||||
return 1
|
||||
fi # (( moonraker_count == 1 ))
|
||||
fi # (( allowed_octoapp_count > 0 ))
|
||||
|
||||
# Special case for one moonraker instance with OctoApp already installed.
|
||||
# If the user selects the install option again, they might be trying to recover the install
|
||||
# or complete a printer link they didn't finish in the past.
|
||||
# So in this case, we will allow them to run the install script again, since it's safe to run
|
||||
# if the service is already installed, it will repair any missing issues.
|
||||
if (( allowed_octoapp_count == 0 && moonraker_count == 1 )); then
|
||||
local yn
|
||||
while true; do
|
||||
echo "${yellow}OctoApp is already installed.${white}"
|
||||
echo "It is safe to run the install again to repair any issues or if the printer isn't linked, run the printer linking logic again."
|
||||
echo ""
|
||||
local question="Do you want to run the OctoApp recovery or linking logic again?"
|
||||
read -p "${cyan}###### ${question} (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
break;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
abort_msg "Exiting OctoApp setup ...\n"
|
||||
return;;
|
||||
*)
|
||||
error_msg "Invalid Input!";;
|
||||
esac
|
||||
done
|
||||
# The user responded yes, allow the install to run again.
|
||||
allowed_octoapp_count=1
|
||||
fi
|
||||
|
||||
# If there's something to install, do it!
|
||||
if (( allowed_octoapp_count > 0 )); then
|
||||
|
||||
(( new_octoapp_count > 1 )) && status_msg "Installing ${new_octoapp_count} OctoApp instances ..."
|
||||
(( new_octoapp_count == 1 )) && status_msg "Installing OctoApp ..."
|
||||
|
||||
# Ensure the basic system dependencies are installed.
|
||||
local dep=(git dfu-util virtualenv python3 python3-pip python3-venv)
|
||||
dependency_check "${dep[@]}"
|
||||
|
||||
# Close the repo
|
||||
clone_octoapp "${OCTOAPP_REPO}"
|
||||
|
||||
# Call install with the correct args.
|
||||
local instance_cfg_dirs
|
||||
read -r -a instance_cfg_dirs <<< "$(get_instance_folder_path "config")"
|
||||
echo instance_cfg_dirs[0]
|
||||
|
||||
if (( moonraker_count == 1 )); then
|
||||
"${OCTOAPP_DIR}/install.sh" "${instance_cfg_dirs[0]}/moonraker.conf"
|
||||
elif (( moonraker_count > 1 )); then
|
||||
local j=${existing_octoapp_count}
|
||||
|
||||
for (( i=1; i <= new_octoapp_count; i++ )); do
|
||||
"${OCTOAPP_DIR}/install.sh" "${instance_cfg_dirs[${j}]}/moonraker.conf"
|
||||
j=$(( j + 1 ))
|
||||
done && unset j
|
||||
fi # (( moonraker_count == 1 ))
|
||||
fi # (( allowed_octoapp_count > 0 ))
|
||||
}
|
||||
|
||||
function octoapp_install() {
|
||||
"${OCTOAPP_DIR}/install.sh" "$@"
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#============= Remove ==============#
|
||||
#===================================================#
|
||||
|
||||
function remove_octoapp_systemd() {
|
||||
[[ -z $(octoapp_systemd) ]] && return
|
||||
status_msg "Removing OctoApp Systemd Services ..."
|
||||
|
||||
for service in $(octoapp_systemd | cut -d"/" -f5); do
|
||||
status_msg "Removing ${service} ..."
|
||||
sudo systemctl stop "${service}"
|
||||
sudo systemctl disable "${service}"
|
||||
sudo rm -f "${SYSTEMD}/${service}"
|
||||
ok_msg "Done!"
|
||||
done
|
||||
|
||||
### reloading units
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl reset-failed
|
||||
ok_msg "OctoApp Services removed!"
|
||||
}
|
||||
|
||||
function remove_octoapp_logs() {
|
||||
local files regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/logs\/octoapp(-[0-9a-zA-Z]+)?\.log(.*)?"
|
||||
files=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${regex}" | sort)
|
||||
|
||||
if [[ -n ${files} ]]; then
|
||||
for file in ${files}; do
|
||||
status_msg "Removing ${file} ..."
|
||||
rm -f "${file}"
|
||||
ok_msg "${file} removed!"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_octoapp_dir() {
|
||||
[[ ! -d ${OCTOAPP_DIR} ]] && return
|
||||
|
||||
status_msg "Removing OctoApp directory ..."
|
||||
rm -rf "${OCTOAPP_DIR}"
|
||||
ok_msg "Directory removed!"
|
||||
}
|
||||
|
||||
function remove_octoapp_config() {
|
||||
# Remove the system config but not the main config, so the printer id doesn't get lost.
|
||||
local files regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/octoapp-system(-[0-9a-zA-Z]+)?\.cfg(.*)?"
|
||||
files=$(find "${HOME}" -maxdepth 4 -regextype posix-extended -regex "${regex}" | sort)
|
||||
|
||||
if [[ -n ${files} ]]; then
|
||||
for file in ${files}; do
|
||||
status_msg "Removing ${file} ..."
|
||||
rm -f "${file}"
|
||||
ok_msg "${file} removed!"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_octoapp_store_dir() {
|
||||
local files regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/octoapp-store"
|
||||
files=$(find "${HOME}" -maxdepth 2 -type d -regextype posix-extended -regex "${regex}" | sort)
|
||||
|
||||
if [[ -n ${files} ]]; then
|
||||
for file in ${files}; do
|
||||
status_msg "Removing ${file} ..."
|
||||
rm -rf "${file}"
|
||||
ok_msg "${file} removed!"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_octoapp_env() {
|
||||
[[ ! -d "${HOME}/octoapp-env" ]] && return
|
||||
|
||||
status_msg "Removing octoapp-env directory ..."
|
||||
rm -rf "${HOME}/octoapp-env"
|
||||
ok_msg "Directory removed!"
|
||||
}
|
||||
|
||||
function remove_octoapp()
|
||||
{
|
||||
remove_octoapp_systemd
|
||||
remove_octoapp_logs
|
||||
remove_octoapp_dir
|
||||
remove_octoapp_env
|
||||
remove_octoapp_config
|
||||
remove_octoapp_store_dir
|
||||
|
||||
print_confirm "OctoApp was successfully removed!"
|
||||
return
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#============= UPDATE ==============#
|
||||
#===================================================#
|
||||
|
||||
function update_octoapp() {
|
||||
do_action_service "stop" "octoapp"
|
||||
|
||||
if [[ ! -d ${OCTOAPP_DIR} ]]; then
|
||||
clone_octoapp "${OCTOAPP_REPO}"
|
||||
else
|
||||
backup_before_update "octoapp"
|
||||
status_msg "Updating OctoApp for Klipper ..."
|
||||
cd "${OCTOAPP_DIR}" && git pull
|
||||
### read PKGLIST and install possible new dependencies
|
||||
install_octoapp_dependencies
|
||||
### install possible new python dependencies
|
||||
"${OCTOAPP_ENV}"/bin/pip install -r "${OCTOAPP_DIR}/requirements.txt"
|
||||
fi
|
||||
|
||||
ok_msg "Update complete!"
|
||||
do_action_service "restart" "octoapp"
|
||||
}
|
||||
|
||||
function clone_octoapp() {
|
||||
local repo=${1}
|
||||
|
||||
status_msg "Cloning OctoApp from ${repo} ..."
|
||||
|
||||
### force remove existing octoapp dir and clone into fresh octoapp dir
|
||||
[[ -d ${OCTOAPP_DIR} ]] && rm -rf "${OCTOAPP_DIR}"
|
||||
|
||||
cd "${HOME}" || exit 1
|
||||
if ! git clone "${OCTOAPP_REPO}" "${OCTOAPP_DIR}"; then
|
||||
print_error "Cloning OctoApp from\n ${repo}\n failed!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function install_octoapp_dependencies() {
|
||||
local packages log_name="OctoApp"
|
||||
local install_script="${OCTOAPP_DIR}/install.sh"
|
||||
|
||||
### read PKGLIST from official install-script
|
||||
status_msg "Reading dependencies..."
|
||||
# shellcheck disable=SC2016
|
||||
packages="$(grep "PKGLIST=" "${install_script}" | cut -d'"' -f2 | sed 's/\${PKGLIST}//g' | tr -d '\n')"
|
||||
|
||||
echo "${cyan}${packages}${white}" | tr '[:space:]' '\n'
|
||||
read -r -a packages <<< "${packages}"
|
||||
|
||||
### Update system package lists if stale
|
||||
update_system_package_lists
|
||||
|
||||
### Install required packages
|
||||
install_system_packages "${log_name}" "packages[@]"
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#============= STATUS ==============#
|
||||
#===================================================#
|
||||
|
||||
function get_octoapp_status() {
|
||||
local status
|
||||
local service_count
|
||||
local octoapp_services
|
||||
|
||||
octoapp_services=$(octoapp_systemd)
|
||||
service_count=$(echo "${octoapp_services}" | wc -w )
|
||||
|
||||
if (( service_count == 0 )); then
|
||||
status="Not installed!"
|
||||
elif [[ ! -d "${OCTOAPP_DIR}" ]]; then
|
||||
status="Incomplete!"
|
||||
else
|
||||
status="Installed!"
|
||||
fi
|
||||
|
||||
echo "${status}"
|
||||
}
|
||||
|
||||
function get_local_octoapp_commit() {
|
||||
[[ ! -d ${OCTOAPP_DIR} || ! -d "${OCTOAPP_DIR}/.git" ]] && return
|
||||
|
||||
local commit
|
||||
cd "${OCTOAPP_DIR}"
|
||||
commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
|
||||
echo "${commit}"
|
||||
}
|
||||
|
||||
function get_remote_octoapp_commit() {
|
||||
[[ ! -d ${OCTOAPP_DIR} || ! -d "${OCTOAPP_DIR}/.git" ]] && return
|
||||
|
||||
local commit
|
||||
cd "${OCTOAPP_DIR}" && git fetch origin -q
|
||||
commit=$(git describe origin/release --always --tags | cut -d "-" -f 1,2)
|
||||
echo "${commit}"
|
||||
}
|
||||
|
||||
function compare_octoapp_versions() {
|
||||
local versions local_ver remote_ver
|
||||
local_ver="$(get_local_octoapp_commit)"
|
||||
remote_ver="$(get_remote_octoapp_commit)"
|
||||
|
||||
if [[ ${local_ver} != "${remote_ver}" ]]; then
|
||||
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
# Add us to the update file, so if the user selects "update all" it includes us.
|
||||
add_to_application_updates "octoapp"
|
||||
else
|
||||
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
fi
|
||||
|
||||
echo "${versions}"
|
||||
}
|
||||
@@ -28,9 +28,10 @@ function install_ui() {
|
||||
echo -e "| 4) [Fluidd] | 9) $(obico_install_title) |"
|
||||
echo -e "| | 10) [OctoEverywhere] |"
|
||||
echo -e "| | 11) [Mobileraker] |"
|
||||
echo -e "| Touchscreen GUI: | |"
|
||||
echo -e "| 5) [KlipperScreen] | Webcam Streamer: |"
|
||||
echo -e "| | 12) [Crowsnest] |"
|
||||
echo -e "| Touchscreen GUI: | 12) [OctoApp for Klipper] |"
|
||||
echo -e "| 5) [KlipperScreen] | |"
|
||||
echo -e "| | Webcam Streamer: |"
|
||||
echo -e "| | 13) [Crowsnest] |"
|
||||
back_footer
|
||||
}
|
||||
|
||||
@@ -72,6 +73,8 @@ function install_menu() {
|
||||
11)
|
||||
do_action "install_mobileraker" "install_ui";;
|
||||
12)
|
||||
do_action "octoapp_setup_dialog" "install_ui";;
|
||||
13)
|
||||
do_action "install_crowsnest" "install_ui";;
|
||||
B|b)
|
||||
clear; main_menu; break;;
|
||||
|
||||
@@ -28,6 +28,7 @@ function main_ui() {
|
||||
echo -e "| | Obico: $(print_status "moonraker_obico")|"
|
||||
echo -e "| | OctoEverywhere: $(print_status "octoeverywhere")|"
|
||||
echo -e "| | Mobileraker: $(print_status "mobileraker")|"
|
||||
echo -e "| | OctoApp: $(print_status "octoapp")|"
|
||||
echo -e "| | |"
|
||||
echo -e "| | Octoprint: $(print_status "octoprint")|"
|
||||
hr
|
||||
|
||||
@@ -31,6 +31,7 @@ function remove_ui() {
|
||||
echo -e "| 7) [KlipperScreen] | 14) [OctoEverywhere] |"
|
||||
echo -e "| | 15) [Mobileraker] |"
|
||||
echo -e "| | 16) [NGINX] |"
|
||||
echo -e "| | 17) [OctoApp] |"
|
||||
back_footer
|
||||
}
|
||||
|
||||
@@ -73,6 +74,8 @@ function remove_menu() {
|
||||
do_action "remove_mobileraker" "remove_ui";;
|
||||
16)
|
||||
do_action "remove_nginx" "remove_ui";;
|
||||
17)
|
||||
do_action "remove_octoapp" "remove_ui";;
|
||||
B|b)
|
||||
clear; main_menu; break;;
|
||||
*)
|
||||
|
||||
@@ -35,8 +35,9 @@ function update_ui() {
|
||||
echo -e "| 9) [OctoEverywhere] |$(compare_octoeverywhere_versions)|"
|
||||
echo -e "| 10) [Mobileraker] |$(compare_mobileraker_versions)|"
|
||||
echo -e "| 11) [Crowsnest] |$(compare_crowsnest_versions)|"
|
||||
echo -e "| 12) [OctoApp] |$(compare_octoapp_versions)|"
|
||||
echo -e "| |------------------------------|"
|
||||
echo -e "| 12) [System] | $(check_system_updates) |"
|
||||
echo -e "| 13) [System] | $(check_system_updates) |"
|
||||
back_footer
|
||||
}
|
||||
|
||||
@@ -73,6 +74,8 @@ function update_menu() {
|
||||
11)
|
||||
do_action "update_crowsnest" "update_ui";;
|
||||
12)
|
||||
do_action "update_octoapp" "update_ui";;
|
||||
13)
|
||||
do_action "upgrade_system_packages" "update_ui";;
|
||||
a)
|
||||
do_action "update_all" "update_ui";;
|
||||
@@ -128,7 +131,10 @@ function update_all() {
|
||||
echo -e "| ${cyan}● OctoEverywhere${white} |"
|
||||
|
||||
[[ "${update_arr[*]}" =~ "mobileraker" ]] && \
|
||||
echo -e "| ${cyan}● Mobileraker${white} |"
|
||||
echo -e "| ${cyan}● Mobileraker${white} |"
|
||||
|
||||
[[ "${update_arr[*]}" =~ "octoapp" ]] && \
|
||||
echo -e "| ${cyan}● OctoApp${white} |"
|
||||
|
||||
[[ "${update_arr[*]}" =~ "system" ]] && \
|
||||
echo -e "| ${cyan}● System${white} |"
|
||||
|
||||
Reference in New Issue
Block a user