mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-11 17:44:28 +05:00
Merge branch 'develop' into develop-docs
# Conflicts: # docs/assets/logo.png
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -10,3 +10,4 @@ __pycache__
|
||||
*.code-workspace
|
||||
*.iml
|
||||
kiauh.cfg
|
||||
klipper_repos.txt
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
source=scripts
|
||||
|
||||
enable=avoid-nullary-conditions
|
||||
enable=deprecate-which
|
||||
enable=quote-safe-variables
|
||||
enable=require-variable-braces
|
||||
enable=require-double-brackets
|
||||
|
||||
# SC2162: `read` without `-r` will mangle backslashes.
|
||||
# https://github.com/koalaman/shellcheck/wiki/SC2162
|
||||
disable=SC2162
|
||||
|
||||
# SC2164: Use `cd ... || exit` in case `cd` fails
|
||||
# https://github.com/koalaman/shellcheck/wiki/SC2164
|
||||
disable=SC2164
|
||||
15
kiauh.py
15
kiauh.py
@@ -1,15 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# ======================================================================= #
|
||||
# Copyright (C) 2020 - 2025 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 kiauh.main import main
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
121
kiauh.sh
121
kiauh.sh
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#=======================================================================#
|
||||
# Copyright (C) 2020 - 2024 Dominik Willner <th33xitus@gmail.com> #
|
||||
# Copyright (C) 2020 - 2025 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||
# https://github.com/dw-0/kiauh #
|
||||
@@ -15,11 +15,6 @@ clear -x
|
||||
# make sure we have the correct permissions while running the script
|
||||
umask 022
|
||||
|
||||
### sourcing all additional scripts
|
||||
KIAUH_SRCDIR="$(dirname -- "$(readlink -f "${BASH_SOURCE[0]}")")"
|
||||
for script in "${KIAUH_SRCDIR}/scripts/"*.sh; do . "${script}"; done
|
||||
for script in "${KIAUH_SRCDIR}/scripts/ui/"*.sh; do . "${script}"; done
|
||||
|
||||
#===================================================#
|
||||
#=================== UPDATE KIAUH ==================#
|
||||
#===================================================#
|
||||
@@ -57,15 +52,6 @@ function kiauh_update_avail() {
|
||||
fi
|
||||
}
|
||||
|
||||
function save_startup_version() {
|
||||
local launch_version
|
||||
|
||||
echo "${1}"
|
||||
|
||||
sed -i "/^version_to_launch=/d" "${INI_FILE}"
|
||||
sed -i '$a'"version_to_launch=${1}" "${INI_FILE}"
|
||||
}
|
||||
|
||||
function kiauh_update_dialog() {
|
||||
[[ ! $(kiauh_update_avail) == "true" ]] && return
|
||||
top_border
|
||||
@@ -93,85 +79,52 @@ function kiauh_update_dialog() {
|
||||
done
|
||||
}
|
||||
|
||||
function launch_kiauh_v5() {
|
||||
main_menu
|
||||
}
|
||||
|
||||
function launch_kiauh_v6() {
|
||||
local entrypoint
|
||||
|
||||
if ! command -v python3 &>/dev/null || [[ $(python3 -V | cut -d " " -f2 | cut -d "." -f2) -lt 8 ]]; then
|
||||
echo "Python 3.8 or higher is not installed!"
|
||||
echo "Please install Python 3.8 or higher and try again."
|
||||
function check_euid() {
|
||||
if [[ ${EUID} -eq 0 ]]; then
|
||||
echo -e "${red}"
|
||||
top_border
|
||||
echo -e "| !!! THIS SCRIPT MUST NOT RUN AS ROOT !!! |"
|
||||
echo -e "| |"
|
||||
echo -e "| It will ask for credentials as needed. |"
|
||||
bottom_border
|
||||
echo -e "${white}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
entrypoint=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
|
||||
|
||||
export PYTHONPATH="${entrypoint}"
|
||||
|
||||
clear -x
|
||||
python3 "${entrypoint}/kiauh.py"
|
||||
function check_if_ratos() {
|
||||
if [[ -n $(which ratos) ]]; then
|
||||
echo -e "${red}"
|
||||
top_border
|
||||
echo -e "| !!! RatOS 2.1 or greater detected !!! |"
|
||||
echo -e "| |"
|
||||
echo -e "| KIAUH does currently not support RatOS. |"
|
||||
echo -e "| If you have any questions, please ask for help on the |"
|
||||
echo -e "| RatRig Community Discord: https://discord.gg/ratrig |"
|
||||
bottom_border
|
||||
echo -e "${white}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function main() {
|
||||
read_kiauh_ini "${FUNCNAME[0]}"
|
||||
local entrypoint
|
||||
|
||||
if [[ ${version_to_launch} -eq 5 ]]; then
|
||||
launch_kiauh_v5
|
||||
elif [[ ${version_to_launch} -eq 6 ]]; then
|
||||
launch_kiauh_v6
|
||||
else
|
||||
top_border
|
||||
echo -e "| ${green}KIAUH v6.0.0-alpha1 is available now!${white} |"
|
||||
hr
|
||||
echo -e "| View Changelog: ${magenta}https://git.io/JnmlX${white} |"
|
||||
blank_line
|
||||
echo -e "| KIAUH v6 was completely rewritten from the ground up. |"
|
||||
echo -e "| It's based on Python 3.8 and has many improvements. |"
|
||||
blank_line
|
||||
echo -e "| ${yellow}NOTE: Version 6 is still in alpha, so bugs may occur!${white} |"
|
||||
echo -e "| ${yellow}Yet, your feedback and bug reports are very much${white} |"
|
||||
echo -e "| ${yellow}appreciated and will help finalize the release.${white} |"
|
||||
hr
|
||||
echo -e "| Would you like to try out KIAUH v6? |"
|
||||
echo -e "| 1) Yes |"
|
||||
echo -e "| 2) No |"
|
||||
echo -e "| 3) Yes, remember my choice for next time |"
|
||||
echo -e "| 4) No, remember my choice for next time |"
|
||||
quit_footer
|
||||
while true; do
|
||||
read -p "${cyan}###### Select action:${white} " -e input
|
||||
case "${input}" in
|
||||
1)
|
||||
launch_kiauh_v6
|
||||
break;;
|
||||
2)
|
||||
launch_kiauh_v5
|
||||
break;;
|
||||
3)
|
||||
save_startup_version 6
|
||||
launch_kiauh_v6
|
||||
break;;
|
||||
4)
|
||||
save_startup_version 5
|
||||
launch_kiauh_v5
|
||||
break;;
|
||||
Q|q)
|
||||
echo -e "${green}###### Happy printing! ######${white}"; echo
|
||||
exit 0;;
|
||||
*)
|
||||
error_msg "Invalid Input!\n";;
|
||||
esac
|
||||
done && input=""
|
||||
fi
|
||||
if ! command -v python3 &>/dev/null || [[ $(python3 -V | cut -d " " -f2 | cut -d "." -f2) -lt 8 ]]; then
|
||||
echo "Python 3.8 or higher is not installed!"
|
||||
echo "Please install Python 3.8 or higher and try again."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
entrypoint=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
|
||||
|
||||
export PYTHONPATH="${entrypoint}"
|
||||
|
||||
clear -x
|
||||
python3 "${entrypoint}/kiauh/main.py"
|
||||
}
|
||||
|
||||
check_if_ratos
|
||||
check_euid
|
||||
init_logfile
|
||||
set_globals
|
||||
kiauh_update_dialog
|
||||
read_kiauh_ini
|
||||
init_ini
|
||||
main
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from core.backup_manager import BACKUP_ROOT_DIR
|
||||
from core.constants import SYSTEMD
|
||||
|
||||
# repo
|
||||
@@ -20,7 +19,6 @@ CROWSNEST_SERVICE_NAME = "crowsnest.service"
|
||||
|
||||
# directories
|
||||
CROWSNEST_DIR = Path.home().joinpath("crowsnest")
|
||||
CROWSNEST_BACKUP_DIR = BACKUP_ROOT_DIR.joinpath("crowsnest-backups")
|
||||
|
||||
# files
|
||||
CROWSNEST_MULTI_CONFIG = CROWSNEST_DIR.joinpath("tools/.config")
|
||||
|
||||
@@ -15,7 +15,6 @@ from subprocess import CalledProcessError, run
|
||||
from typing import List
|
||||
|
||||
from components.crowsnest import (
|
||||
CROWSNEST_BACKUP_DIR,
|
||||
CROWSNEST_BIN_FILE,
|
||||
CROWSNEST_DIR,
|
||||
CROWSNEST_INSTALL_SCRIPT,
|
||||
@@ -26,8 +25,8 @@ from components.crowsnest import (
|
||||
CROWSNEST_SERVICE_NAME,
|
||||
)
|
||||
from components.klipper.klipper import Klipper
|
||||
from core.backup_manager.backup_manager import BackupManager
|
||||
from core.logger import DialogType, Logger
|
||||
from core.services.backup_service import BackupService
|
||||
from core.settings.kiauh_settings import KiauhSettings
|
||||
from core.types.component_status import ComponentStatus
|
||||
from utils.common import (
|
||||
@@ -127,11 +126,11 @@ def update_crowsnest() -> None:
|
||||
|
||||
settings = KiauhSettings()
|
||||
if settings.kiauh.backup_before_update:
|
||||
bm = BackupManager()
|
||||
bm.backup_directory(
|
||||
CROWSNEST_DIR.name,
|
||||
source=CROWSNEST_DIR,
|
||||
target=CROWSNEST_BACKUP_DIR,
|
||||
svc = BackupService()
|
||||
svc.backup_directory(
|
||||
source_path=CROWSNEST_DIR,
|
||||
target_path="crowsnest",
|
||||
backup_name="crowsnest",
|
||||
)
|
||||
|
||||
git_pull_wrapper(CROWSNEST_DIR)
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from core.backup_manager import BACKUP_ROOT_DIR
|
||||
|
||||
MODULE_PATH = Path(__file__).resolve().parent
|
||||
|
||||
KLIPPER_REPO_URL = "https://github.com/Klipper3d/klipper.git"
|
||||
@@ -27,7 +25,6 @@ KLIPPER_SERVICE_NAME = "klipper.service"
|
||||
KLIPPER_DIR = Path.home().joinpath("klipper")
|
||||
KLIPPER_KCONFIGS_DIR = Path.home().joinpath("klipper-kconfigs")
|
||||
KLIPPER_ENV_DIR = Path.home().joinpath("klippy-env")
|
||||
KLIPPER_BACKUP_DIR = BACKUP_ROOT_DIR.joinpath("klipper-backups")
|
||||
|
||||
# files
|
||||
KLIPPER_REQ_FILE = KLIPPER_DIR.joinpath("scripts/klippy-requirements.txt")
|
||||
|
||||
@@ -16,7 +16,6 @@ from subprocess import CalledProcessError, run
|
||||
from typing import Dict, List
|
||||
|
||||
from components.klipper import (
|
||||
KLIPPER_BACKUP_DIR,
|
||||
KLIPPER_DIR,
|
||||
KLIPPER_ENV_DIR,
|
||||
KLIPPER_INSTALL_SCRIPT,
|
||||
@@ -31,10 +30,10 @@ from components.webui_client.base_data import BaseWebClient
|
||||
from components.webui_client.client_config.client_config_setup import (
|
||||
create_client_config_symlink,
|
||||
)
|
||||
from core.backup_manager.backup_manager import BackupManager
|
||||
from core.constants import CURRENT_USER
|
||||
from core.instance_manager.base_instance import SUFFIX_BLACKLIST
|
||||
from core.logger import DialogType, Logger
|
||||
from core.services.backup_service import BackupService
|
||||
from core.submodules.simple_config_parser.src.simple_config_parser.simple_config_parser import (
|
||||
SimpleConfigParser,
|
||||
)
|
||||
@@ -198,9 +197,17 @@ def create_example_printer_cfg(
|
||||
|
||||
|
||||
def backup_klipper_dir() -> None:
|
||||
bm = BackupManager()
|
||||
bm.backup_directory("klipper", source=KLIPPER_DIR, target=KLIPPER_BACKUP_DIR)
|
||||
bm.backup_directory("klippy-env", source=KLIPPER_ENV_DIR, target=KLIPPER_BACKUP_DIR)
|
||||
svc = BackupService()
|
||||
svc.backup_directory(
|
||||
source_path=KLIPPER_DIR,
|
||||
backup_name="klipper",
|
||||
target_path="klipper",
|
||||
)
|
||||
svc.backup_directory(
|
||||
source_path=KLIPPER_ENV_DIR,
|
||||
backup_name="klippy-env",
|
||||
target_path="klipper",
|
||||
)
|
||||
|
||||
|
||||
def install_klipper_packages() -> None:
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
# ======================================================================= #
|
||||
from pathlib import Path
|
||||
|
||||
from core.backup_manager import BACKUP_ROOT_DIR
|
||||
from core.constants import SYSTEMD
|
||||
|
||||
# repo
|
||||
@@ -22,7 +21,6 @@ KLIPPERSCREEN_LOG_NAME = "KlipperScreen.log"
|
||||
# directories
|
||||
KLIPPERSCREEN_DIR = Path.home().joinpath("KlipperScreen")
|
||||
KLIPPERSCREEN_ENV_DIR = Path.home().joinpath(".KlipperScreen-env")
|
||||
KLIPPERSCREEN_BACKUP_DIR = BACKUP_ROOT_DIR.joinpath("klipperscreen-backups")
|
||||
|
||||
# files
|
||||
KLIPPERSCREEN_REQ_FILE = KLIPPERSCREEN_DIR.joinpath(
|
||||
|
||||
@@ -13,7 +13,6 @@ from typing import List
|
||||
|
||||
from components.klipper.klipper import Klipper
|
||||
from components.klipperscreen import (
|
||||
KLIPPERSCREEN_BACKUP_DIR,
|
||||
KLIPPERSCREEN_DIR,
|
||||
KLIPPERSCREEN_ENV_DIR,
|
||||
KLIPPERSCREEN_INSTALL_SCRIPT,
|
||||
@@ -25,10 +24,10 @@ from components.klipperscreen import (
|
||||
KLIPPERSCREEN_UPDATER_SECTION_NAME,
|
||||
)
|
||||
from components.moonraker.moonraker import Moonraker
|
||||
from core.backup_manager.backup_manager import BackupManager
|
||||
from core.constants import SYSTEMD
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
from core.logger import DialogType, Logger
|
||||
from core.services.backup_service import BackupService
|
||||
from core.settings.kiauh_settings import KiauhSettings
|
||||
from core.types.component_status import ComponentStatus
|
||||
from utils.common import (
|
||||
@@ -97,6 +96,7 @@ def install_klipperscreen() -> None:
|
||||
|
||||
|
||||
def patch_klipperscreen_update_manager(instances: List[Moonraker]) -> None:
|
||||
BackupService().backup_moonraker_conf()
|
||||
add_config_section(
|
||||
section=KLIPPERSCREEN_UPDATER_SECTION_NAME,
|
||||
instances=instances,
|
||||
@@ -183,6 +183,7 @@ def remove_klipperscreen() -> None:
|
||||
mr_instances: List[Moonraker] = get_instances(Moonraker)
|
||||
if mr_instances:
|
||||
Logger.print_status("Removing KlipperScreen from update manager ...")
|
||||
BackupService().backup_moonraker_conf()
|
||||
remove_config_section("update_manager KlipperScreen", mr_instances)
|
||||
Logger.print_ok("KlipperScreen successfully removed from update manager!")
|
||||
|
||||
@@ -193,14 +194,14 @@ def remove_klipperscreen() -> None:
|
||||
|
||||
|
||||
def backup_klipperscreen_dir() -> None:
|
||||
bm = BackupManager()
|
||||
bm.backup_directory(
|
||||
KLIPPERSCREEN_DIR.name,
|
||||
source=KLIPPERSCREEN_DIR,
|
||||
target=KLIPPERSCREEN_BACKUP_DIR,
|
||||
svc = BackupService()
|
||||
svc.backup_directory(
|
||||
source_path=KLIPPERSCREEN_DIR,
|
||||
backup_name="KlipperScreen",
|
||||
target_path="KlipperScreen",
|
||||
)
|
||||
bm.backup_directory(
|
||||
KLIPPERSCREEN_ENV_DIR.name,
|
||||
source=KLIPPERSCREEN_ENV_DIR,
|
||||
target=KLIPPERSCREEN_BACKUP_DIR,
|
||||
svc.backup_directory(
|
||||
source_path=KLIPPERSCREEN_ENV_DIR,
|
||||
backup_name="KlipperScreen-env",
|
||||
target_path="KlipperScreen",
|
||||
)
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from core.backup_manager import BACKUP_ROOT_DIR
|
||||
|
||||
MODULE_PATH = Path(__file__).resolve().parent
|
||||
|
||||
MOONRAKER_REPO_URL = "https://github.com/Arksine/moonraker.git"
|
||||
@@ -25,8 +23,6 @@ MOONRAKER_ENV_FILE_NAME = "moonraker.env"
|
||||
# directories
|
||||
MOONRAKER_DIR = Path.home().joinpath("moonraker")
|
||||
MOONRAKER_ENV_DIR = Path.home().joinpath("moonraker-env")
|
||||
MOONRAKER_BACKUP_DIR = BACKUP_ROOT_DIR.joinpath("moonraker-backups")
|
||||
MOONRAKER_DB_BACKUP_DIR = BACKUP_ROOT_DIR.joinpath("moonraker-db-backups")
|
||||
|
||||
# files
|
||||
MOONRAKER_INSTALL_SCRIPT = MOONRAKER_DIR.joinpath("scripts/install-moonraker.sh")
|
||||
|
||||
@@ -61,6 +61,9 @@ class SysDepsParser:
|
||||
version = distro_info.get("distro_version")
|
||||
if version:
|
||||
self.distro_version = _convert_version(version)
|
||||
self.vendor: str = ""
|
||||
if pathlib.Path("/etc/rpi-issue").is_file():
|
||||
self.vendor = "raspberry-pi"
|
||||
|
||||
def _parse_spec(self, full_spec: str) -> str | None:
|
||||
parts = full_spec.split(";", maxsplit=1)
|
||||
@@ -109,6 +112,9 @@ class SysDepsParser:
|
||||
elif req_var == "distro_id":
|
||||
left_op: str | Tuple[int | str, ...] = self.distro_id
|
||||
right_op = dep_parts[2].strip().strip("\"'")
|
||||
elif req_var == "vendor":
|
||||
left_op = self.vendor
|
||||
right_op = dep_parts[2].strip().strip("\"'")
|
||||
elif req_var == "distro_version":
|
||||
if not self.distro_version:
|
||||
logging.info(
|
||||
|
||||
@@ -14,8 +14,6 @@ from typing import Dict, List, Optional
|
||||
|
||||
from components.moonraker import (
|
||||
MODULE_PATH,
|
||||
MOONRAKER_BACKUP_DIR,
|
||||
MOONRAKER_DB_BACKUP_DIR,
|
||||
MOONRAKER_DEFAULT_PORT,
|
||||
MOONRAKER_DEPS_JSON_FILE,
|
||||
MOONRAKER_DIR,
|
||||
@@ -25,8 +23,8 @@ from components.moonraker import (
|
||||
from components.moonraker.moonraker import Moonraker
|
||||
from components.moonraker.utils.sysdeps_parser import SysDepsParser
|
||||
from components.webui_client.base_data import BaseWebClient
|
||||
from core.backup_manager.backup_manager import BackupManager
|
||||
from core.logger import Logger
|
||||
from core.services.backup_service import BackupService
|
||||
from core.submodules.simple_config_parser.src.simple_config_parser.simple_config_parser import (
|
||||
SimpleConfigParser,
|
||||
)
|
||||
@@ -168,21 +166,55 @@ def create_example_moonraker_conf(
|
||||
|
||||
|
||||
def backup_moonraker_dir() -> None:
|
||||
bm = BackupManager()
|
||||
bm.backup_directory("moonraker", source=MOONRAKER_DIR, target=MOONRAKER_BACKUP_DIR)
|
||||
bm.backup_directory(
|
||||
"moonraker-env", source=MOONRAKER_ENV_DIR, target=MOONRAKER_BACKUP_DIR
|
||||
svc = BackupService()
|
||||
svc.backup_directory(
|
||||
source_path=MOONRAKER_DIR, backup_name="moonraker", target_path="moonraker"
|
||||
)
|
||||
svc.backup_directory(
|
||||
source_path=MOONRAKER_ENV_DIR,
|
||||
backup_name="moonraker-env",
|
||||
target_path="moonraker",
|
||||
)
|
||||
|
||||
|
||||
def backup_moonraker_db_dir() -> None:
|
||||
instances: List[Moonraker] = get_instances(Moonraker)
|
||||
bm = BackupManager()
|
||||
svc = BackupService()
|
||||
|
||||
if not instances:
|
||||
# fallback: search for printer data directories in the user's home directory
|
||||
Logger.print_info("No Moonraker instances found via systemd services.")
|
||||
Logger.print_info(
|
||||
"Attempting to find printer data directories in home directory..."
|
||||
)
|
||||
|
||||
home_dir = Path.home()
|
||||
printer_data_dirs = []
|
||||
|
||||
for pattern in ["printer_data", "printer_*_data"]:
|
||||
for data_dir in home_dir.glob(pattern):
|
||||
if data_dir.is_dir():
|
||||
printer_data_dirs.append(data_dir)
|
||||
|
||||
if not printer_data_dirs:
|
||||
Logger.print_info("Unable to find directory to backup!")
|
||||
Logger.print_info("No printer data directories found in home directory.")
|
||||
return
|
||||
|
||||
for data_dir in printer_data_dirs:
|
||||
svc.backup_directory(
|
||||
source_path=data_dir.joinpath("database"),
|
||||
target_path=data_dir.name,
|
||||
backup_name="database",
|
||||
)
|
||||
|
||||
return
|
||||
|
||||
for instance in instances:
|
||||
name = f"database-{instance.data_dir.name}"
|
||||
bm.backup_directory(
|
||||
name, source=instance.db_dir, target=MOONRAKER_DB_BACKUP_DIR
|
||||
svc.backup_directory(
|
||||
source_path=instance.db_dir,
|
||||
target_path=f"{instance.data_dir.name}",
|
||||
backup_name="database",
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -34,7 +34,6 @@ class BaseWebClient(ABC):
|
||||
display_name: str
|
||||
client_dir: Path
|
||||
config_file: Path
|
||||
backup_dir: Path
|
||||
repo_path: str
|
||||
download_url: str
|
||||
nginx_config: Path
|
||||
@@ -52,6 +51,5 @@ class BaseWebClientConfig(ABC):
|
||||
display_name: str
|
||||
config_filename: str
|
||||
config_dir: Path
|
||||
backup_dir: Path
|
||||
repo_url: str
|
||||
config_section: str
|
||||
|
||||
@@ -14,6 +14,7 @@ from components.klipper.klipper import Klipper
|
||||
from components.moonraker.moonraker import Moonraker
|
||||
from components.webui_client.base_data import BaseWebClientConfig
|
||||
from core.logger import Logger
|
||||
from core.services.backup_service import BackupService
|
||||
from core.services.message_service import Message
|
||||
from core.types.color import Color
|
||||
from utils.config_utils import remove_config_section
|
||||
@@ -35,6 +36,8 @@ def run_client_config_removal(
|
||||
if run_remove_routines(client_config.config_dir):
|
||||
completion_msg.text.append(f"● {client_config.display_name} removed")
|
||||
|
||||
BackupService().backup_printer_config_dir()
|
||||
|
||||
completion_msg = remove_moonraker_config_section(
|
||||
completion_msg, client_config, mr_instances
|
||||
)
|
||||
|
||||
@@ -25,8 +25,8 @@ from components.webui_client.client_utils import (
|
||||
)
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
from core.logger import Logger
|
||||
from core.services.backup_service import BackupService
|
||||
from core.settings.kiauh_settings import KiauhSettings
|
||||
from utils.common import backup_printer_config_dir
|
||||
from utils.config_utils import add_config_section, add_config_section_at_top
|
||||
from utils.fs_utils import create_symlink
|
||||
from utils.git_utils import git_clone_wrapper, git_pull_wrapper
|
||||
@@ -57,7 +57,7 @@ def install_client_config(client_data: BaseWebClient, cfg_backup=True) -> None:
|
||||
create_client_config_symlink(client_config, kl_instances)
|
||||
|
||||
if cfg_backup:
|
||||
backup_printer_config_dir()
|
||||
BackupService().backup_printer_config_dir()
|
||||
|
||||
add_config_section(
|
||||
section=f"update_manager {client_config.name}",
|
||||
|
||||
@@ -16,9 +16,9 @@ from components.webui_client.base_data import (
|
||||
from components.webui_client.client_config.client_config_remove import (
|
||||
run_client_config_removal,
|
||||
)
|
||||
from core.backup_manager.backup_manager import BackupManager
|
||||
from core.constants import NGINX_SITES_AVAILABLE, NGINX_SITES_ENABLED
|
||||
from core.logger import Logger
|
||||
from core.services.backup_service import BackupService
|
||||
from core.services.message_service import Message
|
||||
from core.types.color import Color
|
||||
from utils.config_utils import remove_config_section
|
||||
@@ -43,8 +43,19 @@ def run_client_removal(
|
||||
kl_instances: List[Klipper] = get_instances(Klipper)
|
||||
|
||||
if backup_config:
|
||||
bm = BackupManager()
|
||||
if bm.backup_file(client.config_file):
|
||||
version = ""
|
||||
src = client.client_dir
|
||||
if src.joinpath(".version").exists():
|
||||
with open(src.joinpath(".version"), "r") as v:
|
||||
version = v.readlines()[0]
|
||||
|
||||
svc = BackupService()
|
||||
target_path = svc.backup_root.joinpath(f"{client.client_dir.name}_{version}")
|
||||
success = svc.backup_file(
|
||||
source_path=client.config_file,
|
||||
target_path=target_path,
|
||||
)
|
||||
if success:
|
||||
completion_msg.text.append(f"● {client.config_file.name} backup created")
|
||||
|
||||
if remove_client:
|
||||
@@ -56,6 +67,7 @@ def run_client_removal(
|
||||
if remove_client_nginx_logs(client, kl_instances):
|
||||
completion_msg.text.append("● NGINX logs removed")
|
||||
|
||||
BackupService().backup_moonraker_conf()
|
||||
section = f"update_manager {client_name}"
|
||||
handled_instances: List[Moonraker] = remove_config_section(
|
||||
section, mr_instances
|
||||
|
||||
@@ -37,9 +37,10 @@ from components.webui_client.client_utils import (
|
||||
)
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
from core.logger import DialogType, Logger
|
||||
from core.services.backup_service import BackupService
|
||||
from core.settings.kiauh_settings import KiauhSettings
|
||||
from core.types.color import Color
|
||||
from utils.common import backup_printer_config_dir, check_install_dependencies
|
||||
from utils.common import check_install_dependencies
|
||||
from utils.config_utils import add_config_section
|
||||
from utils.fs_utils import unzip
|
||||
from utils.input_utils import get_confirm
|
||||
@@ -97,7 +98,7 @@ def install_client(
|
||||
if enable_remotemode and client.client == WebClientType.MAINSAIL:
|
||||
enable_mainsail_remotemode()
|
||||
|
||||
backup_printer_config_dir()
|
||||
BackupService().backup_printer_config_dir()
|
||||
add_config_section(
|
||||
section=f"update_manager {client.name}",
|
||||
instances=mr_instances,
|
||||
|
||||
@@ -24,13 +24,13 @@ from components.webui_client.base_data import (
|
||||
from components.webui_client.client_dialogs import print_client_port_select_dialog
|
||||
from components.webui_client.fluidd_data import FluiddData
|
||||
from components.webui_client.mainsail_data import MainsailData
|
||||
from core.backup_manager.backup_manager import BackupManager
|
||||
from core.constants import (
|
||||
NGINX_CONFD,
|
||||
NGINX_SITES_AVAILABLE,
|
||||
NGINX_SITES_ENABLED,
|
||||
)
|
||||
from core.logger import Logger
|
||||
from core.services.backup_service import BackupService
|
||||
from core.settings.kiauh_settings import KiauhSettings, WebUiSettings
|
||||
from core.submodules.simple_config_parser.src.simple_config_parser.simple_config_parser import (
|
||||
SimpleConfigParser,
|
||||
@@ -118,7 +118,7 @@ def enable_mainsail_remotemode() -> None:
|
||||
c_json = MainsailData().client_dir.joinpath("config.json")
|
||||
with open(c_json, "r") as f:
|
||||
config_data = json.load(f)
|
||||
|
||||
|
||||
if config_data["instancesDB"] == "browser" or config_data["instancesDB"] == "json":
|
||||
Logger.print_info("Remote mode already configured. Skipped ...")
|
||||
return
|
||||
@@ -175,26 +175,39 @@ def get_remote_client_version(client: BaseWebClient) -> str | None:
|
||||
|
||||
|
||||
def backup_client_data(client: BaseWebClient) -> None:
|
||||
name = client.name
|
||||
version = ""
|
||||
src = client.client_dir
|
||||
dest = client.backup_dir
|
||||
if src.joinpath(".version").exists():
|
||||
with open(src.joinpath(".version"), "r") as v:
|
||||
version = v.readlines()[0]
|
||||
|
||||
with open(src.joinpath(".version"), "r") as v:
|
||||
version = v.readlines()[0]
|
||||
|
||||
bm = BackupManager()
|
||||
bm.backup_directory(f"{name}-{version}", src, dest)
|
||||
bm.backup_file(client.config_file, dest)
|
||||
bm.backup_file(NGINX_SITES_AVAILABLE.joinpath(name), dest)
|
||||
svc = BackupService()
|
||||
target_path = svc.backup_root.joinpath(f"{client.client_dir.name}_{version}")
|
||||
svc.backup_directory(
|
||||
source_path=client.client_dir,
|
||||
target_path=target_path,
|
||||
backup_name=client.name,
|
||||
)
|
||||
svc.backup_file(
|
||||
source_path=client.config_file,
|
||||
target_path=target_path,
|
||||
)
|
||||
|
||||
|
||||
def backup_client_config_data(client: BaseWebClient) -> None:
|
||||
client_config = client.client_config
|
||||
name = client_config.name
|
||||
source = client_config.config_dir
|
||||
target = client_config.backup_dir
|
||||
bm = BackupManager()
|
||||
bm.backup_directory(name, source, target)
|
||||
version = ""
|
||||
src = client.client_dir
|
||||
if src.joinpath(".version").exists():
|
||||
with open(src.joinpath(".version"), "r") as v:
|
||||
version = v.readlines()[0]
|
||||
|
||||
svc = BackupService()
|
||||
target_path = svc.backup_root.joinpath(f"{client.client_dir.name}_{version}")
|
||||
svc.backup_directory(
|
||||
source_path=client.client_config.config_dir,
|
||||
target_path=target_path,
|
||||
backup_name=client.client_config.name,
|
||||
)
|
||||
|
||||
|
||||
def get_existing_clients() -> List[BaseWebClient]:
|
||||
|
||||
@@ -18,7 +18,6 @@ from components.webui_client.base_data import (
|
||||
WebClientConfigType,
|
||||
WebClientType,
|
||||
)
|
||||
from core.backup_manager import BACKUP_ROOT_DIR
|
||||
from core.constants import NGINX_SITES_AVAILABLE
|
||||
|
||||
|
||||
@@ -30,7 +29,6 @@ class FluiddConfigWeb(BaseWebClientConfig):
|
||||
config_dir: Path = Path.home().joinpath("fluidd-config")
|
||||
config_filename: str = "fluidd.cfg"
|
||||
config_section: str = f"include {config_filename}"
|
||||
backup_dir: Path = BACKUP_ROOT_DIR.joinpath("fluidd-config-backups")
|
||||
repo_url: str = "https://github.com/fluidd-core/fluidd-config.git"
|
||||
|
||||
|
||||
@@ -43,7 +41,6 @@ class FluiddData(BaseWebClient):
|
||||
display_name: str = name.capitalize()
|
||||
client_dir: Path = Path.home().joinpath("fluidd")
|
||||
config_file: Path = client_dir.joinpath("config.json")
|
||||
backup_dir: Path = BACKUP_ROOT_DIR.joinpath("fluidd-backups")
|
||||
repo_path: str = "fluidd-core/fluidd"
|
||||
nginx_config: Path = NGINX_SITES_AVAILABLE.joinpath("fluidd")
|
||||
nginx_access_log: Path = Path("/var/log/nginx/fluidd-access.log")
|
||||
|
||||
@@ -18,7 +18,6 @@ from components.webui_client.base_data import (
|
||||
WebClientConfigType,
|
||||
WebClientType,
|
||||
)
|
||||
from core.backup_manager import BACKUP_ROOT_DIR
|
||||
from core.constants import NGINX_SITES_AVAILABLE
|
||||
|
||||
|
||||
@@ -30,7 +29,6 @@ class MainsailConfigWeb(BaseWebClientConfig):
|
||||
config_dir: Path = Path.home().joinpath("mainsail-config")
|
||||
config_filename: str = "mainsail.cfg"
|
||||
config_section: str = f"include {config_filename}"
|
||||
backup_dir: Path = BACKUP_ROOT_DIR.joinpath("mainsail-config-backups")
|
||||
repo_url: str = "https://github.com/mainsail-crew/mainsail-config.git"
|
||||
|
||||
|
||||
@@ -43,7 +41,6 @@ class MainsailData(BaseWebClient):
|
||||
display_name: str = name.capitalize()
|
||||
client_dir: Path = Path.home().joinpath("mainsail")
|
||||
config_file: Path = client_dir.joinpath("config.json")
|
||||
backup_dir: Path = BACKUP_ROOT_DIR.joinpath("mainsail-backups")
|
||||
repo_path: str = "mainsail-crew/mainsail"
|
||||
nginx_config: Path = NGINX_SITES_AVAILABLE.joinpath("mainsail")
|
||||
nginx_access_log: Path = Path("/var/log/nginx/mainsail-access.log")
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
# ======================================================================= #
|
||||
# Copyright (C) 2020 - 2025 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
|
||||
|
||||
BACKUP_ROOT_DIR = Path.home().joinpath("kiauh-backups")
|
||||
@@ -1,108 +0,0 @@
|
||||
# ======================================================================= #
|
||||
# Copyright (C) 2020 - 2025 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 __future__ import annotations
|
||||
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
|
||||
from core.backup_manager import BACKUP_ROOT_DIR
|
||||
from core.logger import Logger
|
||||
from utils.common import get_current_date
|
||||
|
||||
|
||||
class BackupManagerException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
# noinspection PyMethodMayBeStatic
|
||||
class BackupManager:
|
||||
def __init__(self, backup_root_dir: Path = BACKUP_ROOT_DIR):
|
||||
self._backup_root_dir: Path = backup_root_dir
|
||||
self._ignore_folders: List[str] = []
|
||||
|
||||
@property
|
||||
def backup_root_dir(self) -> Path:
|
||||
return self._backup_root_dir
|
||||
|
||||
@backup_root_dir.setter
|
||||
def backup_root_dir(self, value: Path):
|
||||
self._backup_root_dir = value
|
||||
|
||||
@property
|
||||
def ignore_folders(self) -> List[str]:
|
||||
return self._ignore_folders
|
||||
|
||||
@ignore_folders.setter
|
||||
def ignore_folders(self, value: List[str]):
|
||||
self._ignore_folders = value
|
||||
|
||||
def backup_file(
|
||||
self, file: Path, target: Path | None = None, custom_filename=None
|
||||
) -> bool:
|
||||
Logger.print_status(f"Creating backup of {file} ...")
|
||||
|
||||
if not file.exists():
|
||||
Logger.print_info("File does not exist! Skipping ...")
|
||||
return False
|
||||
|
||||
target = self.backup_root_dir if target is None else target
|
||||
|
||||
if Path(file).is_file():
|
||||
date = get_current_date().get("date")
|
||||
time = get_current_date().get("time")
|
||||
filename = f"{file.stem}-{date}-{time}{file.suffix}"
|
||||
filename = custom_filename if custom_filename is not None else filename
|
||||
try:
|
||||
Path(target).mkdir(exist_ok=True)
|
||||
shutil.copyfile(file, target.joinpath(filename))
|
||||
Logger.print_ok("Backup successful!")
|
||||
return True
|
||||
except OSError as e:
|
||||
Logger.print_error(f"Unable to backup '{file}':\n{e}")
|
||||
return False
|
||||
else:
|
||||
Logger.print_info(f"File '{file}' not found ...")
|
||||
return False
|
||||
|
||||
def backup_directory(
|
||||
self, name: str, source: Path, target: Path | None = None
|
||||
) -> Path | None:
|
||||
Logger.print_status(f"Creating backup of {name} in {target} ...")
|
||||
|
||||
if source is None or not Path(source).exists():
|
||||
Logger.print_info("Source directory does not exist! Skipping ...")
|
||||
return None
|
||||
|
||||
target = self.backup_root_dir if target is None else target
|
||||
try:
|
||||
date = get_current_date().get("date")
|
||||
time = get_current_date().get("time")
|
||||
backup_target = target.joinpath(f"{name.lower()}-{date}-{time}")
|
||||
shutil.copytree(
|
||||
source,
|
||||
backup_target,
|
||||
ignore=self.ignore_folders_func,
|
||||
ignore_dangling_symlinks=True,
|
||||
)
|
||||
Logger.print_ok("Backup successful!")
|
||||
|
||||
return backup_target
|
||||
|
||||
except OSError as e:
|
||||
Logger.print_error(f"Unable to backup directory '{source}':\n{e}")
|
||||
raise BackupManagerException(f"Unable to backup directory '{source}':\n{e}")
|
||||
|
||||
def ignore_folders_func(self, dirpath, filenames) -> List[str]:
|
||||
return (
|
||||
[f for f in filenames if f in self._ignore_folders]
|
||||
if self._ignore_folders
|
||||
else []
|
||||
)
|
||||
@@ -11,8 +11,6 @@ import os
|
||||
import pwd
|
||||
from pathlib import Path
|
||||
|
||||
from core.backup_manager import BACKUP_ROOT_DIR
|
||||
|
||||
# global dependencies
|
||||
GLOBAL_DEPS = ["git", "wget", "curl", "unzip", "dfu-util", "python3-virtualenv"]
|
||||
|
||||
@@ -24,7 +22,6 @@ CURRENT_USER = pwd.getpwuid(os.getuid())[0]
|
||||
|
||||
# dirs
|
||||
SYSTEMD = Path("/etc/systemd/system")
|
||||
PRINTER_DATA_BACKUP_DIR = BACKUP_ROOT_DIR.joinpath("printer-data-backups")
|
||||
NGINX_SITES_AVAILABLE = Path("/etc/nginx/sites-available")
|
||||
NGINX_SITES_ENABLED = Path("/etc/nginx/sites-enabled")
|
||||
NGINX_CONFD = Path("/etc/nginx/conf.d")
|
||||
|
||||
@@ -16,8 +16,9 @@ from typing import List
|
||||
|
||||
from utils.fs_utils import get_data_dir
|
||||
|
||||
SUFFIX_BLACKLIST: List[str] = ["None", "mcu", "obico", "bambu", "companion"]
|
||||
|
||||
# suffixes that are not allowed to be used for instances
|
||||
# because they would cause conflicts with other components or are reserved
|
||||
SUFFIX_BLACKLIST: List[str] = ["None", "mcu", "obico", "bambu", "companion", "hmi"]
|
||||
|
||||
@dataclass(repr=True)
|
||||
class BaseInstance:
|
||||
|
||||
@@ -25,8 +25,8 @@ from components.webui_client.fluidd_data import FluiddData
|
||||
from components.webui_client.mainsail_data import MainsailData
|
||||
from core.menus import Option
|
||||
from core.menus.base_menu import BaseMenu
|
||||
from core.services.backup_service import BackupService
|
||||
from core.types.color import Color
|
||||
from utils.common import backup_printer_config_dir
|
||||
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
@@ -86,7 +86,7 @@ class BackupMenu(BaseMenu):
|
||||
backup_moonraker_dir()
|
||||
|
||||
def backup_printer_config(self, **kwargs) -> None:
|
||||
backup_printer_config_dir()
|
||||
BackupService().backup_printer_config_dir()
|
||||
|
||||
def backup_moonraker_db(self, **kwargs) -> None:
|
||||
backup_moonraker_db_dir()
|
||||
|
||||
189
kiauh/core/services/backup_service.py
Normal file
189
kiauh/core/services/backup_service.py
Normal file
@@ -0,0 +1,189 @@
|
||||
# ======================================================================= #
|
||||
# Copyright (C) 2020 - 2025 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 __future__ import annotations
|
||||
|
||||
import shutil
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import List, Optional
|
||||
|
||||
from components.klipper.klipper import Klipper
|
||||
from components.moonraker.moonraker import Moonraker
|
||||
from core.logger import Logger
|
||||
from utils.instance_utils import get_instances
|
||||
|
||||
|
||||
class BackupService:
|
||||
def __init__(self):
|
||||
self._backup_root = Path.home().joinpath("kiauh_backups")
|
||||
|
||||
@property
|
||||
def backup_root(self) -> Path:
|
||||
return self._backup_root
|
||||
|
||||
@property
|
||||
def timestamp(self) -> str:
|
||||
return datetime.now().strftime("%Y%m%d-%H%M%S")
|
||||
|
||||
################################################
|
||||
# GENERIC BACKUP METHODS
|
||||
################################################
|
||||
|
||||
def backup_file(
|
||||
self,
|
||||
source_path: Path,
|
||||
target_path: Optional[Path | str] = None,
|
||||
target_name: Optional[str] = None,
|
||||
) -> bool:
|
||||
source_path = Path(source_path)
|
||||
|
||||
Logger.print_status(f"Creating backup of {source_path} ...")
|
||||
|
||||
if not source_path.exists():
|
||||
Logger.print_info(
|
||||
f"File '{source_path}' does not exist! Skipping backup..."
|
||||
)
|
||||
return False
|
||||
|
||||
if not source_path.is_file():
|
||||
Logger.print_info(f"'{source_path}' is not a file! Skipping backup...")
|
||||
return False
|
||||
|
||||
try:
|
||||
self._backup_root.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
filename = (
|
||||
target_name
|
||||
or f"{source_path.stem}_{self.timestamp}{source_path.suffix}"
|
||||
)
|
||||
if target_path is not None:
|
||||
backup_path = self._backup_root.joinpath(target_path, filename)
|
||||
else:
|
||||
backup_path = self._backup_root.joinpath(filename)
|
||||
|
||||
backup_path.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copy2(source_path, backup_path)
|
||||
|
||||
Logger.print_ok(
|
||||
f"Successfully backed up '{source_path}' to '{backup_path}'"
|
||||
)
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
Logger.print_error(f"Failed to backup '{source_path}': {e}")
|
||||
return False
|
||||
|
||||
def backup_directory(
|
||||
self,
|
||||
source_path: Path,
|
||||
backup_name: str,
|
||||
target_path: Optional[Path | str] = None,
|
||||
) -> Optional[Path]:
|
||||
source_path = Path(source_path)
|
||||
|
||||
Logger.print_status(f"Creating backup of {source_path} ...")
|
||||
|
||||
if not source_path.exists():
|
||||
Logger.print_info(
|
||||
f"Directory '{source_path}' does not exist! Skipping backup..."
|
||||
)
|
||||
return None
|
||||
|
||||
if not source_path.is_dir():
|
||||
Logger.print_info(f"'{source_path}' is not a directory! Skipping backup...")
|
||||
return None
|
||||
|
||||
try:
|
||||
self._backup_root.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
backup_dir_name = f"{backup_name}_{self.timestamp}"
|
||||
|
||||
if target_path is not None:
|
||||
backup_path = self._backup_root.joinpath(target_path, backup_dir_name)
|
||||
else:
|
||||
backup_path = self._backup_root.joinpath(backup_dir_name)
|
||||
|
||||
shutil.copytree(source_path, backup_path)
|
||||
|
||||
Logger.print_ok(
|
||||
f"Successfully backed up '{source_path}' to '{backup_path}'"
|
||||
)
|
||||
return backup_path
|
||||
|
||||
except Exception as e:
|
||||
Logger.print_error(f"Failed to backup directory '{source_path}': {e}")
|
||||
return None
|
||||
|
||||
################################################
|
||||
# SPECIFIC BACKUP METHODS
|
||||
################################################
|
||||
|
||||
def backup_printer_cfg(self):
|
||||
klipper_instances: List[Klipper] = get_instances(Klipper)
|
||||
for instance in klipper_instances:
|
||||
target_path: Path = self._backup_root.joinpath(
|
||||
instance.data_dir.name, f"config_{self.timestamp}"
|
||||
)
|
||||
self.backup_file(
|
||||
source_path=instance.cfg_file,
|
||||
target_path=target_path,
|
||||
target_name=instance.cfg_file.name,
|
||||
)
|
||||
|
||||
def backup_moonraker_conf(self):
|
||||
moonraker_instances: List[Moonraker] = get_instances(Moonraker)
|
||||
for instance in moonraker_instances:
|
||||
target_path: Path = self._backup_root.joinpath(
|
||||
instance.data_dir.name, f"config_{self.timestamp}"
|
||||
)
|
||||
self.backup_file(
|
||||
source_path=instance.cfg_file,
|
||||
target_path=target_path,
|
||||
target_name=instance.cfg_file.name,
|
||||
)
|
||||
|
||||
def backup_printer_config_dir(self) -> None:
|
||||
instances: List[Klipper] = get_instances(Klipper)
|
||||
if not instances:
|
||||
# fallback: search for printer data directories in the user's home directory
|
||||
Logger.print_info("No Klipper instances found via systemd services.")
|
||||
Logger.print_info(
|
||||
"Attempting to find printer data directories in home directory..."
|
||||
)
|
||||
|
||||
home_dir = Path.home()
|
||||
printer_data_dirs = []
|
||||
|
||||
for pattern in ["printer_data", "printer_*_data"]:
|
||||
for data_dir in home_dir.glob(pattern):
|
||||
if data_dir.is_dir():
|
||||
printer_data_dirs.append(data_dir)
|
||||
|
||||
if not printer_data_dirs:
|
||||
Logger.print_info("Unable to find directory to backup!")
|
||||
Logger.print_info(
|
||||
"No printer data directories found in home directory."
|
||||
)
|
||||
return
|
||||
|
||||
for data_dir in printer_data_dirs:
|
||||
self.backup_directory(
|
||||
source_path=data_dir.joinpath("config"),
|
||||
target_path=data_dir.name,
|
||||
backup_name="config",
|
||||
)
|
||||
|
||||
return
|
||||
|
||||
for instance in instances:
|
||||
self.backup_directory(
|
||||
source_path=instance.base.cfg_dir,
|
||||
target_path=f"{instance.data_dir.name}",
|
||||
backup_name="config",
|
||||
)
|
||||
@@ -14,8 +14,8 @@ from typing import Any, Callable, List, TypeVar
|
||||
|
||||
from components.klipper import KLIPPER_REPO_URL
|
||||
from components.moonraker import MOONRAKER_REPO_URL
|
||||
from core.backup_manager.backup_manager import BackupManager
|
||||
from core.logger import DialogType, Logger
|
||||
from core.services.backup_service import BackupService
|
||||
from core.submodules.simple_config_parser.src.simple_config_parser.simple_config_parser import (
|
||||
SimpleConfigParser,
|
||||
)
|
||||
@@ -374,8 +374,8 @@ class KiauhSettings:
|
||||
kill()
|
||||
|
||||
def _migrate_repo_config(self) -> None:
|
||||
bm = BackupManager()
|
||||
if not bm.backup_file(CUSTOM_CFG):
|
||||
svc = BackupService()
|
||||
if not svc.backup_file(CUSTOM_CFG):
|
||||
Logger.print_dialog(
|
||||
DialogType.ERROR,
|
||||
[
|
||||
|
||||
@@ -12,6 +12,7 @@ Specialized for handling Klipper style config files.
|
||||
- Option Block: A line starting with a word, followed by a `:` or `=` and a newline
|
||||
- Comment: A line starting with a `#` or `;`
|
||||
- Blank: A line containing only whitespace characters
|
||||
- SaveConfig: Klippers auto-generated SAVE_CONFIG section that can be found at the very end of the config file
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -49,6 +49,9 @@ LINE_COMMENT_RE = re.compile(r"^\s*[#;].*")
|
||||
# - the line MUST contain only whitespace characters
|
||||
EMPTY_LINE_RE = re.compile(r"^\s*$")
|
||||
|
||||
SAVE_CONFIG_START_RE = re.compile(r"^#\*# <-+ SAVE_CONFIG -+>$")
|
||||
SAVE_CONFIG_CONTENT_RE = re.compile(r"^#\*#.*$")
|
||||
|
||||
BOOLEAN_STATES = {
|
||||
"1": True,
|
||||
"yes": True,
|
||||
|
||||
@@ -18,7 +18,7 @@ from ..simple_config_parser.constants import (
|
||||
LINE_COMMENT_RE,
|
||||
OPTION_RE,
|
||||
OPTIONS_BLOCK_START_RE,
|
||||
SECTION_RE, LineType, INDENT,
|
||||
SECTION_RE, LineType, INDENT, SAVE_CONFIG_START_RE, SAVE_CONFIG_CONTENT_RE,
|
||||
)
|
||||
|
||||
_UNSET = object()
|
||||
@@ -61,25 +61,34 @@ class SimpleConfigParser:
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.header: List[str] = []
|
||||
self.save_config_block: List[str] = []
|
||||
self.config: Dict = {}
|
||||
self.current_section: str | None = None
|
||||
self.current_opt_block: str | None = None
|
||||
self.in_option_block: bool = False
|
||||
|
||||
def _match_section(self, line: str) -> bool:
|
||||
"""Wheter or not the given line matches the definition of a section"""
|
||||
"""Whether the given line matches the definition of a section"""
|
||||
return SECTION_RE.match(line) is not None
|
||||
|
||||
def _match_option(self, line: str) -> bool:
|
||||
"""Wheter or not the given line matches the definition of an option"""
|
||||
"""Whether the given line matches the definition of an option"""
|
||||
return OPTION_RE.match(line) is not None
|
||||
|
||||
def _match_options_block_start(self, line: str) -> bool:
|
||||
"""Wheter or not the given line matches the definition of a multiline option"""
|
||||
"""Whether the given line matches the definition of a multiline option"""
|
||||
return OPTIONS_BLOCK_START_RE.match(line) is not None
|
||||
|
||||
def _match_save_config_start(self, line: str) -> bool:
|
||||
"""Whether the given line matches the definition of a save config start"""
|
||||
return SAVE_CONFIG_START_RE.match(line) is not None
|
||||
|
||||
def _match_save_config_content(self, line: str) -> bool:
|
||||
"""Whether the given line matches the definition of a save config content"""
|
||||
return SAVE_CONFIG_CONTENT_RE.match(line) is not None
|
||||
|
||||
def _match_line_comment(self, line: str) -> bool:
|
||||
"""Wheter or not the given line matches the definition of a comment"""
|
||||
"""Whether the given line matches the definition of a comment"""
|
||||
return LINE_COMMENT_RE.match(line) is not None
|
||||
|
||||
def _match_empty_line(self, line: str) -> bool:
|
||||
@@ -124,6 +133,14 @@ class SimpleConfigParser:
|
||||
element["value"].append(line.strip()) # indentation is removed
|
||||
break
|
||||
|
||||
elif self._match_save_config_start(line):
|
||||
self.current_opt_block = None
|
||||
self.save_config_block.append(line)
|
||||
|
||||
elif self._match_save_config_content(line):
|
||||
self.current_opt_block = None
|
||||
self.save_config_block.append(line)
|
||||
|
||||
elif self._match_empty_line(line) or self._match_line_comment(line):
|
||||
self.current_opt_block = None
|
||||
|
||||
@@ -185,6 +202,11 @@ class SimpleConfigParser:
|
||||
if not last_line.endswith("\n"):
|
||||
f.write("\n")
|
||||
|
||||
if self.save_config_block:
|
||||
for line in self.save_config_block:
|
||||
f.write(line)
|
||||
f.write("\n")
|
||||
|
||||
def get_sections(self) -> List[str]:
|
||||
"""Return a list of all section names, but exclude any section starting with '#_'"""
|
||||
return list(
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
# a comment at the very top
|
||||
# should be treated as the file header
|
||||
|
||||
# up to the first section, including all blank lines
|
||||
|
||||
[section_1]
|
||||
option_1: value_1
|
||||
option_1_1: True # this is a boolean
|
||||
option_1_2: 5 ; this is an integer
|
||||
option_1_3: 1.123 #;this is a float
|
||||
|
||||
[section_2] ; comment
|
||||
option_2: value_2
|
||||
|
||||
; comment
|
||||
|
||||
[section_3]
|
||||
option_3: value_3 # comment
|
||||
|
||||
[section_4]
|
||||
# comment
|
||||
option_4: value_4
|
||||
|
||||
[section number 5]
|
||||
#option_5: value_5
|
||||
option_5 = this.is.value-5
|
||||
multi_option:
|
||||
# these are multi-line values
|
||||
value_5_1
|
||||
value_5_2 ; here is a comment
|
||||
value_5_3
|
||||
option_5_1: value_5_1
|
||||
|
||||
[gcode_macro M117]
|
||||
rename_existing: M117.1
|
||||
gcode:
|
||||
{% if rawparams %}
|
||||
{% set escaped_msg = rawparams.split(';', 1)[0].split('\x23', 1)[0]|replace('"', '\\"') %}
|
||||
SET_DISPLAY_TEXT MSG="{escaped_msg}"
|
||||
RESPOND TYPE=command MSG="{escaped_msg}"
|
||||
{% else %}
|
||||
SET_DISPLAY_TEXT
|
||||
{% endif %}
|
||||
|
||||
# SDCard 'looping' (aka Marlin M808 commands) support
|
||||
#
|
||||
# Support SDCard looping
|
||||
[sdcard_loop]
|
||||
[gcode_macro M486]
|
||||
gcode:
|
||||
# Parameters known to M486 are as follows:
|
||||
# [C<flag>] Cancel the current object
|
||||
# [P<index>] Cancel the object with the given index
|
||||
# [S<index>] Set the index of the current object.
|
||||
# If the object with the given index has been canceled, this will cause
|
||||
# the firmware to skip to the next object. The value -1 is used to
|
||||
# indicate something that isn’t an object and shouldn’t be skipped.
|
||||
# [T<count>] Reset the state and set the number of objects
|
||||
# [U<index>] Un-cancel the object with the given index. This command will be
|
||||
# ignored if the object has already been skipped
|
||||
|
||||
{% if 'exclude_object' not in printer %}
|
||||
{action_raise_error("[exclude_object] is not enabled")}
|
||||
{% endif %}
|
||||
|
||||
{% if 'T' in params %}
|
||||
EXCLUDE_OBJECT RESET=1
|
||||
|
||||
{% for i in range(params.T | int) %}
|
||||
EXCLUDE_OBJECT_DEFINE NAME={i}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% if 'C' in params %}
|
||||
EXCLUDE_OBJECT CURRENT=1
|
||||
{% endif %}
|
||||
|
||||
{% if 'P' in params %}
|
||||
EXCLUDE_OBJECT NAME={params.P}
|
||||
{% endif %}
|
||||
|
||||
{% if 'S' in params %}
|
||||
{% if params.S == '-1' %}
|
||||
{% if printer.exclude_object.current_object %}
|
||||
EXCLUDE_OBJECT_END NAME={printer.exclude_object.current_object}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
EXCLUDE_OBJECT_START NAME={params.S}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if 'U' in params %}
|
||||
EXCLUDE_OBJECT RESET=1 NAME={params.U}
|
||||
{% endif %}
|
||||
|
||||
#*# <---------------------- SAVE_CONFIG ---------------------->
|
||||
#*# DO NOT EDIT THIS BLOCK OR BELOW. The contents are auto-generated.
|
||||
#*#
|
||||
#*# [bed_mesh default]
|
||||
#*# version = 1
|
||||
#*# points =
|
||||
#*# -0.152500, -0.133125, -0.113125, -0.159375, -0.232500
|
||||
#*# -0.095000, -0.078750, -0.068125, -0.133125, -0.235000
|
||||
#*# -0.092500, -0.040625, 0.004375, -0.077500, -0.193125
|
||||
#*# -0.073750, 0.023750, 0.085625, 0.026875, -0.085000
|
||||
#*# -0.140625, 0.038125, 0.126250, 0.097500, 0.003750
|
||||
#*# tension = 0.2
|
||||
#*# min_x = 26.0
|
||||
#*# algo = bicubic
|
||||
#*# y_count = 5
|
||||
#*# mesh_y_pps = 2
|
||||
#*# min_y = 5.0
|
||||
#*# x_count = 5
|
||||
#*# max_y = 174.0
|
||||
#*# mesh_x_pps = 2
|
||||
#*# max_x = 194.0
|
||||
@@ -0,0 +1,22 @@
|
||||
#*# any content
|
||||
#*#
|
||||
#*# DO NOT EDIT THIS BLOCK OR BELOW. The contents are auto-generated.
|
||||
#*#
|
||||
#*# [bed_mesh default]
|
||||
#*# version = 1
|
||||
#*# points =
|
||||
#*# -0.152500, -0.133125, -0.113125, -0.159375, -0.232500
|
||||
#*# -0.095000, -0.078750, -0.068125, -0.133125, -0.235000
|
||||
#*# -0.092500, -0.040625, 0.004375, -0.077500, -0.193125
|
||||
#*# -0.073750, 0.023750, 0.085625, 0.026875, -0.085000
|
||||
#*# -0.140625, 0.038125, 0.126250, 0.097500, 0.003750
|
||||
#*# tension = 0.2
|
||||
#*# min_x = 26.0
|
||||
#*# algo = bicubic
|
||||
#*# y_count = 5
|
||||
#*# mesh_y_pps = 2
|
||||
#*# min_y = 5.0
|
||||
#*# x_count = 5
|
||||
#*# max_y = 174.0
|
||||
#*# mesh_x_pps = 2
|
||||
#*# max_x = 194.0
|
||||
@@ -0,0 +1,6 @@
|
||||
#*# leading space prevents match
|
||||
random
|
||||
*# not starting with hash-star-hash
|
||||
# *# spaced out
|
||||
<- SAVE_CONFIG ->
|
||||
;#*# semicolon first
|
||||
@@ -0,0 +1,37 @@
|
||||
# ======================================================================= #
|
||||
# Copyright (C) 2024 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# https://github.com/dw-0/simple-config-parser #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
# ======================================================================= #
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from src.simple_config_parser.simple_config_parser import SimpleConfigParser
|
||||
from tests.utils import load_testdata_from_file
|
||||
|
||||
BASE_DIR = Path(__file__).parent.joinpath("test_data")
|
||||
MATCHING_TEST_DATA_PATH = BASE_DIR.joinpath("matching_data.txt")
|
||||
NON_MATCHING_TEST_DATA_PATH = BASE_DIR.joinpath("non_matching_data.txt")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def parser():
|
||||
return SimpleConfigParser()
|
||||
|
||||
|
||||
def test_matching_lines(parser):
|
||||
"""Alle Zeilen in matching_data.txt sollen als Save-Config-Content erkannt werden."""
|
||||
matching_lines = load_testdata_from_file(MATCHING_TEST_DATA_PATH)
|
||||
for line in matching_lines:
|
||||
assert parser._match_save_config_content(line) is True, f"Line should be a save config content: {line!r}"
|
||||
|
||||
|
||||
def test_non_matching_lines(parser):
|
||||
"""Alle Zeilen in non_matching_data.txt sollen NICHT als Save-Config-Content erkannt werden."""
|
||||
non_matching_lines = load_testdata_from_file(NON_MATCHING_TEST_DATA_PATH)
|
||||
for line in non_matching_lines:
|
||||
assert parser._match_save_config_content(line) is False, f"Line should not be a save config content: {line!r}"
|
||||
@@ -0,0 +1,6 @@
|
||||
#*# <- SAVE_CONFIG ->
|
||||
#*# <---- SAVE_CONFIG ---->
|
||||
#*# <------------------- SAVE_CONFIG ------------------->
|
||||
#*# <---------------------- SAVE_CONFIG ---------------------->
|
||||
#*# <----- SAVE_CONFIG ->
|
||||
#*# <- SAVE_CONFIG ----------------->
|
||||
@@ -0,0 +1,13 @@
|
||||
#*#<- SAVE_CONFIG ->
|
||||
#*# <-SAVE_CONFIG ->
|
||||
#*# <- SAVE_CONFIG->
|
||||
#*# <- SAVE_CONFIG -> extra
|
||||
#*# SAVE_CONFIG ---->
|
||||
#*# < SAVE_CONFIG >
|
||||
# *# <- SAVE_CONFIG ->
|
||||
<- SAVE_CONFIG ->
|
||||
random text
|
||||
#*# <---------------------- SAVE_CONFIG ---------------------->
|
||||
#*# <---------------------- SAVE_CONFIG ----------------------> #*#
|
||||
#*# <-------------------------------------------->
|
||||
#*# SAVE_CONFIG
|
||||
@@ -0,0 +1,37 @@
|
||||
# ======================================================================= #
|
||||
# Copyright (C) 2024 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# https://github.com/dw-0/simple-config-parser #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
# ======================================================================= #
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from src.simple_config_parser.simple_config_parser import SimpleConfigParser
|
||||
from tests.utils import load_testdata_from_file
|
||||
|
||||
BASE_DIR = Path(__file__).parent.joinpath("test_data")
|
||||
MATCHING_TEST_DATA_PATH = BASE_DIR.joinpath("matching_data.txt")
|
||||
NON_MATCHING_TEST_DATA_PATH = BASE_DIR.joinpath("non_matching_data.txt")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def parser():
|
||||
return SimpleConfigParser()
|
||||
|
||||
|
||||
def test_matching_lines(parser):
|
||||
"""Test that all lines in the matching data file are correctly identified as save config start lines."""
|
||||
matching_lines = load_testdata_from_file(MATCHING_TEST_DATA_PATH)
|
||||
for line in matching_lines:
|
||||
assert parser._match_save_config_start(line) is True, f"Line should be a save config start: {line!r}"
|
||||
|
||||
|
||||
def test_non_matching_lines(parser):
|
||||
"""Test that all lines in the non-matching data file are correctly identified as not save config start lines."""
|
||||
non_matching_lines = load_testdata_from_file(NON_MATCHING_TEST_DATA_PATH)
|
||||
for line in non_matching_lines:
|
||||
assert parser._match_save_config_start(line) is False, f"Line should not be a save config start: {line!r}"
|
||||
@@ -13,7 +13,7 @@ from src.simple_config_parser.simple_config_parser import SimpleConfigParser
|
||||
from tests.utils import load_testdata_from_file
|
||||
|
||||
BASE_DIR = Path(__file__).parent.parent.joinpath("assets")
|
||||
CONFIG_FILES = ["test_config_1.cfg", "test_config_2.cfg", "test_config_3.cfg"]
|
||||
CONFIG_FILES = ["test_config_1.cfg", "test_config_2.cfg", "test_config_3.cfg", "test_config_4.cfg"]
|
||||
|
||||
|
||||
@pytest.fixture(params=CONFIG_FILES)
|
||||
|
||||
@@ -150,9 +150,9 @@ class ExtensionSubmenu(BaseMenu):
|
||||
if website or repo:
|
||||
links_lines: List[str] = ["Links:"]
|
||||
if website:
|
||||
links_lines.append(f"- Website: {website}")
|
||||
links_lines.append(f"● {website}")
|
||||
if repo:
|
||||
links_lines.append(f"- GitHub: {repo}")
|
||||
links_lines.append(f"● {repo}")
|
||||
|
||||
links_text = Logger.format_content(
|
||||
links_lines,
|
||||
|
||||
@@ -9,12 +9,13 @@
|
||||
|
||||
import os
|
||||
import shutil
|
||||
from datetime import datetime
|
||||
from typing import List
|
||||
|
||||
from components.klipper.klipper import Klipper
|
||||
from core.backup_manager.backup_manager import BackupManager
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
from core.logger import Logger
|
||||
from core.services.backup_service import BackupService
|
||||
from core.submodules.simple_config_parser.src.simple_config_parser.simple_config_parser import (
|
||||
SimpleConfigParser,
|
||||
)
|
||||
@@ -109,11 +110,13 @@ class GcodeShellCmdExtension(BaseExtension):
|
||||
Logger.warn(f"Unable to create example config: {e}")
|
||||
|
||||
# backup each printer.cfg before modification
|
||||
bm = BackupManager()
|
||||
svc = BackupService()
|
||||
timestamp = datetime.now().strftime("%Y%m%d-%H%M%S")
|
||||
for instance in instances:
|
||||
bm.backup_file(
|
||||
instance.cfg_file,
|
||||
custom_filename=f"{instance.suffix}.printer.cfg",
|
||||
svc.backup_file(
|
||||
source_path=instance.cfg_file,
|
||||
target_path=f"{instance.data_dir.name}/config_{timestamp}",
|
||||
target_name=instance.cfg_file.name,
|
||||
)
|
||||
|
||||
# add section to printer.cfg if not already defined
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
"module": "gcode_shell_cmd_extension",
|
||||
"maintained_by": "dw-0",
|
||||
"display_name": "G-Code Shell Command",
|
||||
"description": ["Run a shell commands from gcode."]
|
||||
"description": ["Run a shell commands from gcode."],
|
||||
"updates": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
"maintained_by": "Staubgeborener",
|
||||
"display_name": "Klipper-Backup",
|
||||
"description": ["Backup all your Klipper files to GitHub"],
|
||||
"website": "https://klipperbackup.xyz",
|
||||
"repo": "https://github.com/Staubgeborener/klipper-backup",
|
||||
"updates": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
"module": "mainsail_theme_installer_extension",
|
||||
"maintained_by": "dw-0",
|
||||
"display_name": "Mainsail Theme Installer",
|
||||
"description": ["Install Mainsail Themes maintained by the Mainsail community."]
|
||||
"description": ["Install Mainsail Themes maintained by the Mainsail community."],
|
||||
"website": "https://docs.mainsail.xyz/theming/themes",
|
||||
"updates": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from core.backup_manager import BACKUP_ROOT_DIR
|
||||
from core.constants import SYSTEMD
|
||||
|
||||
# repo
|
||||
@@ -23,7 +22,6 @@ MOBILERAKER_LOG_NAME = "mobileraker.log"
|
||||
# directories
|
||||
MOBILERAKER_DIR = Path.home().joinpath("mobileraker_companion")
|
||||
MOBILERAKER_ENV_DIR = Path.home().joinpath("mobileraker-env")
|
||||
MOBILERAKER_BACKUP_DIR = BACKUP_ROOT_DIR.joinpath("mobileraker-backups")
|
||||
|
||||
# files
|
||||
MOBILERAKER_INSTALL_SCRIPT = MOBILERAKER_DIR.joinpath("scripts/install.sh")
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
"description": [
|
||||
"Companion for Mobileraker, enabling push notification for Klipper using Moonraker."
|
||||
],
|
||||
"repo": "https://github.com/Clon1998/mobileraker_companion",
|
||||
"updates": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,13 +13,12 @@ from typing import List
|
||||
|
||||
from components.klipper.klipper import Klipper
|
||||
from components.moonraker.moonraker import Moonraker
|
||||
from core.backup_manager.backup_manager import BackupManager
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
from core.logger import DialogType, Logger
|
||||
from core.services.backup_service import BackupService
|
||||
from core.settings.kiauh_settings import KiauhSettings
|
||||
from extensions.base_extension import BaseExtension
|
||||
from extensions.mobileraker import (
|
||||
MOBILERAKER_BACKUP_DIR,
|
||||
MOBILERAKER_DIR,
|
||||
MOBILERAKER_ENV_DIR,
|
||||
MOBILERAKER_INSTALL_SCRIPT,
|
||||
@@ -152,6 +151,7 @@ class MobilerakerExtension(BaseExtension):
|
||||
Logger.print_status(
|
||||
"Removing Mobileraker's companion from update manager ..."
|
||||
)
|
||||
BackupService().backup_moonraker_conf()
|
||||
remove_config_section(MOBILERAKER_UPDATER_SECTION_NAME, mr_instances)
|
||||
Logger.print_ok(
|
||||
"Mobileraker's companion successfully removed from update manager!"
|
||||
@@ -163,6 +163,7 @@ class MobilerakerExtension(BaseExtension):
|
||||
Logger.print_error(f"Error removing Mobileraker's companion:\n{e}")
|
||||
|
||||
def _patch_mobileraker_update_manager(self, instances: List[Moonraker]) -> None:
|
||||
BackupService().backup_moonraker_conf()
|
||||
add_config_section(
|
||||
section=MOBILERAKER_UPDATER_SECTION_NAME,
|
||||
instances=instances,
|
||||
@@ -179,14 +180,14 @@ class MobilerakerExtension(BaseExtension):
|
||||
)
|
||||
|
||||
def _backup_mobileraker_dir(self) -> None:
|
||||
bm = BackupManager()
|
||||
bm.backup_directory(
|
||||
MOBILERAKER_DIR.name,
|
||||
source=MOBILERAKER_DIR,
|
||||
target=MOBILERAKER_BACKUP_DIR,
|
||||
svc = BackupService()
|
||||
svc.backup_directory(
|
||||
source_path=MOBILERAKER_DIR,
|
||||
backup_name="mobileraker",
|
||||
target_path="mobileraker",
|
||||
)
|
||||
bm.backup_directory(
|
||||
MOBILERAKER_ENV_DIR.name,
|
||||
source=MOBILERAKER_ENV_DIR,
|
||||
target=MOBILERAKER_BACKUP_DIR,
|
||||
svc.backup_directory(
|
||||
source_path=MOBILERAKER_ENV_DIR,
|
||||
backup_name="mobileraker-env",
|
||||
target_path="mobileraker",
|
||||
)
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
"- 25FPS High-Def Webcam Streaming",
|
||||
"- Free 4.9-Star Mobile App"
|
||||
],
|
||||
"website": "https://obico.io",
|
||||
"repo": "github.com/TheSpaghettiDetective/moonraker-obico",
|
||||
"updates": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ from components.moonraker.moonraker import Moonraker
|
||||
from core.instance_manager.base_instance import SUFFIX_BLACKLIST
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
from core.logger import DialogType, Logger
|
||||
from core.services.backup_service import BackupService
|
||||
from core.submodules.simple_config_parser.src.simple_config_parser.simple_config_parser import (
|
||||
SimpleConfigParser,
|
||||
)
|
||||
@@ -31,7 +32,10 @@ from extensions.obico import (
|
||||
from extensions.obico.moonraker_obico import (
|
||||
MoonrakerObico,
|
||||
)
|
||||
from utils.common import check_install_dependencies, moonraker_exists
|
||||
from utils.common import (
|
||||
check_install_dependencies,
|
||||
moonraker_exists,
|
||||
)
|
||||
from utils.config_utils import (
|
||||
add_config_section,
|
||||
remove_config_section,
|
||||
@@ -119,6 +123,8 @@ class ObicoExtension(BaseExtension):
|
||||
|
||||
cmd_sysctl_manage("daemon-reload")
|
||||
|
||||
BackupService().backup_printer_config_dir()
|
||||
|
||||
# add to klippers config
|
||||
self._patch_printer_cfg(kl_instances)
|
||||
InstanceManager.restart_all(kl_instances)
|
||||
@@ -165,6 +171,7 @@ class ObicoExtension(BaseExtension):
|
||||
self._remove_obico_instances(ob_instances)
|
||||
self._remove_obico_dir()
|
||||
self._remove_obico_env()
|
||||
BackupService().backup_printer_config_dir()
|
||||
remove_config_section(f"include {OBICO_MACROS_CFG_NAME}", kl_instances)
|
||||
remove_config_section(f"include {OBICO_UPDATE_CFG_NAME}", mr_instances)
|
||||
Logger.print_dialog(
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
"- Live Gcode preview",
|
||||
"- And much much more!"
|
||||
],
|
||||
"repo": "https://github.com/crysxd/OctoApp-Plugin",
|
||||
"updates": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ from components.klipper.klipper import Klipper
|
||||
from components.moonraker.moonraker import Moonraker
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
from core.logger import DialogType, Logger
|
||||
from core.services.backup_service import BackupService
|
||||
from extensions.base_extension import BaseExtension
|
||||
from extensions.octoapp import (
|
||||
OA_DEPS_JSON_FILE,
|
||||
@@ -133,6 +134,7 @@ class OctoappExtension(BaseExtension):
|
||||
self._remove_OA_store_dirs()
|
||||
self._remove_OA_dir()
|
||||
self._remove_OA_env()
|
||||
BackupService().backup_moonraker_conf()
|
||||
remove_config_section(f"include {OA_SYS_CFG_NAME}", mr_instances)
|
||||
run_remove_routines(OA_INSTALLER_LOG_FILE)
|
||||
Logger.print_dialog(
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
"- Real-time Notifications",
|
||||
"- Live Streaming, and More!"
|
||||
],
|
||||
"website": "https://octoeverywhere.com",
|
||||
"repo": "github.com/QuinnDamerell/OctoPrint-OctoEverywhere",
|
||||
"updates": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ from typing import List
|
||||
from components.moonraker.moonraker import Moonraker
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
from core.logger import DialogType, Logger
|
||||
from core.services.backup_service import BackupService
|
||||
from extensions.base_extension import BaseExtension
|
||||
from extensions.octoeverywhere import (
|
||||
OE_DEPS_JSON_FILE,
|
||||
@@ -133,6 +134,7 @@ class OctoeverywhereExtension(BaseExtension):
|
||||
self._remove_oe_instances(ob_instances)
|
||||
self._remove_oe_dir()
|
||||
self._remove_oe_env()
|
||||
BackupService().backup_moonraker_conf()
|
||||
remove_config_section(f"include {OE_SYS_CFG_NAME}", mr_instances)
|
||||
run_remove_routines(OE_INSTALLER_LOG_FILE)
|
||||
Logger.print_dialog(
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"maintained_by": "Kragrathea",
|
||||
"display_name": "PrettyGCode for Klipper",
|
||||
"description": ["3D G-Code viewer for Klipper"],
|
||||
"repo": "https://github.com/Kragrathea/pgcode",
|
||||
"updates": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
{
|
||||
"metadata": {
|
||||
"index": 10,
|
||||
"module": "simply_print_extension",
|
||||
"maintained_by": "dw-0",
|
||||
"display_name": "SimplyPrint",
|
||||
"description": [
|
||||
"3D Printer Cloud Management Software.",
|
||||
"\n\n",
|
||||
"3D printing doesn't have to be a complicated, analog, SD card-filled experience; step into the future of modern 3D printing"
|
||||
]
|
||||
}
|
||||
"metadata": {
|
||||
"index": 10,
|
||||
"module": "simply_print_extension",
|
||||
"maintained_by": "dw-0",
|
||||
"display_name": "SimplyPrint",
|
||||
"description": [
|
||||
"3D Printer Cloud Management Software.",
|
||||
"\n\n",
|
||||
"3D printing doesn't have to be a complicated, analog, SD card-filled experience; step into the future of modern 3D printing"
|
||||
],
|
||||
"website": "https://simplyprint.io",
|
||||
"repo": "https://github.com/SimplyPrint",
|
||||
"updates": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,11 +11,12 @@ from typing import List
|
||||
from components.moonraker.moonraker import Moonraker
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
from core.logger import DialogType, Logger
|
||||
from core.services.backup_service import BackupService
|
||||
from core.submodules.simple_config_parser.src.simple_config_parser.simple_config_parser import (
|
||||
SimpleConfigParser,
|
||||
)
|
||||
from extensions.base_extension import BaseExtension
|
||||
from utils.common import backup_printer_config_dir, moonraker_exists
|
||||
from utils.common import moonraker_exists
|
||||
from utils.input_utils import get_confirm
|
||||
|
||||
|
||||
@@ -112,10 +113,10 @@ class SimplyPrintExtension(BaseExtension):
|
||||
continue
|
||||
|
||||
if is_install and not scp.has_section("simplyprint"):
|
||||
backup_printer_config_dir()
|
||||
BackupService().backup_printer_config_dir()
|
||||
scp.add_section(section)
|
||||
elif not is_install and scp.has_section("simplyprint"):
|
||||
backup_printer_config_dir()
|
||||
BackupService().backup_printer_config_dir()
|
||||
scp.remove_section(section)
|
||||
scp.write_file(moonraker.cfg_file)
|
||||
patched_files.append(moonraker.cfg_file)
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
"\n\n",
|
||||
"Note: This extension installs Spoolman using Docker. Docker must be installed on your system before installing Spoolman."
|
||||
],
|
||||
"repo": "https://github.com/Donkie/Spoolman",
|
||||
"updates": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,9 +15,9 @@ from components.moonraker.moonraker import Moonraker
|
||||
from components.moonraker.services.moonraker_instance_service import (
|
||||
MoonrakerInstanceService,
|
||||
)
|
||||
from core.backup_manager.backup_manager import BackupManager
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
from core.logger import DialogType, Logger
|
||||
from core.services.backup_service import BackupService
|
||||
from extensions.base_extension import BaseExtension
|
||||
from extensions.spoolman import (
|
||||
SPOOLMAN_COMPOSE_FILE,
|
||||
@@ -100,6 +100,7 @@ class SpoolmanExtension(BaseExtension):
|
||||
mr_instances: List[Moonraker] = mrsvc.get_all_instances()
|
||||
|
||||
Logger.print_status("Removing Spoolman configuration from moonraker.conf...")
|
||||
BackupService().backup_moonraker_conf()
|
||||
remove_config_section("spoolman", mr_instances)
|
||||
|
||||
Logger.print_status("Removing Spoolman from moonraker.asvc...")
|
||||
@@ -123,16 +124,15 @@ class SpoolmanExtension(BaseExtension):
|
||||
"Failed to remove Spoolman image! Please remove it manually."
|
||||
)
|
||||
|
||||
# backup Spoolman directory to ~/spoolman_data-<timestamp> before removing it
|
||||
try:
|
||||
bm = BackupManager()
|
||||
result = bm.backup_directory(
|
||||
f"{SPOOLMAN_DIR.name}_data",
|
||||
source=SPOOLMAN_DIR,
|
||||
target=SPOOLMAN_DIR.parent,
|
||||
svc = BackupService()
|
||||
success = svc.backup_directory(
|
||||
source_path=SPOOLMAN_DIR,
|
||||
backup_name="spoolman",
|
||||
target_path="spoolman",
|
||||
)
|
||||
if result:
|
||||
Logger.print_ok(f"Spoolman data backed up to {result}")
|
||||
if success:
|
||||
Logger.print_ok(f"Spoolman data backed up to {success}")
|
||||
Logger.print_status("Removing Spoolman directory...")
|
||||
if run_remove_routines(SPOOLMAN_DIR):
|
||||
Logger.print_ok("Spoolman directory removed!")
|
||||
@@ -290,6 +290,7 @@ class SpoolmanExtension(BaseExtension):
|
||||
mrsvc.load_instances()
|
||||
mr_instances = mrsvc.get_all_instances()
|
||||
|
||||
BackupService().backup_moonraker_conf()
|
||||
# noinspection HttpUrlsUsage
|
||||
add_config_section(
|
||||
section="spoolman",
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
"maintained_by": "nlef",
|
||||
"display_name": "Moonraker Telegram Bot",
|
||||
"description": ["Control your printer with the Telegram messenger app."],
|
||||
"project_url": "https://github.com/nlef/moonraker-telegram-bot",
|
||||
"repo": "https://github.com/nlef/moonraker-telegram-bot",
|
||||
"updates": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ from typing import List
|
||||
from components.moonraker.moonraker import Moonraker
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
from core.logger import DialogType, Logger
|
||||
from core.services.backup_service import BackupService
|
||||
from extensions.base_extension import BaseExtension
|
||||
from extensions.telegram_bot import TG_BOT_REPO, TG_BOT_REQ_FILE
|
||||
from extensions.telegram_bot.moonraker_telegram_bot import (
|
||||
@@ -105,6 +106,7 @@ class TelegramBotExtension(BaseExtension):
|
||||
cmd_sysctl_manage("daemon-reload")
|
||||
|
||||
# add to moonraker update manager
|
||||
BackupService().backup_moonraker_conf()
|
||||
self._patch_bot_update_manager(mr_instances)
|
||||
|
||||
# restart moonraker
|
||||
@@ -150,6 +152,7 @@ class TelegramBotExtension(BaseExtension):
|
||||
self._remove_bot_instances(tb_instances)
|
||||
self._remove_bot_dir()
|
||||
self._remove_bot_env()
|
||||
BackupService().backup_moonraker_conf()
|
||||
remove_config_section("update_manager moonraker-telegram-bot", mr_instances)
|
||||
self._delete_bot_logs(tb_instances)
|
||||
except Exception as e:
|
||||
|
||||
@@ -27,3 +27,7 @@ def main() -> None:
|
||||
MainMenu().run()
|
||||
except KeyboardInterrupt:
|
||||
Logger.print_ok("\nHappy printing!\n", prefix=False)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
@@ -13,7 +13,6 @@ from pathlib import Path
|
||||
from typing import Literal
|
||||
|
||||
from components.klipper import (
|
||||
KLIPPER_BACKUP_DIR,
|
||||
KLIPPER_DIR,
|
||||
KLIPPER_ENV_DIR,
|
||||
KLIPPER_REQ_FILE,
|
||||
@@ -21,7 +20,6 @@ from components.klipper import (
|
||||
from components.klipper.klipper import Klipper
|
||||
from components.klipper.klipper_utils import install_klipper_packages
|
||||
from components.moonraker import (
|
||||
MOONRAKER_BACKUP_DIR,
|
||||
MOONRAKER_DIR,
|
||||
MOONRAKER_ENV_DIR,
|
||||
MOONRAKER_REQ_FILE,
|
||||
@@ -30,10 +28,10 @@ from components.moonraker.moonraker import Moonraker
|
||||
from components.moonraker.services.moonraker_setup_service import (
|
||||
install_moonraker_packages,
|
||||
)
|
||||
from core.backup_manager.backup_manager import BackupManager, BackupManagerException
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
from core.logger import Logger
|
||||
from utils.git_utils import GitException, get_repo_name, git_clone_wrapper
|
||||
from core.services.backup_service import BackupService
|
||||
from utils.git_utils import GitException, git_clone_wrapper
|
||||
from utils.instance_utils import get_instances
|
||||
from utils.sys_utils import (
|
||||
VenvCreationFailedException,
|
||||
@@ -52,7 +50,6 @@ def run_switch_repo_routine(
|
||||
repo_dir: Path = KLIPPER_DIR if name == "klipper" else MOONRAKER_DIR
|
||||
env_dir: Path = KLIPPER_ENV_DIR if name == "klipper" else MOONRAKER_ENV_DIR
|
||||
req_file = KLIPPER_REQ_FILE if name == "klipper" else MOONRAKER_REQ_FILE
|
||||
backup_dir: Path = KLIPPER_BACKUP_DIR if name == "klipper" else MOONRAKER_BACKUP_DIR
|
||||
_type = Klipper if name == "klipper" else Moonraker
|
||||
|
||||
# step 1: stop all instances
|
||||
@@ -64,19 +61,17 @@ def run_switch_repo_routine(
|
||||
env_dir_backup_path: Path | None = None
|
||||
|
||||
try:
|
||||
# step 2: backup old repo and env
|
||||
org, _ = get_repo_name(repo_dir)
|
||||
backup_dir = backup_dir.joinpath(org)
|
||||
bm = BackupManager()
|
||||
repo_dir_backup_path = bm.backup_directory(
|
||||
repo_dir.name,
|
||||
repo_dir,
|
||||
backup_dir,
|
||||
svc = BackupService()
|
||||
svc.backup_directory(
|
||||
source_path=repo_dir,
|
||||
backup_name=name,
|
||||
target_path=name,
|
||||
)
|
||||
env_dir_backup_path = bm.backup_directory(
|
||||
env_dir.name,
|
||||
env_dir,
|
||||
backup_dir,
|
||||
env_backup_name: str = f"{name if name == 'moonraker' else 'klippy'}-env"
|
||||
svc.backup_directory(
|
||||
source_path=env_dir,
|
||||
backup_name=env_backup_name,
|
||||
target_path=name,
|
||||
)
|
||||
|
||||
if not (repo_url or branch):
|
||||
@@ -101,10 +96,6 @@ def run_switch_repo_routine(
|
||||
|
||||
Logger.print_ok(f"Switched to {repo_url} at branch {branch}!")
|
||||
|
||||
except BackupManagerException as e:
|
||||
Logger.print_error(f"Error during backup of repository: {e}")
|
||||
raise RepoSwitchFailedException(e)
|
||||
|
||||
except (GitException, VenvCreationFailedException) as e:
|
||||
# if something goes wrong during cloning or recreating the virtualenv,
|
||||
# we restore the backup of the repo and env
|
||||
@@ -122,6 +113,9 @@ def run_switch_repo_routine(
|
||||
Logger.print_error(f"Something went wrong: {e}")
|
||||
return
|
||||
|
||||
except Exception as e:
|
||||
raise RepoSwitchFailedException(e)
|
||||
|
||||
Logger.print_status(f"Restarting all {_type.__name__} instances ...")
|
||||
InstanceManager.start_all(instances)
|
||||
|
||||
|
||||
@@ -14,11 +14,9 @@ from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import Dict, List, Literal, Set
|
||||
|
||||
from components.klipper.klipper import Klipper
|
||||
from components.moonraker.moonraker import Moonraker
|
||||
from core.constants import (
|
||||
GLOBAL_DEPS,
|
||||
PRINTER_DATA_BACKUP_DIR,
|
||||
)
|
||||
from core.logger import DialogType, Logger
|
||||
from core.types.color import Color
|
||||
@@ -151,26 +149,6 @@ def get_install_status(
|
||||
)
|
||||
|
||||
|
||||
def backup_printer_config_dir() -> None:
|
||||
# local import to prevent circular import
|
||||
from core.backup_manager.backup_manager import BackupManager
|
||||
|
||||
instances: List[Klipper] = get_instances(Klipper)
|
||||
bm = BackupManager()
|
||||
|
||||
if not instances:
|
||||
Logger.print_info("Unable to find directory to backup!")
|
||||
Logger.print_info("Are there no Klipper instances installed?")
|
||||
return
|
||||
|
||||
for instance in instances:
|
||||
bm.backup_directory(
|
||||
instance.data_dir.name,
|
||||
source=instance.base.cfg_dir,
|
||||
target=PRINTER_DATA_BACKUP_DIR,
|
||||
)
|
||||
|
||||
|
||||
def moonraker_exists(name: str = "") -> List[Moonraker]:
|
||||
"""
|
||||
Helper method to check if a Moonraker instance exists
|
||||
|
||||
@@ -73,7 +73,7 @@ def add_config_section_at_top(section: str, instances: List[InstanceType]) -> No
|
||||
tmp.writelines(org_content)
|
||||
|
||||
cfg_file.unlink()
|
||||
shutil.move(tmp_cfg_path, cfg_file)
|
||||
shutil.move(tmp_cfg_path.as_posix(), cfg_file)
|
||||
|
||||
Logger.print_ok("OK!")
|
||||
|
||||
@@ -81,7 +81,7 @@ def add_config_section_at_top(section: str, instances: List[InstanceType]) -> No
|
||||
def remove_config_section(
|
||||
section: str, instances: List[InstanceType]
|
||||
) -> List[InstanceType]:
|
||||
removed_from: List[instances] = []
|
||||
removed_from: List[InstanceType] = []
|
||||
for instance in instances:
|
||||
cfg_file = instance.cfg_file
|
||||
Logger.print_status(f"Remove section '[{section}]' from '{cfg_file}' ...")
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import re
|
||||
import shutil
|
||||
import urllib.request
|
||||
from http.client import HTTPResponse
|
||||
@@ -121,6 +120,59 @@ def get_local_tags(repo_path: Path, _filter: str | None = None) -> List[str]:
|
||||
:param _filter: Optional filter to filter the tags by
|
||||
:return: List of tags
|
||||
"""
|
||||
|
||||
def parse_version(version: str) -> tuple:
|
||||
# Remove 'v' prefix if present
|
||||
if version.startswith("v") and version[1:][0].isdigit():
|
||||
version = version[1:]
|
||||
|
||||
# Split into version parts and pre-release parts
|
||||
if "-" in version:
|
||||
version_part, pre_part = version.split("-", 1)
|
||||
pre_parts = pre_part.replace("-", ".").split(".")
|
||||
else:
|
||||
version_part = version
|
||||
pre_parts = []
|
||||
|
||||
# Split version into components
|
||||
version_parts = version_part.split(".")
|
||||
|
||||
# Convert to integers where possible
|
||||
def try_int(x):
|
||||
try:
|
||||
return int(x)
|
||||
except ValueError:
|
||||
return (
|
||||
x.lower()
|
||||
) # Convert strings to lowercase for case-insensitive comparison
|
||||
|
||||
version_ints = [try_int(part) for part in version_parts]
|
||||
|
||||
# Pad version parts to at least 3 components
|
||||
while len(version_ints) < 3:
|
||||
version_ints.append(0)
|
||||
|
||||
# Handle pre-release versions
|
||||
pre_type = 999 # High number for stable releases
|
||||
pre_num = 0
|
||||
|
||||
if pre_parts:
|
||||
pre_type_map = {"alpha": 0, "beta": 1, "rc": 2}
|
||||
pre_type = pre_type_map.get(
|
||||
pre_parts[0].lower(), 3
|
||||
) # Default to 3 for unknown pre-release types
|
||||
|
||||
if len(pre_parts) > 1 and str(pre_parts[1]).isdigit():
|
||||
pre_num = int(pre_parts[1])
|
||||
|
||||
return (
|
||||
version_ints[0], # major
|
||||
version_ints[1], # minor
|
||||
version_ints[2], # patch
|
||||
pre_type, # pre-release type (higher number = more stable)
|
||||
pre_num, # pre-release number
|
||||
)
|
||||
|
||||
try:
|
||||
cmd: List[str] = ["git", "tag", "-l"]
|
||||
|
||||
@@ -135,10 +187,8 @@ def get_local_tags(repo_path: Path, _filter: str | None = None) -> List[str]:
|
||||
|
||||
tags: List[str] = result.split("\n")[:-1]
|
||||
|
||||
return sorted(
|
||||
tags,
|
||||
key=lambda x: [int(i) if i.isdigit() else i for i in re.split(r"(\d+)", x)],
|
||||
)
|
||||
# Sort using our custom version parser
|
||||
return sorted(tags, key=parse_version)
|
||||
|
||||
except CalledProcessError:
|
||||
return []
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
requires-python = ">=3.8"
|
||||
|
||||
[project.optional-dependencies]
|
||||
dev=["ruff", "pyright"]
|
||||
dev=["ruff", "mypy"]
|
||||
|
||||
[tool.ruff]
|
||||
required-version = ">=0.9.10"
|
||||
@@ -20,3 +20,14 @@ quote-style = "double"
|
||||
|
||||
[tool.ruff.lint]
|
||||
extend-select = ["I"]
|
||||
|
||||
[tool.mypy]
|
||||
python_version = "3.8"
|
||||
platform = "linux"
|
||||
# strict = true # TODO: enable this once everything is else is handled
|
||||
check_untyped_defs = true
|
||||
ignore_missing_imports = true
|
||||
warn_redundant_casts = true
|
||||
warn_unused_ignores = true
|
||||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"pythonVersion": "3.8",
|
||||
"pythonPlatform": "Linux",
|
||||
"typeCheckingMode": "standard",
|
||||
"venvPath": "./.kiauh-env"
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#####################################################################
|
||||
### Please set the paths accordingly. In case you don't have all ###
|
||||
### the listed folders, just keep that line commented out. ###
|
||||
#####################################################################
|
||||
### Path to your config folder you want to back up
|
||||
#config_folder=~/klipper_config
|
||||
|
||||
### Path to your Klipper folder, by default that is '~/klipper'
|
||||
#klipper_folder=~/klipper
|
||||
|
||||
### Path to your Moonraker folder, by default that is '~/moonraker'
|
||||
#moonraker_folder=~/moonraker
|
||||
|
||||
### Path to your Mainsail folder, by default that is '~/mainsail'
|
||||
#mainsail_folder=~/mainsail
|
||||
|
||||
### Path to your Fluidd folder, by default that is '~/fluidd'
|
||||
#fluidd_folder=~/fluidd
|
||||
|
||||
#####################################################################
|
||||
#####################################################################
|
||||
|
||||
|
||||
#####################################################################
|
||||
################ !!! DO NOT EDIT BELOW THIS LINE !!! ################
|
||||
#####################################################################
|
||||
grab_version() {
|
||||
local klipper_commit moonraker_commit
|
||||
local mainsail_ver fluidd_ver
|
||||
|
||||
if [[ -n ${klipper_folder} ]]; then
|
||||
cd "${klipper_folder}"
|
||||
klipper_commit=$(git rev-parse --short=7 HEAD)
|
||||
m1="Klipper on commit: ${klipper_commit}"
|
||||
fi
|
||||
if [[ -n ${moonraker_folder} ]]; then
|
||||
cd "${moonraker_folder}"
|
||||
moonraker_commit=$(git rev-parse --short=7 HEAD)
|
||||
m2="Moonraker on commit: ${moonraker_commit}"
|
||||
fi
|
||||
if [[ -n ${mainsail_folder} ]]; then
|
||||
mainsail_ver=$(head -n 1 "${mainsail_folder}/.version")
|
||||
m3="Mainsail version: ${mainsail_ver}"
|
||||
fi
|
||||
if [[ -n ${fluidd_folder} ]]; then
|
||||
fluidd_ver=$(head -n 1 "${fluidd_folder}/.version")
|
||||
m4="Fluidd version: ${fluidd_ver}"
|
||||
fi
|
||||
}
|
||||
|
||||
push_config() {
|
||||
local current_date
|
||||
|
||||
cd "${config_folder}" || exit 1
|
||||
git pull
|
||||
git add .
|
||||
current_date=$(date +"%Y-%m-%d %T")
|
||||
git commit -m "Autocommit from ${current_date}" -m "${m1}" -m "${m2}" -m "${m3}" -m "${m4}"
|
||||
git push
|
||||
}
|
||||
|
||||
grab_version
|
||||
push_config
|
||||
@@ -1,6 +0,0 @@
|
||||
# /etc/nginx/conf.d/common_vars.conf
|
||||
|
||||
map $http_upgrade $connection_upgrade {
|
||||
default upgrade;
|
||||
'' close;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
[mcu]
|
||||
serial: /dev/serial/by-id/<your-mcu-id>
|
||||
|
||||
[virtual_sdcard]
|
||||
path: %GCODES_DIR%
|
||||
on_error_gcode: CANCEL_PRINT
|
||||
|
||||
[printer]
|
||||
kinematics: none
|
||||
max_velocity: 1000
|
||||
max_accel: 1000
|
||||
@@ -1,96 +0,0 @@
|
||||
# /etc/nginx/sites-available/fluidd
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
|
||||
access_log /var/log/nginx/fluidd-access.log;
|
||||
error_log /var/log/nginx/fluidd-error.log;
|
||||
|
||||
# disable this section on smaller hardware like a pi zero
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_proxied any;
|
||||
gzip_proxied expired no-cache no-store private auth;
|
||||
gzip_comp_level 4;
|
||||
gzip_buffers 16 8k;
|
||||
gzip_http_version 1.1;
|
||||
gzip_types text/plain text/css text/xml text/javascript application/javascript application/x-javascript application/json application/xml;
|
||||
|
||||
# web_path from fluidd static files
|
||||
root /home/pi/fluidd;
|
||||
|
||||
index index.html;
|
||||
server_name _;
|
||||
|
||||
# disable max upload size checks
|
||||
client_max_body_size 0;
|
||||
|
||||
# disable proxy request buffering
|
||||
proxy_request_buffering off;
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
location = /index.html {
|
||||
add_header Cache-Control "no-store, no-cache, must-revalidate";
|
||||
}
|
||||
|
||||
location /websocket {
|
||||
proxy_pass http://apiserver/websocket;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection $connection_upgrade;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_read_timeout 86400;
|
||||
}
|
||||
|
||||
location ~ ^/(printer|api|access|machine|server)/ {
|
||||
proxy_pass http://apiserver$request_uri;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Scheme $scheme;
|
||||
proxy_read_timeout 600;
|
||||
}
|
||||
|
||||
location /webcam/ {
|
||||
postpone_output 0;
|
||||
proxy_buffering off;
|
||||
proxy_ignore_headers X-Accel-Buffering;
|
||||
access_log off;
|
||||
error_log off;
|
||||
proxy_pass http://mjpgstreamer1/;
|
||||
}
|
||||
|
||||
location /webcam2/ {
|
||||
postpone_output 0;
|
||||
proxy_buffering off;
|
||||
proxy_ignore_headers X-Accel-Buffering;
|
||||
access_log off;
|
||||
error_log off;
|
||||
proxy_pass http://mjpgstreamer2/;
|
||||
}
|
||||
|
||||
location /webcam3/ {
|
||||
postpone_output 0;
|
||||
proxy_buffering off;
|
||||
proxy_ignore_headers X-Accel-Buffering;
|
||||
access_log off;
|
||||
error_log off;
|
||||
proxy_pass http://mjpgstreamer3/;
|
||||
}
|
||||
|
||||
location /webcam4/ {
|
||||
postpone_output 0;
|
||||
proxy_buffering off;
|
||||
proxy_ignore_headers X-Accel-Buffering;
|
||||
access_log off;
|
||||
error_log off;
|
||||
proxy_pass http://mjpgstreamer4/;
|
||||
}
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
# Run a shell command via gcode
|
||||
#
|
||||
# Copyright (C) 2019 Eric Callahan <arksine.code@gmail.com>
|
||||
#
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||
import os
|
||||
import shlex
|
||||
import subprocess
|
||||
import logging
|
||||
|
||||
|
||||
class ShellCommand:
|
||||
def __init__(self, config):
|
||||
self.name = config.get_name().split()[-1]
|
||||
self.printer = config.get_printer()
|
||||
self.gcode = self.printer.lookup_object("gcode")
|
||||
cmd = config.get("command")
|
||||
cmd = os.path.expanduser(cmd)
|
||||
self.command = shlex.split(cmd)
|
||||
self.timeout = config.getfloat("timeout", 2.0, above=0.0)
|
||||
self.verbose = config.getboolean("verbose", True)
|
||||
self.proc_fd = None
|
||||
self.partial_output = ""
|
||||
self.gcode.register_mux_command(
|
||||
"RUN_SHELL_COMMAND",
|
||||
"CMD",
|
||||
self.name,
|
||||
self.cmd_RUN_SHELL_COMMAND,
|
||||
desc=self.cmd_RUN_SHELL_COMMAND_help,
|
||||
)
|
||||
|
||||
def _process_output(self, eventime):
|
||||
if self.proc_fd is None:
|
||||
return
|
||||
try:
|
||||
data = os.read(self.proc_fd, 4096)
|
||||
except Exception:
|
||||
pass
|
||||
data = self.partial_output + data.decode()
|
||||
if "\n" not in data:
|
||||
self.partial_output = data
|
||||
return
|
||||
elif data[-1] != "\n":
|
||||
split = data.rfind("\n") + 1
|
||||
self.partial_output = data[split:]
|
||||
data = data[:split]
|
||||
else:
|
||||
self.partial_output = ""
|
||||
self.gcode.respond_info(data)
|
||||
|
||||
cmd_RUN_SHELL_COMMAND_help = "Run a linux shell command"
|
||||
|
||||
def cmd_RUN_SHELL_COMMAND(self, params):
|
||||
gcode_params = params.get("PARAMS", "")
|
||||
gcode_params = shlex.split(gcode_params)
|
||||
reactor = self.printer.get_reactor()
|
||||
try:
|
||||
proc = subprocess.Popen(
|
||||
self.command + gcode_params,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
)
|
||||
except Exception:
|
||||
logging.exception("shell_command: Command {%s} failed" % (self.name))
|
||||
raise self.gcode.error("Error running command {%s}" % (self.name))
|
||||
if self.verbose:
|
||||
self.proc_fd = proc.stdout.fileno()
|
||||
self.gcode.respond_info("Running Command {%s}...:" % (self.name))
|
||||
hdl = reactor.register_fd(self.proc_fd, self._process_output)
|
||||
eventtime = reactor.monotonic()
|
||||
endtime = eventtime + self.timeout
|
||||
complete = False
|
||||
while eventtime < endtime:
|
||||
eventtime = reactor.pause(eventtime + 0.05)
|
||||
if proc.poll() is not None:
|
||||
complete = True
|
||||
break
|
||||
if not complete:
|
||||
proc.terminate()
|
||||
if self.verbose:
|
||||
if self.partial_output:
|
||||
self.gcode.respond_info(self.partial_output)
|
||||
self.partial_output = ""
|
||||
if complete:
|
||||
msg = "Command {%s} finished\n" % (self.name)
|
||||
else:
|
||||
msg = "Command {%s} timed out" % (self.name)
|
||||
self.gcode.respond_info(msg)
|
||||
reactor.unregister_fd(hdl)
|
||||
self.proc_fd = None
|
||||
|
||||
|
||||
def load_config_prefix(config):
|
||||
return ShellCommand(config)
|
||||
@@ -1 +0,0 @@
|
||||
KLIPPER_ARGS="%KLIPPER_DIR%/klippy/klippy.py %CFG% -I %PRINTER% -l %LOG% -a %UDS%"
|
||||
@@ -1,18 +0,0 @@
|
||||
[Unit]
|
||||
Description=Klipper 3D Printer Firmware SV1
|
||||
Documentation=https://www.klipper3d.org/
|
||||
After=network-online.target
|
||||
Wants=udev.target
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=%USER%
|
||||
RemainAfterExit=yes
|
||||
WorkingDirectory=%KLIPPER_DIR%
|
||||
EnvironmentFile=%ENV_FILE%
|
||||
ExecStart=%ENV%/bin/python $KLIPPER_ARGS
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
@@ -1,96 +0,0 @@
|
||||
# /etc/nginx/sites-available/mainsail
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
|
||||
access_log /var/log/nginx/mainsail-access.log;
|
||||
error_log /var/log/nginx/mainsail-error.log;
|
||||
|
||||
# disable this section on smaller hardware like a pi zero
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_proxied any;
|
||||
gzip_proxied expired no-cache no-store private auth;
|
||||
gzip_comp_level 4;
|
||||
gzip_buffers 16 8k;
|
||||
gzip_http_version 1.1;
|
||||
gzip_types text/plain text/css text/xml text/javascript application/javascript application/x-javascript application/json application/xml;
|
||||
|
||||
# web_path from mainsail static files
|
||||
root /home/pi/mainsail;
|
||||
|
||||
index index.html;
|
||||
server_name _;
|
||||
|
||||
# disable max upload size checks
|
||||
client_max_body_size 0;
|
||||
|
||||
# disable proxy request buffering
|
||||
proxy_request_buffering off;
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
location = /index.html {
|
||||
add_header Cache-Control "no-store, no-cache, must-revalidate";
|
||||
}
|
||||
|
||||
location /websocket {
|
||||
proxy_pass http://apiserver/websocket;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection $connection_upgrade;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_read_timeout 86400;
|
||||
}
|
||||
|
||||
location ~ ^/(printer|api|access|machine|server)/ {
|
||||
proxy_pass http://apiserver$request_uri;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Scheme $scheme;
|
||||
proxy_read_timeout 600;
|
||||
}
|
||||
|
||||
location /webcam/ {
|
||||
postpone_output 0;
|
||||
proxy_buffering off;
|
||||
proxy_ignore_headers X-Accel-Buffering;
|
||||
access_log off;
|
||||
error_log off;
|
||||
proxy_pass http://mjpgstreamer1/;
|
||||
}
|
||||
|
||||
location /webcam2/ {
|
||||
postpone_output 0;
|
||||
proxy_buffering off;
|
||||
proxy_ignore_headers X-Accel-Buffering;
|
||||
access_log off;
|
||||
error_log off;
|
||||
proxy_pass http://mjpgstreamer2/;
|
||||
}
|
||||
|
||||
location /webcam3/ {
|
||||
postpone_output 0;
|
||||
proxy_buffering off;
|
||||
proxy_ignore_headers X-Accel-Buffering;
|
||||
access_log off;
|
||||
error_log off;
|
||||
proxy_pass http://mjpgstreamer3/;
|
||||
}
|
||||
|
||||
location /webcam4/ {
|
||||
postpone_output 0;
|
||||
proxy_buffering off;
|
||||
proxy_ignore_headers X-Accel-Buffering;
|
||||
access_log off;
|
||||
error_log off;
|
||||
proxy_pass http://mjpgstreamer4/;
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
### Windows users: To edit this file use Notepad++, VSCode, Atom or SublimeText.
|
||||
### Do not use Notepad or WordPad.
|
||||
|
||||
### MacOSX users: If you use Textedit to edit this file make sure to use
|
||||
### "plain text format" and "disable smart quotes" in "Textedit > Preferences"
|
||||
|
||||
### Configure which camera to use
|
||||
#
|
||||
# Available options are:
|
||||
# - auto: tries first usb webcam, if that's not available tries raspi cam
|
||||
# - usb: only tries usb webcam
|
||||
# - raspi: only tries raspi cam
|
||||
#
|
||||
# Defaults to auto
|
||||
#
|
||||
#camera="auto"
|
||||
|
||||
### Additional options to supply to MJPG Streamer for the USB camera
|
||||
#
|
||||
# See https://faq.octoprint.org/mjpg-streamer-config for available options
|
||||
#
|
||||
# Defaults to a resolution of 640x480 px and a framerate of 10 fps
|
||||
#
|
||||
#camera_usb_options="-r 640x480 -f 10"
|
||||
|
||||
### Additional webcam devices known to cause problems with -f
|
||||
#
|
||||
# Apparently there a some devices out there that with the current
|
||||
# mjpg_streamer release do not support the -f parameter (for specifying
|
||||
# the capturing framerate) and will just refuse to output an image if it
|
||||
# is supplied.
|
||||
#
|
||||
# The webcam daemon will detect those devices by their USB Vendor and Product
|
||||
# ID and remove the -f parameter from the options provided to mjpg_streamer.
|
||||
#
|
||||
# By default, this is done for the following devices:
|
||||
# Logitech C170 (046d:082b)
|
||||
# GEMBIRD (1908:2310)
|
||||
# Genius F100 (0458:708c)
|
||||
# Cubeternet GL-UPC822 UVC WebCam (1e4e:0102)
|
||||
#
|
||||
# Using the following option it is possible to add additional devices. If
|
||||
# your webcam happens to show above symptoms, try determining your cam's
|
||||
# vendor and product id via lsusb, activating the line below by removing # and
|
||||
# adding it, e.g. for two broken cameras "aabb:ccdd" and "aabb:eeff"
|
||||
#
|
||||
# additional_brokenfps_usb_devices=("aabb:ccdd" "aabb:eeff")
|
||||
#
|
||||
#
|
||||
#additional_brokenfps_usb_devices=()
|
||||
|
||||
### Additional options to supply to MJPG Streamer for the RasPi Cam
|
||||
#
|
||||
# See https://faq.octoprint.org/mjpg-streamer-config for available options
|
||||
#
|
||||
# Defaults to 10fps
|
||||
#
|
||||
#camera_raspi_options="-fps 10"
|
||||
|
||||
### Configuration of camera HTTP output
|
||||
#
|
||||
# Usually you should NOT need to change this at all! Only touch if you
|
||||
# know what you are doing and what the parameters mean.
|
||||
#
|
||||
# Below settings are used in the mjpg-streamer call like this:
|
||||
#
|
||||
# -o "output_http.so -w $camera_http_webroot $camera_http_options"
|
||||
#
|
||||
# Current working directory is the mjpg-streamer base directory.
|
||||
#
|
||||
#camera_http_webroot="./www-mainsail"
|
||||
#camera_http_options="-n"
|
||||
|
||||
### EXPERIMENTAL
|
||||
# Support for different streamer types.
|
||||
#
|
||||
# Available options:
|
||||
# mjpeg [default] - stable MJPG-streamer
|
||||
#camera_streamer=mjpeg
|
||||
@@ -1,303 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
########################################################################
|
||||
### DO NOT EDIT THIS FILE TO CHANGE THE CONFIG!!! ###
|
||||
### ---------------------------------------------------------------- ###
|
||||
### There is no need to edit this file for changing resolution, ###
|
||||
### frame rates or any other mjpg-streamer parameters. Please edit ###
|
||||
### /home/pi/klipper_config/webcam.txt instead - that's what it's ###
|
||||
### there for! You can even do this with your Pi powered down by ###
|
||||
### directly accessing the file when using the SD card as thumb ###
|
||||
### drive in your regular computer. ###
|
||||
########################################################################
|
||||
|
||||
MJPGSTREAMER_HOME=/home/pi/mjpg-streamer
|
||||
MJPGSTREAMER_INPUT_USB="input_uvc.so"
|
||||
MJPGSTREAMER_INPUT_RASPICAM="input_raspicam.so"
|
||||
|
||||
brokenfps_usb_devices=("046d:082b" "1908:2310" "0458:708c" "1e4e:0102" "0471:0311" "038f:6001" "046d:0804" "046d:0825" "046d:0994" "0ac8:3450")
|
||||
|
||||
config_dir="/home/pi/klipper_config"
|
||||
|
||||
echo "Starting up webcamDaemon..."
|
||||
echo ""
|
||||
|
||||
cfg_files=()
|
||||
#cfg_files+=/boot/mainsail.txt
|
||||
if [[ -d ${config_dir} ]]; then
|
||||
cfg_files+=( `ls ${config_dir}/webcam*.txt` )
|
||||
fi
|
||||
|
||||
array_camera_config=()
|
||||
array_camera=()
|
||||
array_camera_usb_options=()
|
||||
array_camera_usb_device=()
|
||||
array_camera_raspi_options=()
|
||||
array_camera_http_webroot=()
|
||||
array_camera_http_options=()
|
||||
array_additional_brokenfps_usb_devices=()
|
||||
array_camera_device=()
|
||||
array_assigned_device=()
|
||||
|
||||
echo "--- Configuration: ----------------------------"
|
||||
for cfg_file in ${cfg_files[@]}; do
|
||||
# init configuration - DO NOT EDIT, USE /home/pi/klipper_config/webcam*.txt INSTEAD!
|
||||
camera="auto"
|
||||
camera_usb_options="-r 640x480 -f 10"
|
||||
camera_raspi_options="-fps 10"
|
||||
camera_http_webroot="./www-mjpgstreamer"
|
||||
camera_http_options="-n"
|
||||
additional_brokenfps_usb_devices=()
|
||||
|
||||
if [[ -e ${cfg_file} ]]; then
|
||||
source "$cfg_file"
|
||||
fi
|
||||
usb_options="$camera_usb_options"
|
||||
|
||||
# if webcam device is explicitly given in /home/pi/klipper_config/webcam*.txt, save the path of the device
|
||||
# to a variable and remove its parameter from usb_options
|
||||
extracted_device=`echo $usb_options | sed 's@.*-d \(/dev/\(video[0-9]\+\|v4l/[^ ]*\)\).*@\1@'`
|
||||
if [ "$extracted_device" != "$usb_options" ]
|
||||
then
|
||||
# the camera options refer to a device, save it in a variable
|
||||
# replace video device parameter with empty string and strip extra whitespace
|
||||
usb_options=`echo $usb_options | sed 's/\-d \/dev\/\(video[0-9]\+\|v4l\/[^ ]*\)//g' | awk '$1=$1'`
|
||||
else
|
||||
extracted_device=""
|
||||
fi
|
||||
|
||||
# echo configuration
|
||||
echo "cfg_file: $cfg_file"
|
||||
echo "camera: $camera"
|
||||
echo "usb options: $camera_usb_options"
|
||||
echo "raspi options: $camera_raspi_options"
|
||||
echo "http options: -w $camera_http_webroot $camera_http_options"
|
||||
echo ""
|
||||
echo "Explicitly USB device: $extracted_device"
|
||||
echo "-----------------------------------------------"
|
||||
echo ""
|
||||
|
||||
array_camera_config+=( $cfg_file )
|
||||
array_camera+=( $camera )
|
||||
array_camera_usb_options+=("$usb_options")
|
||||
array_camera_usb_device+=("$extracted_device")
|
||||
array_camera_raspi_options+=("$camera_raspi_options")
|
||||
array_camera_http_webroot+=("$camera_http_webroot")
|
||||
array_camera_http_options+=("$camera_http_options")
|
||||
array_camera_brokenfps_usb_devices+=("${brokenfps_usb_devices[*]} ${additional_brokenfps_usb_devices[*]}")
|
||||
array_camera_device+=("")
|
||||
done
|
||||
|
||||
# check if array contains a string
|
||||
function containsString() {
|
||||
local e match="$1"
|
||||
shift
|
||||
for e; do [[ "$e" == "$match" ]] && return 0; done
|
||||
return 1
|
||||
}
|
||||
|
||||
# cleans up when the script receives a SIGINT or SIGTERM
|
||||
function cleanup() {
|
||||
# make sure that all child processed die when we die
|
||||
local pids=$(jobs -pr)
|
||||
[ -n "$pids" ] && kill $pids
|
||||
exit 0
|
||||
}
|
||||
|
||||
# says goodbye when the script shuts down
|
||||
function goodbye() {
|
||||
# say goodbye
|
||||
echo ""
|
||||
echo "Goodbye..."
|
||||
echo ""
|
||||
}
|
||||
|
||||
# runs MJPG Streamer, using the provided input plugin + configuration
|
||||
function runMjpgStreamer {
|
||||
input=$1
|
||||
|
||||
# There are problems with 0x000137ab firmware on VL805 (Raspberry Pi 4}).
|
||||
# Try to autodetect offending firmware and temporarily fix the issue
|
||||
# by changing power management mode
|
||||
echo "Checking for VL805 (Raspberry Pi 4)..."
|
||||
if [[ -f /usr/bin/vl805 ]]; then
|
||||
VL805_VERSION=$(/usr/bin/vl805)
|
||||
VL805_VERSION=${VL805_VERSION#*: }
|
||||
echo " - version 0x${VL805_VERSION} detected"
|
||||
case "$VL805_VERSION" in
|
||||
00013701)
|
||||
echo " - nothing to be done. It shouldn't cause USB problems."
|
||||
;;
|
||||
000137ab)
|
||||
echo -e " - \e[31mThis version is known to cause problems with USB cameras.\e[39m"
|
||||
echo -e " You may want to downgrade to 0x0013701."
|
||||
echo -e " - [FIXING] Trying the setpci -s 01:00.0 0xD4.B=0x41 hack to mitigate the"
|
||||
echo -e " issue. It disables ASPM L1 on the VL805. Your board may (or may not) get"
|
||||
echo -e " slightly hotter. For details see:"
|
||||
echo -e " https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=244421"
|
||||
setpci -s 01:00.0 0xD4.B=0x41
|
||||
;;
|
||||
*)
|
||||
echo " - unknown firmware version. Doing nothing."
|
||||
;;
|
||||
esac
|
||||
else
|
||||
echo " - It seems that you don't have VL805 (Raspberry Pi 4)."
|
||||
echo " There should be no problems with USB (a.k.a. select() timeout)"
|
||||
fi
|
||||
|
||||
pushd $MJPGSTREAMER_HOME > /dev/null 2>&1
|
||||
echo Running ./mjpg_streamer -o "output_http.so -w $camera_http_webroot $camera_http_options" -i "$input"
|
||||
LD_LIBRARY_PATH=. ./mjpg_streamer -o "output_http.so -w $camera_http_webroot $camera_http_options" -i "$input" &
|
||||
sleep 1 &
|
||||
sleep_pid=$!
|
||||
wait ${sleep_pid}
|
||||
popd > /dev/null 2>&1
|
||||
}
|
||||
|
||||
# starts up the RasPiCam
|
||||
function startRaspi {
|
||||
logger -s "Starting Raspberry Pi camera"
|
||||
runMjpgStreamer "$MJPGSTREAMER_INPUT_RASPICAM $camera_raspi_options"
|
||||
}
|
||||
|
||||
# starts up the USB webcam
|
||||
function startUsb {
|
||||
options="$usb_options"
|
||||
device="video0"
|
||||
|
||||
# check for parameter and set the device if it is given as a parameter
|
||||
input=$1
|
||||
if [[ -n $input ]]; then
|
||||
device=`basename "$input"`
|
||||
fi
|
||||
|
||||
# add video device into options
|
||||
options="$options -d /dev/$device"
|
||||
|
||||
uevent_file="/sys/class/video4linux/$device/device/uevent"
|
||||
if [ -e $uevent_file ]; then
|
||||
# let's see what kind of webcam we have here, fetch vid and pid...
|
||||
product=`cat $uevent_file | grep PRODUCT | cut -d"=" -f2`
|
||||
vid=`echo $product | cut -d"/" -f1`
|
||||
pid=`echo $product | cut -d"/" -f2`
|
||||
vidpid=`printf "%04x:%04x" "0x$vid" "0x$pid"`
|
||||
|
||||
# ... then look if it is in our list of known broken-fps-devices and if so remove
|
||||
# the -f parameter from the options (if it's in there, else that's just a no-op)
|
||||
for identifier in ${brokenfps_usb_devices[@]};
|
||||
do
|
||||
if [ "$vidpid" = "$identifier" ]; then
|
||||
echo
|
||||
echo "Camera model $vidpid is known to not work with -f parameter, stripping it out"
|
||||
echo
|
||||
options=`echo $options | sed -e "s/\(\s\+\|^\)-f\s\+[0-9]\+//g"`
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
logger -s "Starting USB webcam"
|
||||
runMjpgStreamer "$MJPGSTREAMER_INPUT_USB $options"
|
||||
}
|
||||
|
||||
# make sure our cleanup function gets called when we receive SIGINT, SIGTERM
|
||||
trap "cleanup" SIGINT SIGTERM
|
||||
# say goodbye when we EXIT
|
||||
trap "goodbye" EXIT
|
||||
|
||||
# we need this to prevent the later calls to vcgencmd from blocking
|
||||
# I have no idea why, but that's how it is...
|
||||
vcgencmd version > /dev/null 2>&1
|
||||
|
||||
# keep mjpg streamer running if some camera is attached
|
||||
while true; do
|
||||
|
||||
# get list of usb video devices into an array
|
||||
video_devices=($(find /dev -regextype sed -regex '\/dev/video[0-9]\+' | sort -nk1.11 2> /dev/null))
|
||||
|
||||
# add list of raspi camera into an array
|
||||
if [ "`vcgencmd get_camera`" = "supported=1 detected=1" ]; then
|
||||
video_devices+=( "raspi" )
|
||||
fi
|
||||
|
||||
echo "Found video devices:"
|
||||
printf '%s\n' "${video_devices[@]}"
|
||||
|
||||
for scan_mode in "usb" "usb-auto" "raspi" "auto"; do
|
||||
camera=$scan_mode
|
||||
if [[ "usb-auto" == "$scan_mode" ]]; then
|
||||
camera="usb"
|
||||
fi
|
||||
for ((i=0;i<${#array_camera[@]};i++)); do
|
||||
if [[ -z ${array_camera_device[${i}]} ]] && [[ $camera == ${array_camera[${i}]} ]]; then
|
||||
camera_config="${array_camera_config[${i}]}"
|
||||
usb_options="${array_camera_usb_options[${i}]}"
|
||||
camera_usb_device="${array_camera_usb_device[${i}]}"
|
||||
camera_raspi_options="${array_camera_raspi_options[${i}]}"
|
||||
camera_http_webroot="${array_camera_http_webroot[${i}]}"
|
||||
camera_http_options="${array_camera_http_options[${i}]}"
|
||||
brokenfps_usb_devices="${array_camera_brokenfps_usb_devices[${i}]}"
|
||||
if [[ ${camera_usb_device} ]] && { [[ "usb" == ${scan_mode} ]] || [[ "auto" == ${scan_mode} ]]; }; then
|
||||
# usb device is explicitly set in options
|
||||
usb_device_path=`readlink -f ${camera_usb_device}`
|
||||
if containsString "$usb_device_path" "${array_camera_device[@]}"; then
|
||||
if [[ "auto" != ${scan_mode} ]]; then
|
||||
array_camera_device[${i}]="alredy_in_use"
|
||||
echo "config file='$camera_config':Video device already in use."
|
||||
continue
|
||||
fi
|
||||
elif containsString "$usb_device_path" "${video_devices[@]}"; then
|
||||
array_camera_device[${i}]="$usb_device_path"
|
||||
# explicitly set usb device was found in video_devices array, start usb with the found device
|
||||
echo "config file='$camera_config':USB device was set in options and found in devices, start MJPG-streamer with the configured USB video device: $usb_device_path"
|
||||
startUsb "$usb_device_path"
|
||||
continue
|
||||
fi
|
||||
elif [[ -z ${camera_usb_device} ]] && { [[ "usb-auto" == ${scan_mode} ]] || [[ "auto" == ${scan_mode} ]]; }; then
|
||||
for video_device in "${video_devices[@]}"; do
|
||||
if [[ "raspi" != "$video_device" ]]; then
|
||||
if containsString "$video_device" "${array_camera_device[@]}"; then
|
||||
: #already in use
|
||||
else
|
||||
array_camera_device[${i}]="$video_device"
|
||||
# device is not set explicitly in options, start usb with first found usb camera as the device
|
||||
echo "config file='$camera_config':USB device was not set in options, start MJPG-streamer with the first found video device: ${video_device}"
|
||||
startUsb "${video_device}"
|
||||
break
|
||||
fi
|
||||
fi
|
||||
done
|
||||
if [[ -n ${array_camera_device[${i}]} ]]; then
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
if [[ "raspi" == ${scan_mode} ]] || [[ "auto" == ${scan_mode} ]]; then
|
||||
video_device="raspi"
|
||||
if containsString "$video_device" "${array_camera_device[@]}"; then
|
||||
if [[ "auto" != ${scan_mode} ]]; then
|
||||
array_camera_device[${i}]="alredy_in_use"
|
||||
echo "config file='$camera_config':RasPiCam device already in use."
|
||||
fi
|
||||
elif containsString "$video_device" "${video_devices[@]}"; then
|
||||
array_camera_device[${i}]="$video_device"
|
||||
echo "config file='$camera_config':Start MJPG-streamer with video device: ${video_device}"
|
||||
startRaspi
|
||||
sleep 30 &
|
||||
sleep_pid=$!
|
||||
wait ${sleep_pid}
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done
|
||||
done
|
||||
array_assigned_device=( ${array_camera_device[*]} )
|
||||
if [[ ${#array_camera[@]} -eq ${#array_assigned_device[@]} ]]; then
|
||||
echo "Done bring up all configured video device"
|
||||
exit 0
|
||||
else
|
||||
echo "Scan again in two minutes"
|
||||
sleep 120 &
|
||||
sleep_pid=$!
|
||||
wait ${sleep_pid}
|
||||
fi
|
||||
done
|
||||
@@ -1,15 +0,0 @@
|
||||
[Unit]
|
||||
Description=Starts mjpg-streamer on startup
|
||||
After=network.target
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
[Service]
|
||||
Type=forking
|
||||
User=%USER%
|
||||
WorkingDirectory=/usr/local/bin
|
||||
StandardOutput=append:/var/log/webcamd.log
|
||||
StandardError=append:/var/log/webcamd.log
|
||||
ExecStart=/usr/local/bin/webcamd
|
||||
Restart=always
|
||||
@@ -1 +0,0 @@
|
||||
TELEGRAM_BOT_ARGS="%TELEGRAM_BOT_DIR%/bot/main.py -c %CFG% -l %LOG%"
|
||||
@@ -1,16 +0,0 @@
|
||||
[Unit]
|
||||
Description=Moonraker Telegram Bot SV1 %INST%
|
||||
Documentation=https://github.com/nlef/moonraker-telegram-bot/wiki
|
||||
After=network-online.target
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=%USER%
|
||||
WorkingDirectory=%TELEGRAM_BOT_DIR%
|
||||
EnvironmentFile=%ENV_FILE%
|
||||
ExecStart=%ENV%/bin/python $TELEGRAM_BOT_ARGS
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
@@ -1,31 +0,0 @@
|
||||
[server]
|
||||
host: 0.0.0.0
|
||||
port: %PORT%
|
||||
klippy_uds_address: %UDS%
|
||||
|
||||
[authorization]
|
||||
trusted_clients:
|
||||
%LAN%
|
||||
10.0.0.0/8
|
||||
127.0.0.0/8
|
||||
169.254.0.0/16
|
||||
172.16.0.0/12
|
||||
192.168.0.0/16
|
||||
FE80::/10
|
||||
::1/128
|
||||
cors_domains:
|
||||
*.lan
|
||||
*.local
|
||||
*.internal
|
||||
*://localhost
|
||||
*://localhost:*
|
||||
*://my.mainsail.xyz
|
||||
*://app.fluidd.xyz
|
||||
|
||||
[octoprint_compat]
|
||||
|
||||
[history]
|
||||
|
||||
[update_manager]
|
||||
channel: dev
|
||||
refresh_interval: 168
|
||||
@@ -1 +0,0 @@
|
||||
MOONRAKER_ARGS="%MOONRAKER_DIR%/moonraker/moonraker.py -d %PRINTER_DATA%"
|
||||
@@ -1,19 +0,0 @@
|
||||
[Unit]
|
||||
Description=API Server for Klipper SV1 %INST%
|
||||
Documentation=https://moonraker.readthedocs.io/
|
||||
Requires=network-online.target
|
||||
After=network-online.target
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=%USER%
|
||||
SupplementaryGroups=moonraker-admin
|
||||
RemainAfterExit=yes
|
||||
WorkingDirectory=%MOONRAKER_DIR%
|
||||
EnvironmentFile=%ENV_FILE%
|
||||
ExecStart=%ENV%/bin/python $MOONRAKER_ARGS
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 49 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 58 KiB |
@@ -1,7 +0,0 @@
|
||||
[gcode_shell_command hello_world]
|
||||
command: echo hello world
|
||||
timeout: 2.
|
||||
verbose: True
|
||||
[gcode_macro HELLO_WORLD]
|
||||
gcode:
|
||||
RUN_SHELL_COMMAND CMD=hello_world
|
||||
@@ -1,25 +0,0 @@
|
||||
# /etc/nginx/conf.d/upstreams.conf
|
||||
upstream apiserver {
|
||||
ip_hash;
|
||||
server 127.0.0.1:7125;
|
||||
}
|
||||
|
||||
upstream mjpgstreamer1 {
|
||||
ip_hash;
|
||||
server 127.0.0.1:8080;
|
||||
}
|
||||
|
||||
upstream mjpgstreamer2 {
|
||||
ip_hash;
|
||||
server 127.0.0.1:8081;
|
||||
}
|
||||
|
||||
upstream mjpgstreamer3 {
|
||||
ip_hash;
|
||||
server 127.0.0.1:8082;
|
||||
}
|
||||
|
||||
upstream mjpgstreamer4 {
|
||||
ip_hash;
|
||||
server 127.0.0.1:8083;
|
||||
}
|
||||
@@ -1,231 +0,0 @@
|
||||
#!/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 #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
function get_date() {
|
||||
local current_date
|
||||
current_date=$(date +"%y%m%d-%H%M")
|
||||
echo "${current_date}"
|
||||
}
|
||||
|
||||
function check_for_backup_dir() {
|
||||
[[ -d ${BACKUP_DIR} ]] && return
|
||||
|
||||
status_msg "Create KIAUH backup directory ..."
|
||||
mkdir -p "${BACKUP_DIR}" && ok_msg "Directory created!"
|
||||
}
|
||||
|
||||
function backup_before_update() {
|
||||
read_kiauh_ini "${FUNCNAME[0]}"
|
||||
local state="${backup_before_update}"
|
||||
[[ ${state} = "false" ]] && return
|
||||
backup_"${1}"
|
||||
}
|
||||
|
||||
function backup_config_dir() {
|
||||
check_for_backup_dir
|
||||
local current_date config_pathes
|
||||
|
||||
config_pathes=$(get_config_folders)
|
||||
|
||||
if [[ -n "${config_pathes}" ]]; then
|
||||
current_date=$(get_date)
|
||||
status_msg "Timestamp: ${current_date}"
|
||||
|
||||
local i=0 folder folder_name target_dir
|
||||
for folder in ${config_pathes}; do
|
||||
if [[ -d ${folder} ]]; then
|
||||
status_msg "Create backup of ${folder} ..."
|
||||
|
||||
folder_name=$(echo "${folder}" | rev | cut -d"/" -f2 | rev)
|
||||
target_dir="${BACKUP_DIR}/configs/${current_date}/${folder_name}"
|
||||
mkdir -p "${target_dir}"
|
||||
cp -r "${folder}" "${target_dir}"
|
||||
i=$(( i + 1 ))
|
||||
|
||||
ok_msg "Backup created in:\n${target_dir}"
|
||||
fi
|
||||
done
|
||||
else
|
||||
ok_msg "No config directory found! Skipping backup ..."
|
||||
fi
|
||||
}
|
||||
|
||||
function backup_moonraker_database() {
|
||||
check_for_backup_dir
|
||||
local current_date db_pathes
|
||||
|
||||
db_pathes=$(get_instance_folder_path "database")
|
||||
|
||||
if [[ -n ${db_pathes} ]]; then
|
||||
current_date=$(get_date)
|
||||
status_msg "Timestamp: ${current_date}"
|
||||
|
||||
local i=0 database folder_name target_dir
|
||||
for database in ${db_pathes}; do
|
||||
status_msg "Create backup of ${database} ..."
|
||||
|
||||
folder_name=$(echo "${database}" | rev | cut -d"/" -f2 | rev)
|
||||
target_dir="${BACKUP_DIR}/moonraker_databases/${current_date}/${folder_name}"
|
||||
mkdir -p "${target_dir}"
|
||||
cp -r "${database}" "${target_dir}"
|
||||
i=$(( i + 1 ))
|
||||
|
||||
ok_msg "Backup created in:\n${target_dir}"
|
||||
done
|
||||
else
|
||||
print_error "No Moonraker database found! Skipping backup ..."
|
||||
fi
|
||||
}
|
||||
|
||||
function backup_klipper() {
|
||||
local current_date
|
||||
|
||||
if [[ -d ${KLIPPER_DIR} && -d ${KLIPPY_ENV} ]]; then
|
||||
status_msg "Creating Klipper backup ..."
|
||||
check_for_backup_dir
|
||||
current_date=$(get_date)
|
||||
status_msg "Timestamp: ${current_date}"
|
||||
mkdir -p "${BACKUP_DIR}/klipper-backups/${current_date}"
|
||||
cp -r "${KLIPPER_DIR}" "${_}" && cp -r "${KLIPPY_ENV}" "${_}"
|
||||
print_confirm "Klipper backup complete!"
|
||||
else
|
||||
print_error "Can't back up 'klipper' and/or 'klipper-env' directory! Not found!"
|
||||
fi
|
||||
}
|
||||
|
||||
function backup_mainsail() {
|
||||
local current_date
|
||||
|
||||
if [[ -d ${MAINSAIL_DIR} ]]; then
|
||||
status_msg "Creating Mainsail backup ..."
|
||||
check_for_backup_dir
|
||||
current_date=$(get_date)
|
||||
status_msg "Timestamp: ${current_date}"
|
||||
mkdir -p "${BACKUP_DIR}/mainsail-backups/${current_date}"
|
||||
cp -r "${MAINSAIL_DIR}" "${_}"
|
||||
print_confirm "Mainsail backup complete!"
|
||||
else
|
||||
print_error "Can't back up 'mainsail' directory! Not found!"
|
||||
fi
|
||||
}
|
||||
|
||||
function backup_fluidd() {
|
||||
local current_date
|
||||
|
||||
if [[ -d ${FLUIDD_DIR} ]]; then
|
||||
status_msg "Creating Fluidd backup ..."
|
||||
check_for_backup_dir
|
||||
current_date=$(get_date)
|
||||
status_msg "Timestamp: ${current_date}"
|
||||
mkdir -p "${BACKUP_DIR}/fluidd-backups/${current_date}"
|
||||
cp -r "${FLUIDD_DIR}" "${_}"
|
||||
print_confirm "Fluidd backup complete!"
|
||||
else
|
||||
print_error "Can't back up 'fluidd' directory! Not found!"
|
||||
fi
|
||||
}
|
||||
|
||||
function backup_moonraker() {
|
||||
local current_date
|
||||
|
||||
if [[ -d ${MOONRAKER_DIR} && -d ${MOONRAKER_ENV} ]]; then
|
||||
status_msg "Creating Moonraker backup ..."
|
||||
check_for_backup_dir
|
||||
current_date=$(get_date)
|
||||
status_msg "Timestamp: ${current_date}"
|
||||
mkdir -p "${BACKUP_DIR}/moonraker-backups/${current_date}"
|
||||
cp -r "${MOONRAKER_DIR}" "${_}" && cp -r "${MOONRAKER_ENV}" "${_}"
|
||||
print_confirm "Moonraker backup complete!"
|
||||
else
|
||||
print_error "Can't back up moonraker and/or moonraker-env directory! Not found!"
|
||||
fi
|
||||
}
|
||||
|
||||
function backup_octoprint() {
|
||||
local current_date
|
||||
|
||||
if [[ -d ${OCTOPRINT_DIR} && -d ${OCTOPRINT_CFG_DIR} ]]; then
|
||||
status_msg "Creating OctoPrint backup ..."
|
||||
check_for_backup_dir
|
||||
current_date=$(get_date)
|
||||
status_msg "Timestamp: ${current_date}"
|
||||
mkdir -p "${BACKUP_DIR}/octoprint-backups/${current_date}"
|
||||
cp -r "${OCTOPRINT_DIR}" "${_}" && cp -r "${OCTOPRINT_CFG_DIR}" "${_}"
|
||||
print_confirm " OctoPrint backup complete!"
|
||||
else
|
||||
print_error "Can't back up OctoPrint and/or .octoprint directory!\n Not found!"
|
||||
fi
|
||||
}
|
||||
|
||||
function backup_klipperscreen() {
|
||||
local current_date
|
||||
if [[ -d ${KLIPPERSCREEN_DIR} ]] ; then
|
||||
status_msg "Creating KlipperScreen backup ..."
|
||||
check_for_backup_dir
|
||||
current_date=$(get_date)
|
||||
status_msg "Timestamp: ${current_date}"
|
||||
mkdir -p "${BACKUP_DIR}/klipperscreen-backups/${current_date}"
|
||||
cp -r "${KLIPPERSCREEN_DIR}" "${_}"
|
||||
print_confirm "KlipperScreen backup complete!"
|
||||
else
|
||||
print_error "Can't back up KlipperScreen directory!\n Not found!"
|
||||
fi
|
||||
}
|
||||
|
||||
function backup_telegram_bot() {
|
||||
local current_date
|
||||
|
||||
if [[ -d ${TELEGRAM_BOT_DIR} ]] ; then
|
||||
status_msg "Creating MoonrakerTelegramBot backup ..."
|
||||
check_for_backup_dir
|
||||
current_date=$(get_date)
|
||||
status_msg "Timestamp: ${current_date}"
|
||||
mkdir -p "${BACKUP_DIR}/MoonrakerTelegramBot-backups/${current_date}"
|
||||
cp -r "${TELEGRAM_BOT_DIR}" "${_}"
|
||||
print_confirm "MoonrakerTelegramBot backup complete!"
|
||||
else
|
||||
print_error "Can't back up MoonrakerTelegramBot directory!\n Not found!"
|
||||
fi
|
||||
}
|
||||
|
||||
function backup_octoeverywhere() {
|
||||
local current_date
|
||||
|
||||
if [[ -d ${OCTOEVERYWHERE_DIR} ]] ; then
|
||||
status_msg "Creating OctoEverywhere backup ..."
|
||||
check_for_backup_dir
|
||||
current_date=$(get_date)
|
||||
status_msg "Timestamp: ${current_date}"
|
||||
mkdir -p "${BACKUP_DIR}/OctoEverywhere-backups/${current_date}"
|
||||
cp -r "${OCTOEVERYWHERE_DIR}" "${_}" && cp -r "${OCTOEVERYWHERE_ENV}" "${_}"
|
||||
print_confirm "OctoEverywhere backup complete!"
|
||||
else
|
||||
print_error "Can't back up OctoEverywhere directory!\n Not found!"
|
||||
fi
|
||||
}
|
||||
|
||||
function backup_spoolman() {
|
||||
local current_date
|
||||
|
||||
if [[ -d ${SPOOLMAN_DIR} ]] ; then
|
||||
status_msg "Creating Spoolman backup ..."
|
||||
check_for_backup_dir
|
||||
current_date=$(get_date)
|
||||
status_msg "Timestamp: ${current_date}"
|
||||
mkdir -p "${BACKUP_DIR}/Spoolman-backups/${current_date}"
|
||||
cp -r "${SPOOLMAN_DIR}" "${_}" && cp -r "${SPOOLMAN_DB_DIR}/spoolman.db" "${_}"
|
||||
print_confirm "Spoolman backup complete!"
|
||||
else
|
||||
print_error "Can't back up Spoolman directory!\n Not found!"
|
||||
fi
|
||||
}
|
||||
@@ -1,235 +0,0 @@
|
||||
#!/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 #
|
||||
#=======================================================================#
|
||||
|
||||
#=======================================================================#
|
||||
# Crowsnest Installer brought to you by KwadFan <me@stephanwe.de> #
|
||||
# Copyright (C) 2022 KwadFan <me@stephanwe.de> #
|
||||
# https://github.com/KwadFan/crowsnest #
|
||||
#=======================================================================#
|
||||
|
||||
# Error Handling
|
||||
set -e
|
||||
|
||||
# Helper messages
|
||||
|
||||
function multi_instance_message(){
|
||||
echo -e "Crowsnest is NOT designed to support multi instances."
|
||||
echo -e "A workaround for this is to choose the most used instance as a 'master'"
|
||||
echo -e "Use this instance to set up your 'crowsnest.conf' and steering it's service.\n"
|
||||
echo -e "Found the following instances:\n"
|
||||
for i in ${1}; do
|
||||
select_msg "${i}"
|
||||
done
|
||||
echo -e "\nLaunching crowsnest's configuration tool ..."
|
||||
continue_config
|
||||
}
|
||||
|
||||
# Helper funcs
|
||||
function clone_crowsnest(){
|
||||
$(command -v git) clone "${CROWSNEST_REPO}" -b master "${CROWSNEST_DIR}"
|
||||
}
|
||||
|
||||
function check_multi_instance(){
|
||||
local -a instances
|
||||
readarray -t instances < <(find "${HOME}" -regex "${HOME}/[a-zA-Z0-9_]+_data/*" -printf "%P\n" 2> /dev/null | sort)
|
||||
if [[ "${#instances[@]}" -gt 1 ]]; then
|
||||
status_msg "Multi instance install detected ..."
|
||||
multi_instance_message "${instances[*]}"
|
||||
if [[ -d "${HOME}/crowsnest" ]]; then
|
||||
pushd "${HOME}/crowsnest" &> /dev/null || exit 1
|
||||
if ! make config ;then
|
||||
error_msg "Something went wrong! Please try again..."
|
||||
if [[ -f "tools/.config" ]]; then
|
||||
rm -f tools/.config
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
if [[ ! -f "tools/.config" ]]; then
|
||||
log_error "failure while generating .config"
|
||||
error_msg "Generating .config failed, installation aborted"
|
||||
exit 1
|
||||
fi
|
||||
popd &> /dev/null || exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function continue_config() {
|
||||
local reply
|
||||
while true; do
|
||||
read -erp "${cyan}###### Continue with configuration? (y/N):${white} " reply
|
||||
case "${reply}" in
|
||||
Y|y|Yes|yes)
|
||||
select_msg "Yes"
|
||||
break;;
|
||||
N|n|No|no|"")
|
||||
select_msg "No"
|
||||
warn_msg "Installation aborted by user ... Exiting!"
|
||||
exit 1;;
|
||||
*)
|
||||
error_msg "Invalid Input!\n";;
|
||||
esac
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
||||
# Install func
|
||||
function install_crowsnest(){
|
||||
|
||||
# Step 1: jump to home directory
|
||||
pushd "${HOME}" &> /dev/null || exit 1
|
||||
|
||||
# Step 2: Clone crowsnest repo
|
||||
status_msg "Cloning 'crowsnest' repository ..."
|
||||
if [[ ! -d "${HOME}/crowsnest" && -z "$(ls -A "${HOME}/crowsnest" 2> /dev/null)" ]]; then
|
||||
clone_crowsnest
|
||||
else
|
||||
ok_msg "crowsnest repository already exists ..."
|
||||
fi
|
||||
|
||||
# Step 3: Install dependencies
|
||||
dependency_check git make
|
||||
|
||||
# Step 4: Check for Multi Instance
|
||||
check_multi_instance
|
||||
|
||||
# Step 5: Launch crowsnest installer
|
||||
pushd "${HOME}/crowsnest" &> /dev/null || exit 1
|
||||
title_msg "Installer will prompt you for sudo password!"
|
||||
status_msg "Launching crowsnest installer ..."
|
||||
if ! sudo make install; then
|
||||
error_msg "Something went wrong! Please try again..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Step 5: Leave directory (twice due two pushd)
|
||||
popd &> /dev/null || exit 1
|
||||
popd &> /dev/null || exit 1
|
||||
}
|
||||
|
||||
# Remove func
|
||||
function remove_crowsnest(){
|
||||
if [[ -d "${CROWSNEST_DIR}" ]]; then
|
||||
pushd "${HOME}/crowsnest" &> /dev/null || exit 1
|
||||
title_msg "Uninstaller will prompt you for sudo password!"
|
||||
status_msg "Launching crowsnest uninstaller ..."
|
||||
|
||||
if ! make uninstall; then
|
||||
error_msg "Something went wrong! Please try again..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
status_msg "Removing crowsnest directory ..."
|
||||
rm -rf "${CROWSNEST_DIR}"
|
||||
ok_msg "Directory removed!"
|
||||
fi
|
||||
|
||||
print_confirm "Crowsnest successfully removed!"
|
||||
}
|
||||
|
||||
# Status funcs
|
||||
get_crowsnest_status(){
|
||||
local -a files
|
||||
local env_file
|
||||
env_file="$(grep "EnvironmentFile" /etc/systemd/system/crowsnest.service 2>/dev/null | cut -d "=" -f2)"
|
||||
files=(
|
||||
"${CROWSNEST_DIR}"
|
||||
"/usr/local/bin/crowsnest"
|
||||
"/etc/logrotate.d/crowsnest"
|
||||
"/etc/systemd/system/crowsnest.service"
|
||||
"${env_file}"
|
||||
)
|
||||
local count
|
||||
count=0
|
||||
|
||||
for file in "${files[@]}"; do
|
||||
[[ -e "${file}" ]] && count=$(( count +1 ))
|
||||
done
|
||||
if [[ "${count}" -eq "${#files[*]}" ]]; then
|
||||
echo "Installed"
|
||||
elif [[ "${count}" -gt 0 ]]; then
|
||||
echo "Incomplete!"
|
||||
else
|
||||
echo "Not installed!"
|
||||
fi
|
||||
}
|
||||
|
||||
# Update funcs
|
||||
# Shameless stolen from KlipperScreen.sh
|
||||
function get_local_crowsnest_commit() {
|
||||
[[ ! -d ${CROWSNEST_DIR} || ! -d "${CROWSNEST_DIR}/.git" ]] && return
|
||||
|
||||
local commit
|
||||
cd "${CROWSNEST_DIR}"
|
||||
commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
|
||||
echo "${commit}"
|
||||
}
|
||||
|
||||
function get_remote_crowsnest_commit() {
|
||||
[[ ! -d ${CROWSNEST_DIR} || ! -d "${CROWSNEST_DIR}/.git" ]] && return
|
||||
|
||||
local commit
|
||||
cd "${CROWSNEST_DIR}" && git fetch origin -q
|
||||
commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2)
|
||||
echo "${commit}"
|
||||
}
|
||||
|
||||
function compare_crowsnest_versions() {
|
||||
local versions local_ver remote_ver
|
||||
local_ver="$(get_local_crowsnest_commit)"
|
||||
remote_ver="$(get_remote_crowsnest_commit)"
|
||||
|
||||
if [[ ${local_ver} != "${remote_ver}" ]]; then
|
||||
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
# add moonraker to application_updates_available in kiauh.ini
|
||||
add_to_application_updates "crowsnest"
|
||||
else
|
||||
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
fi
|
||||
|
||||
echo "${versions}"
|
||||
}
|
||||
|
||||
function install_crowsnest_dependencies() {
|
||||
local packages log_name="Crowsnest"
|
||||
local install_script="${CROWSNEST_DIR}/tools/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[@]"
|
||||
}
|
||||
|
||||
function update_crowsnest() {
|
||||
do_action_service "stop" "crowsnest"
|
||||
|
||||
if [[ ! -d ${CROWSNEST_DIR} ]]; then
|
||||
clone_crowsnest
|
||||
else
|
||||
status_msg "Updating Crowsnest ..."
|
||||
cd "${CROWSNEST_DIR}" && git pull
|
||||
### read PKGLIST and install possible new dependencies
|
||||
install_crowsnest_dependencies
|
||||
fi
|
||||
ok_msg "Update complete!"
|
||||
do_action_service "restart" "crowsnest"
|
||||
}
|
||||
@@ -1,494 +0,0 @@
|
||||
#!/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 #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
function init_flash_process() {
|
||||
### step 1: check for required userhgroups (tty & dialout)
|
||||
check_usergroups
|
||||
|
||||
top_border
|
||||
echo -e "| ~~~~~~~~~~~~ [ Flash MCU ] ~~~~~~~~~~~~ |"
|
||||
hr
|
||||
echo -e "| Please select the flashing method to flash your MCU. |"
|
||||
echo -e "| Make sure to only select a method your MCU supports. |"
|
||||
echo -e "| Not all MCUs support both methods! |"
|
||||
hr
|
||||
blank_line
|
||||
echo -e "| 1) Regular flashing method |"
|
||||
echo -e "| 2) Updating via SD-Card Update |"
|
||||
blank_line
|
||||
back_help_footer
|
||||
|
||||
local choice method
|
||||
while true; do
|
||||
read -p "${cyan}###### Please select:${white} " choice
|
||||
case "${choice}" in
|
||||
1)
|
||||
select_msg "Regular flashing method"
|
||||
method="regular"
|
||||
break;;
|
||||
2)
|
||||
select_msg "SD-Card Update"
|
||||
method="sdcard"
|
||||
break;;
|
||||
B|b)
|
||||
advanced_menu
|
||||
break;;
|
||||
H|h)
|
||||
clear && print_header
|
||||
show_flash_method_help
|
||||
break;;
|
||||
*)
|
||||
error_msg "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
|
||||
### step 2: select how the mcu is flashed (flash/serialflash)
|
||||
select_flash_command
|
||||
|
||||
### step 3: select how the mcu is connected to the host
|
||||
select_mcu_connection
|
||||
|
||||
### step 4: select which detected mcu should be flashed
|
||||
select_mcu_id "${method}"
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=================== STEP 2 =====================#
|
||||
#================================================#
|
||||
function select_flash_command() {
|
||||
unset flash_command
|
||||
|
||||
top_border
|
||||
echo -e "| How to flash MCU? |"
|
||||
echo -e "| 1) make flash (default) |"
|
||||
echo -e "| 2) make serialflash (stm32flash) |"
|
||||
blank_line
|
||||
back_help_footer
|
||||
|
||||
local choice
|
||||
while true; do
|
||||
read -p "${cyan}###### Flashing command:${white} " -i "1" -e choice
|
||||
case "${choice}" in
|
||||
1)
|
||||
select_msg "Selected 'make flash' command"
|
||||
flash_command="flash"
|
||||
break;;
|
||||
2)
|
||||
select_msg "Selected 'make serialflash' command"
|
||||
flash_command="serialflash"
|
||||
break;;
|
||||
B|b)
|
||||
advanced_menu
|
||||
break;;
|
||||
H|h)
|
||||
clear && print_header
|
||||
show_mcu_flash_command_help
|
||||
break;;
|
||||
*)
|
||||
error_msg "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=================== STEP 3 =====================#
|
||||
#================================================#
|
||||
function select_mcu_connection() {
|
||||
top_border
|
||||
echo -e "| ${yellow}Make sure that the controller board is connected now!${white} |"
|
||||
hr
|
||||
blank_line
|
||||
echo -e "| How is the controller board connected to the host? |"
|
||||
echo -e "| 1) USB |"
|
||||
echo -e "| 2) UART |"
|
||||
echo -e "| 3) USB (DFU mode) |"
|
||||
blank_line
|
||||
back_help_footer
|
||||
|
||||
local choice
|
||||
while true; do
|
||||
read -p "${cyan}###### Connection method:${white} " choice
|
||||
case "${choice}" in
|
||||
1)
|
||||
status_msg "Identifying MCU connected via USB ...\n"
|
||||
get_usb_id || true # continue even after exit code 1
|
||||
break;;
|
||||
2)
|
||||
status_msg "Identifying MCU possibly connected via UART ...\n"
|
||||
get_uart_id || true # continue even after exit code 1
|
||||
break;;
|
||||
3)
|
||||
status_msg "Identifying MCU connected via USB in DFU mode ...\n"
|
||||
get_dfu_id || true # continue even after exit code 1
|
||||
break;;
|
||||
B|b)
|
||||
advanced_menu
|
||||
break;;
|
||||
H|h)
|
||||
clear && print_header
|
||||
show_mcu_connection_help
|
||||
break;;
|
||||
*)
|
||||
error_msg "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
function print_detected_mcu_to_screen() {
|
||||
local i=1
|
||||
|
||||
if (( ${#mcu_list[@]} < 1 )); then
|
||||
print_error "No MCU found!\n MCU either not connected or not detected!"
|
||||
return
|
||||
fi
|
||||
|
||||
for mcu in "${mcu_list[@]}"; do
|
||||
echo -e " ● MCU #${i}: ${cyan}${mcu}${white}"
|
||||
i=$(( i + 1 ))
|
||||
done
|
||||
echo
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=================== STEP 4 =====================#
|
||||
#================================================#
|
||||
function select_mcu_id() {
|
||||
local i=0 sel_index=0 method=${1}
|
||||
|
||||
if (( ${#mcu_list[@]} < 1 )); then
|
||||
print_error "No MCU found!\n MCU either not connected or not detected!"
|
||||
return
|
||||
fi
|
||||
|
||||
top_border
|
||||
echo -e "| ${red}!!! ATTENTION !!!${white} |"
|
||||
hr
|
||||
echo -e "| Make sure, to select the correct MCU! |"
|
||||
echo -e "| ${red}ONLY flash a firmware created for the respective MCU!${white} |"
|
||||
bottom_border
|
||||
echo -e "${cyan}###### List of available MCU:${white}"
|
||||
|
||||
### list all mcus
|
||||
for mcu in "${mcu_list[@]}"; do
|
||||
i=$(( i + 1 ))
|
||||
mcu=$(echo "${mcu}" | rev | cut -d"/" -f1 | rev)
|
||||
echo -e " ● MCU #${i}: ${cyan}${mcu}${white}"
|
||||
done
|
||||
|
||||
### verify user input
|
||||
local regex="^[1-9]+$"
|
||||
while [[ ! ${sel_index} =~ ${regex} ]] || [[ ${sel_index} -gt ${i} ]]; do
|
||||
echo
|
||||
read -p "${cyan}###### Select MCU to flash:${white} " sel_index
|
||||
|
||||
if [[ ! ${sel_index} =~ ${regex} ]]; then
|
||||
error_msg "Invalid input!"
|
||||
elif [[ ${sel_index} -lt 1 ]] || [[ ${sel_index} -gt ${i} ]]; then
|
||||
error_msg "Please select a number between 1 and ${i}!"
|
||||
fi
|
||||
|
||||
local mcu_index=$(( sel_index - 1 ))
|
||||
local selected_mcu_id="${mcu_list[${mcu_index}]}"
|
||||
done
|
||||
|
||||
### confirm selection
|
||||
local yn
|
||||
while true; do
|
||||
echo -e "\n###### You selected:\n ● MCU #${sel_index}: ${selected_mcu_id}\n"
|
||||
read -p "${cyan}###### Continue? (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
status_msg "Flashing ${selected_mcu_id} ..."
|
||||
if [[ ${method} == "regular" ]]; then
|
||||
log_info "Flashing device '${selected_mcu_id}' with method '${method}'"
|
||||
start_flash_mcu "${selected_mcu_id}"
|
||||
elif [[ ${method} == "sdcard" ]]; then
|
||||
log_info "Flashing device '${selected_mcu_id}' with method '${method}'"
|
||||
start_flash_sd "${selected_mcu_id}"
|
||||
else
|
||||
print_error "No flash method set! Aborting..."
|
||||
log_error "No flash method set!"
|
||||
return
|
||||
fi
|
||||
break;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
break;;
|
||||
*)
|
||||
error_msg "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
function start_flash_mcu() {
|
||||
local device=${1}
|
||||
do_action_service "stop" "klipper"
|
||||
|
||||
if make ${flash_command} FLASH_DEVICE="${device}"; then
|
||||
ok_msg "Flashing successfull!"
|
||||
else
|
||||
warn_msg "Flashing failed!"
|
||||
warn_msg "Please read the console output above!"
|
||||
fi
|
||||
|
||||
do_action_service "start" "klipper"
|
||||
}
|
||||
|
||||
function start_flash_sd() {
|
||||
local i=0 board_list=() device=${1}
|
||||
local flash_script="${KLIPPER_DIR}/scripts/flash-sdcard.sh"
|
||||
|
||||
### write each supported board to the array to make it selectable
|
||||
for board in $("${flash_script}" -l | tail -n +2); do
|
||||
board_list+=("${board}")
|
||||
done
|
||||
|
||||
top_border
|
||||
echo -e "| Please select the type of board that corresponds to |"
|
||||
echo -e "| the currently selected MCU ID you chose before. |"
|
||||
blank_line
|
||||
echo -e "| The following boards are currently supported: |"
|
||||
hr
|
||||
### display all supported boards to the user
|
||||
for board in "${board_list[@]}"; do
|
||||
if [[ ${i} -lt 10 ]]; then
|
||||
printf "| ${i}) %-50s|\n" "${board_list[${i}]}"
|
||||
else
|
||||
printf "| ${i}) %-49s|\n" "${board_list[${i}]}"
|
||||
fi
|
||||
i=$(( i + 1 ))
|
||||
done
|
||||
quit_footer
|
||||
|
||||
### make the user select one of the boards
|
||||
local choice
|
||||
while true; do
|
||||
read -p "${cyan}###### Please select board type:${white} " choice
|
||||
if [[ ${choice} = "q" || ${choice} = "Q" ]]; then
|
||||
clear && advanced_menu && break
|
||||
elif [[ ${choice} -le ${#board_list[@]} ]]; then
|
||||
local selected_board="${board_list[${choice}]}"
|
||||
break
|
||||
else
|
||||
clear && print_header
|
||||
error_msg "Invalid choice!"
|
||||
flash_mcu_sd
|
||||
fi
|
||||
done
|
||||
|
||||
while true; do
|
||||
echo
|
||||
top_border
|
||||
echo -e "| If your board is flashed with firmware that connects |"
|
||||
echo -e "| at a custom baud rate, please change it now. |"
|
||||
blank_line
|
||||
echo -e "| If you are unsure, stick to the default 250000! |"
|
||||
bottom_border
|
||||
|
||||
local baud_rate regex="^[0-9]+$"
|
||||
echo -e "${cyan}###### Please set the baud rate:${white} "
|
||||
while [[ ! ${baud_rate} =~ ${regex} ]]; do
|
||||
read -e -i "250000" -e baud_rate
|
||||
local selected_baud_rate=${baud_rate}
|
||||
break
|
||||
done
|
||||
break
|
||||
done
|
||||
|
||||
###flash process
|
||||
do_action_service "stop" "klipper"
|
||||
if "${flash_script}" -b "${selected_baud_rate}" "${device}" "${selected_board}"; then
|
||||
print_confirm "Flashing successfull!"
|
||||
log_info "Flash successfull!"
|
||||
else
|
||||
print_error "Flashing failed!\n Please read the console output above!"
|
||||
log_error "Flash failed!"
|
||||
fi
|
||||
do_action_service "start" "klipper"
|
||||
}
|
||||
|
||||
function build_fw() {
|
||||
local python_version
|
||||
|
||||
if [[ ! -d ${KLIPPER_DIR} || ! -d ${KLIPPY_ENV} ]]; then
|
||||
print_error "Klipper not found!\n Cannot build firmware without Klipper!"
|
||||
return
|
||||
fi
|
||||
|
||||
python_version=$(get_klipper_python_ver)
|
||||
|
||||
cd "${KLIPPER_DIR}"
|
||||
status_msg "Initializing firmware build ..."
|
||||
local dep=(build-essential dpkg-dev make)
|
||||
dependency_check "${dep[@]}"
|
||||
|
||||
make clean
|
||||
|
||||
status_msg "Building firmware ..."
|
||||
if (( python_version == 3 )); then
|
||||
make PYTHON=python3 menuconfig
|
||||
make PYTHON=python3
|
||||
elif (( python_version == 2 )); then
|
||||
make PYTHON=python2 menuconfig
|
||||
make PYTHON=python2
|
||||
else
|
||||
warn_msg "Error reading Python version!"
|
||||
return 1
|
||||
fi
|
||||
|
||||
ok_msg "Firmware built!"
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=================== HELPERS ====================#
|
||||
#================================================#
|
||||
|
||||
function get_usb_id() {
|
||||
unset mcu_list
|
||||
sleep 1
|
||||
mcus=$(find /dev/serial/by-id/* 2>/dev/null)
|
||||
|
||||
for mcu in ${mcus}; do
|
||||
mcu_list+=("${mcu}")
|
||||
done
|
||||
}
|
||||
|
||||
function get_uart_id() {
|
||||
unset mcu_list
|
||||
sleep 1
|
||||
mcus=$(find /dev -maxdepth 1 -regextype posix-extended -regex "^\/dev\/tty(AMA0|S0)$" 2>/dev/null)
|
||||
|
||||
for mcu in ${mcus}; do
|
||||
mcu_list+=("${mcu}")
|
||||
done
|
||||
}
|
||||
|
||||
function get_dfu_id() {
|
||||
unset mcu_list
|
||||
sleep 1
|
||||
mcus=$(lsusb | grep "DFU" | cut -d " " -f 6 2>/dev/null)
|
||||
|
||||
for mcu in ${mcus}; do
|
||||
mcu_list+=("${mcu}")
|
||||
done
|
||||
}
|
||||
|
||||
function show_flash_method_help() {
|
||||
top_border
|
||||
echo -e "| ~~~~~~~~ < ? > Help: Flash MCU < ? > ~~~~~~~~ |"
|
||||
hr
|
||||
echo -e "| ${cyan}Regular flashing method:${white} |"
|
||||
echo -e "| The default method to flash controller boards which |"
|
||||
echo -e "| are connected and updated over USB and not by placing |"
|
||||
echo -e "| a compiled firmware file onto an internal SD-Card. |"
|
||||
blank_line
|
||||
echo -e "| Common controllers that get flashed that way are: |"
|
||||
echo -e "| - Arduino Mega 2560 |"
|
||||
echo -e "| - Fysetc F6 / S6 (used without a Display + SD-Slot) |"
|
||||
blank_line
|
||||
echo -e "| ${cyan}Updating via SD-Card Update:${white} |"
|
||||
echo -e "| Many popular controller boards ship with a bootloader |"
|
||||
echo -e "| capable of updating the firmware via SD-Card. |"
|
||||
echo -e "| Choose this method if your controller board supports |"
|
||||
echo -e "| this way of updating. This method ONLY works for up- |"
|
||||
echo -e "| grading firmware. The initial flashing procedure must |"
|
||||
echo -e "| be done manually per the instructions that apply to |"
|
||||
echo -e "| your controller board. |"
|
||||
blank_line
|
||||
echo -e "| Common controllers that can be flashed that way are: |"
|
||||
echo -e "| - BigTreeTech SKR 1.3 / 1.4 (Turbo) / E3 / Mini E3 |"
|
||||
echo -e "| - Fysetc F6 / S6 (used with a Display + SD-Slot) |"
|
||||
echo -e "| - Fysetc Spider |"
|
||||
blank_line
|
||||
back_footer
|
||||
|
||||
local choice
|
||||
while true; do
|
||||
read -p "${cyan}###### Please select:${white} " choice
|
||||
case "${choice}" in
|
||||
B|b)
|
||||
clear && print_header
|
||||
init_flash_process
|
||||
break;;
|
||||
*)
|
||||
error_msg "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
function show_mcu_flash_command_help() {
|
||||
top_border
|
||||
echo -e "| ~~~~~~~~ < ? > Help: Flash MCU < ? > ~~~~~~~~ |"
|
||||
hr
|
||||
echo -e "| ${cyan}make flash:${white} |"
|
||||
echo -e "| The default command to flash controller board, it |"
|
||||
echo -e "| will detect selected microcontroller and use suitable |"
|
||||
echo -e "| tool for flashing it. |"
|
||||
blank_line
|
||||
echo -e "| ${cyan}make serialflash:${white} |"
|
||||
echo -e "| Special command to flash STM32 microcontrollers in |"
|
||||
echo -e "| DFU mode but connected via serial. stm32flash command |"
|
||||
echo -e "| will be used internally. |"
|
||||
blank_line
|
||||
back_footer
|
||||
|
||||
local choice
|
||||
while true; do
|
||||
read -p "${cyan}###### Please select:${white} " choice
|
||||
case "${choice}" in
|
||||
B|b)
|
||||
clear && print_header
|
||||
select_flash_command
|
||||
break;;
|
||||
*)
|
||||
error_msg "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
function show_mcu_connection_help() {
|
||||
top_border
|
||||
echo -e "| ~~~~~~~~ < ? > Help: Flash MCU < ? > ~~~~~~~~ |"
|
||||
hr
|
||||
echo -e "| ${cyan}USB:${white} |"
|
||||
echo -e "| Selecting USB as the connection method will scan the |"
|
||||
echo -e "| USB ports for connected controller boards. This will |"
|
||||
echo -e "| be similar to the 'ls /dev/serial/by-id/*' command |"
|
||||
echo -e "| suggested by the official Klipper documentation for |"
|
||||
echo -e "| determining successfull USB connections! |"
|
||||
blank_line
|
||||
echo -e "| ${cyan}UART:${white} |"
|
||||
echo -e "| Selecting UART as the connection method will list all |"
|
||||
echo -e "| possible UART serial ports. Note: This method ALWAYS |"
|
||||
echo -e "| returns something as it seems impossible to determine |"
|
||||
echo -e "| if a valid Klipper controller board is connected or |"
|
||||
echo -e "| not. Because of that, you ${red}MUST${white} know which UART serial |"
|
||||
echo -e "| port your controller board is connected to when using |"
|
||||
echo -e "| this connection method. |"
|
||||
blank_line
|
||||
back_footer
|
||||
|
||||
local choice
|
||||
while true; do
|
||||
read -p "${cyan}###### Please select:${white} " choice
|
||||
case "${choice}" in
|
||||
B|b)
|
||||
clear && print_header
|
||||
select_mcu_connection
|
||||
break;;
|
||||
*)
|
||||
error_msg "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
}
|
||||
@@ -1,510 +0,0 @@
|
||||
#!/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 #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
#===================================================#
|
||||
#================== INSTALL FLUIDD =================#
|
||||
#===================================================#
|
||||
|
||||
function install_fluidd() {
|
||||
if [[ -z $(moonraker_systemd) ]]; then
|
||||
local error="Moonraker not installed! It's recommended to install Moonraker first!"
|
||||
print_error "${error}"
|
||||
while true; do
|
||||
local yn
|
||||
read -p "${cyan}###### Proceed to install Fluidd without installing Moonraker? (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 Fluidd setup ...\n"
|
||||
return;;
|
||||
*)
|
||||
error_msg "Invalid Input!";;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
|
||||
### checking dependencies
|
||||
local dep=(wget nginx unzip)
|
||||
dependency_check "${dep[@]}"
|
||||
### detect conflicting Haproxy and Apache2 installations
|
||||
detect_conflicting_packages
|
||||
|
||||
status_msg "Initializing Fluidd installation ..."
|
||||
### first, we create a backup of the full klipper_config dir - safety first!
|
||||
backup_config_dir
|
||||
|
||||
### check for other enabled web interfaces
|
||||
unset SET_LISTEN_PORT
|
||||
detect_enabled_sites
|
||||
|
||||
### check if another site already listens to port 80
|
||||
fluidd_port_check
|
||||
|
||||
### download fluidd
|
||||
download_fluidd
|
||||
|
||||
### ask user to install the recommended webinterface macros
|
||||
install_fluidd_macros
|
||||
|
||||
### create /etc/nginx/conf.d/upstreams.conf
|
||||
set_upstream_nginx_cfg
|
||||
### create /etc/nginx/sites-available/<interface config>
|
||||
set_nginx_cfg "fluidd"
|
||||
### nginx on ubuntu 21 and above needs special permissions to access the files
|
||||
set_nginx_permissions
|
||||
|
||||
### symlink nginx log
|
||||
symlink_webui_nginx_log "fluidd"
|
||||
|
||||
### add fluidd to the update manager in moonraker.conf
|
||||
patch_fluidd_update_manager
|
||||
|
||||
fetch_webui_ports #WIP
|
||||
|
||||
### confirm message
|
||||
print_confirm "Fluidd has been set up!"
|
||||
}
|
||||
|
||||
function install_fluidd_macros() {
|
||||
local yn
|
||||
while true; do
|
||||
echo
|
||||
top_border
|
||||
echo -e "| It is recommended to use special macros in order to |"
|
||||
echo -e "| have Fluidd fully functional and working. |"
|
||||
blank_line
|
||||
echo -e "| The recommended macros for Fluidd can be found here: |"
|
||||
echo -e "| https://github.com/fluidd-core/fluidd-config |"
|
||||
blank_line
|
||||
echo -e "| If you already use these macros skip this step. |"
|
||||
echo -e "| Otherwise you should consider to answer with 'yes' to |"
|
||||
echo -e "| download the recommended macros. |"
|
||||
bottom_border
|
||||
read -p "${cyan}###### Download the recommended macros? (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
download_fluidd_macros
|
||||
break;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
break;;
|
||||
*)
|
||||
print_error "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
return
|
||||
}
|
||||
|
||||
function download_fluidd_macros() {
|
||||
local ms_cfg_repo path configs regex line gcode_dir
|
||||
|
||||
ms_cfg_repo="https://github.com/fluidd-core/fluidd-config.git"
|
||||
regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/printer\.cfg"
|
||||
configs=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${regex}" | sort)
|
||||
|
||||
if [[ -z ${configs} ]]; then
|
||||
print_error "No printer.cfg found! Installation of Macros will be skipped ..."
|
||||
log_error "execution stopped! reason: no printer.cfg found"
|
||||
return
|
||||
fi
|
||||
|
||||
status_msg "Cloning fluidd-config ..."
|
||||
[[ -d "${HOME}/fluidd-config" ]] && rm -rf "${HOME}/fluidd-config"
|
||||
if git clone --recurse-submodules "${ms_cfg_repo}" "${HOME}/fluidd-config"; then
|
||||
for config in ${configs}; do
|
||||
path=$(echo "${config}" | rev | cut -d"/" -f2- | rev)
|
||||
|
||||
if [[ -e "${path}/fluidd.cfg" && ! -h "${path}/fluidd.cfg" ]]; then
|
||||
warn_msg "Attention! Existing fluidd.cfg detected!"
|
||||
warn_msg "The file will be renamed to 'fluidd.bak.cfg' to be able to continue with the installation."
|
||||
if ! mv "${path}/fluidd.cfg" "${path}/fluidd.bak.cfg"; then
|
||||
error_msg "Renaming fluidd.cfg failed! Aborting installation ..."
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -h "${path}/fluidd.cfg" ]]; then
|
||||
warn_msg "Recreating symlink in ${path} ..."
|
||||
rm -rf "${path}/fluidd.cfg"
|
||||
fi
|
||||
|
||||
if ! ln -sf "${HOME}/fluidd-config/client.cfg" "${path}/fluidd.cfg"; then
|
||||
error_msg "Creating symlink failed! Aborting installation ..."
|
||||
return
|
||||
fi
|
||||
|
||||
if ! grep -Eq "^\[include fluidd.cfg\]$" "${path}/printer.cfg"; then
|
||||
log_info "${path}/printer.cfg"
|
||||
sed -i "1 i [include fluidd.cfg]" "${path}/printer.cfg"
|
||||
fi
|
||||
|
||||
line=$(($(grep -n "\[include fluidd.cfg\]" "${path}/printer.cfg" | tail -1 | cut -d: -f1) + 1))
|
||||
gcode_dir=${path/config/gcodes}
|
||||
if ! grep -Eq "^\[virtual_sdcard\]$" "${path}/printer.cfg"; then
|
||||
log_info "${path}/printer.cfg"
|
||||
sed -i "${line} i \[virtual_sdcard]\npath: ${gcode_dir}\non_error_gcode: CANCEL_PRINT\n" "${path}/printer.cfg"
|
||||
fi
|
||||
done
|
||||
else
|
||||
print_error "Cloning failed! Aborting installation ..."
|
||||
log_error "execution stopped! reason: cloning failed"
|
||||
return
|
||||
fi
|
||||
|
||||
patch_fluidd_config_update_manager
|
||||
|
||||
ok_msg "Done!"
|
||||
}
|
||||
|
||||
function download_fluidd() {
|
||||
local url
|
||||
url=$(get_fluidd_download_url)
|
||||
|
||||
status_msg "Downloading Fluidd from ${url} ..."
|
||||
|
||||
if [[ -d ${FLUIDD_DIR} ]]; then
|
||||
rm -rf "${FLUIDD_DIR}"
|
||||
fi
|
||||
|
||||
mkdir "${FLUIDD_DIR}" && cd "${FLUIDD_DIR}"
|
||||
|
||||
if wget "${url}"; then
|
||||
ok_msg "Download complete!"
|
||||
status_msg "Extracting archive ..."
|
||||
unzip -q -o ./*.zip && ok_msg "Done!"
|
||||
status_msg "Remove downloaded archive ..."
|
||||
rm -rf ./*.zip && ok_msg "Done!"
|
||||
else
|
||||
print_error "Downloading Fluidd from\n ${url}\n failed!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#================== REMOVE FLUIDD ==================#
|
||||
#===================================================#
|
||||
|
||||
function remove_fluidd_dir() {
|
||||
[[ ! -d ${FLUIDD_DIR} ]] && return
|
||||
|
||||
status_msg "Removing Fluidd directory ..."
|
||||
rm -rf "${FLUIDD_DIR}" && ok_msg "Directory removed!"
|
||||
}
|
||||
|
||||
function remove_fluidd_nginx_config() {
|
||||
if [[ -e "/etc/nginx/sites-available/fluidd" ]]; then
|
||||
status_msg "Removing Fluidd configuration for Nginx ..."
|
||||
sudo rm "/etc/nginx/sites-available/fluidd" && ok_msg "File removed!"
|
||||
fi
|
||||
if [[ -L "/etc/nginx/sites-enabled/fluidd" ]]; then
|
||||
status_msg "Removing Fluidd Symlink for Nginx ..."
|
||||
sudo rm "/etc/nginx/sites-enabled/fluidd" && ok_msg "File removed!"
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_fluidd_logs() {
|
||||
local files
|
||||
files=$(find /var/log/nginx -name "fluidd*" 2> /dev/null | sort)
|
||||
|
||||
if [[ -n ${files} ]]; then
|
||||
for file in ${files}; do
|
||||
status_msg "Removing ${file} ..."
|
||||
sudo rm -f "${file}"
|
||||
ok_msg "${file} removed!"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_fluidd_log_symlinks() {
|
||||
local files regex
|
||||
|
||||
regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/logs\/fluidd-.*"
|
||||
files=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${regex}" 2> /dev/null | 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_legacy_fluidd_log_symlinks() {
|
||||
local files
|
||||
files=$(find "${HOME}/klipper_logs" -name "fluidd*" 2> /dev/null | 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_fluidd_config() {
|
||||
if [[ -d "${HOME}/fluidd-config" ]]; then
|
||||
status_msg "Removing ${HOME}/fluidd-config ..."
|
||||
rm -rf "${HOME}/fluidd-config"
|
||||
ok_msg "${HOME}/fluidd-config removed!"
|
||||
print_confirm "Fluidd-Config successfully removed!"
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_fluidd() {
|
||||
remove_fluidd_dir
|
||||
remove_fluidd_nginx_config
|
||||
remove_fluidd_logs
|
||||
remove_fluidd_log_symlinks
|
||||
remove_legacy_fluidd_log_symlinks
|
||||
|
||||
### remove fluidd_port from ~/.kiauh.ini
|
||||
sed -i "/^fluidd_port=/d" "${INI_FILE}"
|
||||
|
||||
print_confirm "Fluidd successfully removed!"
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#================== UPDATE FLUIDD ==================#
|
||||
#===================================================#
|
||||
|
||||
function update_fluidd() {
|
||||
backup_before_update "fluidd"
|
||||
status_msg "Updating Fluidd ..."
|
||||
download_fluidd
|
||||
match_nginx_configs
|
||||
symlink_webui_nginx_log "fluidd"
|
||||
print_confirm "Fluidd successfully updated!"
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#================== FLUIDD STATUS ==================#
|
||||
#===================================================#
|
||||
|
||||
function get_fluidd_status() {
|
||||
local status
|
||||
local data_arr=("${FLUIDD_DIR}" "${NGINX_SA}/fluidd" "${NGINX_SE}/fluidd")
|
||||
|
||||
### count+1 for each found data-item from array
|
||||
local filecount=0
|
||||
for data in "${data_arr[@]}"; do
|
||||
[[ -e ${data} ]] && filecount=$(( filecount + 1 ))
|
||||
done
|
||||
|
||||
if (( filecount == ${#data_arr[*]} )); then
|
||||
status="Installed!"
|
||||
elif (( filecount == 0 )); then
|
||||
status="Not installed!"
|
||||
else
|
||||
status="Incomplete!"
|
||||
fi
|
||||
echo "${status}"
|
||||
}
|
||||
|
||||
function get_local_fluidd_version() {
|
||||
local versionfile="${FLUIDD_DIR}/.version"
|
||||
local relinfofile="${FLUIDD_DIR}/release_info.json"
|
||||
local version
|
||||
|
||||
if [[ -f ${relinfofile} ]]; then
|
||||
version=$(grep -o '"version":"[^"]*' "${relinfofile}" | grep -o '[^"]*$')
|
||||
elif [[ -f ${versionfile} ]]; then
|
||||
version=$(head -n 1 "${versionfile}")
|
||||
fi
|
||||
|
||||
echo "${version}"
|
||||
}
|
||||
|
||||
function get_remote_fluidd_version() {
|
||||
[[ ! $(dpkg-query -f'${Status}' --show curl 2>/dev/null) = *\ installed ]] && return
|
||||
|
||||
local tags
|
||||
tags=$(curl -s "https://api.github.com/repos/fluidd-core/fluidd/tags" | grep "name" | cut -d'"' -f4)
|
||||
echo "${tags}" | head -1
|
||||
}
|
||||
|
||||
function compare_fluidd_versions() {
|
||||
local versions local_ver remote_ver
|
||||
local_ver="$(get_local_fluidd_version)"
|
||||
remote_ver="$(get_remote_fluidd_version)"
|
||||
|
||||
if [[ ${local_ver} != "${remote_ver}" && ${local_ver} != "" ]]; then
|
||||
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
# add moonraker to application_updates_available in kiauh.ini
|
||||
add_to_application_updates "fluidd"
|
||||
else
|
||||
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
fi
|
||||
|
||||
echo "${versions}"
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=================== HELPERS ====================#
|
||||
#================================================#
|
||||
|
||||
function get_fluidd_download_url() {
|
||||
local releases_by_tag tags tag unstable_url url
|
||||
|
||||
### latest stable download url
|
||||
url="https://github.com/fluidd-core/fluidd/releases/latest/download/fluidd.zip"
|
||||
|
||||
read_kiauh_ini "${FUNCNAME[0]}"
|
||||
if [[ ${fluidd_install_unstable} == "true" ]]; then
|
||||
releases_by_tag="https://api.github.com/repos/fluidd-core/fluidd/tags"
|
||||
tags=$(curl -s "${releases_by_tag}" | grep "name" | cut -d'"' -f4)
|
||||
tag=$(echo "${tags}" | head -1)
|
||||
|
||||
### latest unstable download url including pre-releases (alpha, beta, rc)
|
||||
unstable_url="https://github.com/fluidd-core/fluidd/releases/download/${tag}/fluidd.zip"
|
||||
|
||||
if [[ ${unstable_url} == *"download//"* ]]; then
|
||||
warn_msg "Download URL broken! Falling back to URL of latest stable release!"
|
||||
else
|
||||
url=${unstable_url}
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "${url}"
|
||||
}
|
||||
|
||||
function fluidd_port_check() {
|
||||
if [[ ${FLUIDD_ENABLED} == "false" ]]; then
|
||||
|
||||
if [[ ${SITE_ENABLED} == "true" ]]; then
|
||||
status_msg "Detected other enabled interfaces:"
|
||||
|
||||
[[ ${MAINSAIL_ENABLED} == "true" ]] && \
|
||||
echo " ${cyan}● Mainsail - Port: ${MAINSAIL_PORT}${white}"
|
||||
|
||||
if [[ ${MAINSAIL_PORT} == "80" ]]; then
|
||||
PORT_80_BLOCKED="true"
|
||||
select_fluidd_port
|
||||
fi
|
||||
else
|
||||
DEFAULT_PORT=$(grep listen "${KIAUH_SRCDIR}/resources/fluidd" | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1)
|
||||
SET_LISTEN_PORT=${DEFAULT_PORT}
|
||||
fi
|
||||
SET_NGINX_CFG="true"
|
||||
|
||||
else
|
||||
SET_NGINX_CFG="false"
|
||||
fi
|
||||
}
|
||||
|
||||
function select_fluidd_port() {
|
||||
if [[ ${PORT_80_BLOCKED} == "true" ]]; then
|
||||
echo
|
||||
top_border
|
||||
echo -e "| ${red}!!!WARNING!!!${white} |"
|
||||
echo -e "| ${red}You need to choose a different port for Fluidd!${white} |"
|
||||
echo -e "| ${red}The following web interface is listening at port 80:${white} |"
|
||||
blank_line
|
||||
[[ ${MAINSAIL_PORT} == "80" ]] && echo "| ● Mainsail |"
|
||||
blank_line
|
||||
echo -e "| Make sure you don't choose a port which was already |"
|
||||
echo -e "| assigned to another webinterface! |"
|
||||
blank_line
|
||||
echo -e "| Be aware: there is ${red}NO${white} sanity check for the following |"
|
||||
echo -e "| input. So make sure to choose a valid port! |"
|
||||
bottom_border
|
||||
|
||||
local new_port re="^[0-9]+$"
|
||||
while true; do
|
||||
read -p "${cyan}Please enter a new Port:${white} " new_port
|
||||
if [[ ${new_port} =~ ${re} && ${new_port} != "${MAINSAIL_PORT}" ]]; then
|
||||
select_msg "Setting port ${new_port} for Fluidd!"
|
||||
SET_LISTEN_PORT=${new_port}
|
||||
break
|
||||
else
|
||||
if [[ ! ${new_port} =~ ${re} ]]; then
|
||||
error_msg "Invalid input!"
|
||||
else
|
||||
error_msg "Port already taken! Select a different one!"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function patch_fluidd_update_manager() {
|
||||
local patched moonraker_configs regex
|
||||
regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/moonraker\.conf"
|
||||
moonraker_configs=$(find "${HOME}" -maxdepth 3 -type f -regextype posix-extended -regex "${regex}" | sort)
|
||||
|
||||
patched="false"
|
||||
for conf in ${moonraker_configs}; do
|
||||
if ! grep -Eq "^\[update_manager fluidd\]\s*$" "${conf}"; then
|
||||
### add new line to conf if it doesn't end with one
|
||||
[[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}"
|
||||
|
||||
### add Fluidds update manager section to moonraker.conf
|
||||
status_msg "Adding Fluidd to update manager in file:\n ${conf}"
|
||||
/bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF
|
||||
|
||||
[update_manager fluidd]
|
||||
type: web
|
||||
channel: stable
|
||||
repo: fluidd-core/fluidd
|
||||
path: ~/fluidd
|
||||
MOONRAKER_CONF
|
||||
|
||||
fi
|
||||
|
||||
patched="true"
|
||||
done
|
||||
|
||||
if [[ ${patched} == "true" ]]; then
|
||||
do_action_service "restart" "moonraker"
|
||||
fi
|
||||
}
|
||||
|
||||
function patch_fluidd_config_update_manager() {
|
||||
local patched moonraker_configs regex
|
||||
regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/moonraker\.conf"
|
||||
moonraker_configs=$(find "${HOME}" -maxdepth 3 -type f -regextype posix-extended -regex "${regex}" | sort)
|
||||
|
||||
patched="false"
|
||||
for conf in ${moonraker_configs}; do
|
||||
if ! grep -Eq "^\[update_manager fluidd-config\]\s*$" "${conf}"; then
|
||||
### add new line to conf if it doesn't end with one
|
||||
[[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}"
|
||||
|
||||
### add Fluidds update manager section to moonraker.conf
|
||||
status_msg "Adding Fluidd-Config to update manager in file:\n ${conf}"
|
||||
/bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF
|
||||
|
||||
[update_manager fluidd-config]
|
||||
type: git_repo
|
||||
primary_branch: master
|
||||
path: ~/fluidd-config
|
||||
origin: https://github.com/fluidd-core/fluidd-config.git
|
||||
managed_services: klipper
|
||||
MOONRAKER_CONF
|
||||
|
||||
fi
|
||||
|
||||
patched="true"
|
||||
done
|
||||
|
||||
if [[ ${patched} == "true" ]]; then
|
||||
do_action_service "restart" "moonraker"
|
||||
fi
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
#!/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 #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
#=================================================#
|
||||
#======== INSTALL GCODE_SHELL_COMMAND.PY =========#
|
||||
#=================================================#
|
||||
|
||||
function setup_gcode_shell_command() {
|
||||
top_border
|
||||
echo -e "| You are about to install the 'G-Code Shell Command' |"
|
||||
echo -e "| extension. Please make sure to read the instructions |"
|
||||
echo -e "| before you continue and remember that potential risks |"
|
||||
echo -e "| can be involved after installing this extension! |"
|
||||
blank_line
|
||||
echo -e "| ${red}You accept that you are doing this on your own risk!${white} |"
|
||||
bottom_border
|
||||
|
||||
local yn
|
||||
while true; do
|
||||
read -p "${cyan}###### Do you want to continue? (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
|
||||
if [[ ! -d "${KLIPPER_DIR}/klippy/extras" ]]; then
|
||||
print_error "Folder ~/klipper/klippy/extras not found!\n Klipper not installed yet?"
|
||||
return
|
||||
fi
|
||||
|
||||
status_msg "Installing gcode shell command extension ..."
|
||||
|
||||
if [[ ! -f "${KLIPPER_DIR}/klippy/extras/gcode_shell_command.py" ]]; then
|
||||
install_gcode_shell_command
|
||||
else
|
||||
echo; warn_msg "File 'gcode_shell_command.py' already exists in the destination location!"
|
||||
|
||||
while true; do
|
||||
read -p "${cyan}###### Do you want to overwrite it? (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
rm -f "${KLIPPER_DIR}/klippy/extras/gcode_shell_command.py"
|
||||
install_gcode_shell_command
|
||||
break;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
break;;
|
||||
*)
|
||||
error_msg "Invalid Input!";;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
return;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
return;;
|
||||
*)
|
||||
error_msg "Invalid Input!";;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
function install_gcode_shell_command() {
|
||||
do_action_service "stop" "klipper"
|
||||
status_msg "Copy 'gcode_shell_command.py' to '${KLIPPER_DIR}/klippy/extras' ..."
|
||||
|
||||
if cp "${KIAUH_SRCDIR}/resources/gcode_shell_command.py" "${KLIPPER_DIR}/klippy/extras"; then
|
||||
ok_msg "Done!"
|
||||
else
|
||||
error_msg "Cannot copy file to target destination...Exiting!"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local yn
|
||||
while true; do
|
||||
echo
|
||||
read -p "${cyan}###### Create an example shell command? (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
create_example_shell_command
|
||||
break;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
break;;
|
||||
esac
|
||||
done
|
||||
|
||||
do_action_service "restart" "klipper"
|
||||
print_confirm "Shell command extension installed!"
|
||||
return
|
||||
}
|
||||
|
||||
function create_example_shell_command() {
|
||||
### create a backup of the config folder
|
||||
backup_config_dir
|
||||
|
||||
local configs regex path
|
||||
regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/printer\.cfg"
|
||||
configs=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${regex}" | sort)
|
||||
|
||||
for cfg in ${configs}; do
|
||||
path=$(echo "${cfg}" | rev | cut -d"/" -f2- | rev)
|
||||
|
||||
if [[ ! -f "${path}/shell_command.cfg" ]]; then
|
||||
status_msg "Copy shell_command.cfg to ${path} ..."
|
||||
cp "${KIAUH_SRCDIR}/resources/shell_command.cfg" "${path}"
|
||||
ok_msg "${path}/shell_command.cfg created!"
|
||||
### write include to the very first line of the printer.cfg
|
||||
sed -i "1 i [include shell_command.cfg]" "${cfg}"
|
||||
fi
|
||||
done
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
#!/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 #
|
||||
#=======================================================================#
|
||||
|
||||
# shellcheck disable=SC2034
|
||||
set -e
|
||||
|
||||
function set_globals() {
|
||||
#=================== SYSTEM ===================#
|
||||
SYSTEMD="/etc/systemd/system"
|
||||
INITD="/etc/init.d"
|
||||
ETCDEF="/etc/default"
|
||||
|
||||
#=================== KIAUH ====================#
|
||||
green=$(echo -en "\e[92m")
|
||||
yellow=$(echo -en "\e[93m")
|
||||
magenta=$(echo -en "\e[35m")
|
||||
red=$(echo -en "\e[91m")
|
||||
cyan=$(echo -en "\e[96m")
|
||||
white=$(echo -en "\e[39m")
|
||||
INI_FILE="${HOME}/.kiauh.ini"
|
||||
LOGFILE="/tmp/kiauh.log"
|
||||
RESOURCES="${KIAUH_SRCDIR}/resources"
|
||||
BACKUP_DIR="${HOME}/kiauh-backups"
|
||||
|
||||
#================== KLIPPER ===================#
|
||||
KLIPPY_ENV="${HOME}/klippy-env"
|
||||
KLIPPER_DIR="${HOME}/klipper"
|
||||
KLIPPER_REPO="https://github.com/Klipper3d/klipper.git"
|
||||
|
||||
#================= MOONRAKER ==================#
|
||||
MOONRAKER_ENV="${HOME}/moonraker-env"
|
||||
MOONRAKER_DIR="${HOME}/moonraker"
|
||||
MOONRAKER_REPO="https://github.com/Arksine/moonraker.git"
|
||||
|
||||
#================= MAINSAIL ===================#
|
||||
MAINSAIL_DIR="${HOME}/mainsail"
|
||||
|
||||
#================== FLUIDD ====================#
|
||||
FLUIDD_DIR="${HOME}/fluidd"
|
||||
|
||||
#=============== KLIPPERSCREEN ================#
|
||||
KLIPPERSCREEN_ENV="${HOME}/.KlipperScreen-env"
|
||||
KLIPPERSCREEN_DIR="${HOME}/KlipperScreen"
|
||||
KLIPPERSCREEN_REPO="https://github.com/jordanruthe/KlipperScreen.git"
|
||||
|
||||
#========== MOONRAKER-TELEGRAM-BOT ============#
|
||||
TELEGRAM_BOT_ENV="${HOME}/moonraker-telegram-bot-env"
|
||||
TELEGRAM_BOT_DIR="${HOME}/moonraker-telegram-bot"
|
||||
TELEGRAM_BOT_REPO="https://github.com/nlef/moonraker-telegram-bot.git"
|
||||
|
||||
#=============== PRETTY-GCODE =================#
|
||||
PGC_DIR="${HOME}/pgcode"
|
||||
PGC_REPO="https://github.com/Kragrathea/pgcode"
|
||||
|
||||
#================== NGINX =====================#
|
||||
NGINX_SA="/etc/nginx/sites-available"
|
||||
NGINX_SE="/etc/nginx/sites-enabled"
|
||||
NGINX_CONFD="/etc/nginx/conf.d"
|
||||
|
||||
#=============== MOONRAKER-OBICO ================#
|
||||
MOONRAKER_OBICO_DIR="${HOME}/moonraker-obico"
|
||||
MOONRAKER_OBICO_REPO="https://github.com/TheSpaghettiDetective/moonraker-obico.git"
|
||||
|
||||
#=============== OCTOEVERYWHERE ================#
|
||||
OCTOEVERYWHERE_ENV="${HOME}/octoeverywhere-env"
|
||||
OCTOEVERYWHERE_DIR="${HOME}/octoeverywhere"
|
||||
OCTOEVERYWHERE_REPO="https://github.com/QuinnDamerell/OctoPrint-OctoEverywhere.git"
|
||||
|
||||
#=============== Crowsnest ================#
|
||||
CROWSNEST_DIR="${HOME}/crowsnest"
|
||||
CROWSNEST_REPO="https://github.com/mainsail-crew/crowsnest.git"
|
||||
|
||||
#=============== Mobileraker ================#
|
||||
MOBILERAKER_ENV="${HOME}/mobileraker-env"
|
||||
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"
|
||||
|
||||
#=============== Spoolman ================#
|
||||
SPOOLMAN_DIR="${HOME}/Spoolman"
|
||||
SPOOLMAN_DB_DIR="${HOME}/.local/share/spoolman"
|
||||
SPOOLMAN_REPO="https://api.github.com/repos/Donkie/Spoolman/releases/latest"
|
||||
}
|
||||
@@ -1,664 +0,0 @@
|
||||
#!/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 #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
#TODO (multi instance):
|
||||
# if the klipper installer is started another time while other klipper
|
||||
# instances are detected, ask if new instances should be added
|
||||
|
||||
#=================================================#
|
||||
#================ INSTALL KLIPPER ================#
|
||||
#=================================================#
|
||||
|
||||
###
|
||||
# this function detects all installed klipper
|
||||
# systemd instances and returns their absolute path
|
||||
function klipper_systemd() {
|
||||
local services
|
||||
local blacklist
|
||||
local ignore
|
||||
local match
|
||||
|
||||
###
|
||||
# any service that uses "klipper" in its own name but isn't a full klipper service must be blacklisted using
|
||||
# this variable, otherwise they will be falsely recognized as klipper instances. E.g. "klipper-mcu.service"
|
||||
# is not a klipper service, but related to klippers linux mcu, which also requires its own service file, hence
|
||||
# it must be blacklisted.
|
||||
blacklist="mcu"
|
||||
|
||||
ignore="${SYSTEMD}/klipper-(${blacklist}).service"
|
||||
match="${SYSTEMD}/klipper(-[0-9a-zA-Z]+)?.service"
|
||||
|
||||
services=$(find "${SYSTEMD}" -maxdepth 1 -regextype awk ! -regex "${ignore}" -regex "${match}" | sort)
|
||||
echo "${services}"
|
||||
}
|
||||
|
||||
function start_klipper_setup() {
|
||||
local klipper_systemd_services
|
||||
local python_version
|
||||
local instance_count
|
||||
local instance_names
|
||||
local use_custom_names
|
||||
local input
|
||||
local regex
|
||||
local blacklist
|
||||
local error
|
||||
|
||||
status_msg "Initializing Klipper installation ...\n"
|
||||
|
||||
### return early if klipper already exists
|
||||
klipper_systemd_services=$(klipper_systemd)
|
||||
|
||||
if [[ -n ${klipper_systemd_services} ]]; then
|
||||
error="At least one Klipper service is already installed:"
|
||||
|
||||
for s in ${klipper_systemd_services}; do
|
||||
log_info "Found Klipper service: ${s}"
|
||||
error="${error}\n ➔ ${s}"
|
||||
done
|
||||
fi
|
||||
[[ -n ${error} ]] && print_error "${error}" && return
|
||||
|
||||
### user selection for python version
|
||||
print_dialog_user_select_python_version
|
||||
while true; do
|
||||
read -p "${cyan}###### Select Python version:${white} " -i "1" -e input
|
||||
case "${input}" in
|
||||
1)
|
||||
select_msg "Python 3.x\n"
|
||||
python_version=3
|
||||
break;;
|
||||
2)
|
||||
select_msg "Python 2.7\n"
|
||||
python_version=2
|
||||
break;;
|
||||
B|b)
|
||||
clear; install_menu; break;;
|
||||
*)
|
||||
error_msg "Invalid Input!\n";;
|
||||
esac
|
||||
done && input=""
|
||||
|
||||
### user selection for instance count
|
||||
print_dialog_user_select_instance_count
|
||||
regex="^[1-9][0-9]*$"
|
||||
while [[ ! ${input} =~ ${regex} ]]; do
|
||||
read -p "${cyan}###### Number of Klipper instances to set up:${white} " -i "1" -e input
|
||||
|
||||
if [[ ${input} =~ ${regex} ]]; then
|
||||
instance_count="${input}"
|
||||
select_msg "Instance count: ${instance_count}\n"
|
||||
break
|
||||
elif [[ ${input} == "B" || ${input} == "b" ]]; then
|
||||
install_menu
|
||||
else
|
||||
error_msg "Invalid Input!\n"
|
||||
fi
|
||||
done && input=""
|
||||
|
||||
### user selection for custom names
|
||||
use_custom_names="false"
|
||||
if (( instance_count > 1 )); then
|
||||
print_dialog_user_select_custom_name_bool
|
||||
while true; do
|
||||
read -p "${cyan}###### Assign custom names? (y/N):${white} " input
|
||||
case "${input}" in
|
||||
Y|y|Yes|yes)
|
||||
select_msg "Yes\n"
|
||||
use_custom_names="true"
|
||||
break;;
|
||||
N|n|No|no|"")
|
||||
select_msg "No\n"
|
||||
break;;
|
||||
B|b)
|
||||
clear; install_menu; break;;
|
||||
*)
|
||||
error_msg "Invalid Input!\n";;
|
||||
esac
|
||||
done && input=""
|
||||
else
|
||||
instance_names+=("printer")
|
||||
fi
|
||||
|
||||
### user selection for setting the actual custom names
|
||||
shopt -s nocasematch
|
||||
if (( instance_count > 1 )) && [[ ${use_custom_names} == "true" ]]; then
|
||||
local i
|
||||
|
||||
i=1
|
||||
regex="^[0-9a-zA-Z]+$"
|
||||
blacklist="mcu"
|
||||
while [[ ! ${input} =~ ${regex} || ${input} =~ ${blacklist} || ${i} -le ${instance_count} ]]; do
|
||||
read -p "${cyan}###### Name for instance #${i}:${white} " input
|
||||
|
||||
if [[ ${input} =~ ${blacklist} ]]; then
|
||||
error_msg "Name not allowed! You are trying to use a reserved name."
|
||||
elif [[ ${input} =~ ${regex} && ! ${input} =~ ${blacklist} ]]; then
|
||||
select_msg "Name: ${input}\n"
|
||||
if [[ ${input} =~ ^[0-9]+$ ]]; then
|
||||
instance_names+=("printer_${input}")
|
||||
else
|
||||
instance_names+=("${input}")
|
||||
fi
|
||||
i=$(( i + 1 ))
|
||||
else
|
||||
error_msg "Invalid Input!\n"
|
||||
fi
|
||||
done && input=""
|
||||
elif (( instance_count > 1 )) && [[ ${use_custom_names} == "false" ]]; then
|
||||
for (( i=1; i <= instance_count; i++ )); do
|
||||
instance_names+=("printer_${i}")
|
||||
done
|
||||
fi
|
||||
shopt -u nocasematch
|
||||
|
||||
(( instance_count > 1 )) && status_msg "Installing ${instance_count} Klipper instances ..."
|
||||
(( instance_count == 1 )) && status_msg "Installing single Klipper instance ..."
|
||||
|
||||
run_klipper_setup "${python_version}" "${instance_names[@]}"
|
||||
}
|
||||
|
||||
function print_dialog_user_select_python_version() {
|
||||
top_border
|
||||
echo -e "| Please select your preferred Python version. | "
|
||||
echo -e "| The recommended version is Python 3.x. | "
|
||||
hr
|
||||
echo -e "| 1) [Python 3.x] (recommended) | "
|
||||
echo -e "| 2) [Python 2.7] ${yellow}(legacy)${white} | "
|
||||
back_footer
|
||||
}
|
||||
|
||||
function print_dialog_user_select_instance_count() {
|
||||
top_border
|
||||
echo -e "| Please select the number of Klipper instances to set |"
|
||||
echo -e "| up. The number of Klipper instances will determine |"
|
||||
echo -e "| the amount of printers you can run from this host. |"
|
||||
blank_line
|
||||
echo -e "| ${yellow}WARNING:${white} |"
|
||||
echo -e "| ${yellow}Setting up too many instances may crash your system.${white} |"
|
||||
back_footer
|
||||
}
|
||||
|
||||
function print_dialog_user_select_custom_name_bool() {
|
||||
top_border
|
||||
echo -e "| You can now assign a custom name to each instance. |"
|
||||
echo -e "| If skipped, each instance will get an index assigned |"
|
||||
echo -e "| in ascending order, starting at index '1'. |"
|
||||
blank_line
|
||||
echo -e "| Info: |"
|
||||
echo -e "| Only alphanumeric characters for names are allowed! |"
|
||||
back_footer
|
||||
}
|
||||
|
||||
function run_klipper_setup() {
|
||||
read_kiauh_ini "${FUNCNAME[0]}"
|
||||
|
||||
local python_version=${1}
|
||||
local instance_names
|
||||
local confirm
|
||||
local custom_repo
|
||||
local custom_branch
|
||||
local dep
|
||||
|
||||
shift 1
|
||||
read -r -a instance_names <<< "${@}"
|
||||
|
||||
custom_repo="${custom_klipper_repo}"
|
||||
custom_branch="${custom_klipper_repo_branch}"
|
||||
dep=(git)
|
||||
|
||||
### checking dependencies
|
||||
dependency_check "${dep[@]}"
|
||||
|
||||
### step 1: clone klipper
|
||||
clone_klipper "${custom_repo}" "${custom_branch}"
|
||||
|
||||
### step 2: install klipper dependencies and create python virtualenv
|
||||
install_klipper_packages "${python_version}"
|
||||
create_klipper_virtualenv "${python_version}"
|
||||
|
||||
### step 3: create klipper instances
|
||||
for instance in "${instance_names[@]}"; do
|
||||
create_klipper_service "${instance}"
|
||||
done
|
||||
|
||||
### step 4: enable and start all instances
|
||||
do_action_service "enable" "klipper"
|
||||
do_action_service "start" "klipper"
|
||||
|
||||
### step 5: check for dialout group membership
|
||||
check_usergroups
|
||||
|
||||
### confirm message
|
||||
(( ${#instance_names[@]} == 1 )) && confirm="Klipper has been set up!"
|
||||
(( ${#instance_names[@]} > 1 )) && confirm="${#instance_names[@]} Klipper instances have been set up!"
|
||||
|
||||
### finalizing the setup with writing instance names to the kiauh.ini
|
||||
set_multi_instance_names
|
||||
mask_disrupting_services
|
||||
|
||||
print_confirm "${confirm}" && return
|
||||
}
|
||||
|
||||
function clone_klipper() {
|
||||
local repo=${1} branch=${2}
|
||||
|
||||
[[ -z ${repo} ]] && repo="${KLIPPER_REPO}"
|
||||
repo=$(echo "${repo}" | sed -r "s/^(http|https):\/\/github\.com\///i; s/\.git$//")
|
||||
repo="https://github.com/${repo}"
|
||||
|
||||
[[ -z ${branch} ]] && branch="master"
|
||||
|
||||
### force remove existing klipper dir and clone into fresh klipper dir
|
||||
[[ -d ${KLIPPER_DIR} ]] && rm -rf "${KLIPPER_DIR}"
|
||||
|
||||
status_msg "Cloning Klipper from ${repo} ..."
|
||||
|
||||
cd "${HOME}" || exit 1
|
||||
if git clone "${repo}" "${KLIPPER_DIR}"; then
|
||||
cd "${KLIPPER_DIR}" && git checkout "${branch}"
|
||||
else
|
||||
print_error "Cloning Klipper from\n ${repo}\n failed!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function create_klipper_virtualenv() {
|
||||
local python_version="${1}"
|
||||
|
||||
[[ -d ${KLIPPY_ENV} ]] && rm -rf "${KLIPPY_ENV}"
|
||||
|
||||
status_msg "Installing $("python${python_version}" -V) virtual environment..."
|
||||
|
||||
if virtualenv -p "python${python_version}" "${KLIPPY_ENV}"; then
|
||||
"${KLIPPY_ENV}"/bin/pip install -r "${KLIPPER_DIR}"/scripts/klippy-requirements.txt
|
||||
else
|
||||
log_error "failure while creating python3 klippy-env"
|
||||
error_msg "Creation of Klipper virtualenv failed!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
###
|
||||
# extracts the required packages from the
|
||||
# install-debian.sh script and installs them
|
||||
#
|
||||
# @param {string}: python_version - klipper-env python version
|
||||
#
|
||||
function install_klipper_packages() {
|
||||
local packages log_name="Klipper" python_version="${1}"
|
||||
local install_script="${KLIPPER_DIR}/scripts/install-debian.sh"
|
||||
|
||||
status_msg "Reading dependencies..."
|
||||
# shellcheck disable=SC2016
|
||||
packages=$(grep "PKGLIST=" "${install_script}" | cut -d'"' -f2 | sed 's/\${PKGLIST}//g' | tr -d '\n')
|
||||
### add dfu-util for octopi-images
|
||||
packages+=" dfu-util"
|
||||
### add pkg-config for rp2040 build
|
||||
packages+=" pkg-config"
|
||||
### add dbus requirement for DietPi distro
|
||||
[[ -e "/boot/dietpi/.version" ]] && packages+=" dbus"
|
||||
|
||||
if (( python_version == 3 )); then
|
||||
### replace python-dev with python3-dev if python3 was selected
|
||||
packages="${packages//python-dev/python3-dev}"
|
||||
elif (( python_version == 2 )); then
|
||||
### package name 'python-dev' is deprecated (-> no installation candidate) on more modern linux distros
|
||||
packages="${packages//python-dev/python2-dev}"
|
||||
else
|
||||
log_error "Internal Error: missing parameter 'python_version' during function call of ${FUNCNAME[0]}"
|
||||
error_msg "Internal Error: missing parameter 'python_version' during function call of ${FUNCNAME[0]}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
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[@]"
|
||||
}
|
||||
|
||||
function create_klipper_service() {
|
||||
local instance_name=${1}
|
||||
|
||||
local printer_data
|
||||
local cfg_dir
|
||||
local gcodes_dir
|
||||
local cfg
|
||||
local log
|
||||
local klippy_serial
|
||||
local klippy_socket
|
||||
local env_file
|
||||
local service
|
||||
local service_template
|
||||
local env_template
|
||||
local suffix
|
||||
|
||||
printer_data="${HOME}/${instance_name}_data"
|
||||
cfg_dir="${printer_data}/config"
|
||||
gcodes_dir="${printer_data}/gcodes"
|
||||
cfg="${cfg_dir}/printer.cfg"
|
||||
log="${printer_data}/logs/klippy.log"
|
||||
klippy_serial="${printer_data}/comms/klippy.serial"
|
||||
klippy_socket="${printer_data}/comms/klippy.sock"
|
||||
env_file="${printer_data}/systemd/klipper.env"
|
||||
|
||||
if [[ ${instance_name} == "printer" ]]; then
|
||||
suffix="${instance_name//printer/}"
|
||||
else
|
||||
suffix="-${instance_name//printer_/}"
|
||||
fi
|
||||
|
||||
create_required_folders "${printer_data}"
|
||||
|
||||
service_template="${KIAUH_SRCDIR}/resources/klipper.service"
|
||||
env_template="${KIAUH_SRCDIR}/resources/klipper.env"
|
||||
service="${SYSTEMD}/klipper${suffix}.service"
|
||||
|
||||
if [[ ! -f ${service} ]]; then
|
||||
status_msg "Create Klipper service file ..."
|
||||
|
||||
sudo cp "${service_template}" "${service}"
|
||||
sudo cp "${env_template}" "${env_file}"
|
||||
sudo sed -i "s|%USER%|${USER}|g; s|%KLIPPER_DIR%|${KLIPPER_DIR}|; s|%ENV%|${KLIPPY_ENV}|; s|%ENV_FILE%|${env_file}|" "${service}"
|
||||
sudo sed -i "s|%USER%|${USER}|; s|%KLIPPER_DIR%|${KLIPPER_DIR}|; s|%LOG%|${log}|; s|%CFG%|${cfg}|; s|%PRINTER%|${klippy_serial}|; s|%UDS%|${klippy_socket}|" "${env_file}"
|
||||
|
||||
ok_msg "Klipper service file created!"
|
||||
fi
|
||||
|
||||
if [[ ! -f ${cfg} ]]; then
|
||||
write_example_printer_cfg "${cfg}" "${gcodes_dir}"
|
||||
fi
|
||||
}
|
||||
|
||||
function write_example_printer_cfg() {
|
||||
local cfg=${1}
|
||||
local gcodes_dir=${2}
|
||||
local cfg_template
|
||||
|
||||
cfg_template="${KIAUH_SRCDIR}/resources/example.printer.cfg"
|
||||
|
||||
status_msg "Creating minimal example printer.cfg ..."
|
||||
if cp "${cfg_template}" "${cfg}"; then
|
||||
sed -i "s|%GCODES_DIR%|${gcodes_dir}|" "${cfg}"
|
||||
ok_msg "Minimal example printer.cfg created!"
|
||||
else
|
||||
error_msg "Couldn't create minimal example printer.cfg!"
|
||||
fi
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#================ REMOVE KLIPPER ================#
|
||||
#================================================#
|
||||
|
||||
function remove_klipper_service() {
|
||||
[[ -z $(klipper_systemd) ]] && return
|
||||
|
||||
status_msg "Removing Klipper services ..."
|
||||
|
||||
for service in $(klipper_systemd | cut -d"/" -f5); do
|
||||
status_msg "Removing ${service} ..."
|
||||
sudo systemctl stop "${service}"
|
||||
sudo systemctl disable "${service}"
|
||||
sudo rm -f "${SYSTEMD}/${service}"
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl reset-failed
|
||||
done
|
||||
|
||||
ok_msg "All Klipper services removed!"
|
||||
}
|
||||
|
||||
function find_instance_files() {
|
||||
local target_folder=${1}
|
||||
local target_name=${2}
|
||||
local files
|
||||
|
||||
readarray -t files < <(find "${HOME}" -regex "${HOME}/[A-Za-z0-9_]+_data/${target_folder}/${target_name}" | sort)
|
||||
|
||||
echo -e "${files[@]}"
|
||||
}
|
||||
|
||||
function find_legacy_klipper_logs() {
|
||||
local files
|
||||
local regex="klippy(-[0-9a-zA-Z]+)?\.log(.*)?"
|
||||
|
||||
readarray -t files < <(find "${HOME}/klipper_logs" -maxdepth 1 -regextype posix-extended -regex "${HOME}/klipper_logs/${regex}" 2> /dev/null | sort)
|
||||
echo -e "${files[@]}"
|
||||
}
|
||||
|
||||
function find_legacy_klipper_uds() {
|
||||
local files
|
||||
|
||||
readarray -t files < <(find /tmp -maxdepth 1 -regextype posix-extended -regex "/tmp/klippy_uds(-[0-9a-zA-Z]+)?" | sort)
|
||||
echo -e "${files[@]}"
|
||||
}
|
||||
|
||||
function find_legacy_klipper_printer() {
|
||||
local files
|
||||
|
||||
readarray -t files < <(find /tmp -maxdepth 1 -regextype posix-extended -regex "/tmp/printer(-[0-9a-zA-Z]+)?" | sort)
|
||||
echo -e "${files[@]}"
|
||||
}
|
||||
|
||||
function remove_klipper_dir() {
|
||||
[[ ! -d ${KLIPPER_DIR} ]] && return
|
||||
|
||||
status_msg "Removing Klipper directory ..."
|
||||
rm -rf "${KLIPPER_DIR}"
|
||||
ok_msg "Directory removed!"
|
||||
}
|
||||
|
||||
function remove_klipper_env() {
|
||||
[[ ! -d ${KLIPPY_ENV} ]] && return
|
||||
|
||||
status_msg "Removing klippy-env directory ..."
|
||||
rm -rf "${KLIPPY_ENV}"
|
||||
ok_msg "Directory removed!"
|
||||
}
|
||||
|
||||
###
|
||||
# takes in a string of space separated absolute
|
||||
# filepaths and removes those files one after another
|
||||
#
|
||||
function remove_files() {
|
||||
local files
|
||||
read -r -a files <<< "${@}"
|
||||
|
||||
if (( ${#files[@]} > 0 )); then
|
||||
for file in "${files[@]}"; do
|
||||
status_msg "Removing ${file} ..."
|
||||
rm -f "${file}"
|
||||
ok_msg "${file} removed!"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_klipper() {
|
||||
remove_klipper_service
|
||||
remove_files "$(find_instance_files "systemd" "klipper.env")"
|
||||
remove_files "$(find_instance_files "logs" "klippy.log.*")"
|
||||
remove_files "$(find_instance_files "comms" "klippy.sock")"
|
||||
remove_files "$(find_instance_files "comms" "klippy.serial")"
|
||||
|
||||
remove_files "$(find_legacy_klipper_logs)"
|
||||
remove_files "$(find_legacy_klipper_uds)"
|
||||
remove_files "$(find_legacy_klipper_printer)"
|
||||
|
||||
remove_klipper_dir
|
||||
remove_klipper_env
|
||||
|
||||
print_confirm "Klipper was successfully removed!" && return
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#================ UPDATE KLIPPER ================#
|
||||
#================================================#
|
||||
|
||||
###
|
||||
# stops klipper, performs a git pull, installs
|
||||
# possible new dependencies, then restarts klipper
|
||||
#
|
||||
function update_klipper() {
|
||||
read_kiauh_ini "${FUNCNAME[0]}"
|
||||
|
||||
local py_ver
|
||||
local custom_repo="${custom_klipper_repo}"
|
||||
local custom_branch="${custom_klipper_repo_branch}"
|
||||
|
||||
py_ver=$(get_klipper_python_ver)
|
||||
|
||||
do_action_service "stop" "klipper"
|
||||
|
||||
if [[ ! -d ${KLIPPER_DIR} ]]; then
|
||||
clone_klipper "${custom_repo}" "${custom_branch}"
|
||||
else
|
||||
backup_before_update "klipper"
|
||||
|
||||
status_msg "Updating Klipper ..."
|
||||
cd "${KLIPPER_DIR}" && git pull
|
||||
### read PKGLIST and install possible new dependencies
|
||||
install_klipper_packages "${py_ver}"
|
||||
### install possible new python dependencies
|
||||
"${KLIPPY_ENV}"/bin/pip install -r "${KLIPPER_DIR}/scripts/klippy-requirements.txt"
|
||||
fi
|
||||
|
||||
ok_msg "Update complete!"
|
||||
do_action_service "restart" "klipper"
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#================ KLIPPER STATUS ================#
|
||||
#================================================#
|
||||
|
||||
function get_klipper_status() {
|
||||
local sf_count status py_ver
|
||||
sf_count="$(klipper_systemd | wc -w)"
|
||||
|
||||
py_ver=$(get_klipper_python_ver)
|
||||
|
||||
### remove the "SERVICE" entry from the data array if a klipper service is installed
|
||||
local data_arr=(SERVICE "${KLIPPER_DIR}" "${KLIPPY_ENV}")
|
||||
(( sf_count > 0 )) && unset "data_arr[0]"
|
||||
|
||||
### count+1 for each found data-item from array
|
||||
local filecount=0
|
||||
for data in "${data_arr[@]}"; do
|
||||
[[ -e ${data} ]] && filecount=$(( filecount + 1 ))
|
||||
done
|
||||
|
||||
if (( filecount == ${#data_arr[*]} )); then
|
||||
if (( py_ver == 3 )); then
|
||||
status="Installed: ${sf_count}(py${py_ver})"
|
||||
else
|
||||
status="Installed: ${sf_count}"
|
||||
fi
|
||||
elif (( filecount == 0 )); then
|
||||
status="Not installed!"
|
||||
else
|
||||
status="Incomplete!"
|
||||
fi
|
||||
|
||||
echo "${status}"
|
||||
}
|
||||
|
||||
function get_local_klipper_commit() {
|
||||
[[ ! -d ${KLIPPER_DIR} || ! -d "${KLIPPER_DIR}/.git" ]] && return
|
||||
|
||||
local commit
|
||||
cd "${KLIPPER_DIR}"
|
||||
commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
|
||||
echo "${commit}"
|
||||
}
|
||||
|
||||
function get_remote_klipper_commit() {
|
||||
[[ ! -d ${KLIPPER_DIR} || ! -d "${KLIPPER_DIR}/.git" ]] && return
|
||||
|
||||
local commit
|
||||
local branch
|
||||
|
||||
read_kiauh_ini "${FUNCNAME[0]}"
|
||||
branch="${custom_klipper_repo_branch}"
|
||||
[[ -z ${branch} ]] && branch="master"
|
||||
|
||||
cd "${KLIPPER_DIR}" && git fetch origin -q
|
||||
commit=$(git describe "origin/${branch}" --always --tags | cut -d "-" -f 1,2)
|
||||
echo "${commit}"
|
||||
}
|
||||
|
||||
function compare_klipper_versions() {
|
||||
local versions local_ver remote_ver
|
||||
local_ver="$(get_local_klipper_commit)"
|
||||
remote_ver="$(get_remote_klipper_commit)"
|
||||
|
||||
if [[ ${local_ver} != "${remote_ver}" ]]; then
|
||||
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
# add klipper to application_updates_available in kiauh.ini
|
||||
add_to_application_updates "klipper"
|
||||
else
|
||||
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
fi
|
||||
|
||||
echo "${versions}"
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=================== HELPERS ====================#
|
||||
#================================================#
|
||||
|
||||
###
|
||||
# reads the python version from the klipper virtual environment
|
||||
#
|
||||
# @output: writes the python major version to STDOUT
|
||||
#
|
||||
function get_klipper_python_ver() {
|
||||
[[ ! -d ${KLIPPY_ENV} ]] && return
|
||||
|
||||
local version
|
||||
version=$("${KLIPPY_ENV}"/bin/python --version 2>&1 | cut -d" " -f2 | cut -d"." -f1)
|
||||
echo "${version}"
|
||||
}
|
||||
|
||||
function mask_disrupting_services() {
|
||||
local brltty="false"
|
||||
local brltty_udev="false"
|
||||
local modem_manager="false"
|
||||
|
||||
[[ $(dpkg -s brltty 2>/dev/null | grep "Status") = *\ installed ]] && brltty="true"
|
||||
[[ $(dpkg -s brltty-udev 2>/dev/null | grep "Status") = *\ installed ]] && brltty_udev="true"
|
||||
[[ $(dpkg -s ModemManager 2>/dev/null | grep "Status") = *\ installed ]] && modem_manager="true"
|
||||
|
||||
status_msg "Installed brltty package detected, masking brltty service ..."
|
||||
if [[ ${brltty} == "true" ]]; then
|
||||
sudo systemctl stop brltty
|
||||
sudo systemctl mask brltty
|
||||
fi
|
||||
ok_msg "brltty service masked!"
|
||||
|
||||
status_msg "Installed brltty-udev package detected, masking brltty-udev service ..."
|
||||
if [[ ${brltty_udev} == "true" ]]; then
|
||||
sudo systemctl stop brltty-udev
|
||||
sudo systemctl mask brltty-udev
|
||||
fi
|
||||
ok_msg "brltty-udev service masked!"
|
||||
|
||||
status_msg "Installed ModemManager package detected, masking ModemManager service ..."
|
||||
if [[ ${modem_manager} == "true" ]]; then
|
||||
sudo systemctl stop ModemManager
|
||||
sudo systemctl mask ModemManager
|
||||
fi
|
||||
ok_msg "ModemManager service masked!"
|
||||
}
|
||||
@@ -1,237 +0,0 @@
|
||||
#!/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 #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
#===================================================#
|
||||
#============== INSTALL KLIPPERSCREEN ==============#
|
||||
#===================================================#
|
||||
|
||||
function klipperscreen_systemd() {
|
||||
local services
|
||||
services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/KlipperScreen.service")
|
||||
echo "${services}"
|
||||
}
|
||||
|
||||
function install_klipperscreen() {
|
||||
### return early if python version check fails
|
||||
if [[ $(python3_check) == "false" ]]; then
|
||||
local error="Versioncheck failed! Python 3.7 or newer required!\n"
|
||||
error="${error} Please upgrade Python."
|
||||
print_error "${error}" && return
|
||||
fi
|
||||
|
||||
### first, we create a backup of the full klipper_config dir - safety first!
|
||||
backup_config_dir
|
||||
|
||||
### install KlipperScreen
|
||||
klipperscreen_setup
|
||||
|
||||
### add klipperscreen to the update manager in moonraker.conf
|
||||
patch_klipperscreen_update_manager
|
||||
|
||||
do_action_service "restart" "KlipperScreen"
|
||||
}
|
||||
|
||||
function klipperscreen_setup() {
|
||||
local dep=(wget curl unzip dfu-util)
|
||||
dependency_check "${dep[@]}"
|
||||
status_msg "Cloning KlipperScreen from ${KLIPPERSCREEN_REPO} ..."
|
||||
|
||||
# force remove existing KlipperScreen dir
|
||||
[[ -d ${KLIPPERSCREEN_DIR} ]] && rm -rf "${KLIPPERSCREEN_DIR}"
|
||||
|
||||
# clone into fresh KlipperScreen dir
|
||||
cd "${HOME}" || exit 1
|
||||
if ! git clone "${KLIPPERSCREEN_REPO}" "${KLIPPERSCREEN_DIR}"; then
|
||||
print_error "Cloning KlipperScreen from\n ${KLIPPERSCREEN_REPO}\n failed!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
status_msg "Installing KlipperScreen ..."
|
||||
if "${KLIPPERSCREEN_DIR}"/scripts/KlipperScreen-install.sh; then
|
||||
ok_msg "KlipperScreen successfully installed!"
|
||||
else
|
||||
print_error "KlipperScreen installation failed!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#=============== REMOVE KLIPPERSCREEN ==============#
|
||||
#===================================================#
|
||||
|
||||
function remove_klipperscreen() {
|
||||
### remove KlipperScreen dir
|
||||
if [[ -d ${KLIPPERSCREEN_DIR} ]]; then
|
||||
status_msg "Removing KlipperScreen directory ..."
|
||||
rm -rf "${KLIPPERSCREEN_DIR}" && ok_msg "Directory removed!"
|
||||
fi
|
||||
|
||||
### remove KlipperScreen VENV dir
|
||||
if [[ -d ${KLIPPERSCREEN_ENV} ]]; then
|
||||
status_msg "Removing KlipperScreen VENV directory ..."
|
||||
rm -rf "${KLIPPERSCREEN_ENV}" && ok_msg "Directory removed!"
|
||||
fi
|
||||
|
||||
### remove KlipperScreen service
|
||||
if [[ -e "${SYSTEMD}/KlipperScreen.service" ]]; then
|
||||
status_msg "Removing KlipperScreen service ..."
|
||||
do_action_service "stop" "KlipperScreen"
|
||||
do_action_service "disable" "KlipperScreen"
|
||||
sudo rm -f "${SYSTEMD}/KlipperScreen.service"
|
||||
|
||||
###reloading units
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl reset-failed
|
||||
ok_msg "KlipperScreen Service removed!"
|
||||
fi
|
||||
|
||||
### remove KlipperScreen log
|
||||
if [[ -e "/tmp/KlipperScreen.log" ]]; then
|
||||
status_msg "Removing KlipperScreen log file ..."
|
||||
rm -f "/tmp/KlipperScreen.log" && ok_msg "File removed!"
|
||||
fi
|
||||
|
||||
### remove KlipperScreen log symlink in config dir
|
||||
if [[ -e "${KLIPPER_CONFIG}/KlipperScreen.log" ]]; then
|
||||
status_msg "Removing KlipperScreen log symlink ..."
|
||||
rm -f "${KLIPPER_CONFIG}/KlipperScreen.log" && ok_msg "File removed!"
|
||||
fi
|
||||
|
||||
print_confirm "KlipperScreen successfully removed!"
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#=============== UPDATE KLIPPERSCREEN ==============#
|
||||
#===================================================#
|
||||
|
||||
function update_klipperscreen() {
|
||||
local old_md5
|
||||
old_md5=$(md5sum "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt" | cut -d " " -f1)
|
||||
|
||||
do_action_service "stop" "KlipperScreen"
|
||||
backup_before_update "klipperscreen"
|
||||
|
||||
cd "${KLIPPERSCREEN_DIR}"
|
||||
git pull origin master -q && ok_msg "Fetch successfull!"
|
||||
git checkout -f master && ok_msg "Checkout successfull"
|
||||
|
||||
if [[ $(md5sum "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt" | cut -d " " -f1) != "${old_md5}" ]]; then
|
||||
status_msg "New dependencies detected..."
|
||||
"${KLIPPERSCREEN_ENV}"/bin/pip install -r "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt"
|
||||
ok_msg "Dependencies have been installed!"
|
||||
fi
|
||||
|
||||
ok_msg "Update complete!"
|
||||
do_action_service "start" "KlipperScreen"
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#=============== KLIPPERSCREEN STATUS ==============#
|
||||
#===================================================#
|
||||
|
||||
function get_klipperscreen_status() {
|
||||
local sf_count status
|
||||
sf_count="$(klipperscreen_systemd | wc -w)"
|
||||
|
||||
### remove the "SERVICE" entry from the data array if a moonraker service is installed
|
||||
local data_arr=(SERVICE "${KLIPPERSCREEN_DIR}" "${KLIPPERSCREEN_ENV}")
|
||||
(( sf_count > 0 )) && unset "data_arr[0]"
|
||||
|
||||
### count+1 for each found data-item from array
|
||||
local filecount=0
|
||||
for data in "${data_arr[@]}"; do
|
||||
[[ -e ${data} ]] && filecount=$(( filecount + 1 ))
|
||||
done
|
||||
|
||||
if (( filecount == ${#data_arr[*]} )); then
|
||||
status="Installed!"
|
||||
elif (( filecount == 0 )); then
|
||||
status="Not installed!"
|
||||
else
|
||||
status="Incomplete!"
|
||||
fi
|
||||
echo "${status}"
|
||||
}
|
||||
|
||||
function get_local_klipperscreen_commit() {
|
||||
[[ ! -d ${KLIPPERSCREEN_DIR} || ! -d "${KLIPPERSCREEN_DIR}/.git" ]] && return
|
||||
|
||||
local commit
|
||||
cd "${KLIPPERSCREEN_DIR}"
|
||||
commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
|
||||
echo "${commit}"
|
||||
}
|
||||
|
||||
function get_remote_klipperscreen_commit() {
|
||||
[[ ! -d ${KLIPPERSCREEN_DIR} || ! -d "${KLIPPERSCREEN_DIR}/.git" ]] && return
|
||||
|
||||
local commit
|
||||
cd "${KLIPPERSCREEN_DIR}" && git fetch origin -q
|
||||
commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2)
|
||||
echo "${commit}"
|
||||
}
|
||||
|
||||
function compare_klipperscreen_versions() {
|
||||
local versions local_ver remote_ver
|
||||
local_ver="$(get_local_klipperscreen_commit)"
|
||||
remote_ver="$(get_remote_klipperscreen_commit)"
|
||||
|
||||
if [[ ${local_ver} != "${remote_ver}" ]]; then
|
||||
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
# add moonraker to application_updates_available in kiauh.ini
|
||||
add_to_application_updates "klipperscreen"
|
||||
else
|
||||
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
fi
|
||||
|
||||
echo "${versions}"
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=================== HELPERS ====================#
|
||||
#================================================#
|
||||
|
||||
function patch_klipperscreen_update_manager() {
|
||||
local patched="false"
|
||||
local moonraker_configs
|
||||
moonraker_configs=$(find "${KLIPPER_CONFIG}" -type f -name "moonraker.conf" | sort)
|
||||
|
||||
for conf in ${moonraker_configs}; do
|
||||
if ! grep -Eq "^\[update_manager KlipperScreen\]\s*$" "${conf}"; then
|
||||
### add new line to conf if it doesn't end with one
|
||||
[[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}"
|
||||
|
||||
### add KlipperScreens update manager section to moonraker.conf
|
||||
status_msg "Adding KlipperScreen to update manager in file:\n ${conf}"
|
||||
/bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF
|
||||
|
||||
[update_manager KlipperScreen]
|
||||
type: git_repo
|
||||
path: ${HOME}/KlipperScreen
|
||||
origin: https://github.com/jordanruthe/KlipperScreen.git
|
||||
env: ${HOME}/.KlipperScreen-env/bin/python
|
||||
requirements: scripts/KlipperScreen-requirements.txt
|
||||
install_script: scripts/KlipperScreen-install.sh
|
||||
MOONRAKER_CONF
|
||||
|
||||
fi
|
||||
|
||||
patched="true"
|
||||
done
|
||||
|
||||
if [[ ${patched} == "true" ]]; then
|
||||
do_action_service "restart" "moonraker"
|
||||
fi
|
||||
}
|
||||
@@ -1,690 +0,0 @@
|
||||
#!/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 #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
#===================================================#
|
||||
#================= INSTALL MAINSAIL ================#
|
||||
#===================================================#
|
||||
|
||||
function install_mainsail() {
|
||||
if [[ -z $(moonraker_systemd) ]]; then
|
||||
local error="Moonraker not installed! It's recommended to install Moonraker first!"
|
||||
print_error "${error}"
|
||||
while true; do
|
||||
local yn
|
||||
read -p "${cyan}###### Proceed to install Mainsail without installing Moonraker? (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 Mainsail setup ...\n"
|
||||
return;;
|
||||
*)
|
||||
error_msg "Invalid Input!";;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
|
||||
### checking dependencies
|
||||
local dep=(wget nginx unzip)
|
||||
dependency_check "${dep[@]}"
|
||||
### detect conflicting Haproxy and Apache2 installations
|
||||
detect_conflicting_packages
|
||||
|
||||
status_msg "Initializing Mainsail installation ..."
|
||||
### first, we create a backup of the full klipper_config dir - safety first!
|
||||
backup_config_dir
|
||||
|
||||
### check for other enabled web interfaces
|
||||
unset SET_LISTEN_PORT
|
||||
detect_enabled_sites
|
||||
|
||||
### check if another site already listens to port 80
|
||||
mainsail_port_check
|
||||
|
||||
### download mainsail
|
||||
download_mainsail
|
||||
|
||||
### ask user to install the recommended webinterface macros
|
||||
install_mainsail_macros
|
||||
|
||||
### create /etc/nginx/conf.d/upstreams.conf
|
||||
set_upstream_nginx_cfg
|
||||
### create /etc/nginx/sites-available/<interface config>
|
||||
set_nginx_cfg "mainsail"
|
||||
### nginx on ubuntu 21 and above needs special permissions to access the files
|
||||
set_nginx_permissions
|
||||
|
||||
### symlink nginx log
|
||||
symlink_webui_nginx_log "mainsail"
|
||||
|
||||
### add mainsail to the update manager in moonraker.conf
|
||||
patch_mainsail_update_manager
|
||||
|
||||
fetch_webui_ports #WIP
|
||||
|
||||
### confirm message
|
||||
print_confirm "Mainsail has been set up!"
|
||||
}
|
||||
|
||||
function install_mainsail_macros() {
|
||||
local yn
|
||||
while true; do
|
||||
echo
|
||||
top_border
|
||||
echo -e "| It is recommended to use special macros in order to |"
|
||||
echo -e "| have Mainsail fully functional and working. |"
|
||||
blank_line
|
||||
echo -e "| The recommended macros for Mainsail can be seen here: |"
|
||||
echo -e "| https://github.com/mainsail-crew/mainsail-config |"
|
||||
blank_line
|
||||
echo -e "| If you already use these macros skip this step. |"
|
||||
echo -e "| Otherwise you should consider to answer with 'yes' to |"
|
||||
echo -e "| download the recommended macros. |"
|
||||
bottom_border
|
||||
read -p "${cyan}###### Download the recommended macros? (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
select_msg "Yes"
|
||||
download_mainsail_macros
|
||||
break;;
|
||||
N|n|No|no)
|
||||
select_msg "No"
|
||||
break;;
|
||||
*)
|
||||
print_error "Invalid command!";;
|
||||
esac
|
||||
done
|
||||
return
|
||||
}
|
||||
|
||||
function download_mainsail_macros() {
|
||||
local ms_cfg_repo path configs regex line gcode_dir
|
||||
|
||||
ms_cfg_repo="https://github.com/mainsail-crew/mainsail-config.git"
|
||||
regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/printer\.cfg"
|
||||
configs=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${regex}" | sort)
|
||||
|
||||
if [[ -z ${configs} ]]; then
|
||||
print_error "No printer.cfg found! Installation of Macros will be skipped ..."
|
||||
log_error "execution stopped! reason: no printer.cfg found"
|
||||
return
|
||||
fi
|
||||
|
||||
status_msg "Cloning mainsail-config ..."
|
||||
[[ -d "${HOME}/mainsail-config" ]] && rm -rf "${HOME}/mainsail-config"
|
||||
if git clone "${ms_cfg_repo}" "${HOME}/mainsail-config"; then
|
||||
for config in ${configs}; do
|
||||
path=$(echo "${config}" | rev | cut -d"/" -f2- | rev)
|
||||
|
||||
if [[ -e "${path}/mainsail.cfg" && ! -h "${path}/mainsail.cfg" ]]; then
|
||||
warn_msg "Attention! Existing mainsail.cfg detected!"
|
||||
warn_msg "The file will be renamed to 'mainsail.bak.cfg' to be able to continue with the installation."
|
||||
if ! mv "${path}/mainsail.cfg" "${path}/mainsail.bak.cfg"; then
|
||||
error_msg "Renaming mainsail.cfg failed! Aborting installation ..."
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -h "${path}/mainsail.cfg" ]]; then
|
||||
warn_msg "Recreating symlink in ${path} ..."
|
||||
rm -rf "${path}/mainsail.cfg"
|
||||
fi
|
||||
|
||||
if ! ln -sf "${HOME}/mainsail-config/client.cfg" "${path}/mainsail.cfg"; then
|
||||
error_msg "Creating symlink failed! Aborting installation ..."
|
||||
return
|
||||
fi
|
||||
|
||||
if ! grep -Eq "^\[include mainsail.cfg\]$" "${path}/printer.cfg"; then
|
||||
log_info "${path}/printer.cfg"
|
||||
sed -i "1 i [include mainsail.cfg]" "${path}/printer.cfg"
|
||||
fi
|
||||
|
||||
line=$(($(grep -n "\[include mainsail.cfg\]" "${path}/printer.cfg" | tail -1 | cut -d: -f1) + 1))
|
||||
gcode_dir=${path/config/gcodes}
|
||||
if ! grep -Eq "^\[virtual_sdcard\]$" "${path}/printer.cfg"; then
|
||||
log_info "${path}/printer.cfg"
|
||||
sed -i "${line} i \[virtual_sdcard]\npath: ${gcode_dir}\non_error_gcode: CANCEL_PRINT\n" "${path}/printer.cfg"
|
||||
fi
|
||||
done
|
||||
else
|
||||
print_error "Cloning failed! Aborting installation ..."
|
||||
log_error "execution stopped! reason: cloning failed"
|
||||
return
|
||||
fi
|
||||
|
||||
patch_mainsail_config_update_manager
|
||||
|
||||
ok_msg "Done!"
|
||||
}
|
||||
|
||||
function download_mainsail() {
|
||||
local services
|
||||
local url
|
||||
url=$(get_mainsail_download_url)
|
||||
|
||||
status_msg "Downloading Mainsail from ${url} ..."
|
||||
|
||||
if [[ -d ${MAINSAIL_DIR} ]]; then
|
||||
rm -rf "${MAINSAIL_DIR}"
|
||||
fi
|
||||
|
||||
mkdir "${MAINSAIL_DIR}" && cd "${MAINSAIL_DIR}"
|
||||
|
||||
if wget "${url}"; then
|
||||
ok_msg "Download complete!"
|
||||
status_msg "Extracting archive ..."
|
||||
unzip -q -o ./*.zip && ok_msg "Done!"
|
||||
status_msg "Remove downloaded archive ..."
|
||||
rm -rf ./*.zip && ok_msg "Done!"
|
||||
else
|
||||
print_error "Downloading Mainsail from\n ${url}\n failed!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
### check for moonraker multi-instance and if no-instance or multi-instance was found, enable mainsails remoteMode
|
||||
services=$(moonraker_systemd)
|
||||
if [[ ( -z "${services}" ) || ( $(echo "${services}" | wc -w) -gt 1 ) ]]; then
|
||||
enable_mainsail_remotemode
|
||||
fi
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#================= REMOVE MAINSAIL =================#
|
||||
#===================================================#
|
||||
|
||||
function remove_mainsail_dir() {
|
||||
[[ ! -d ${MAINSAIL_DIR} ]] && return
|
||||
|
||||
status_msg "Removing Mainsail directory ..."
|
||||
rm -rf "${MAINSAIL_DIR}" && ok_msg "Directory removed!"
|
||||
}
|
||||
|
||||
function remove_mainsail_nginx_config() {
|
||||
if [[ -e "/etc/nginx/sites-available/mainsail" ]]; then
|
||||
status_msg "Removing Mainsail configuration for Nginx ..."
|
||||
sudo rm "/etc/nginx/sites-available/mainsail" && ok_msg "File removed!"
|
||||
fi
|
||||
if [[ -L "/etc/nginx/sites-enabled/mainsail" ]]; then
|
||||
status_msg "Removing Mainsail Symlink for Nginx ..."
|
||||
sudo rm "/etc/nginx/sites-enabled/mainsail" && ok_msg "File removed!"
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_mainsail_logs() {
|
||||
local files
|
||||
files=$(find /var/log/nginx -name "mainsail*" 2> /dev/null | sort)
|
||||
|
||||
if [[ -n ${files} ]]; then
|
||||
for file in ${files}; do
|
||||
status_msg "Removing ${file} ..."
|
||||
sudo rm -f "${file}"
|
||||
ok_msg "${file} removed!"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_mainsail_log_symlinks() {
|
||||
local files regex
|
||||
|
||||
regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/logs\/mainsail-.*"
|
||||
files=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${regex}" 2> /dev/null | 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_legacy_mainsail_log_symlinks() {
|
||||
local files
|
||||
files=$(find "${HOME}/klipper_logs" -name "mainsail*" 2> /dev/null | 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_mainsail_config() {
|
||||
if [[ -d "${HOME}/mainsail-config" ]]; then
|
||||
status_msg "Removing ${HOME}/mainsail-config ..."
|
||||
rm -rf "${HOME}/mainsail-config"
|
||||
ok_msg "${HOME}/mainsail-config removed!"
|
||||
print_confirm "Mainsail-Config successfully removed!"
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_mainsail() {
|
||||
remove_mainsail_dir
|
||||
remove_mainsail_nginx_config
|
||||
remove_mainsail_logs
|
||||
remove_mainsail_log_symlinks
|
||||
remove_legacy_mainsail_log_symlinks
|
||||
|
||||
### remove mainsail_port from ~/.kiauh.ini
|
||||
sed -i "/^mainsail_port=/d" "${INI_FILE}"
|
||||
|
||||
print_confirm "Mainsail successfully removed!"
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#================= UPDATE MAINSAIL =================#
|
||||
#===================================================#
|
||||
|
||||
function update_mainsail() {
|
||||
backup_before_update "mainsail"
|
||||
status_msg "Updating Mainsail ..."
|
||||
download_mainsail
|
||||
match_nginx_configs
|
||||
symlink_webui_nginx_log "mainsail"
|
||||
print_confirm "Mainsail successfully updated!"
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#================= MAINSAIL STATUS =================#
|
||||
#===================================================#
|
||||
|
||||
function get_mainsail_status() {
|
||||
local status
|
||||
local data_arr=("${MAINSAIL_DIR}" "${NGINX_SA}/mainsail" "${NGINX_SE}/mainsail")
|
||||
|
||||
### count+1 for each found data-item from array
|
||||
local filecount=0
|
||||
for data in "${data_arr[@]}"; do
|
||||
[[ -e ${data} ]] && filecount=$(( filecount + 1 ))
|
||||
done
|
||||
|
||||
if (( filecount == ${#data_arr[*]} )); then
|
||||
status="Installed!"
|
||||
elif (( filecount == 0 )); then
|
||||
status="Not installed!"
|
||||
else
|
||||
status="Incomplete!"
|
||||
fi
|
||||
echo "${status}"
|
||||
}
|
||||
|
||||
function get_local_mainsail_version() {
|
||||
local versionfile="${MAINSAIL_DIR}/.version"
|
||||
local relinfofile="${MAINSAIL_DIR}/release_info.json"
|
||||
local version
|
||||
|
||||
if [[ -f ${relinfofile} ]]; then
|
||||
version=$(grep -o '"version":"[^"]*' "${relinfofile}" | grep -o '[^"]*$')
|
||||
elif [[ -f ${versionfile} ]]; then
|
||||
version=$(head -n 1 "${versionfile}")
|
||||
fi
|
||||
|
||||
echo "${version}"
|
||||
}
|
||||
|
||||
function get_remote_mainsail_version() {
|
||||
[[ ! $(dpkg-query -f'${Status}' --show curl 2>/dev/null) = *\ installed ]] && return
|
||||
|
||||
local tags
|
||||
tags=$(curl -s "https://api.github.com/repos/mainsail-crew/mainsail/tags" | grep "name" | cut -d'"' -f4)
|
||||
echo "${tags}" | head -1
|
||||
}
|
||||
|
||||
function compare_mainsail_versions() {
|
||||
local versions local_ver remote_ver
|
||||
local_ver="$(get_local_mainsail_version)"
|
||||
remote_ver="$(get_remote_mainsail_version)"
|
||||
|
||||
if [[ ${local_ver} != "${remote_ver}" && ${local_ver} != "" ]]; then
|
||||
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
# add moonraker to application_updates_available in kiauh.ini
|
||||
add_to_application_updates "mainsail"
|
||||
else
|
||||
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
fi
|
||||
|
||||
echo "${versions}"
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=========== MAINSAIL THEME INSTALLER ===========#
|
||||
#================================================#
|
||||
|
||||
function print_theme_list() {
|
||||
local i=0 theme_list=${1}
|
||||
|
||||
while IFS="," read -r col1 col2 col3 col4; do
|
||||
if [[ ${col1} != "name" ]]; then
|
||||
printf "| ${i}) %-51s|\n" "[${col1}]"
|
||||
fi
|
||||
i=$(( i + 1 ))
|
||||
done <<< "${theme_list}"
|
||||
}
|
||||
|
||||
function ms_theme_installer_menu() {
|
||||
local theme_list theme_author theme_repo theme_name theme_note theme_url
|
||||
local theme_csv_url="https://raw.githubusercontent.com/mainsail-crew/gb-docs/main/_data/themes.csv"
|
||||
theme_list=$(curl -s -L "${theme_csv_url}")
|
||||
|
||||
top_border
|
||||
echo -e "| ${red}~~~~~~~~ [ Mainsail Theme Installer ] ~~~~~~~${white} |"
|
||||
hr
|
||||
echo -e "| ${cyan}A preview of each Mainsail theme can be found here:${white} |"
|
||||
echo -e "| https://docs.mainsail.xyz/theming/themes |"
|
||||
blank_line
|
||||
echo -e "| ${yellow}Important note:${white} |"
|
||||
echo -e "| Installing a theme from this menu will overwrite an |"
|
||||
echo -e "| already installed theme or modified custom.css file! |"
|
||||
hr
|
||||
print_theme_list "${theme_list}"
|
||||
echo -e "| |"
|
||||
echo -e "| R) [Remove Theme] |"
|
||||
back_footer
|
||||
|
||||
while IFS="," read -r col1 col2 col3 col4; do
|
||||
theme_name+=("${col1}")
|
||||
theme_note+=("${col2}")
|
||||
theme_author+=("${col3}")
|
||||
theme_repo+=("${col4}")
|
||||
done <<< "${theme_list}"
|
||||
|
||||
local option
|
||||
while true; do
|
||||
read -p "${cyan}Install theme:${white} " option
|
||||
if (( option > 0 && option < ${#theme_name[@]} )); then
|
||||
theme_url="https://github.com/${theme_author[${option}]}/${theme_repo[${option}]}"
|
||||
ms_theme_install "${theme_url}" "${theme_name[${option}]}" "${theme_note[${option}]}"
|
||||
break
|
||||
elif [[ ${option} == "R" || ${option} == "r" ]]; then
|
||||
ms_theme_delete
|
||||
break
|
||||
elif [[ ${option} == "B" || ${option} == "b" ]]; then
|
||||
advanced_menu
|
||||
break
|
||||
else
|
||||
error_msg "Invalid command!"
|
||||
fi
|
||||
done
|
||||
ms_theme_installer_menu
|
||||
}
|
||||
|
||||
function ms_theme_install() {
|
||||
read_kiauh_ini "${FUNCNAME[0]}"
|
||||
|
||||
local theme_url
|
||||
local theme_name
|
||||
local theme_note
|
||||
theme_url=${1}
|
||||
theme_name=${2}
|
||||
theme_note=${3}
|
||||
|
||||
local folder_arr
|
||||
local folder_names="${multi_instance_names}"
|
||||
local target_folders=()
|
||||
|
||||
IFS=',' read -r -a folder_arr <<< "${folder_names}"
|
||||
|
||||
### build theme target folder array
|
||||
if (( ${#folder_arr[@]} > 1 )); then
|
||||
for folder in "${folder_arr[@]}"; do
|
||||
### instance names/identifier of only numbers need to be prefixed with 'printer_'
|
||||
if [[ ${folder} =~ ^[0-9]+$ ]]; then
|
||||
target_folders+=("${HOME}/printer_${folder}_data/config")
|
||||
else
|
||||
target_folders+=("${HOME}/${folder}_data/config")
|
||||
fi
|
||||
done
|
||||
else
|
||||
target_folders+=("${HOME}/printer_data/config")
|
||||
fi
|
||||
|
||||
if (( ${#target_folders[@]} > 1 )); then
|
||||
top_border
|
||||
echo -e "| Please select the printer you want to apply the theme |"
|
||||
echo -e "| installation to: |"
|
||||
for (( i=0; i < ${#target_folders[@]}; i++ )); do
|
||||
folder=$(echo "${target_folders[${i}]}" | rev | cut -d "/" -f2 | cut -d"_" -f2- | rev)
|
||||
printf "|${cyan}%-55s${white}|\n" " ${i}) ${folder}"
|
||||
done
|
||||
bottom_border
|
||||
|
||||
local target re="^[0-9]*$"
|
||||
while true; do
|
||||
read -p "${cyan}###### Select printer:${white} " target
|
||||
### break while loop if input is valid, else display error
|
||||
[[ ${target} =~ ${re} && ${target} -lt ${#target_folders[@]} ]] && break
|
||||
error_msg "Invalid command!"
|
||||
done
|
||||
fi
|
||||
|
||||
[[ -d "${target_folders[${target}]}/.theme" ]] && rm -rf "${target_folders[${target}]}/.theme"
|
||||
|
||||
status_msg "Installing '${theme_name}' to ${target_folders[${target}]} ..."
|
||||
cd "${target_folders[${target}]}"
|
||||
|
||||
if git clone "${theme_url}" ".theme"; then
|
||||
ok_msg "Theme installation complete!"
|
||||
[[ -n ${theme_note} ]] && echo "${yellow}###### Theme Info: ${theme_note}${white}"
|
||||
ok_msg "Please remember to delete your browser cache!\n"
|
||||
else
|
||||
error_msg "Theme installation failed!\n"
|
||||
fi
|
||||
}
|
||||
|
||||
function ms_theme_delete() {
|
||||
local regex theme_folders target_folders=()
|
||||
|
||||
regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/\.theme"
|
||||
theme_folders=$(find "${HOME}" -maxdepth 3 -type d -regextype posix-extended -regex "${regex}" | sort)
|
||||
# theme_folders=$(find "${KLIPPER_CONFIG}" -mindepth 1 -type d -name ".theme" | sort)
|
||||
|
||||
### build target folder array
|
||||
for folder in ${theme_folders}; do
|
||||
target_folders+=("${folder}")
|
||||
done
|
||||
|
||||
if (( ${#target_folders[@]} == 0 )); then
|
||||
status_msg "No Themes installed!\n"
|
||||
return
|
||||
elif (( ${#target_folders[@]} > 1 )); then
|
||||
top_border
|
||||
echo -e "| Please select the printer you want to remove the |"
|
||||
echo -e "| theme installation from. |"
|
||||
for (( i=0; i < ${#target_folders[@]}; i++ )); do
|
||||
folder=$(echo "${target_folders[${i}]}" | rev | cut -d "/" -f2 | rev)
|
||||
printf "|${cyan}%-55s${white}|\n" " ${i}) ${folder}"
|
||||
done
|
||||
bottom_border
|
||||
|
||||
local target re="^[0-9]*$"
|
||||
while true; do
|
||||
read -p "${cyan}###### Select printer:${white} " target
|
||||
### break while loop if input is valid, else display error
|
||||
[[ ${target} =~ ${re} && ${target} -lt ${#target_folders[@]} ]] && break
|
||||
error_msg "Invalid command!"
|
||||
done
|
||||
fi
|
||||
|
||||
status_msg "Removing ${target_folders[${target}]} ..."
|
||||
rm -rf "${target_folders[${target}]}" && ok_msg "Theme removed!\n"
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=================== HELPERS ====================#
|
||||
#================================================#
|
||||
|
||||
function get_mainsail_download_url() {
|
||||
local releases_by_tag tags tag unstable_url url
|
||||
|
||||
### latest stable download url
|
||||
url="https://github.com/mainsail-crew/mainsail/releases/latest/download/mainsail.zip"
|
||||
|
||||
read_kiauh_ini "${FUNCNAME[0]}"
|
||||
if [[ ${mainsail_install_unstable} == "true" ]]; then
|
||||
releases_by_tag="https://api.github.com/repos/mainsail-crew/mainsail/tags"
|
||||
tags=$(curl -s "${releases_by_tag}" | grep "name" | cut -d'"' -f4)
|
||||
tag=$(echo "${tags}" | head -1)
|
||||
|
||||
### latest unstable download url including pre-releases (alpha, beta, rc)
|
||||
unstable_url="https://github.com/mainsail-crew/mainsail/releases/download/${tag}/mainsail.zip"
|
||||
|
||||
if [[ ${unstable_url} == *"download//"* ]]; then
|
||||
warn_msg "Download URL broken! Falling back to URL of latest stable release!"
|
||||
else
|
||||
url=${unstable_url}
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "${url}"
|
||||
}
|
||||
|
||||
function mainsail_port_check() {
|
||||
if [[ ${MAINSAIL_ENABLED} == "false" ]]; then
|
||||
|
||||
if [[ ${SITE_ENABLED} == "true" ]]; then
|
||||
status_msg "Detected other enabled interfaces:"
|
||||
|
||||
[[ ${FLUIDD_ENABLED} == "true" ]] && \
|
||||
echo -e " ${cyan}● Fluidd - Port: ${FLUIDD_PORT}${white}"
|
||||
|
||||
if [[ ${FLUIDD_PORT} == "80" ]]; then
|
||||
PORT_80_BLOCKED="true"
|
||||
select_mainsail_port
|
||||
fi
|
||||
else
|
||||
DEFAULT_PORT=$(grep listen "${KIAUH_SRCDIR}/resources/mainsail" | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1)
|
||||
SET_LISTEN_PORT=${DEFAULT_PORT}
|
||||
fi
|
||||
SET_NGINX_CFG="true"
|
||||
|
||||
else
|
||||
SET_NGINX_CFG="false"
|
||||
fi
|
||||
}
|
||||
|
||||
function select_mainsail_port() {
|
||||
if [[ ${PORT_80_BLOCKED} == "true" ]]; then
|
||||
echo
|
||||
top_border
|
||||
echo -e "| ${red}!!!WARNING!!!${white} |"
|
||||
echo -e "| ${red}You need to choose a different port for Mainsail!${white} |"
|
||||
echo -e "| ${red}The following web interface is listening at port 80:${white} |"
|
||||
blank_line
|
||||
[[ ${FLUIDD_PORT} == "80" ]] && echo "| ● Fluidd |"
|
||||
blank_line
|
||||
echo -e "| Make sure you don't choose a port which was already |"
|
||||
echo -e "| assigned to another webinterface! |"
|
||||
blank_line
|
||||
echo -e "| Be aware: there is ${red}NO${white} sanity check for the following |"
|
||||
echo -e "| input. So make sure to choose a valid port! |"
|
||||
bottom_border
|
||||
|
||||
local new_port re="^[0-9]+$"
|
||||
while true; do
|
||||
read -p "${cyan}Please enter a new Port:${white} " new_port
|
||||
if [[ ${new_port} =~ ${re} && ${new_port} != "${FLUIDD_PORT}" ]]; then
|
||||
select_msg "Setting port ${new_port} for Mainsail!"
|
||||
SET_LISTEN_PORT=${new_port}
|
||||
break
|
||||
else
|
||||
if [[ ! ${new_port} =~ ${re} ]]; then
|
||||
error_msg "Invalid input!"
|
||||
else
|
||||
error_msg "Port already taken! Select a different one!"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function enable_mainsail_remotemode() {
|
||||
[[ ! -f "${MAINSAIL_DIR}/config.json" ]] && return
|
||||
|
||||
status_msg "Setting instance storage location to 'browser' ..."
|
||||
sed -i 's|"instancesDB": "moonraker"|"instancesDB": "browser"|' "${MAINSAIL_DIR}/config.json"
|
||||
ok_msg "Done!"
|
||||
}
|
||||
|
||||
function patch_mainsail_update_manager() {
|
||||
local patched moonraker_configs regex
|
||||
regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/moonraker\.conf"
|
||||
moonraker_configs=$(find "${HOME}" -maxdepth 3 -type f -regextype posix-extended -regex "${regex}" | sort)
|
||||
|
||||
patched="false"
|
||||
for conf in ${moonraker_configs}; do
|
||||
if ! grep -Eq "^\[update_manager mainsail\]\s*$" "${conf}"; then
|
||||
### add new line to conf if it doesn't end with one
|
||||
[[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}"
|
||||
|
||||
### add Mainsails update manager section to moonraker.conf
|
||||
status_msg "Adding Mainsail to update manager in file:\n ${conf}"
|
||||
/bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF
|
||||
|
||||
[update_manager mainsail]
|
||||
type: web
|
||||
channel: stable
|
||||
repo: mainsail-crew/mainsail
|
||||
path: ~/mainsail
|
||||
MOONRAKER_CONF
|
||||
|
||||
fi
|
||||
|
||||
patched="true"
|
||||
done
|
||||
|
||||
if [[ ${patched} == "true" ]]; then
|
||||
do_action_service "restart" "moonraker"
|
||||
fi
|
||||
}
|
||||
|
||||
function patch_mainsail_config_update_manager() {
|
||||
local patched moonraker_configs regex
|
||||
regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/moonraker\.conf"
|
||||
moonraker_configs=$(find "${HOME}" -maxdepth 3 -type f -regextype posix-extended -regex "${regex}" | sort)
|
||||
|
||||
patched="false"
|
||||
for conf in ${moonraker_configs}; do
|
||||
if ! grep -Eq "^\[update_manager mainsail-config\]\s*$" "${conf}"; then
|
||||
### add new line to conf if it doesn't end with one
|
||||
[[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}"
|
||||
|
||||
### add Mainsails update manager section to moonraker.conf
|
||||
status_msg "Adding Mainsail-Config to update manager in file:\n ${conf}"
|
||||
/bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF
|
||||
|
||||
[update_manager mainsail-config]
|
||||
type: git_repo
|
||||
primary_branch: master
|
||||
path: ~/mainsail-config
|
||||
origin: https://github.com/mainsail-crew/mainsail-config.git
|
||||
managed_services: klipper
|
||||
MOONRAKER_CONF
|
||||
|
||||
fi
|
||||
|
||||
patched="true"
|
||||
done
|
||||
|
||||
if [[ ${patched} == "true" ]]; then
|
||||
do_action_service "restart" "moonraker"
|
||||
fi
|
||||
}
|
||||
@@ -1,193 +0,0 @@
|
||||
#!/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 #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
#=================================================#
|
||||
#============= INSTALL MJPG-STREAMER =============#
|
||||
#=================================================#
|
||||
|
||||
function install_mjpg-streamer() {
|
||||
local webcamd="${KIAUH_SRCDIR}/resources/mjpg-streamer/webcamd"
|
||||
local webcam_txt="${KIAUH_SRCDIR}/resources/mjpg-streamer/webcam.txt"
|
||||
local service="${KIAUH_SRCDIR}/resources/mjpg-streamer/webcamd.service"
|
||||
local repo="https://github.com/jacksonliam/mjpg-streamer.git"
|
||||
|
||||
### return early if webcamd.service already exists
|
||||
if [[ -f "${SYSTEMD}/webcamd.service" ]]; then
|
||||
print_error "Looks like MJPG-streamer is already installed!\n Please remove it first before you try to re-install it!"
|
||||
return
|
||||
fi
|
||||
|
||||
status_msg "Initializing MJPG-Streamer installation ..."
|
||||
|
||||
### check and install dependencies if missing
|
||||
local dep=(git cmake build-essential imagemagick libv4l-dev ffmpeg)
|
||||
if apt-cache search libjpeg62-turbo-dev | grep -Eq "^libjpeg62-turbo-dev "; then
|
||||
dep+=(libjpeg62-turbo-dev)
|
||||
elif apt-cache search libjpeg8-dev | grep -Eq "^libjpeg8-dev "; then
|
||||
dep+=(libjpeg8-dev)
|
||||
fi
|
||||
|
||||
dependency_check "${dep[@]}"
|
||||
|
||||
### step 1: clone mjpg-streamer
|
||||
status_msg "Cloning MJPG-Streamer from ${repo} ..."
|
||||
[[ -d "${HOME}/mjpg-streamer" ]] && rm -rf "${HOME}/mjpg-streamer"
|
||||
|
||||
cd "${HOME}" || exit 1
|
||||
if ! git clone "${repo}" "${HOME}/mjpg-streamer"; then
|
||||
print_error "Cloning MJPG-Streamer from\n ${repo}\n failed!"
|
||||
exit 1
|
||||
fi
|
||||
ok_msg "Cloning complete!"
|
||||
|
||||
### step 2: compiling mjpg-streamer
|
||||
status_msg "Compiling MJPG-Streamer ..."
|
||||
cd "${HOME}/mjpg-streamer/mjpg-streamer-experimental"
|
||||
if ! make; then
|
||||
print_error "Compiling MJPG-Streamer failed!"
|
||||
exit 1
|
||||
fi
|
||||
ok_msg "Compiling complete!"
|
||||
|
||||
#step 3: install mjpg-streamer
|
||||
status_msg "Installing MJPG-Streamer ..."
|
||||
cd "${HOME}/mjpg-streamer" && mv mjpg-streamer-experimental/* .
|
||||
mkdir www-mjpgstreamer
|
||||
|
||||
cat <<EOT >> ./www-mjpgstreamer/index.html
|
||||
<html>
|
||||
<head><title>mjpg_streamer test page</title></head>
|
||||
<body>
|
||||
<h1>Snapshot</h1>
|
||||
<p>Refresh the page to refresh the snapshot</p>
|
||||
<img src="./?action=snapshot" alt="Snapshot">
|
||||
<h1>Stream</h1>
|
||||
<img src="./?action=stream" alt="Stream">
|
||||
</body>
|
||||
</html>
|
||||
EOT
|
||||
|
||||
sudo cp "${webcamd}" "/usr/local/bin/webcamd"
|
||||
sudo sed -i "/^config_dir=/ s|=.*|=${KLIPPER_CONFIG}|" /usr/local/bin/webcamd
|
||||
sudo sed -i "/MJPGSTREAMER_HOME/ s/pi/${USER}/" /usr/local/bin/webcamd
|
||||
sudo chmod +x /usr/local/bin/webcamd
|
||||
|
||||
### step 4: create webcam.txt config file
|
||||
[[ ! -d ${KLIPPER_CONFIG} ]] && mkdir -p "${KLIPPER_CONFIG}"
|
||||
if [[ ! -f "${KLIPPER_CONFIG}/webcam.txt" ]]; then
|
||||
status_msg "Creating webcam.txt config file ..."
|
||||
cp "${webcam_txt}" "${KLIPPER_CONFIG}/webcam.txt"
|
||||
ok_msg "Done!"
|
||||
fi
|
||||
|
||||
### step 5: create systemd service
|
||||
status_msg "Creating MJPG-Streamer service ..."
|
||||
sudo cp "${service}" "${SYSTEMD}/webcamd.service"
|
||||
sudo sed -i "s|%USER%|${USER}|" "${SYSTEMD}/webcamd.service"
|
||||
ok_msg "MJPG-Streamer service created!"
|
||||
|
||||
### step 6: enabling and starting mjpg-streamer service
|
||||
status_msg "Starting MJPG-Streamer service, please wait ..."
|
||||
sudo systemctl enable webcamd.service
|
||||
if sudo systemctl start webcamd.service; then
|
||||
ok_msg "MJPG-Streamer service started!"
|
||||
else
|
||||
status_msg "MJPG-Streamer service couldn't be started! No webcam connected?\n###### You need to manually restart the service once your webcam is set up correctly."
|
||||
fi
|
||||
|
||||
### step 6.1: create webcamd.log symlink
|
||||
[[ ! -d ${KLIPPER_LOGS} ]] && mkdir -p "${KLIPPER_LOGS}"
|
||||
if [[ -f "/var/log/webcamd.log" && ! -L "${KLIPPER_LOGS}/webcamd.log" ]]; then
|
||||
ln -s "/var/log/webcamd.log" "${KLIPPER_LOGS}/webcamd.log"
|
||||
fi
|
||||
|
||||
### step 6.2: add webcamd.log logrotate
|
||||
if [[ ! -f "/etc/logrotate.d/webcamd" ]]; then
|
||||
status_msg "Create logrotate rule ..."
|
||||
sudo /bin/sh -c "cat > /etc/logrotate.d/webcamd" << EOF
|
||||
/var/log/webcamd.log
|
||||
{
|
||||
rotate 2
|
||||
weekly
|
||||
maxsize 32M
|
||||
missingok
|
||||
notifempty
|
||||
compress
|
||||
delaycompress
|
||||
sharedscripts
|
||||
}
|
||||
EOF
|
||||
ok_msg "Done!"
|
||||
fi
|
||||
|
||||
### step 7: check if user is in group "video"
|
||||
local usergroup_changed="false"
|
||||
if ! groups "${USER}" | grep -q "video"; then
|
||||
status_msg "Adding user '${USER}' to group 'video' ..."
|
||||
sudo usermod -a -G video "${USER}" && ok_msg "Done!"
|
||||
usergroup_changed="true"
|
||||
fi
|
||||
|
||||
### confirm message
|
||||
local confirm_msg="MJPG-Streamer has been set up!"
|
||||
if [[ ${usergroup_changed} == "true" ]]; then
|
||||
confirm_msg="${confirm_msg}\n ${yellow}INFO: Your User was added to a new group!${green}"
|
||||
confirm_msg="${confirm_msg}\n ${yellow}You need to relog/restart for the group to be applied!${green}"
|
||||
fi
|
||||
|
||||
print_confirm "${confirm_msg}"
|
||||
|
||||
### print webcam ip adress/url
|
||||
local ip
|
||||
ip=$(hostname -I | cut -d" " -f1)
|
||||
local cam_url="http://${ip}:8080/?action=stream"
|
||||
local cam_url_alt="http://${ip}/webcam/?action=stream"
|
||||
echo -e " ${cyan}● Webcam URL:${white} ${cam_url}"
|
||||
echo -e " ${cyan}● Webcam URL:${white} ${cam_url_alt}"
|
||||
echo
|
||||
}
|
||||
|
||||
#=================================================#
|
||||
#============== REMOVE MJPG-STREAMER =============#
|
||||
#=================================================#
|
||||
|
||||
function remove_mjpg-streamer() {
|
||||
### remove MJPG-Streamer service
|
||||
if [[ -e "${SYSTEMD}/webcamd.service" ]]; then
|
||||
status_msg "Removing MJPG-Streamer service ..."
|
||||
sudo systemctl stop webcamd && sudo systemctl disable webcamd
|
||||
sudo rm -f "${SYSTEMD}/webcamd.service"
|
||||
###reloading units
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl reset-failed
|
||||
ok_msg "MJPG-Streamer Service removed!"
|
||||
fi
|
||||
|
||||
### remove webcamd from /usr/local/bin
|
||||
if [[ -e "/usr/local/bin/webcamd" ]]; then
|
||||
sudo rm -f "/usr/local/bin/webcamd"
|
||||
fi
|
||||
|
||||
### remove MJPG-Streamer directory
|
||||
if [[ -d "${HOME}/mjpg-streamer" ]]; then
|
||||
status_msg "Removing MJPG-Streamer directory ..."
|
||||
rm -rf "${HOME}/mjpg-streamer"
|
||||
ok_msg "MJPG-Streamer directory removed!"
|
||||
fi
|
||||
|
||||
### remove webcamd log and symlink
|
||||
[[ -f "/var/log/webcamd.log" ]] && sudo rm -f "/var/log/webcamd.log"
|
||||
[[ -L "${KLIPPER_LOGS}/webcamd.log" ]] && rm -f "${KLIPPER_LOGS}/webcamd.log"
|
||||
|
||||
print_confirm "MJPG-Streamer successfully removed!"
|
||||
}
|
||||
@@ -1,247 +0,0 @@
|
||||
#!/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 Patrick Schmidt author of Mobileraker
|
||||
# It is based of the kliperscreen.sh install script!
|
||||
|
||||
|
||||
set -e
|
||||
|
||||
#===================================================#
|
||||
#========== INSTALL MOBILERAKER COMPANION ==========#
|
||||
#===================================================#
|
||||
|
||||
function mobileraker_systemd() {
|
||||
local services
|
||||
services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/mobileraker.service")
|
||||
echo "${services}"
|
||||
}
|
||||
|
||||
function install_mobileraker() {
|
||||
### return early if python version check fails
|
||||
if [[ $(python3_check) == "false" ]]; then
|
||||
local error="Versioncheck failed! Python 3.7 or newer required!\n"
|
||||
error="${error} Please upgrade Python."
|
||||
print_error "${error}" && return
|
||||
fi
|
||||
|
||||
### first, we create a backup of the full klipper_config dir - safety first!
|
||||
backup_config_dir
|
||||
|
||||
### install Mobileraker's Companion
|
||||
mobileraker_setup
|
||||
|
||||
### add Mobileraker's Companion to the update manager in moonraker.conf
|
||||
patch_mobileraker_update_manager
|
||||
|
||||
do_action_service "restart" "mobileraker"
|
||||
}
|
||||
|
||||
function mobileraker_setup() {
|
||||
local dep=(wget curl unzip dfu-util)
|
||||
dependency_check "${dep[@]}"
|
||||
status_msg "Cloning Mobileraker's companion from ${MOBILERAKER_REPO} ..."
|
||||
|
||||
# force remove existing Mobileraker's companion dir
|
||||
[[ -d ${MOBILERAKER_DIR} ]] && rm -rf "${MOBILERAKER_DIR}"
|
||||
|
||||
# clone into fresh Mobileraker's companion dir
|
||||
cd "${HOME}" || exit 1
|
||||
if ! git clone "${MOBILERAKER_REPO}" "${MOBILERAKER_DIR}"; then
|
||||
print_error "Cloning mobileraker's companion from\n ${MOBILERAKER_REPO}\n failed!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
status_msg "Starting installer of Mobileraker's companion ..."
|
||||
if "${MOBILERAKER_DIR}"/scripts/install.sh; then
|
||||
ok_msg "Mobileraker's companion successfully installed!"
|
||||
else
|
||||
print_error "Mobileraker's companion installation failed!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#=========== REMOVE MOBILERAKER COMPANION ==========#
|
||||
#===================================================#
|
||||
|
||||
function remove_mobileraker() {
|
||||
### remove Mobileraker's companion dir
|
||||
if [[ -d ${MOBILERAKER_DIR} ]]; then
|
||||
status_msg "Removing Mobileraker's companion directory ..."
|
||||
rm -rf "${MOBILERAKER_DIR}" && ok_msg "Directory removed!"
|
||||
fi
|
||||
|
||||
### remove Mobileraker's companion VENV dir
|
||||
if [[ -d ${MOBILERAKER_ENV} ]]; then
|
||||
status_msg "Removing Mobileraker's companion VENV directory ..."
|
||||
rm -rf "${MOBILERAKER_ENV}" && ok_msg "Directory removed!"
|
||||
fi
|
||||
|
||||
### remove Mobileraker's companion service
|
||||
if [[ -e "${SYSTEMD}/mobileraker.service" ]]; then
|
||||
status_msg "Removing mobileraker service ..."
|
||||
do_action_service "stop" "mobileraker"
|
||||
do_action_service "disable" "mobileraker"
|
||||
sudo rm -f "${SYSTEMD}/mobileraker.service"
|
||||
|
||||
###reloading units
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl reset-failed
|
||||
ok_msg "Mobileraker's companion Service removed!"
|
||||
fi
|
||||
|
||||
|
||||
remove_mobileraker_logs
|
||||
|
||||
print_confirm "Mobileraker's companion successfully removed!"
|
||||
}
|
||||
|
||||
function remove_mobileraker_logs() {
|
||||
local files regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/logs\/mobileraker\.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
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#=========== UPDATE MOBILERAKER COMPANION ==========#
|
||||
#===================================================#
|
||||
|
||||
function update_mobileraker() {
|
||||
local old_md5
|
||||
old_md5=$(md5sum "${MOBILERAKER_DIR}/scripts/mobileraker-requirements.txt" | cut -d " " -f1)
|
||||
|
||||
do_action_service "stop" "mobileraker"
|
||||
cd "${MOBILERAKER_DIR}"
|
||||
git pull origin main -q && ok_msg "Fetch successfull!"
|
||||
git checkout -f main && ok_msg "Checkout successfull"
|
||||
|
||||
if [[ $(md5sum "${MOBILERAKER_DIR}/scripts/mobileraker-requirements.txt" | cut -d " " -f1) != "${old_md5}" ]]; then
|
||||
status_msg "New dependencies detected..."
|
||||
"${MOBILERAKER_ENV}"/bin/pip install -r "${MOBILERAKER_DIR}/scripts/mobileraker-requirements.txt"
|
||||
ok_msg "Dependencies have been installed!"
|
||||
fi
|
||||
|
||||
ok_msg "Update complete!"
|
||||
do_action_service "start" "mobileraker"
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#=========== MOBILERAKER COMPANION STATUS ==========#
|
||||
#===================================================#
|
||||
|
||||
function get_mobileraker_status() {
|
||||
local sf_count status
|
||||
sf_count="$(mobileraker_systemd | wc -w)"
|
||||
|
||||
### remove the "SERVICE" entry from the data array if a moonraker service is installed
|
||||
local data_arr=(SERVICE "${MOBILERAKER_DIR}" "${MOBILERAKER_ENV}")
|
||||
(( sf_count > 0 )) && unset "data_arr[0]"
|
||||
|
||||
### count+1 for each found data-item from array
|
||||
local filecount=0
|
||||
for data in "${data_arr[@]}"; do
|
||||
[[ -e ${data} ]] && filecount=$(( filecount + 1 ))
|
||||
done
|
||||
|
||||
if (( filecount == ${#data_arr[*]} )); then
|
||||
status="Installed!"
|
||||
elif (( filecount == 0 )); then
|
||||
status="Not installed!"
|
||||
else
|
||||
status="Incomplete!"
|
||||
fi
|
||||
echo "${status}"
|
||||
}
|
||||
|
||||
function get_local_mobileraker_commit() {
|
||||
[[ ! -d ${MOBILERAKER_DIR} || ! -d "${MOBILERAKER_DIR}/.git" ]] && return
|
||||
|
||||
local commit
|
||||
cd "${MOBILERAKER_DIR}"
|
||||
commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
|
||||
echo "${commit}"
|
||||
}
|
||||
|
||||
function get_remote_mobileraker_commit() {
|
||||
[[ ! -d ${MOBILERAKER_DIR} || ! -d "${MOBILERAKER_DIR}/.git" ]] && return
|
||||
|
||||
local commit
|
||||
cd "${MOBILERAKER_DIR}" && git fetch origin -q
|
||||
commit=$(git describe origin/main --always --tags | cut -d "-" -f 1,2)
|
||||
echo "${commit}"
|
||||
}
|
||||
|
||||
function compare_mobileraker_versions() {
|
||||
local versions local_ver remote_ver
|
||||
local_ver="$(get_local_mobileraker_commit)"
|
||||
remote_ver="$(get_remote_mobileraker_commit)"
|
||||
|
||||
if [[ ${local_ver} != "${remote_ver}" ]]; then
|
||||
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
# add moonraker to application_updates_available in kiauh.ini
|
||||
add_to_application_updates "mobileraker"
|
||||
else
|
||||
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
fi
|
||||
|
||||
echo "${versions}"
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=================== HELPERS ====================#
|
||||
#================================================#
|
||||
|
||||
function patch_mobileraker_update_manager() {
|
||||
local patched moonraker_configs regex
|
||||
regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/moonraker\.conf"
|
||||
moonraker_configs=$(find "${HOME}" -maxdepth 3 -type f -regextype posix-extended -regex "${regex}" | sort)
|
||||
|
||||
patched="false"
|
||||
for conf in ${moonraker_configs}; do
|
||||
if ! grep -Eq "^\[update_manager mobileraker\]\s*$" "${conf}"; then
|
||||
### add new line to conf if it doesn't end with one
|
||||
[[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}"
|
||||
|
||||
### add Mobileraker's Companion update manager section to moonraker.conf
|
||||
status_msg "Adding Mobileraker's Companion to update manager in file:\n ${conf}"
|
||||
/bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF
|
||||
|
||||
[update_manager mobileraker]
|
||||
type: git_repo
|
||||
path: ${HOME}/mobileraker_companion
|
||||
origin: https://github.com/Clon1998/mobileraker_companion.git
|
||||
primary_branch:main
|
||||
managed_services: mobileraker
|
||||
env: ${HOME}/mobileraker-env/bin/python
|
||||
requirements: scripts/mobileraker-requirements.txt
|
||||
install_script: scripts/install.sh
|
||||
MOONRAKER_CONF
|
||||
|
||||
fi
|
||||
|
||||
patched="true"
|
||||
done
|
||||
|
||||
if [[ ${patched} == "true" ]]; then
|
||||
do_action_service "restart" "moonraker"
|
||||
fi
|
||||
}
|
||||
@@ -1,542 +0,0 @@
|
||||
#!/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 #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
#===================================================#
|
||||
#========== INSTALL MOONRAKERTELEGRAMBOT ===========#
|
||||
#===================================================#
|
||||
|
||||
function telegram_bot_systemd() {
|
||||
local services
|
||||
services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/moonraker-telegram-bot(-[0-9a-zA-Z]+)?.service" | sort)
|
||||
echo "${services}"
|
||||
}
|
||||
|
||||
function telegram_bot_setup_dialog() {
|
||||
### return early if moonraker is not installed
|
||||
local moonraker_services
|
||||
moonraker_services=$(moonraker_systemd)
|
||||
|
||||
if [[ -z ${moonraker_services} ]]; then
|
||||
local error="Moonraker not installed! Please install Moonraker first!"
|
||||
print_error "${error}" && return
|
||||
fi
|
||||
|
||||
status_msg "Initializing Telegram Bot installation ..."
|
||||
### first, we create a backup of the full klipper_config dir - safety first!
|
||||
backup_config_dir
|
||||
|
||||
local moonraker_count user_input=() moonraker_names=()
|
||||
moonraker_count=$(echo "${moonraker_services}" | wc -w )
|
||||
for service in ${moonraker_services}; do
|
||||
moonraker_names+=( "$(get_instance_name "${service}")" )
|
||||
done
|
||||
|
||||
local telegram_bot_count
|
||||
if (( moonraker_count == 1 )); then
|
||||
ok_msg "Moonraker installation found!\n"
|
||||
telegram_bot_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" " ● ${name}"
|
||||
done
|
||||
blank_line
|
||||
echo -e "| The setup will apply the same names to Telegram Bot! |"
|
||||
blank_line
|
||||
echo -e "| Please select the number of Telegram Bot instances to |"
|
||||
echo -e "| install. Usually one Telegram Bot instance per |"
|
||||
echo -e "| Moonraker instance is required, but you may not |"
|
||||
echo -e "| install more Telegram Bot instances than available |"
|
||||
echo -e "| Moonraker instances. |"
|
||||
bottom_border
|
||||
|
||||
### ask for amount of instances
|
||||
local re="^[1-9][0-9]*$"
|
||||
while [[ ! ${telegram_bot_count} =~ ${re} || ${telegram_bot_count} -gt ${moonraker_count} ]]; do
|
||||
read -p "${cyan}###### Number of Telegram Bot instances to set up:${white} " -i "${moonraker_count}" -e telegram_bot_count
|
||||
### break if input is valid
|
||||
[[ ${telegram_bot_count} =~ ${re} && ${telegram_bot_count} -le ${moonraker_count} ]] && break
|
||||
### conditional error messages
|
||||
[[ ! ${telegram_bot_count} =~ ${re} ]] && error_msg "Input not a number"
|
||||
(( telegram_bot_count > moonraker_count )) && error_msg "Number of Telegram Bot instances larger than existing Moonraker instances"
|
||||
done && select_msg "${telegram_bot_count}"
|
||||
else
|
||||
log_error "Internal error. moonraker_count of '${moonraker_count}' not equal or grather than one!"
|
||||
return 1
|
||||
fi
|
||||
|
||||
user_input+=("${telegram_bot_count}")
|
||||
|
||||
### confirm instance amount
|
||||
local yn
|
||||
while true; do
|
||||
(( telegram_bot_count == 1 )) && local question="Install Telegram Bot?"
|
||||
(( telegram_bot_count > 1 )) && local question="Install ${telegram_bot_count} Telegram Bot instances?"
|
||||
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 Telegram Bot setup ...\n"
|
||||
return;;
|
||||
*)
|
||||
error_msg "Invalid Input!";;
|
||||
esac
|
||||
done
|
||||
|
||||
### write existing klipper names into user_input array to use them as names for moonraker
|
||||
if (( moonraker_count > 1 )); then
|
||||
for name in "${moonraker_names[@]}"; do
|
||||
user_input+=("${name}")
|
||||
done
|
||||
fi
|
||||
|
||||
(( telegram_bot_count > 1 )) && status_msg "Installing ${telegram_bot_count} Telegram Bot instances ..."
|
||||
(( telegram_bot_count == 1 )) && status_msg "Installing Telegram Bot ..."
|
||||
telegram_bot_setup "${user_input[@]}"
|
||||
}
|
||||
|
||||
function install_telegram_bot_dependencies() {
|
||||
local packages log_name="Telegram Bot"
|
||||
local install_script="${TELEGRAM_BOT_DIR}/scripts/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[@]"
|
||||
}
|
||||
|
||||
function create_telegram_bot_virtualenv() {
|
||||
status_msg "Installing python virtual environment..."
|
||||
### always create a clean virtualenv
|
||||
[[ -d ${TELEGRAM_BOT_ENV} ]] && rm -rf "${TELEGRAM_BOT_ENV}"
|
||||
if virtualenv -p /usr/bin/python3 --system-site-packages "${TELEGRAM_BOT_ENV}"; then
|
||||
"${TELEGRAM_BOT_ENV}"/bin/pip install -r "${TELEGRAM_BOT_DIR}/scripts/requirements.txt"
|
||||
else
|
||||
log_error "failure while creating python3 moonraker-telegram-bot-env"
|
||||
error_msg "Creation of Moonraker Telegram Bot virtualenv failed!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function telegram_bot_setup() {
|
||||
local instance_arr=("${@}")
|
||||
### checking dependencies
|
||||
local dep=(git virtualenv)
|
||||
dependency_check "${dep[@]}"
|
||||
|
||||
### step 1: clone telegram bot
|
||||
clone_telegram_bot "${TELEGRAM_BOT_REPO}"
|
||||
|
||||
### step 2: install telegram bot dependencies and create python virtualenv
|
||||
status_msg "Installing dependencies ..."
|
||||
install_telegram_bot_dependencies
|
||||
create_telegram_bot_virtualenv
|
||||
|
||||
### step 3: create telegram.conf
|
||||
create_telegram_conf "${instance_arr[@]}"
|
||||
|
||||
### step 4: create telegram bot instances
|
||||
create_telegram_bot_service "${instance_arr[@]}"
|
||||
|
||||
### step 5: add telegram-bot to the update manager in moonraker.conf
|
||||
patch_telegram_bot_update_manager
|
||||
|
||||
### step 6: enable and start all instances
|
||||
do_action_service "enable" "moonraker-telegram-bot"
|
||||
do_action_service "start" "moonraker-telegram-bot"
|
||||
|
||||
### confirm message
|
||||
local confirm=""
|
||||
(( instance_arr[0] == 1 )) && confirm="Telegram Bot has been set up!"
|
||||
(( instance_arr[0] > 1 )) && confirm="${instance_arr[0]} Telegram Bot instances have been set up!"
|
||||
print_confirm "${confirm}" && return
|
||||
}
|
||||
|
||||
function clone_telegram_bot() {
|
||||
local repo=${1}
|
||||
|
||||
status_msg "Cloning Moonraker-Telegram-Bot from ${repo} ..."
|
||||
### force remove existing Moonraker-Telegram-Bot dir
|
||||
[[ -d ${repo} ]] && rm -rf "${TELEGRAM_BOT_DIR}"
|
||||
|
||||
cd "${HOME}" || exit 1
|
||||
if ! git clone "${repo}" "${TELEGRAM_BOT_DIR}"; then
|
||||
print_error "Cloning Moonraker-Telegram-Bot from\n ${repo}\n failed!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function create_telegram_conf() {
|
||||
local input=("${@}")
|
||||
local telegram_bot_count=${input[0]} && unset "input[0]"
|
||||
local names=("${input[@]}") && unset "input[@]"
|
||||
local printer_data log_dir cfg cfg_dir
|
||||
|
||||
if (( telegram_bot_count == 1 )); then
|
||||
printer_data="${HOME}/printer_data"
|
||||
log_dir="${printer_data}/logs"
|
||||
cfg_dir="${printer_data}/config"
|
||||
cfg="${cfg_dir}/telegram.conf"
|
||||
|
||||
### create required folder structure
|
||||
create_required_folders "${printer_data}"
|
||||
|
||||
### write single instance config
|
||||
write_telegram_conf "${cfg_dir}" "${cfg}"
|
||||
|
||||
elif (( telegram_bot_count > 1 )); then
|
||||
local j=0 re="^[1-9][0-9]*$"
|
||||
|
||||
for (( i=1; i <= telegram_bot_count; i++ )); do
|
||||
|
||||
printer_data="${HOME}/${names[${j}]}_data"
|
||||
### prefix instance name with "printer_" if it is only a number
|
||||
[[ ${names[j]} =~ ${re} ]] && printer_data="${HOME}/printer_${names[${j}]}_data"
|
||||
|
||||
|
||||
cfg_dir="${printer_data}/config"
|
||||
cfg="${cfg_dir}/telegram.conf"
|
||||
log_dir="${printer_data}/logs"
|
||||
|
||||
### create required folder structure
|
||||
create_required_folders "${printer_data}"
|
||||
|
||||
### write multi instance config
|
||||
write_telegram_conf "${cfg_dir}" "${cfg}"
|
||||
|
||||
j=$(( j + 1 ))
|
||||
done && unset j
|
||||
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function write_telegram_conf() {
|
||||
local cfg_dir=${1} cfg=${2}
|
||||
local conf_template="${TELEGRAM_BOT_DIR}/scripts/base_install_template"
|
||||
|
||||
if [[ ! -f ${cfg} ]]; then
|
||||
status_msg "Creating telegram.conf in ${cfg_dir} ..."
|
||||
cp "${conf_template}" "${cfg}"
|
||||
ok_msg "telegram.conf created!"
|
||||
else
|
||||
ok_msg "File '${cfg}' already exists! Skipping..."
|
||||
fi
|
||||
}
|
||||
|
||||
function create_telegram_bot_service() {
|
||||
local input=("${@}")
|
||||
local instances=${input[0]} && unset "input[0]"
|
||||
local names=("${input[@]}") && unset "input[@]"
|
||||
local printer_data cfg_dir cfg log service env_file
|
||||
|
||||
if (( instances == 1 )); then
|
||||
printer_data="${HOME}/printer_data"
|
||||
cfg_dir="${printer_data}/config"
|
||||
cfg="${cfg_dir}/telegram.conf"
|
||||
log="${printer_data}/logs/telegram.log"
|
||||
service="${SYSTEMD}/moonraker-telegram-bot.service"
|
||||
env_file="${printer_data}/systemd/moonraker-telegram-bot.env"
|
||||
|
||||
### create required folder structure
|
||||
create_required_folders "${printer_data}"
|
||||
|
||||
### write single instance service
|
||||
write_telegram_bot_service "" "${cfg}" "${log}" "${service}" "${env_file}"
|
||||
ok_msg "Telegram Bot instance created!"
|
||||
|
||||
elif (( instances > 1 )); then
|
||||
local j=0 re="^[1-9][0-9]*$"
|
||||
|
||||
for (( i=1; i <= instances; i++ )); do
|
||||
### overwrite config folder if name is only a number
|
||||
if [[ ${names[j]} =~ ${re} ]]; then
|
||||
printer_data="${HOME}/printer_${names[${j}]}_data"
|
||||
else
|
||||
printer_data="${HOME}/${names[${j}]}_data"
|
||||
fi
|
||||
|
||||
cfg_dir="${printer_data}/config"
|
||||
cfg="${cfg_dir}/telegram.conf"
|
||||
log="${printer_data}/logs/telegram.log"
|
||||
service="${SYSTEMD}/moonraker-telegram-bot-${names[${j}]}.service"
|
||||
env_file="${printer_data}/systemd/moonraker-telegram-bot.env"
|
||||
|
||||
### create required folder structure
|
||||
create_required_folders "${printer_data}"
|
||||
|
||||
### write multi instance service
|
||||
if write_telegram_bot_service "${names[${j}]}" "${cfg}" "${log}" "${service}" "${env_file}"; then
|
||||
ok_msg "Telegram Bot instance moonraker-telegram-bot-${names[${j}]} created!"
|
||||
else
|
||||
error_msg "An error occured during creation of instance moonraker-telegram-bot-${names[${j}]}!"
|
||||
fi
|
||||
|
||||
j=$(( j + 1 ))
|
||||
done && unset j
|
||||
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function write_telegram_bot_service() {
|
||||
local i=${1} cfg=${2} log=${3} service=${4} env_file=${5}
|
||||
local service_template="${KIAUH_SRCDIR}/resources/moonraker-telegram-bot.service"
|
||||
local env_template="${KIAUH_SRCDIR}/resources/moonraker-telegram-bot.env"
|
||||
|
||||
### replace all placeholders
|
||||
if [[ ! -f ${service} ]]; then
|
||||
status_msg "Creating service file for instance ${i} ..."
|
||||
sudo cp "${service_template}" "${service}"
|
||||
if [[ -z ${i} ]]; then
|
||||
sudo sed -i "s| %INST%||" "${service}"
|
||||
else
|
||||
sudo sed -i "s|%INST%|${i}|" "${service}"
|
||||
fi
|
||||
sudo sed -i "s|%USER%|${USER}|g; s|%TELEGRAM_BOT_DIR%|${TELEGRAM_BOT_DIR}|; s|%ENV%|${TELEGRAM_BOT_ENV}|; s|%ENV_FILE%|${env_file}|" "${service}"
|
||||
|
||||
status_msg "Creating environment file for instance ${i} ..."
|
||||
cp "${env_template}" "${env_file}"
|
||||
sed -i "s|%USER%|${USER}|; s|%TELEGRAM_BOT_DIR%|${TELEGRAM_BOT_DIR}|; s|%CFG%|${cfg}|; s|%LOG%|${log}|" "${env_file}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
#===================================================#
|
||||
#=========== REMOVE MOONRAKERTELEGRAMBOT ===========#
|
||||
#===================================================#
|
||||
|
||||
function remove_telegram_bot_systemd() {
|
||||
[[ -z $(telegram_bot_systemd) ]] && return
|
||||
|
||||
status_msg "Removing Telegram Bot Systemd Services ..."
|
||||
for service in $(telegram_bot_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 "Telegram Bot Services removed!"
|
||||
}
|
||||
|
||||
function remove_telegram_bot_dir() {
|
||||
[[ ! -d ${TELEGRAM_BOT_DIR} ]] && return
|
||||
|
||||
status_msg "Removing Moonraker-Telegram-Bot directory ..."
|
||||
rm -rf "${TELEGRAM_BOT_DIR}"
|
||||
ok_msg "Directory removed!"
|
||||
}
|
||||
|
||||
function remove_telegram_bot_env() {
|
||||
[[ ! -d ${TELEGRAM_BOT_ENV} ]] && return
|
||||
|
||||
status_msg "Removing moonraker-telegram-bot-env directory ..."
|
||||
rm -rf "${TELEGRAM_BOT_ENV}"
|
||||
ok_msg "Directory removed!"
|
||||
}
|
||||
|
||||
function remove_telegram_bot_env_file() {
|
||||
local files regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/systemd\/moonraker-telegram-bot\.env"
|
||||
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_telegram_bot_logs() {
|
||||
local files regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/logs\/telegram\.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_legacy_telegram_bot_logs() {
|
||||
local files regex="telegram(-[0-9a-zA-Z]+)?\.log(.*)?"
|
||||
files=$(find "${HOME}/klipper_logs" -maxdepth 1 -regextype posix-extended -regex "${HOME}/klipper_logs/${regex}" 2> /dev/null | 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_telegram_bot() {
|
||||
remove_telegram_bot_systemd
|
||||
remove_telegram_bot_dir
|
||||
remove_telegram_bot_env
|
||||
remove_telegram_bot_env_file
|
||||
remove_telegram_bot_logs
|
||||
remove_legacy_telegram_bot_logs
|
||||
|
||||
local confirm="Moonraker-Telegram-Bot was successfully removed!"
|
||||
print_confirm "${confirm}" && return
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#=========== UPDATE MOONRAKERTELEGRAMBOT ===========#
|
||||
#===================================================#
|
||||
|
||||
function update_telegram_bot() {
|
||||
do_action_service "stop" "moonraker-telegram-bot"
|
||||
|
||||
if [[ ! -d ${TELEGRAM_BOT_DIR} ]]; then
|
||||
clone_telegram_bot "${TELEGRAM_BOT_REPO}"
|
||||
else
|
||||
backup_before_update "moonraker-telegram-bot"
|
||||
status_msg "Updating Moonraker ..."
|
||||
cd "${TELEGRAM_BOT_DIR}" && git pull
|
||||
### read PKGLIST and install possible new dependencies
|
||||
install_telegram_bot_dependencies
|
||||
### install possible new python dependencies
|
||||
"${TELEGRAM_BOT_ENV}"/bin/pip install -r "${TELEGRAM_BOT_DIR}/scripts/requirements.txt"
|
||||
fi
|
||||
|
||||
ok_msg "Update complete!"
|
||||
do_action_service "start" "moonraker-telegram-bot"
|
||||
}
|
||||
|
||||
#===================================================#
|
||||
#=========== MOONRAKERTELEGRAMBOT STATUS ===========#
|
||||
#===================================================#
|
||||
|
||||
function get_telegram_bot_status() {
|
||||
local sf_count status
|
||||
sf_count="$(telegram_bot_systemd | wc -w)"
|
||||
|
||||
### remove the "SERVICE" entry from the data array if a moonraker service is installed
|
||||
local data_arr=(SERVICE "${TELEGRAM_BOT_DIR}" "${TELEGRAM_BOT_ENV}")
|
||||
(( sf_count > 0 )) && unset "data_arr[0]"
|
||||
|
||||
### count+1 for each found data-item from array
|
||||
local filecount=0
|
||||
for data in "${data_arr[@]}"; do
|
||||
[[ -e ${data} ]] && filecount=$(( filecount + 1 ))
|
||||
done
|
||||
|
||||
if (( filecount == ${#data_arr[*]} )); then
|
||||
status="Installed: ${sf_count}"
|
||||
elif (( filecount == 0 )); then
|
||||
status="Not installed!"
|
||||
else
|
||||
status="Incomplete!"
|
||||
fi
|
||||
echo "${status}"
|
||||
}
|
||||
|
||||
function get_local_telegram_bot_commit() {
|
||||
[[ ! -d ${TELEGRAM_BOT_DIR} || ! -d "${TELEGRAM_BOT_DIR}/.git" ]] && return
|
||||
|
||||
local commit
|
||||
cd "${TELEGRAM_BOT_DIR}"
|
||||
commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
|
||||
echo "${commit}"
|
||||
}
|
||||
|
||||
function get_remote_telegram_bot_commit() {
|
||||
[[ ! -d ${TELEGRAM_BOT_DIR} || ! -d "${TELEGRAM_BOT_DIR}/.git" ]] && return
|
||||
|
||||
local commit
|
||||
cd "${TELEGRAM_BOT_DIR}" && git fetch origin -q
|
||||
commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2)
|
||||
echo "${commit}"
|
||||
}
|
||||
|
||||
function compare_telegram_bot_versions() {
|
||||
local versions local_ver remote_ver
|
||||
local_ver="$(get_local_telegram_bot_commit)"
|
||||
remote_ver="$(get_remote_telegram_bot_commit)"
|
||||
|
||||
if [[ ${local_ver} != "${remote_ver}" ]]; then
|
||||
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
# add moonraker to application_updates_available in kiauh.ini
|
||||
add_to_application_updates "telegram_bot"
|
||||
else
|
||||
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
fi
|
||||
|
||||
echo "${versions}"
|
||||
}
|
||||
|
||||
#================================================#
|
||||
#=================== HELPERS ====================#
|
||||
#================================================#
|
||||
|
||||
function patch_telegram_bot_update_manager() {
|
||||
local patched moonraker_configs regex
|
||||
regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/moonraker\.conf"
|
||||
moonraker_configs=$(find "${HOME}" -maxdepth 3 -type f -regextype posix-extended -regex "${regex}" | sort)
|
||||
|
||||
patched="false"
|
||||
for conf in ${moonraker_configs}; do
|
||||
if ! grep -Eq "^\[update_manager moonraker-telegram-bot\]\s*$" "${conf}"; then
|
||||
### add new line to conf if it doesn't end with one
|
||||
[[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}"
|
||||
|
||||
### add Moonraker-Telegram-Bot update manager section to moonraker.conf
|
||||
status_msg "Adding Moonraker-Telegram-Bot to update manager in file:\n ${conf}"
|
||||
/bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF
|
||||
|
||||
[update_manager moonraker-telegram-bot]
|
||||
type: git_repo
|
||||
path: ~/moonraker-telegram-bot
|
||||
origin: https://github.com/nlef/moonraker-telegram-bot.git
|
||||
env: ~/moonraker-telegram-bot-env/bin/python
|
||||
requirements: scripts/requirements.txt
|
||||
install_script: scripts/install.sh
|
||||
MOONRAKER_CONF
|
||||
|
||||
fi
|
||||
|
||||
patched="true"
|
||||
done
|
||||
|
||||
if [[ ${patched} == "true" ]]; then
|
||||
do_action_service "restart" "moonraker"
|
||||
fi
|
||||
}
|
||||
@@ -1,809 +0,0 @@
|
||||
#!/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 #
|
||||
#=======================================================================#
|
||||
|
||||
set -e
|
||||
|
||||
#===================================================#
|
||||
#================ INSTALL MOONRAKER ================#
|
||||
#===================================================#
|
||||
|
||||
###
|
||||
# this function detects all installed moonraker
|
||||
# systemd instances and returns their absolute path
|
||||
function moonraker_systemd() {
|
||||
local services
|
||||
local blacklist
|
||||
local ignore
|
||||
local match
|
||||
|
||||
###
|
||||
# any moonraker client that uses "moonraker" in its own name must be blacklisted using
|
||||
# this variable, otherwise they will be falsely recognized as moonraker instances
|
||||
blacklist="obico"
|
||||
|
||||
ignore="${SYSTEMD}/moonraker-(${blacklist}).service"
|
||||
match="${SYSTEMD}/moonraker(-[0-9a-zA-Z]+)?.service"
|
||||
|
||||
services=$(find "${SYSTEMD}" -maxdepth 1 -regextype awk ! -regex "${ignore}" -regex "${match}" | sort)
|
||||
echo "${services}"
|
||||
}
|
||||
|
||||
function moonraker_setup_dialog() {
|
||||
status_msg "Initializing Moonraker installation ..."
|
||||
|
||||
### return early if python version check fails
|
||||
if [[ $(python3_check) == "false" ]]; then
|
||||
local error="Versioncheck failed! Python 3.7 or newer required!\n"
|
||||
error="${error} Please upgrade Python."
|
||||
print_error "${error}" && return
|
||||
fi
|
||||
|
||||
### return early if moonraker already exists
|
||||
local moonraker_services
|
||||
moonraker_services=$(moonraker_systemd)
|
||||
if [[ -n ${moonraker_services} ]]; then
|
||||
local error="At least one Moonraker service is already installed:"
|
||||
for s in ${moonraker_services}; do
|
||||
log_info "Found Moonraker service: ${s}"
|
||||
error="${error}\n ➔ ${s}"
|
||||
done
|
||||
print_error "${error}" && return
|
||||
fi
|
||||
|
||||
### return early if klipper is not installed
|
||||
local klipper_services
|
||||
klipper_services=$(klipper_systemd)
|
||||
if [[ -z ${klipper_services} ]]; then
|
||||
local error="Klipper not installed! Please install Klipper first!"
|
||||
log_error "Moonraker setup started without Klipper being installed. Aborting setup."
|
||||
print_error "${error}" && return
|
||||
fi
|
||||
|
||||
local klipper_count user_input=() klipper_names=()
|
||||
klipper_count=$(echo "${klipper_services}" | wc -w )
|
||||
for service in ${klipper_services}; do
|
||||
klipper_names+=( "$(get_instance_name "${service}")" )
|
||||
done
|
||||
|
||||
local moonraker_count
|
||||
if (( klipper_count == 1 )); then
|
||||
ok_msg "Klipper installation found!\n"
|
||||
moonraker_count=1
|
||||
elif (( klipper_count > 1 )); then
|
||||
top_border
|
||||
printf "|${green}%-55s${white}|\n" " ${klipper_count} Klipper instances found!"
|
||||
for name in "${klipper_names[@]}"; do
|
||||
printf "|${cyan}%-57s${white}|\n" " ● klipper-${name}"
|
||||
done
|
||||
blank_line
|
||||
echo -e "| The setup will apply the same names to Moonraker! |"
|
||||
blank_line
|
||||
echo -e "| Please select the number of Moonraker instances to |"
|
||||
echo -e "| install. Usually one Moonraker instance per Klipper |"
|
||||
echo -e "| instance is required, but you may not install more |"
|
||||
echo -e "| Moonraker instances than available Klipper instances. |"
|
||||
bottom_border
|
||||
|
||||
### ask for amount of instances
|
||||
local re="^[1-9][0-9]*$"
|
||||
while [[ ! ${moonraker_count} =~ ${re} || ${moonraker_count} -gt ${klipper_count} ]]; do
|
||||
read -p "${cyan}###### Number of Moonraker instances to set up:${white} " -i "${klipper_count}" -e moonraker_count
|
||||
### break if input is valid
|
||||
[[ ${moonraker_count} =~ ${re} && ${moonraker_count} -le ${klipper_count} ]] && break
|
||||
### conditional error messages
|
||||
[[ ! ${moonraker_count} =~ ${re} ]] && error_msg "Input not a number"
|
||||
(( moonraker_count > klipper_count )) && error_msg "Number of Moonraker instances larger than installed Klipper instances"
|
||||
done && select_msg "${moonraker_count}"
|
||||
else
|
||||
log_error "Internal error. klipper_count of '${klipper_count}' not equal or grather than one!"
|
||||
return 1
|
||||
fi
|
||||
|
||||
user_input+=("${moonraker_count}")
|
||||
|
||||
### confirm instance amount
|
||||
local yn
|
||||
while true; do
|
||||
(( moonraker_count == 1 )) && local question="Install Moonraker?"
|
||||
(( moonraker_count > 1 )) && local question="Install ${moonraker_count} Moonraker instances?"
|
||||
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 Moonraker setup ...\n"
|
||||
return;;
|
||||
*)
|
||||
error_msg "Invalid Input!";;
|
||||
esac
|
||||
done
|
||||
|
||||
### write existing klipper names into user_input array to use them as names for moonraker
|
||||
if (( klipper_count > 1 )); then
|
||||
for name in "${klipper_names[@]}"; do
|
||||
user_input+=("${name}")
|
||||
done
|
||||
fi
|
||||
|
||||
(( moonraker_count > 1 )) && status_msg "Installing ${moonraker_count} Moonraker instances ..."
|
||||
(( moonraker_count == 1 )) && status_msg "Installing Moonraker ..."
|
||||
moonraker_setup "${user_input[@]}"
|
||||
}
|
||||
|
||||
function install_moonraker_dependencies() {
|
||||
local packages log_name="Moonraker"
|
||||
local package_json="${MOONRAKER_DIR}/scripts/system-dependencies.json"
|
||||
|
||||
### read PKGLIST from official install-script
|
||||
status_msg "Reading dependencies..."
|
||||
# shellcheck disable=SC2016
|
||||
packages=$(python3 - << EOF
|
||||
from __future__ import annotations
|
||||
import shlex
|
||||
import re
|
||||
import pathlib
|
||||
import logging
|
||||
import json
|
||||
|
||||
from typing import Tuple, Dict, List, Any
|
||||
|
||||
def _get_distro_info() -> Dict[str, Any]:
|
||||
release_file = pathlib.Path("/etc/os-release")
|
||||
release_info: Dict[str, str] = {}
|
||||
with release_file.open("r") as f:
|
||||
lexer = shlex.shlex(f, posix=True)
|
||||
lexer.whitespace_split = True
|
||||
for item in list(lexer):
|
||||
if "=" in item:
|
||||
key, val = item.split("=", maxsplit=1)
|
||||
release_info[key] = val
|
||||
return dict(
|
||||
distro_id=release_info.get("ID", ""),
|
||||
distro_version=release_info.get("VERSION_ID", ""),
|
||||
aliases=release_info.get("ID_LIKE", "").split()
|
||||
)
|
||||
|
||||
def _convert_version(version: str) -> Tuple[str | int, ...]:
|
||||
version = version.strip()
|
||||
ver_match = re.match(r"\d+(\.\d+)*((?:-|\.).+)?", version)
|
||||
if ver_match is not None:
|
||||
return tuple([
|
||||
int(part) if part.isdigit() else part
|
||||
for part in re.split(r"\.|-", version)
|
||||
])
|
||||
return (version,)
|
||||
|
||||
class SysDepsParser:
|
||||
def __init__(self, distro_info: Dict[str, Any] | None = None) -> None:
|
||||
if distro_info is None:
|
||||
distro_info = _get_distro_info()
|
||||
self.distro_id: str = distro_info.get("distro_id", "")
|
||||
self.aliases: List[str] = distro_info.get("aliases", [])
|
||||
self.distro_version: Tuple[int | str, ...] = tuple()
|
||||
version = distro_info.get("distro_version")
|
||||
if version:
|
||||
self.distro_version = _convert_version(version)
|
||||
|
||||
def _parse_spec(self, full_spec: str) -> str | None:
|
||||
parts = full_spec.split(";", maxsplit=1)
|
||||
if len(parts) == 1:
|
||||
return full_spec
|
||||
pkg_name = parts[0].strip()
|
||||
expressions = re.split(r"( and | or )", parts[1].strip())
|
||||
if not len(expressions) & 1:
|
||||
logging.info(
|
||||
f"Requirement specifier is missing an expression "
|
||||
f"between logical operators : {full_spec}"
|
||||
)
|
||||
return None
|
||||
last_result: bool = True
|
||||
last_logical_op: str | None = "and"
|
||||
for idx, exp in enumerate(expressions):
|
||||
if idx & 1:
|
||||
if last_logical_op is not None:
|
||||
logging.info(
|
||||
"Requirement specifier contains sequential logical "
|
||||
f"operators: {full_spec}"
|
||||
)
|
||||
return None
|
||||
logical_op = exp.strip()
|
||||
if logical_op not in ("and", "or"):
|
||||
logging.info(
|
||||
f"Invalid logical operator {logical_op} in requirement "
|
||||
f"specifier: {full_spec}")
|
||||
return None
|
||||
last_logical_op = logical_op
|
||||
continue
|
||||
elif last_logical_op is None:
|
||||
logging.info(
|
||||
f"Requirement specifier contains two seqential expressions "
|
||||
f"without a logical operator: {full_spec}")
|
||||
return None
|
||||
dep_parts = re.split(r"(==|!=|<=|>=|<|>)", exp.strip())
|
||||
req_var = dep_parts[0].strip().lower()
|
||||
if len(dep_parts) != 3:
|
||||
logging.info(f"Invalid comparison, must be 3 parts: {full_spec}")
|
||||
return None
|
||||
elif req_var == "distro_id":
|
||||
left_op: str | Tuple[int | str, ...] = self.distro_id
|
||||
right_op = dep_parts[2].strip().strip("\"'")
|
||||
elif req_var == "distro_version":
|
||||
if not self.distro_version:
|
||||
logging.info(
|
||||
"Distro Version not detected, cannot satisfy requirement: "
|
||||
f"{full_spec}"
|
||||
)
|
||||
return None
|
||||
left_op = self.distro_version
|
||||
right_op = _convert_version(dep_parts[2].strip().strip("\"'"))
|
||||
else:
|
||||
logging.info(f"Invalid requirement specifier: {full_spec}")
|
||||
return None
|
||||
operator = dep_parts[1].strip()
|
||||
try:
|
||||
compfunc = {
|
||||
"<": lambda x, y: x < y,
|
||||
">": lambda x, y: x > y,
|
||||
"==": lambda x, y: x == y,
|
||||
"!=": lambda x, y: x != y,
|
||||
">=": lambda x, y: x >= y,
|
||||
"<=": lambda x, y: x <= y
|
||||
}.get(operator, lambda x, y: False)
|
||||
result = compfunc(left_op, right_op)
|
||||
if last_logical_op == "and":
|
||||
last_result &= result
|
||||
else:
|
||||
last_result |= result
|
||||
last_logical_op = None
|
||||
except Exception:
|
||||
logging.exception(f"Error comparing requirements: {full_spec}")
|
||||
return None
|
||||
if last_result:
|
||||
return pkg_name
|
||||
return None
|
||||
|
||||
def parse_dependencies(self, sys_deps: Dict[str, List[str]]) -> List[str]:
|
||||
if not self.distro_id:
|
||||
logging.info(
|
||||
"Failed to detect current distro ID, cannot parse dependencies"
|
||||
)
|
||||
return []
|
||||
all_ids = [self.distro_id] + self.aliases
|
||||
for distro_id in all_ids:
|
||||
if distro_id in sys_deps:
|
||||
if not sys_deps[distro_id]:
|
||||
logging.info(
|
||||
f"Dependency data contains an empty package definition "
|
||||
f"for linux distro '{distro_id}'"
|
||||
)
|
||||
continue
|
||||
processed_deps: List[str] = []
|
||||
for dep in sys_deps[distro_id]:
|
||||
parsed_dep = self._parse_spec(dep)
|
||||
if parsed_dep is not None:
|
||||
processed_deps.append(parsed_dep)
|
||||
return processed_deps
|
||||
else:
|
||||
logging.info(
|
||||
f"Dependency data has no package definition for linux "
|
||||
f"distro '{self.distro_id}'"
|
||||
)
|
||||
return []
|
||||
# *** SYSTEM DEPENDENCIES START ***
|
||||
system_deps = {
|
||||
"debian": [
|
||||
"python3-virtualenv", "python3-dev", "libopenjp2-7", "libsodium-dev",
|
||||
"zlib1g-dev", "libjpeg-dev", "packagekit",
|
||||
"wireless-tools; distro_id != 'ubuntu' or distro_version <= '24.04'",
|
||||
"iw; distro_id == 'ubuntu' and distro_version >= '24.10'", "curl",
|
||||
"build-essential"
|
||||
],
|
||||
}
|
||||
system_deps_json = pathlib.Path("$package_json")
|
||||
system_deps = json.loads(system_deps_json.read_bytes())
|
||||
parser = SysDepsParser()
|
||||
pkgs = parser.parse_dependencies(system_deps)
|
||||
if pkgs:
|
||||
print(' '.join(pkgs), end="")
|
||||
exit(0)
|
||||
EOF
|
||||
)
|
||||
|
||||
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[@]"
|
||||
}
|
||||
|
||||
function create_moonraker_virtualenv() {
|
||||
status_msg "Installing python virtual environment..."
|
||||
|
||||
### always create a clean virtualenv
|
||||
[[ -d ${MOONRAKER_ENV} ]] && rm -rf "${MOONRAKER_ENV}"
|
||||
|
||||
if virtualenv -p /usr/bin/python3 "${MOONRAKER_ENV}"; then
|
||||
"${MOONRAKER_ENV}"/bin/pip install -r "${MOONRAKER_DIR}/scripts/moonraker-requirements.txt"
|
||||
else
|
||||
log_error "failure while creating python3 moonraker-env"
|
||||
error_msg "Creation of Moonraker virtualenv failed!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function moonraker_setup() {
|
||||
local instance_arr=("${@}")
|
||||
### checking dependencies
|
||||
local dep=(git wget curl unzip dfu-util virtualenv)
|
||||
### additional required dependencies on armbian
|
||||
dep+=(libjpeg-dev zlib1g-dev)
|
||||
dependency_check "${dep[@]}"
|
||||
|
||||
### step 1: clone moonraker
|
||||
clone_moonraker "${MOONRAKER_REPO}"
|
||||
|
||||
### step 2: install moonraker dependencies and create python virtualenv
|
||||
status_msg "Installing dependencies ..."
|
||||
install_moonraker_dependencies
|
||||
create_moonraker_virtualenv
|
||||
|
||||
### step 3: create moonraker.conf
|
||||
create_moonraker_conf "${instance_arr[@]}"
|
||||
|
||||
### step 4: create moonraker instances
|
||||
configure_moonraker_service "${instance_arr[@]}"
|
||||
|
||||
### step 5: create polkit rules for moonraker
|
||||
install_moonraker_polkit || true
|
||||
|
||||
### step 6: enable and start all instances
|
||||
do_action_service "enable" "moonraker"
|
||||
do_action_service "start" "moonraker"
|
||||
|
||||
### confirm message
|
||||
local confirm=""
|
||||
(( instance_arr[0] == 1 )) && confirm="Moonraker has been set up!"
|
||||
(( instance_arr[0] > 1 )) && confirm="${instance_arr[0]} Moonraker instances have been set up!"
|
||||
print_confirm "${confirm}" && print_mr_ip_list "${instance_arr[0]}" && return
|
||||
}
|
||||
|
||||
function clone_moonraker() {
|
||||
local repo=${1}
|
||||
|
||||
status_msg "Cloning Moonraker from ${repo} ..."
|
||||
|
||||
### force remove existing moonraker dir and clone into fresh moonraker dir
|
||||
[[ -d ${MOONRAKER_DIR} ]] && rm -rf "${MOONRAKER_DIR}"
|
||||
|
||||
cd "${HOME}" || exit 1
|
||||
if ! git clone "${MOONRAKER_REPO}" "${MOONRAKER_DIR}"; then
|
||||
print_error "Cloning Moonraker from\n ${repo}\n failed!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function create_moonraker_conf() {
|
||||
local input=("${@}")
|
||||
local moonraker_count=${input[0]} && unset "input[0]"
|
||||
local names=("${input[@]}") && unset "input[@]"
|
||||
local port lan printer_data cfg_dir cfg uds
|
||||
|
||||
port=7125
|
||||
lan="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-2).0.0/16"
|
||||
|
||||
if (( moonraker_count == 1 )); then
|
||||
printer_data="${HOME}/printer_data"
|
||||
cfg_dir="${printer_data}/config"
|
||||
cfg="${cfg_dir}/moonraker.conf"
|
||||
uds="${printer_data}/comms/klippy.sock"
|
||||
|
||||
### write single instance config
|
||||
write_moonraker_conf "${cfg_dir}" "${cfg}" "${port}" "${uds}" "${lan}"
|
||||
|
||||
elif (( moonraker_count > 1 )); then
|
||||
local j=0 re="^[1-9][0-9]*$"
|
||||
|
||||
for (( i=1; i <= moonraker_count; i++ )); do
|
||||
### overwrite config folder if name is only a number
|
||||
if [[ ${names[j]} =~ ${re} ]]; then
|
||||
printer_data="${HOME}/printer_${names[${j}]}_data"
|
||||
else
|
||||
printer_data="${HOME}/${names[${j}]}_data"
|
||||
fi
|
||||
|
||||
cfg_dir="${printer_data}/config"
|
||||
cfg="${cfg_dir}/moonraker.conf"
|
||||
uds="${printer_data}/comms/klippy.sock"
|
||||
|
||||
### write multi instance config
|
||||
write_moonraker_conf "${cfg_dir}" "${cfg}" "${port}" "${uds}" "${lan}"
|
||||
port=$(( port + 1 ))
|
||||
j=$(( j + 1 ))
|
||||
done && unset j
|
||||
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function write_moonraker_conf() {
|
||||
local cfg_dir=${1} cfg=${2} port=${3} uds=${4} lan=${5}
|
||||
local conf_template="${KIAUH_SRCDIR}/resources/moonraker.conf"
|
||||
|
||||
[[ ! -d ${cfg_dir} ]] && mkdir -p "${cfg_dir}"
|
||||
|
||||
if [[ ! -f ${cfg} ]]; then
|
||||
status_msg "Creating moonraker.conf in ${cfg_dir} ..."
|
||||
cp "${conf_template}" "${cfg}"
|
||||
sed -i "s|%USER%|${USER}|g; s|%PORT%|${port}|; s|%UDS%|${uds}|" "${cfg}"
|
||||
# if host ip is not in the default ip ranges replace placeholder,
|
||||
# otherwise remove placeholder from config
|
||||
if ! grep -q "${lan}" "${cfg}"; then
|
||||
sed -i "s|%LAN%|${lan}|" "${cfg}"
|
||||
else
|
||||
sed -i "/%LAN%/d" "${cfg}"
|
||||
fi
|
||||
ok_msg "moonraker.conf created!"
|
||||
else
|
||||
status_msg "File '${cfg_dir}/moonraker.conf' already exists!\nSkipping..."
|
||||
fi
|
||||
}
|
||||
|
||||
function configure_moonraker_service() {
|
||||
local input=("${@}")
|
||||
local moonraker_count=${input[0]} && unset "input[0]"
|
||||
local names=("${input[@]}") && unset "input[@]"
|
||||
local printer_data cfg_dir service env_file
|
||||
|
||||
if (( moonraker_count == 1 )) && [[ ${#names[@]} -eq 0 ]]; then
|
||||
i=""
|
||||
printer_data="${HOME}/printer_data"
|
||||
cfg_dir="${printer_data}/config"
|
||||
service="${SYSTEMD}/moonraker.service"
|
||||
env_file="${printer_data}/systemd/moonraker.env"
|
||||
|
||||
### create required folder structure
|
||||
create_required_folders "${printer_data}"
|
||||
|
||||
### write single instance service
|
||||
write_moonraker_service "" "${printer_data}" "${service}" "${env_file}"
|
||||
ok_msg "Moonraker instance created!"
|
||||
|
||||
elif (( moonraker_count > 1 )) && [[ ${#names[@]} -gt 0 ]]; then
|
||||
local j=0 re="^[1-9][0-9]*$"
|
||||
|
||||
for (( i=1; i <= moonraker_count; i++ )); do
|
||||
### overwrite config folder if name is only a number
|
||||
if [[ ${names[j]} =~ ${re} ]]; then
|
||||
printer_data="${HOME}/printer_${names[${j}]}_data"
|
||||
else
|
||||
printer_data="${HOME}/${names[${j}]}_data"
|
||||
fi
|
||||
|
||||
cfg_dir="${printer_data}/config"
|
||||
service="${SYSTEMD}/moonraker-${names[${j}]}.service"
|
||||
env_file="${printer_data}/systemd/moonraker.env"
|
||||
|
||||
### create required folder structure
|
||||
create_required_folders "${printer_data}"
|
||||
|
||||
### write multi instance service
|
||||
write_moonraker_service "${names[${j}]}" "${printer_data}" "${service}" "${env_file}"
|
||||
ok_msg "Moonraker instance 'moonraker-${names[${j}]}' created!"
|
||||
j=$(( j + 1 ))
|
||||
done && unset i
|
||||
|
||||
### enable mainsails remoteMode if mainsail is found
|
||||
if [[ -d ${MAINSAIL_DIR} ]]; then
|
||||
enable_mainsail_remotemode
|
||||
fi
|
||||
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function write_moonraker_service() {
|
||||
local i=${1} printer_data=${2} service=${3} env_file=${4}
|
||||
local service_template="${KIAUH_SRCDIR}/resources/moonraker.service"
|
||||
local env_template="${KIAUH_SRCDIR}/resources/moonraker.env"
|
||||
|
||||
### replace all placeholders
|
||||
if [[ ! -f ${service} ]]; then
|
||||
status_msg "Creating Moonraker Service ${i} ..."
|
||||
sudo cp "${service_template}" "${service}"
|
||||
sudo cp "${env_template}" "${env_file}"
|
||||
|
||||
[[ -z ${i} ]] && sudo sed -i "s| %INST%||" "${service}"
|
||||
[[ -n ${i} ]] && sudo sed -i "s|%INST%|${i}|" "${service}"
|
||||
sudo sed -i "s|%USER%|${USER}|g; s|%MOONRAKER_DIR%|${MOONRAKER_DIR}|; s|%ENV%|${MOONRAKER_ENV}|; s|%ENV_FILE%|${env_file}|" "${service}"
|
||||
sudo sed -i "s|%USER%|${USER}|; s|%MOONRAKER_DIR%|${MOONRAKER_DIR}|; s|%PRINTER_DATA%|${printer_data}|" "${env_file}"
|
||||
fi
|
||||
}
|
||||
|
||||
function print_mr_ip_list() {
|
||||
local ip count=${1} port=7125
|
||||
ip=$(hostname -I | cut -d" " -f1)
|
||||
|
||||
for (( i=1; i <= count; i++ )); do
|
||||
echo -e " ${cyan}● Instance ${i}:${white} ${ip}:${port}"
|
||||
port=$(( port + 1 ))
|
||||
done && echo
|
||||
}
|
||||
|
||||
### introduced due to
|
||||
### https://github.com/Arksine/moonraker/issues/349
|
||||
### https://github.com/Arksine/moonraker/pull/346
|
||||
function install_moonraker_polkit() {
|
||||
local POLKIT_LEGACY_FILE="/etc/polkit-1/localauthority/50-local.d/10-moonraker.pkla"
|
||||
local POLKIT_FILE="/etc/polkit-1/rules.d/moonraker.rules"
|
||||
local POLKIT_USR_FILE="/usr/share/polkit-1/rules.d/moonraker.rules"
|
||||
local legacy_file_exists
|
||||
local file_exists
|
||||
local usr_file_exists
|
||||
|
||||
local has_sup
|
||||
local require_daemon_reload="false"
|
||||
|
||||
legacy_file_exists=$(sudo find "${POLKIT_LEGACY_FILE}" 2> /dev/null)
|
||||
file_exists=$(sudo find "${POLKIT_FILE}" 2> /dev/null)
|
||||
usr_file_exists=$(sudo find "${POLKIT_USR_FILE}" 2> /dev/null)
|
||||
|
||||
### check for required SupplementaryGroups entry in service files
|
||||
### write it to the service if it doesn't exist
|
||||
for service in $(moonraker_systemd); do
|
||||
has_sup="$(grep "SupplementaryGroups=moonraker-admin" "${service}")"
|
||||
if [[ -z ${has_sup} ]]; then
|
||||
status_msg "Adding moonraker-admin supplementary group to ${service} ..."
|
||||
sudo sed -i "/^Type=simple$/a SupplementaryGroups=moonraker-admin" "${service}"
|
||||
require_daemon_reload="true"
|
||||
ok_msg "Adding moonraker-admin supplementary group successfull!"
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ ${require_daemon_reload} == "true" ]]; then
|
||||
status_msg "Reloading unit files ..."
|
||||
sudo systemctl daemon-reload
|
||||
ok_msg "Unit files reloaded!"
|
||||
fi
|
||||
|
||||
### execute moonrakers policykit-rules script only if rule files do not already exist
|
||||
if [[ -z ${legacy_file_exists} && ( -z ${file_exists} || -z ${usr_file_exists} ) ]]; then
|
||||
status_msg "Installing Moonraker policykit rules ..."
|
||||
"${HOME}"/moonraker/scripts/set-policykit-rules.sh
|
||||
ok_msg "Moonraker policykit rules installed!"
|
||||
fi
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
#==================================================#
|
||||
#================ REMOVE MOONRAKER ================#
|
||||
#==================================================#
|
||||
|
||||
function remove_moonraker_sysvinit() {
|
||||
[[ ! -e "${INITD}/moonraker" ]] && return
|
||||
|
||||
status_msg "Removing Moonraker SysVinit service ..."
|
||||
sudo systemctl stop moonraker
|
||||
sudo update-rc.d -f moonraker remove
|
||||
sudo rm -f "${INITD}/moonraker" "${ETCDEF}/moonraker"
|
||||
ok_msg "Moonraker SysVinit service removed!"
|
||||
}
|
||||
|
||||
function remove_moonraker_systemd() {
|
||||
[[ -z $(moonraker_systemd) ]] && return
|
||||
|
||||
status_msg "Removing Moonraker Systemd Services ..."
|
||||
|
||||
for service in $(moonraker_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 "Moonraker Services removed!"
|
||||
}
|
||||
|
||||
function remove_moonraker_env_file() {
|
||||
local files regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/systemd\/moonraker\.env"
|
||||
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_moonraker_logs() {
|
||||
local files regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/logs\/moonraker\.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_legacy_moonraker_logs() {
|
||||
local files regex="moonraker(-[0-9a-zA-Z]+)?\.log(.*)?"
|
||||
files=$(find "${HOME}/klipper_logs" -maxdepth 1 -regextype posix-extended -regex "${HOME}/klipper_logs/${regex}" 2> /dev/null | 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_moonraker_api_key() {
|
||||
### remove legacy api key
|
||||
if [[ -e "${HOME}/.klippy_api_key" ]]; then
|
||||
status_msg "Removing legacy API Key ..."
|
||||
rm "${HOME}/.klippy_api_key"
|
||||
ok_msg "Done!"
|
||||
fi
|
||||
|
||||
### remove api key
|
||||
if [[ -e "${HOME}/.moonraker_api_key" ]]; then
|
||||
status_msg "Removing API Key ..."
|
||||
rm "${HOME}/.moonraker_api_key"
|
||||
ok_msg "Done!"
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_moonraker_dir() {
|
||||
[[ ! -d ${MOONRAKER_DIR} ]] && return
|
||||
|
||||
status_msg "Removing Moonraker directory ..."
|
||||
rm -rf "${MOONRAKER_DIR}"
|
||||
ok_msg "Directory removed!"
|
||||
}
|
||||
|
||||
function remove_moonraker_env() {
|
||||
[[ ! -d ${MOONRAKER_ENV} ]] && return
|
||||
|
||||
status_msg "Removing moonraker-env directory ..."
|
||||
rm -rf "${MOONRAKER_ENV}"
|
||||
ok_msg "Directory removed!"
|
||||
}
|
||||
|
||||
function remove_moonraker_polkit() {
|
||||
[[ ! -d ${MOONRAKER_DIR} ]] && return
|
||||
|
||||
status_msg "Removing all Moonraker PolicyKit rules ..."
|
||||
"${MOONRAKER_DIR}"/scripts/set-policykit-rules.sh --clear
|
||||
ok_msg "Done!"
|
||||
}
|
||||
|
||||
function remove_moonraker() {
|
||||
remove_moonraker_sysvinit
|
||||
remove_moonraker_systemd
|
||||
remove_moonraker_env_file
|
||||
remove_moonraker_logs
|
||||
remove_legacy_moonraker_logs
|
||||
remove_moonraker_api_key
|
||||
remove_moonraker_polkit
|
||||
remove_moonraker_dir
|
||||
remove_moonraker_env
|
||||
|
||||
print_confirm "Moonraker was successfully removed!"
|
||||
return
|
||||
}
|
||||
|
||||
#==================================================#
|
||||
#================ UPDATE MOONRAKER ================#
|
||||
#==================================================#
|
||||
|
||||
function update_moonraker() {
|
||||
do_action_service "stop" "moonraker"
|
||||
|
||||
if [[ ! -d ${MOONRAKER_DIR} ]]; then
|
||||
clone_moonraker "${MOONRAKER_REPO}"
|
||||
else
|
||||
backup_before_update "moonraker"
|
||||
status_msg "Updating Moonraker ..."
|
||||
cd "${MOONRAKER_DIR}" && git pull
|
||||
### read PKGLIST and install possible new dependencies
|
||||
install_moonraker_dependencies
|
||||
### install possible new python dependencies
|
||||
"${MOONRAKER_ENV}"/bin/pip install -r "${MOONRAKER_DIR}/scripts/moonraker-requirements.txt"
|
||||
fi
|
||||
|
||||
### required due to https://github.com/Arksine/moonraker/issues/349
|
||||
install_moonraker_polkit || true
|
||||
|
||||
ok_msg "Update complete!"
|
||||
do_action_service "restart" "moonraker"
|
||||
}
|
||||
|
||||
#==================================================#
|
||||
#================ MOONRAKER STATUS ================#
|
||||
#==================================================#
|
||||
|
||||
function get_moonraker_status() {
|
||||
local sf_count status
|
||||
sf_count="$(moonraker_systemd | wc -w)"
|
||||
|
||||
### remove the "SERVICE" entry from the data array if a moonraker service is installed
|
||||
local data_arr=(SERVICE "${MOONRAKER_DIR}" "${MOONRAKER_ENV}")
|
||||
(( sf_count > 0 )) && unset "data_arr[0]"
|
||||
|
||||
### count+1 for each found data-item from array
|
||||
local filecount=0
|
||||
for data in "${data_arr[@]}"; do
|
||||
[[ -e ${data} ]] && filecount=$(( filecount + 1 ))
|
||||
done
|
||||
|
||||
if (( filecount == ${#data_arr[*]} )); then
|
||||
status="Installed: ${sf_count}"
|
||||
elif (( filecount == 0 )); then
|
||||
status="Not installed!"
|
||||
else
|
||||
status="Incomplete!"
|
||||
fi
|
||||
|
||||
echo "${status}"
|
||||
}
|
||||
|
||||
function get_local_moonraker_commit() {
|
||||
[[ ! -d ${MOONRAKER_DIR} || ! -d "${MOONRAKER_DIR}/.git" ]] && return
|
||||
|
||||
local commit
|
||||
cd "${MOONRAKER_DIR}"
|
||||
commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
|
||||
echo "${commit}"
|
||||
}
|
||||
|
||||
function get_remote_moonraker_commit() {
|
||||
[[ ! -d ${MOONRAKER_DIR} || ! -d "${MOONRAKER_DIR}/.git" ]] && return
|
||||
|
||||
local commit
|
||||
cd "${MOONRAKER_DIR}" && git fetch origin -q
|
||||
commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2)
|
||||
echo "${commit}"
|
||||
}
|
||||
|
||||
function compare_moonraker_versions() {
|
||||
local versions local_ver remote_ver
|
||||
local_ver="$(get_local_moonraker_commit)"
|
||||
remote_ver="$(get_remote_moonraker_commit)"
|
||||
|
||||
if [[ ${local_ver} != "${remote_ver}" ]]; then
|
||||
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
# add moonraker to application_updates_available in kiauh.ini
|
||||
add_to_application_updates "moonraker"
|
||||
else
|
||||
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
|
||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||
fi
|
||||
|
||||
echo "${versions}"
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user