diff --git a/docs/changelog.md b/docs/changelog.md index 765f92f..6d1a9db 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -2,11 +2,11 @@ This document covers possible important changes to KIAUH. -### 2022-10-30 +### 2022-10-31 Some functions got updated, though not all of them. The following functions are still currently unavailable: -- Installation of: Obico, MJPG-Streamer +- Installation of: MJPG-Streamer - All backup functions and the Log-Upload ### 2022-10-20 diff --git a/scripts/klipper.sh b/scripts/klipper.sh index 2fdaa50..26fb5a5 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -172,6 +172,9 @@ function klipper_setup() { (( instance_arr[0] == 1 )) && confirm="Klipper has been set up!" (( instance_arr[0] > 1 )) && confirm="${instance_arr[0]} Klipper instances have been set up!" + ### finalizing the setup with writing instance names to the kiauh.ini + set_multi_instance_names + print_confirm "${confirm}" && return } diff --git a/scripts/obico.sh b/scripts/obico.sh index 5ccca70..1b0b393 100644 --- a/scripts/obico.sh +++ b/scripts/obico.sh @@ -24,7 +24,7 @@ function moonraker_obico_systemd() { function moonraker_obico_config() { local moonraker_cfg_dirs - read -r -a moonraker_cfg_dirs <<< "$(get_config_folders)" + read -r -a moonraker_cfg_dirs <<< "$(get_instance_folder_path "config")" if (( ${#moonraker_cfg_dirs[@]} > 0 )); then echo "${moonraker_cfg_dirs[${1}]}/moonraker-obico.cfg" @@ -65,7 +65,6 @@ function obico_server_url_prompt() { function moonraker_obico_setup_dialog() { status_msg "Initializing Moonraker-obico installation ..." - local moonraker_count local moonraker_names @@ -103,7 +102,6 @@ function moonraker_obico_setup_dialog() { if (( existing_moonraker_obico_count > 0 )); then printf "|${green}%-55s${white}|\n" " ${existing_moonraker_obico_count} Moonraker-obico instances already installed!" for svc in ${moonraker_obico_services}; do -# printf "|${cyan}%-57s${white}|\n" " ● moonraker-obco-$(get_instance_name "${svc}" moonraker-obico)" printf "|${cyan}%-57s${white}|\n" " ● moonraker-obco-$(get_instance_name "${svc}")" done fi @@ -179,17 +177,29 @@ function moonraker_obico_setup_dialog() { ### step 6: call moonrake-obico/install.sh with the correct params local port=7125 - local moonraker_cfg_dirs + local instance_cfg_dirs + local instance_log_dirs - read -r -a moonraker_cfg_dirs <<< "$(get_config_folders)" + read -r -a instance_cfg_dirs <<< "$(get_instance_folder_path "config")" + read -r -a instance_log_dirs <<< "$(get_instance_folder_path "logs")" if (( moonraker_count == 1 )); then - "${MOONRAKER_OBICO_DIR}/install.sh" -C "${moonraker_cfg_dirs[0]}/moonraker.conf" -p "${port}" -H 127.0.0.1 -l "${KLIPPER_LOGS}" -s -L -S "${obico_server_url}" + "${MOONRAKER_OBICO_DIR}/install.sh"\ + -C "${instance_cfg_dirs[0]}/moonraker.conf"\ + -p "${port}" -H 127.0.0.1 -l\ + "${instance_log_dirs[0]}"\ + -s -L -S "${obico_server_url}" elif (( moonraker_count > 1 )); then local j=${existing_moonraker_obico_count} for (( i=1; i <= new_moonraker_obico_count; i++ )); do - "${MOONRAKER_OBICO_DIR}/install.sh" -n "${moonraker_names[${j}]}" -C "${moonraker_cfg_dirs[${j}]}/moonraker.conf" -p $((port+j)) -H 127.0.0.1 -l "${KLIPPER_LOGS}" -s -L -S "${obico_server_url}" + "${MOONRAKER_OBICO_DIR}/install.sh"\ + -n "${moonraker_names[${j}]}"\ + -C "${instance_cfg_dirs[${j}]}/moonraker.conf"\ + -p $((port+j))\ + -H 127.0.0.1\ + -l "${instance_log_dirs[${j}]}"\ + -s -L -S "${obico_server_url}" j=$(( j + 1 )) done && unset j fi # (( moonraker_count == 1 )) @@ -301,8 +311,21 @@ function remove_moonraker_obico_systemd() { } function remove_moonraker_obico_logs() { + local files regex="\/home\/${USER}\/([A-Za-z0-9_]+)\/logs\/moonraker-obico(-[0-9a-zA-Z]+)?\.log(.*)?" + files=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${regex}" | sort) + + if [[ -n ${files} ]]; then + for file in ${files}; do + status_msg "Removing ${file} ..." + rm -f "${file}" + ok_msg "${file} removed!" + done + fi +} + +function remove_legacy_moonraker_obico_logs() { local files regex="moonraker-obico(-[0-9a-zA-Z]+)?\.log(.*)?" - files=$(find "${KLIPPER_LOGS}" -maxdepth 1 -regextype posix-extended -regex "${KLIPPER_LOGS}/${regex}" 2> /dev/null | sort) + 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 @@ -372,7 +395,7 @@ function get_moonraker_obico_status() { is_linked="true" if [[ -n ${moonraker_obico_services} ]]; then - for cfg_dir in $(get_config_folders); do + for cfg_dir in $(get_instance_folder_path "config"); do if moonraker_obico_needs_linking "${cfg_dir}/moonraker-obico.cfg"; then is_linked="false" fi diff --git a/scripts/ui/install_menu.sh b/scripts/ui/install_menu.sh index 918bda2..53656f1 100755 --- a/scripts/ui/install_menu.sh +++ b/scripts/ui/install_menu.sh @@ -63,10 +63,7 @@ function install_menu() { 8) do_action "telegram_bot_setup_dialog" "install_ui";; 9) - #do_action "moonraker_obico_setup_dialog" "install_ui";; - clear && print_header - print_error "Function currently disabled! Sorry!" - install_ui;; + do_action "moonraker_obico_setup_dialog" "install_ui";; 10) #do_action "install_mjpg-streamer" "install_ui";; clear && print_header diff --git a/scripts/utilities.sh b/scripts/utilities.sh index bf5ae73..5c3a6ed 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -597,7 +597,9 @@ function set_multi_instance_names() { local name local names="" - local services=$(find_klipper_systemd) + local services + + services=$(find_klipper_systemd) ### # if value of 'multi_instance_names' is not an empty @@ -657,16 +659,60 @@ function get_config_folders() { # by KIAUH convention, all instance names of only numbers # need to be prefixed with 'printer_' if [[ ${name} =~ ^[0-9]+$ ]]; then - cfg_dirs+=("${KLIPPER_CONFIG}/printer_${name}") + cfg_dirs+=("${HOME}/printer_${name}_data/config") else - cfg_dirs+=("${KLIPPER_CONFIG}/${name}") + cfg_dirs+=("${HOME}/${name}_data/config") fi done elif [[ -z ${instance_names} && $(find_klipper_systemd | wc -w) -gt 0 ]]; then - cfg_dirs+=("${KLIPPER_CONFIG}") + cfg_dirs+=("${HOME}/printer_data/config") else cfg_dirs=() fi echo "${cfg_dirs[@]}" } + +### +# helper function that returns all available absolute directory paths +# based on their instance name and specified target folder +# +# @param {string}: folder name - target instance folder name (e.g. config) +# +# => return an empty string if klipper is not installed +# => return space-separated string of absolute directory paths +# +function get_instance_folder_path() { + local folder_name=${1} + local folder_paths=() + local instance_names + local path + + instance_names=$(get_multi_instance_names) + + if [[ -n ${instance_names} ]]; then + for name in ${instance_names}; do + ### + # by KIAUH convention, all instance names of only numbers + # need to be prefixed with 'printer_' + if [[ ${name} =~ ^[0-9]+$ ]]; then + path="${HOME}/printer_${name}_data/${folder_name}" + if [[ -d ${path} ]]; then + folder_paths+=("${path}") + fi + else + path="${HOME}/${name}_data/${folder_name}" + if [[ -d ${path} ]]; then + folder_paths+=("${path}") + fi + fi + done + elif [[ -z ${instance_names} && $(find_klipper_systemd | wc -w) -gt 0 ]]; then + path="${HOME}/printer_data/${folder_name}" + if [[ -d ${path} ]]; then + folder_paths+=("${path}") + fi + fi + + echo "${folder_paths[@]}" +}