refactor(klipper): refactor klipper file removal functions
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -413,58 +413,36 @@ function remove_klipper_service() {
|
|||||||
ok_msg "All Klipper services removed!"
|
ok_msg "All Klipper services removed!"
|
||||||
}
|
}
|
||||||
|
|
||||||
function remove_instance_files() {
|
function find_instance_files() {
|
||||||
local target_folder=${1}
|
local target_folder=${1}
|
||||||
local target_name=${2}
|
local target_name=${2}
|
||||||
local files
|
local files
|
||||||
|
|
||||||
files=$(find "${HOME}" -regex "${HOME}/[A-Za-z0-9_]+_data/${target_folder}/${target_name}")
|
readarray -t files < <(find "${HOME}" -regex "${HOME}/[A-Za-z0-9_]+_data/${target_folder}/${target_name}" | sort)
|
||||||
if [[ -n ${files} ]]; then
|
|
||||||
for file in ${files}; do
|
echo -e "${files[@]}"
|
||||||
status_msg "Removing ${file} ..."
|
|
||||||
rm -f "${file}"
|
|
||||||
ok_msg "${file} removed!"
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function remove_legacy_klipper_logs() {
|
function find_legacy_klipper_logs() {
|
||||||
local files regex="klippy(-[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_legacy_klipper_uds() {
|
|
||||||
local files
|
local files
|
||||||
files=$(find /tmp -maxdepth 1 -regextype posix-extended -regex "/tmp/klippy_uds(-[0-9a-zA-Z]+)?" | sort)
|
local regex="klippy(-[0-9a-zA-Z]+)?\.log(.*)?"
|
||||||
|
|
||||||
if [[ -n ${files} ]]; then
|
readarray -t files < <(find "${HOME}/klipper_logs" -maxdepth 1 -regextype posix-extended -regex "${HOME}/klipper_logs/${regex}" 2> /dev/null | sort)
|
||||||
for file in ${files}; do
|
echo -e "${files[@]}"
|
||||||
status_msg "Removing ${file} ..."
|
|
||||||
rm -f "${file}"
|
|
||||||
ok_msg "${file} removed!"
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function remove_legacy_klipper_printer() {
|
function find_legacy_klipper_uds() {
|
||||||
local files
|
local files
|
||||||
files=$(find /tmp -maxdepth 1 -regextype posix-extended -regex "/tmp/printer(-[0-9a-zA-Z]+)?" | sort)
|
|
||||||
|
|
||||||
if [[ -n ${files} ]]; then
|
readarray -t files < <(find /tmp -maxdepth 1 -regextype posix-extended -regex "/tmp/klippy_uds(-[0-9a-zA-Z]+)?" | sort)
|
||||||
for file in ${files}; do
|
echo -e "${files[@]}"
|
||||||
status_msg "Removing ${file} ..."
|
}
|
||||||
rm -f "${file}"
|
|
||||||
ok_msg "${file} removed!"
|
function find_legacy_klipper_printer() {
|
||||||
done
|
local files
|
||||||
fi
|
|
||||||
|
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() {
|
function remove_klipper_dir() {
|
||||||
@@ -483,16 +461,33 @@ function remove_klipper_env() {
|
|||||||
ok_msg "Directory removed!"
|
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() {
|
function remove_klipper() {
|
||||||
remove_klipper_service
|
remove_klipper_service
|
||||||
remove_instance_files "systemd" "klipper.env"
|
remove_files "$(find_instance_files "systemd" "klipper.env")"
|
||||||
remove_instance_files "logs" "klippy.log.*"
|
remove_files "$(find_instance_files "logs" "klippy.log.*")"
|
||||||
remove_instance_files "comms" "klippy.sock"
|
remove_files "$(find_instance_files "comms" "klippy.sock")"
|
||||||
remove_instance_files "comms" "klippy.serial"
|
remove_files "$(find_instance_files "comms" "klippy.serial")"
|
||||||
|
|
||||||
remove_legacy_klipper_logs
|
remove_files "$(find_legacy_klipper_logs)"
|
||||||
remove_legacy_klipper_uds
|
remove_files "$(find_legacy_klipper_uds)"
|
||||||
remove_legacy_klipper_printer
|
remove_files "$(find_legacy_klipper_printer)"
|
||||||
|
|
||||||
remove_klipper_dir
|
remove_klipper_dir
|
||||||
remove_klipper_env
|
remove_klipper_env
|
||||||
|
|||||||
Reference in New Issue
Block a user