refactor(obico): update obico installer (#254)

This commit is contained in:
th33xitus
2022-10-31 16:06:45 +01:00
committed by GitHub
parent 811c071b74
commit 54be7e4e21
5 changed files with 88 additions and 19 deletions

View File

@@ -2,11 +2,11 @@
This document covers possible important changes to KIAUH. This document covers possible important changes to KIAUH.
### 2022-10-30 ### 2022-10-31
Some functions got updated, though not all of them. Some functions got updated, though not all of them.
The following functions are still currently unavailable: The following functions are still currently unavailable:
- Installation of: Obico, MJPG-Streamer - Installation of: MJPG-Streamer
- All backup functions and the Log-Upload - All backup functions and the Log-Upload
### 2022-10-20 ### 2022-10-20

View File

@@ -172,6 +172,9 @@ function klipper_setup() {
(( instance_arr[0] == 1 )) && confirm="Klipper has been set up!" (( instance_arr[0] == 1 )) && confirm="Klipper has been set up!"
(( instance_arr[0] > 1 )) && confirm="${instance_arr[0]} Klipper instances have 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 print_confirm "${confirm}" && return
} }

View File

@@ -24,7 +24,7 @@ function moonraker_obico_systemd() {
function moonraker_obico_config() { function moonraker_obico_config() {
local moonraker_cfg_dirs 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 if (( ${#moonraker_cfg_dirs[@]} > 0 )); then
echo "${moonraker_cfg_dirs[${1}]}/moonraker-obico.cfg" echo "${moonraker_cfg_dirs[${1}]}/moonraker-obico.cfg"
@@ -65,7 +65,6 @@ function obico_server_url_prompt() {
function moonraker_obico_setup_dialog() { function moonraker_obico_setup_dialog() {
status_msg "Initializing Moonraker-obico installation ..." status_msg "Initializing Moonraker-obico installation ..."
local moonraker_count local moonraker_count
local moonraker_names local moonraker_names
@@ -103,7 +102,6 @@ function moonraker_obico_setup_dialog() {
if (( existing_moonraker_obico_count > 0 )); then if (( existing_moonraker_obico_count > 0 )); then
printf "|${green}%-55s${white}|\n" " ${existing_moonraker_obico_count} Moonraker-obico instances already installed!" printf "|${green}%-55s${white}|\n" " ${existing_moonraker_obico_count} Moonraker-obico instances already installed!"
for svc in ${moonraker_obico_services}; do 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}")" printf "|${cyan}%-57s${white}|\n" " ● moonraker-obco-$(get_instance_name "${svc}")"
done done
fi fi
@@ -179,17 +177,29 @@ function moonraker_obico_setup_dialog() {
### step 6: call moonrake-obico/install.sh with the correct params ### step 6: call moonrake-obico/install.sh with the correct params
local port=7125 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 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 elif (( moonraker_count > 1 )); then
local j=${existing_moonraker_obico_count} local j=${existing_moonraker_obico_count}
for (( i=1; i <= new_moonraker_obico_count; i++ )); do 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 )) j=$(( j + 1 ))
done && unset j done && unset j
fi # (( moonraker_count == 1 )) fi # (( moonraker_count == 1 ))
@@ -301,8 +311,21 @@ function remove_moonraker_obico_systemd() {
} }
function remove_moonraker_obico_logs() { 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(.*)?" 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 if [[ -n ${files} ]]; then
for file in ${files}; do for file in ${files}; do
@@ -372,7 +395,7 @@ function get_moonraker_obico_status() {
is_linked="true" is_linked="true"
if [[ -n ${moonraker_obico_services} ]]; then 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 if moonraker_obico_needs_linking "${cfg_dir}/moonraker-obico.cfg"; then
is_linked="false" is_linked="false"
fi fi

View File

@@ -63,10 +63,7 @@ function install_menu() {
8) 8)
do_action "telegram_bot_setup_dialog" "install_ui";; do_action "telegram_bot_setup_dialog" "install_ui";;
9) 9)
#do_action "moonraker_obico_setup_dialog" "install_ui";; do_action "moonraker_obico_setup_dialog" "install_ui";;
clear && print_header
print_error "Function currently disabled! Sorry!"
install_ui;;
10) 10)
#do_action "install_mjpg-streamer" "install_ui";; #do_action "install_mjpg-streamer" "install_ui";;
clear && print_header clear && print_header

View File

@@ -597,7 +597,9 @@ function set_multi_instance_names() {
local name local name
local names="" local names=""
local services=$(find_klipper_systemd) local services
services=$(find_klipper_systemd)
### ###
# if value of 'multi_instance_names' is not an empty # 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 # by KIAUH convention, all instance names of only numbers
# need to be prefixed with 'printer_' # need to be prefixed with 'printer_'
if [[ ${name} =~ ^[0-9]+$ ]]; then if [[ ${name} =~ ^[0-9]+$ ]]; then
cfg_dirs+=("${KLIPPER_CONFIG}/printer_${name}") cfg_dirs+=("${HOME}/printer_${name}_data/config")
else else
cfg_dirs+=("${KLIPPER_CONFIG}/${name}") cfg_dirs+=("${HOME}/${name}_data/config")
fi fi
done done
elif [[ -z ${instance_names} && $(find_klipper_systemd | wc -w) -gt 0 ]]; then elif [[ -z ${instance_names} && $(find_klipper_systemd | wc -w) -gt 0 ]]; then
cfg_dirs+=("${KLIPPER_CONFIG}") cfg_dirs+=("${HOME}/printer_data/config")
else else
cfg_dirs=() cfg_dirs=()
fi fi
echo "${cfg_dirs[@]}" 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[@]}"
}