mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-24 00:03:42 +05:00
fix(klipper): handle disruptive system packages/services
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -9,10 +9,11 @@
|
|||||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||||
# ======================================================================= #
|
# ======================================================================= #
|
||||||
|
|
||||||
|
import grp
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import grp
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import textwrap
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional, List, Union
|
from typing import Optional, List, Union
|
||||||
|
|
||||||
@@ -26,7 +27,7 @@ from kiauh.utils.logger import Logger
|
|||||||
from kiauh.utils.system_utils import parse_packages_from_file, \
|
from kiauh.utils.system_utils import parse_packages_from_file, \
|
||||||
clone_repo, create_python_venv, \
|
clone_repo, create_python_venv, \
|
||||||
install_python_requirements, update_system_package_lists, \
|
install_python_requirements, update_system_package_lists, \
|
||||||
install_system_packages
|
install_system_packages, mask_system_service
|
||||||
|
|
||||||
|
|
||||||
def run_klipper_setup(install: bool) -> None:
|
def run_klipper_setup(install: bool) -> None:
|
||||||
@@ -98,6 +99,7 @@ def install_klipper(instance_manager: InstanceManager) -> None:
|
|||||||
instance_manager.reload_daemon()
|
instance_manager.reload_daemon()
|
||||||
|
|
||||||
# step 4: check/handle conflicting packages/services
|
# step 4: check/handle conflicting packages/services
|
||||||
|
handle_disruptive_system_packages()
|
||||||
|
|
||||||
# step 5: check for required group membership
|
# step 5: check for required group membership
|
||||||
check_user_groups()
|
check_user_groups()
|
||||||
@@ -237,6 +239,7 @@ def remove_multi_instance(instance_manager: InstanceManager) -> None:
|
|||||||
|
|
||||||
instance_manager.reload_daemon()
|
instance_manager.reload_daemon()
|
||||||
|
|
||||||
|
|
||||||
def check_user_groups():
|
def check_user_groups():
|
||||||
current_groups = [grp.getgrgid(gid).gr_name for gid in os.getgroups()]
|
current_groups = [grp.getgrgid(gid).gr_name for gid in os.getgroups()]
|
||||||
|
|
||||||
@@ -265,3 +268,27 @@ def check_user_groups():
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
Logger.print_warn("Remember to relog/restart this machine for the group(s) to be applied!")
|
Logger.print_warn("Remember to relog/restart this machine for the group(s) to be applied!")
|
||||||
|
|
||||||
|
|
||||||
|
def handle_disruptive_system_packages() -> None:
|
||||||
|
services = []
|
||||||
|
brltty_status = subprocess.run(["systemctl", "is-enabled", "brltty"], capture_output=True, text=True)
|
||||||
|
modem_manager_status = subprocess.run(["systemctl", "is-enabled", "ModemManager"], capture_output=True, text=True)
|
||||||
|
|
||||||
|
if "enabled" in brltty_status.stdout:
|
||||||
|
services.append("brltty")
|
||||||
|
if "enabled" in modem_manager_status.stdout:
|
||||||
|
services.append("ModemManager")
|
||||||
|
|
||||||
|
for service in services if services else []:
|
||||||
|
try:
|
||||||
|
Logger.print_info(f"{service} service detected! Masking {service} service ...")
|
||||||
|
mask_system_service(service)
|
||||||
|
Logger.print_ok(f"{service} service masked!")
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
warn_msg = textwrap.dedent(f"""
|
||||||
|
KIAUH was unable to mask the {service} system service.
|
||||||
|
Please fix the problem manually. Otherwise, this may have
|
||||||
|
undesirable effects on the operation of Klipper.
|
||||||
|
""")[1:]
|
||||||
|
Logger.print_warn(warn_msg)
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ from pathlib import Path
|
|||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from kiauh.utils.constants import COLOR_RED, RESET_FORMAT
|
from kiauh.utils.constants import COLOR_RED, RESET_FORMAT
|
||||||
from kiauh.utils.logger import Logger
|
|
||||||
from kiauh.utils.input_utils import get_user_confirm
|
from kiauh.utils.input_utils import get_user_confirm
|
||||||
|
from kiauh.utils.logger import Logger
|
||||||
|
|
||||||
|
|
||||||
def kill(opt_err_msg=None) -> None:
|
def kill(opt_err_msg=None) -> None:
|
||||||
@@ -201,3 +201,12 @@ def create_directory(_dir: Path) -> None:
|
|||||||
except OSError as e:
|
except OSError as e:
|
||||||
Logger.print_error(f"Error creating folder: {e}")
|
Logger.print_error(f"Error creating folder: {e}")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
def mask_system_service(service_name: str) -> None:
|
||||||
|
try:
|
||||||
|
command = ["sudo", "systemctl", "mask", service_name]
|
||||||
|
subprocess.run(command, stderr=subprocess.PIPE, check=True)
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
Logger.print_error(f"Unable to mask system service {service_name}: {e.stderr.decode()}")
|
||||||
|
raise
|
||||||
|
|||||||
Reference in New Issue
Block a user