mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-25 16:53:36 +05:00
feat: OctoEverywhere for KIAUH v6 (#485)
* feat: scaffold OE installer Signed-off-by: Dominik Willner <th33xitus@gmail.com> * refactor: remove redundant steps ocoeverywhere already takes care of Signed-off-by: Dominik Willner <th33xitus@gmail.com> * refactor: add padding option to dialog Signed-off-by: Dominik Willner <th33xitus@gmail.com> * refactor: oe uninstaller Signed-off-by: Dominik Willner <th33xitus@gmail.com> * fix: add recursive removal of files Signed-off-by: Dominik Willner <th33xitus@gmail.com> * refactor: implement octoeverywhere update Signed-off-by: Dominik Willner <th33xitus@gmail.com> * chore: cleanup Signed-off-by: Dominik Willner <th33xitus@gmail.com> * chore: remove unused argument Signed-off-by: Dominik Willner <th33xitus@gmail.com> * fix: add instance names to blacklist Signed-off-by: Dominik Willner <th33xitus@gmail.com> * refactor: use update.sh script of OctoEverywhere for updating Signed-off-by: Dominik Willner <th33xitus@gmail.com> * fix: typo Signed-off-by: Dominik Willner <th33xitus@gmail.com> * refactor: add force flag to git_clone_wrapper Signed-off-by: Dominik Willner <th33xitus@gmail.com> --------- Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -88,7 +88,6 @@ def print_multi_instance_warning(instances: List[Klipper]) -> None:
|
||||
"The following instances were found:",
|
||||
*_instances,
|
||||
],
|
||||
end="",
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -145,7 +145,6 @@ def update_klipper() -> None:
|
||||
"All Klipper instances will be restarted during the update process and "
|
||||
"ongoing prints WILL FAIL.",
|
||||
],
|
||||
end="",
|
||||
)
|
||||
|
||||
if not get_confirm("Update Klipper now?"):
|
||||
|
||||
@@ -220,7 +220,6 @@ def check_user_groups():
|
||||
"INFO:",
|
||||
"Relog required for group assignments to take effect!",
|
||||
],
|
||||
end="",
|
||||
)
|
||||
|
||||
if not get_confirm(f"Add user '{CURRENT_USER}' to group(s) now?"):
|
||||
@@ -272,7 +271,6 @@ def handle_disruptive_system_packages() -> None:
|
||||
"Please fix the problem manually. Otherwise, this may have "
|
||||
"undesirable effects on the operation of Klipper."
|
||||
],
|
||||
end="",
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -353,7 +353,6 @@ class KlipperSelectSDFlashBoardMenu(BaseMenu):
|
||||
"\n\n",
|
||||
"If you are unsure, stick to the default 250000!",
|
||||
],
|
||||
end="",
|
||||
)
|
||||
self.flash_options.selected_baudrate = get_number_input(
|
||||
question="Please set the baud rate",
|
||||
|
||||
@@ -62,7 +62,6 @@ def install_klipperscreen() -> None:
|
||||
"KlipperScreens update manager configuration for Moonraker "
|
||||
"will not be added to any moonraker.conf.",
|
||||
],
|
||||
end="",
|
||||
)
|
||||
if not get_confirm(
|
||||
"Continue KlipperScreen installation?",
|
||||
|
||||
@@ -58,7 +58,6 @@ def install_mobileraker() -> None:
|
||||
"Mobileraker's companion's update manager configuration for Moonraker "
|
||||
"will not be added to any moonraker.conf.",
|
||||
],
|
||||
end="",
|
||||
)
|
||||
if not get_confirm(
|
||||
"Continue Mobileraker's companion installation?",
|
||||
|
||||
28
kiauh/components/octoeverywhere/__init__.py
Normal file
28
kiauh/components/octoeverywhere/__init__.py
Normal file
@@ -0,0 +1,28 @@
|
||||
# ======================================================================= #
|
||||
# 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 #
|
||||
# ======================================================================= #
|
||||
from pathlib import Path
|
||||
|
||||
# repo
|
||||
OE_REPO = "https://github.com/QuinnDamerell/OctoPrint-OctoEverywhere.git"
|
||||
|
||||
# directories
|
||||
OE_DIR = Path.home().joinpath("octoeverywhere")
|
||||
OE_ENV_DIR = Path.home().joinpath("octoeverywhere-env")
|
||||
OE_STORE_DIR = OE_DIR.joinpath("octoeverywhere-store")
|
||||
|
||||
# files
|
||||
OE_REQ_FILE = OE_DIR.joinpath("requirements.txt")
|
||||
OE_DEPS_JSON_FILE = OE_DIR.joinpath("moonraker-system-dependencies.json")
|
||||
OE_INSTALL_SCRIPT = OE_DIR.joinpath("install.sh")
|
||||
OE_UPDATE_SCRIPT = OE_DIR.joinpath("update.sh")
|
||||
|
||||
# filenames
|
||||
OE_CFG_NAME = "octoeverywhere.conf"
|
||||
OE_LOG_NAME = "octoeverywhere.log"
|
||||
OE_SYS_CFG_NAME = "octoeverywhere-system.cfg"
|
||||
88
kiauh/components/octoeverywhere/octoeverywhere.py
Normal file
88
kiauh/components/octoeverywhere/octoeverywhere.py
Normal file
@@ -0,0 +1,88 @@
|
||||
# ======================================================================= #
|
||||
# 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 #
|
||||
# ======================================================================= #
|
||||
|
||||
from pathlib import Path
|
||||
from subprocess import CalledProcessError, run
|
||||
from typing import List
|
||||
|
||||
from components.octoeverywhere import (
|
||||
OE_CFG_NAME,
|
||||
OE_DIR,
|
||||
OE_ENV_DIR,
|
||||
OE_INSTALL_SCRIPT,
|
||||
OE_LOG_NAME,
|
||||
OE_STORE_DIR,
|
||||
OE_SYS_CFG_NAME,
|
||||
OE_UPDATE_SCRIPT,
|
||||
)
|
||||
from core.instance_manager.base_instance import BaseInstance
|
||||
from utils.logger import Logger
|
||||
|
||||
|
||||
class Octoeverywhere(BaseInstance):
|
||||
@classmethod
|
||||
def blacklist(cls) -> List[str]:
|
||||
return ["None", "mcu", "bambu", "companion"]
|
||||
|
||||
def __init__(self, suffix: str = ""):
|
||||
super().__init__(instance_type=self, suffix=suffix)
|
||||
self.dir: Path = OE_DIR
|
||||
self.env_dir: Path = OE_ENV_DIR
|
||||
self.store_dir: Path = OE_STORE_DIR
|
||||
self._cfg_file = self.cfg_dir.joinpath(OE_CFG_NAME)
|
||||
self._sys_cfg_file = self.cfg_dir.joinpath(OE_SYS_CFG_NAME)
|
||||
self._log = self.log_dir.joinpath(OE_LOG_NAME)
|
||||
|
||||
@property
|
||||
def cfg_file(self) -> Path:
|
||||
return self._cfg_file
|
||||
|
||||
@property
|
||||
def sys_cfg_file(self) -> Path:
|
||||
return self._sys_cfg_file
|
||||
|
||||
@property
|
||||
def log(self) -> Path:
|
||||
return self._log
|
||||
|
||||
def create(self) -> None:
|
||||
Logger.print_status("Creating OctoEverywhere for Klipper Instance ...")
|
||||
|
||||
try:
|
||||
cmd = f"{OE_INSTALL_SCRIPT} {self.cfg_dir}/moonraker.conf"
|
||||
run(cmd, check=True, shell=True)
|
||||
|
||||
except CalledProcessError as e:
|
||||
Logger.print_error(f"Error creating instance: {e}")
|
||||
raise
|
||||
|
||||
@staticmethod
|
||||
def update():
|
||||
try:
|
||||
run(str(OE_UPDATE_SCRIPT), check=True, shell=True, cwd=OE_DIR)
|
||||
|
||||
except CalledProcessError as e:
|
||||
Logger.print_error(f"Error updating OctoEverywhere for Klipper: {e}")
|
||||
raise
|
||||
|
||||
def delete(self) -> None:
|
||||
service_file = self.get_service_file_name(extension=True)
|
||||
service_file_path = self.get_service_file_path()
|
||||
|
||||
Logger.print_status(
|
||||
f"Deleting OctoEverywhere for Klipper Instance: {service_file}"
|
||||
)
|
||||
|
||||
try:
|
||||
command = ["sudo", "rm", "-f", service_file_path]
|
||||
run(command, check=True)
|
||||
Logger.print_ok(f"Service file deleted: {service_file_path}")
|
||||
except CalledProcessError as e:
|
||||
Logger.print_error(f"Error deleting service file: {e}")
|
||||
raise
|
||||
231
kiauh/components/octoeverywhere/octoeverywhere_setup.py
Normal file
231
kiauh/components/octoeverywhere/octoeverywhere_setup.py
Normal file
@@ -0,0 +1,231 @@
|
||||
# ======================================================================= #
|
||||
# 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 #
|
||||
# ======================================================================= #
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
|
||||
from components.moonraker.moonraker import Moonraker
|
||||
from components.octoeverywhere import (
|
||||
OE_DEPS_JSON_FILE,
|
||||
OE_DIR,
|
||||
OE_ENV_DIR,
|
||||
OE_INSTALL_SCRIPT,
|
||||
OE_LOG_NAME,
|
||||
OE_REPO,
|
||||
OE_REQ_FILE,
|
||||
OE_SYS_CFG_NAME,
|
||||
)
|
||||
from components.octoeverywhere.octoeverywhere import Octoeverywhere
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
from utils.common import (
|
||||
check_install_dependencies,
|
||||
get_install_status,
|
||||
moonraker_exists,
|
||||
)
|
||||
from utils.config_utils import (
|
||||
remove_config_section,
|
||||
)
|
||||
from utils.fs_utils import run_remove_routines
|
||||
from utils.git_utils import git_clone_wrapper
|
||||
from utils.input_utils import get_confirm
|
||||
from utils.logger import DialogType, Logger
|
||||
from utils.sys_utils import (
|
||||
cmd_sysctl_manage,
|
||||
install_python_requirements,
|
||||
parse_packages_from_file,
|
||||
)
|
||||
from utils.types import ComponentStatus
|
||||
|
||||
|
||||
def get_octoeverywhere_status() -> ComponentStatus:
|
||||
return get_install_status(OE_DIR, OE_ENV_DIR, Octoeverywhere)
|
||||
|
||||
|
||||
def install_octoeverywhere() -> None:
|
||||
Logger.print_status("Installing OctoEverywhere for Klipper ...")
|
||||
|
||||
# check if moonraker is installed. if not, notify the user and exit
|
||||
if not moonraker_exists():
|
||||
return
|
||||
|
||||
force_clone = False
|
||||
oe_im = InstanceManager(Octoeverywhere)
|
||||
oe_instances: List[Octoeverywhere] = oe_im.instances
|
||||
if oe_instances:
|
||||
Logger.print_dialog(
|
||||
DialogType.INFO,
|
||||
[
|
||||
"OctoEverywhere is already installed!",
|
||||
"It is safe to run the installer again to link your "
|
||||
"printer or repair any issues.",
|
||||
],
|
||||
padding_top=0,
|
||||
padding_bottom=0,
|
||||
)
|
||||
if not get_confirm("Re-run OctoEverywhere installation?"):
|
||||
Logger.print_info("Exiting OctoEverywhere for Klipper installation ...")
|
||||
return
|
||||
else:
|
||||
Logger.print_status("Re-Installing OctoEverywhere for Klipper ...")
|
||||
force_clone = True
|
||||
|
||||
mr_im = InstanceManager(Moonraker)
|
||||
mr_instances: List[Moonraker] = mr_im.instances
|
||||
|
||||
mr_names = [f"● {moonraker.data_dir_name}" for moonraker in mr_instances]
|
||||
if len(mr_names) > 1:
|
||||
Logger.print_dialog(
|
||||
DialogType.INFO,
|
||||
[
|
||||
"The following Moonraker instances were found:",
|
||||
*mr_names,
|
||||
"\n\n",
|
||||
"The setup will apply the same names to OctoEverywhere!",
|
||||
],
|
||||
padding_top=0,
|
||||
padding_bottom=0,
|
||||
)
|
||||
|
||||
if not get_confirm(
|
||||
"Continue OctoEverywhere for Klipper installation?",
|
||||
default_choice=True,
|
||||
allow_go_back=True,
|
||||
):
|
||||
Logger.print_info("Exiting OctoEverywhere for Klipper installation ...")
|
||||
return
|
||||
|
||||
try:
|
||||
git_clone_wrapper(OE_REPO, OE_DIR, force=force_clone)
|
||||
|
||||
for moonraker in mr_instances:
|
||||
oe_im.current_instance = Octoeverywhere(suffix=moonraker.suffix)
|
||||
oe_im.create_instance()
|
||||
|
||||
mr_im.restart_all_instance()
|
||||
|
||||
Logger.print_dialog(
|
||||
DialogType.SUCCESS,
|
||||
["OctoEverywhere for Klipper successfully installed!"],
|
||||
center_content=True,
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
Logger.print_error(
|
||||
f"Error during OctoEverywhere for Klipper installation:\n{e}"
|
||||
)
|
||||
|
||||
|
||||
def update_octoeverywhere() -> None:
|
||||
Logger.print_status("Updating OctoEverywhere for Klipper ...")
|
||||
try:
|
||||
Octoeverywhere.update()
|
||||
Logger.print_dialog(
|
||||
DialogType.SUCCESS,
|
||||
["OctoEverywhere for Klipper successfully updated!"],
|
||||
center_content=True,
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
Logger.print_error(f"Error during OctoEverywhere for Klipper update:\n{e}")
|
||||
|
||||
|
||||
def remove_octoeverywhere() -> None:
|
||||
Logger.print_status("Removing OctoEverywhere for Klipper ...")
|
||||
mr_im = InstanceManager(Moonraker)
|
||||
mr_instances: List[Moonraker] = mr_im.instances
|
||||
ob_im = InstanceManager(Octoeverywhere)
|
||||
ob_instances: List[Octoeverywhere] = ob_im.instances
|
||||
|
||||
try:
|
||||
remove_oe_instances(ob_im, ob_instances)
|
||||
remove_oe_dir()
|
||||
remove_oe_env()
|
||||
remove_config_section(f"include {OE_SYS_CFG_NAME}", mr_instances)
|
||||
delete_oe_logs(ob_instances)
|
||||
Logger.print_dialog(
|
||||
DialogType.SUCCESS,
|
||||
["OctoEverywhere for Klipper successfully removed!"],
|
||||
center_content=True,
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
Logger.print_error(f"Error during OctoEverywhere for Klipper removal:\n{e}")
|
||||
|
||||
|
||||
def install_oe_dependencies() -> None:
|
||||
oe_deps = []
|
||||
if OE_DEPS_JSON_FILE.exists():
|
||||
with open(OE_DEPS_JSON_FILE, "r") as deps:
|
||||
oe_deps = json.load(deps).get("debian", [])
|
||||
elif OE_INSTALL_SCRIPT.exists():
|
||||
oe_deps = parse_packages_from_file(OE_INSTALL_SCRIPT)
|
||||
|
||||
if not oe_deps:
|
||||
raise ValueError("Error reading OctoEverywhere dependencies!")
|
||||
|
||||
check_install_dependencies(oe_deps)
|
||||
install_python_requirements(OE_ENV_DIR, OE_REQ_FILE)
|
||||
|
||||
|
||||
def remove_oe_instances(
|
||||
instance_manager: InstanceManager,
|
||||
instance_list: List[Octoeverywhere],
|
||||
) -> None:
|
||||
if not instance_list:
|
||||
Logger.print_info("No OctoEverywhere instances found. Skipped ...")
|
||||
return
|
||||
|
||||
for instance in instance_list:
|
||||
Logger.print_status(f"Removing instance {instance.get_service_file_name()} ...")
|
||||
instance_manager.current_instance = instance
|
||||
instance_manager.stop_instance()
|
||||
instance_manager.disable_instance()
|
||||
instance_manager.delete_instance()
|
||||
|
||||
cmd_sysctl_manage("daemon-reload")
|
||||
|
||||
|
||||
def remove_oe_dir() -> None:
|
||||
Logger.print_status("Removing OctoEverywhere for Klipper directory ...")
|
||||
|
||||
if not OE_DIR.exists():
|
||||
Logger.print_info(f"'{OE_DIR}' does not exist. Skipped ...")
|
||||
return
|
||||
|
||||
run_remove_routines(OE_DIR)
|
||||
|
||||
|
||||
def remove_oe_env() -> None:
|
||||
Logger.print_status("Removing OctoEverywhere for Klipper environment ...")
|
||||
|
||||
if not OE_ENV_DIR.exists():
|
||||
Logger.print_info(f"'{OE_ENV_DIR}' does not exist. Skipped ...")
|
||||
return
|
||||
|
||||
run_remove_routines(OE_ENV_DIR)
|
||||
|
||||
|
||||
def delete_oe_logs(instances: List[Octoeverywhere]) -> None:
|
||||
Logger.print_status("Removing OctoEverywhere logs ...")
|
||||
|
||||
all_logfiles = []
|
||||
for instance in instances:
|
||||
all_logfiles = list(instance.log_dir.glob(f"{OE_LOG_NAME}*"))
|
||||
|
||||
install_log = Path.home().joinpath("octoeverywhere-installer.log")
|
||||
if install_log.exists():
|
||||
all_logfiles.append(install_log)
|
||||
|
||||
if not all_logfiles:
|
||||
Logger.print_info("No OctoEverywhere logs found. Skipped ...")
|
||||
return
|
||||
|
||||
for log in all_logfiles:
|
||||
Logger.print_status(f"Remove '{log}'")
|
||||
run_remove_routines(log)
|
||||
@@ -100,7 +100,6 @@ def print_install_client_config_dialog(client: BaseWebClient) -> None:
|
||||
"If you already use these macros skip this step. Otherwise you should "
|
||||
"consider to answer with 'Y' to download the recommended macros.",
|
||||
],
|
||||
end="",
|
||||
)
|
||||
|
||||
|
||||
@@ -115,5 +114,4 @@ def print_ipv6_warning_dialog() -> None:
|
||||
"If you think this warning is a false alarm, and you are sure that "
|
||||
"IPv6 is disabled, you can continue with the installation.",
|
||||
],
|
||||
end="",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user