mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-14 11:04:29 +05:00
feat: save multi instance klipper names/identifier to kiauh.ini
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -138,6 +138,7 @@ function init_ini() {
|
|||||||
echo -e "# DO NOT edit this file! #"
|
echo -e "# DO NOT edit this file! #"
|
||||||
echo -e "#=================================================#"
|
echo -e "#=================================================#"
|
||||||
echo -e "# KIAUH v4.0.0"
|
echo -e "# KIAUH v4.0.0"
|
||||||
|
echo -e "#"
|
||||||
} >> "${INI_FILE}"
|
} >> "${INI_FILE}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -175,7 +176,20 @@ function init_ini() {
|
|||||||
echo -e "\nfluidd_install_unstable=false\c" >> "${INI_FILE}"
|
echo -e "\nfluidd_install_unstable=false\c" >> "${INI_FILE}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if ! grep -Eq "^multi_instance_names=" "${INI_FILE}"; then
|
||||||
|
echo -e "\nmulti_instance_names=\c" >> "${INI_FILE}"
|
||||||
|
else
|
||||||
|
sed -i "/multi_instance_names=/s/=.*/=/" "${INI_FILE}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
### save all installed webinterface ports to the ini file
|
||||||
fetch_webui_ports
|
fetch_webui_ports
|
||||||
|
|
||||||
|
### save all klipper multi-instance names to the ini file
|
||||||
|
fetch_multi_instance_names
|
||||||
|
|
||||||
|
### strip all empty lines out of the file
|
||||||
|
sed -i "/^[[:blank:]]*$/ d" "${INI_FILE}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function change_klipper_cfg_folder() {
|
function change_klipper_cfg_folder() {
|
||||||
@@ -669,3 +683,54 @@ function get_instance_name() {
|
|||||||
name=$(echo "${instance}" | rev | cut -d"/" -f1 | rev | cut -d"-" -f2 | cut -d"." -f1)
|
name=$(echo "${instance}" | rev | cut -d"/" -f1 | rev | cut -d"-" -f2 | cut -d"." -f1)
|
||||||
echo "${name}"
|
echo "${name}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
###
|
||||||
|
# returns the instance name/identifier of the klipper service
|
||||||
|
# if the klipper service is part of a multi instance setup
|
||||||
|
# otherwise returns an emtpy string
|
||||||
|
#
|
||||||
|
# @param {string}: name - klipper service name (e.g. klipper-name.service)
|
||||||
|
#
|
||||||
|
function get_klipper_instance_name() {
|
||||||
|
local instance=${1}
|
||||||
|
local name
|
||||||
|
|
||||||
|
name=$(echo "${instance}" | rev | cut -d"/" -f1 | cut -d"." -f2 | rev)
|
||||||
|
|
||||||
|
local regex="^klipper-[0-9a-zA-Z]+$"
|
||||||
|
if [[ ${name} =~ ${regex} ]]; then
|
||||||
|
name=$(echo "${name}" | cut -d"-" -f2)
|
||||||
|
else
|
||||||
|
name=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "${name}"
|
||||||
|
}
|
||||||
|
|
||||||
|
###
|
||||||
|
# combines and saves each instance name/identifier
|
||||||
|
# to the kiauh.ini file in a comma separated format
|
||||||
|
#
|
||||||
|
function add_to_multi_instance_names() {
|
||||||
|
read_kiauh_ini "${FUNCNAME[0]}"
|
||||||
|
|
||||||
|
local name="${1}"
|
||||||
|
local names="${multi_instance_names}"
|
||||||
|
|
||||||
|
if ! grep -Eq "${name}" <<< "${names}"; then
|
||||||
|
names="${names}${name},"
|
||||||
|
sed -i "/multi_instance_names=/s/=.*/=${names}/" "${INI_FILE}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
###
|
||||||
|
# loops through all installed klipper services and
|
||||||
|
# calls the 'add_to_multi_instance_names' on each one
|
||||||
|
#
|
||||||
|
function fetch_multi_instance_names() {
|
||||||
|
for service in $(klipper_systemd); do
|
||||||
|
local name
|
||||||
|
name=$(get_klipper_instance_name "${service}")
|
||||||
|
add_to_multi_instance_names "${name}"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user