From 937ad4cffd94c455c3706e505a2725adea15486a Mon Sep 17 00:00:00 2001 From: coderus Date: Sat, 7 Jan 2023 17:32:33 +0100 Subject: [PATCH] refactor(utilities): get_data_folder function --- scripts/utilities.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/scripts/utilities.sh b/scripts/utilities.sh index 5c3a6ed..cf51ef5 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -641,6 +641,28 @@ function get_multi_instance_names() { echo "${instance_names[@]}" } +### +# helper function that returns klipper data directory +# path based on systemd service name. +# +# => return an empty string if klipper is not installed +# => return absolute config directory path +# +function get_data_folder() { + local service_name=${1} + local service_type=${2} + if [[ "${service_name}" == "${service_type}.service" ]]; then + echo "${HOME}/printer_data" + else + local instance_name=$(get_instance_name "${service_name}") + if [[ ${instance_name} =~ ^[0-9]+$ ]]; then + echo "${HOME}/printer_${instance_name}_data" + else + echo "${HOME}/${instance_name}_data" + fi + fi +} + ### # helper function that returns all possibly available absolute # klipper config directory paths based on their instance name.