From 81d8144c306cf702b6a4d53855e1e114784a1c1a Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 16 Oct 2022 18:57:50 +0200 Subject: [PATCH] refactor(kiauh): remove feature for changing the klipper config path Signed-off-by: Dominik Willner --- scripts/gcode_shell_command.sh | 1 + scripts/klipper.sh | 13 --- scripts/ui/settings_menu.sh | 45 +++------- scripts/utilities.sh | 155 --------------------------------- 4 files changed, 11 insertions(+), 203 deletions(-) diff --git a/scripts/gcode_shell_command.sh b/scripts/gcode_shell_command.sh index d546839..5402659 100644 --- a/scripts/gcode_shell_command.sh +++ b/scripts/gcode_shell_command.sh @@ -106,6 +106,7 @@ function create_example_shell_command() { backup_klipper_config_dir local printer_cfgs path + # TODO: fix cfg path printer_cfgs=$(find "$(get_klipper_cfg_dir)" -type f -name "printer.cfg" | sort) for cfg in ${printer_cfgs}; do diff --git a/scripts/klipper.sh b/scripts/klipper.sh index 64fe777..579d2b0 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -607,19 +607,6 @@ function compare_klipper_versions() { #=================== HELPERS ====================# #================================================# -function get_klipper_cfg_dir() { - local cfg_dir - read_kiauh_ini "${FUNCNAME[0]}" - - if [[ -z ${custom_klipper_cfg_loc} ]]; then - cfg_dir="${HOME}/klipper_config" - else - cfg_dir="${custom_klipper_cfg_loc}" - fi - - echo "${cfg_dir}" -} - ### # reads the python version from the klipper virtual environment # diff --git a/scripts/ui/settings_menu.sh b/scripts/ui/settings_menu.sh index bb10bb6..3146102 100755 --- a/scripts/ui/settings_menu.sh +++ b/scripts/ui/settings_menu.sh @@ -14,20 +14,12 @@ set -e function settings_ui() { read_kiauh_ini "${FUNCNAME[0]}" - local custom_cfg_loc="${custom_klipper_cfg_loc}" local custom_repo="${custom_klipper_repo}" local custom_branch="${custom_klipper_repo_branch}" local ms_pre_rls="${mainsail_install_unstable}" local fl_pre_rls="${fluidd_install_unstable}" local bbu="${backup_before_update}" - ### config location - if [[ -z ${custom_cfg_loc} ]]; then - custom_cfg_loc="${cyan}${KLIPPER_CONFIG}${white}" - else - custom_cfg_loc="${cyan}${custom_cfg_loc}${white}" - fi - ### custom repository custom_repo=$(echo "${custom_repo}" | sed "s/https:\/\/github\.com\///" | sed "s/\.git$//" ) if [[ -z ${custom_repo} ]]; then @@ -67,8 +59,6 @@ function settings_ui() { echo -e "| $(title_msg "~~~~~~~~~~~~ [ KIAUH Settings ] ~~~~~~~~~~~~~") |" hr echo -e "| Klipper: |" - echo -e "| ● Config folder: |" - printf "| %-60s|\n" "${custom_cfg_loc}" echo -e "| ● Repository: |" printf "| %-70s|\n" "${custom_repo} (${custom_branch})" hr @@ -77,24 +67,23 @@ function settings_ui() { hr printf "| Backup before updating: %-42s|\n" "${bbu}" hr - echo -e "| 1) Change Klipper config folder location |" - echo -e "| 2) Set custom Klipper repository |" + echo -e "| 1) Set custom Klipper repository |" blank_line if [[ ${mainsail_install_unstable} == "false" ]]; then - echo -e "| 3) ${green}Allow${white} unstable Mainsail releases |" + echo -e "| 2) ${green}Allow${white} unstable Mainsail releases |" else - echo -e "| 3) ${red}Disallow${white} unstable Mainsail releases |" + echo -e "| 2) ${red}Disallow${white} unstable Mainsail releases |" fi if [[ ${fluidd_install_unstable} == "false" ]]; then - echo -e "| 4) ${green}Allow${white} unstable Fluidd releases |" + echo -e "| 3) ${green}Allow${white} unstable Fluidd releases |" else - echo -e "| 4) ${red}Disallow${white} unstable Fluidd releases |" + echo -e "| 3) ${red}Disallow${white} unstable Fluidd releases |" fi blank_line if [[ ${backup_before_update} == "false" ]]; then - echo -e "| 5) ${green}Enable${white} automatic backups before updates |" + echo -e "| 4) ${green}Enable${white} automatic backups before updates |" else - echo -e "| 5) ${red}Disable${white} automatic backups before updates |" + echo -e "| 4) ${red}Disable${white} automatic backups before updates |" fi back_help_footer } @@ -105,16 +94,6 @@ function show_settings_help() { top_border echo -e "| ~~~~~~ < ? > Help: KIAUH Settings < ? > ~~~~~~ |" hr - echo -e "| ${cyan}Klipper config folder:${white} |" - echo -e "| The location of your printer.cfg and all other config |" - echo -e "| files that gets used during installation of Klipper |" - echo -e "| and all other components which need that location. |" - echo -e "| It is not recommended to change this location. |" - echo -e "| Be advised, that negative side effects could occur. |" - blank_line - printf "| Default: %-55s|\n" "${default_cfg}" - blank_line - hr echo -e "| ${cyan}Install unstable releases:${white} |" echo -e "| If set to ${green}true${white}, KIAUH installs/updates the software |" echo -e "| with the latest, currently available release. |" @@ -160,20 +139,16 @@ function settings_menu() { read -p "${cyan}####### Perform action:${white} " action case "${action}" in 1) - clear && print_header - change_klipper_cfg_folder - settings_ui;; - 2) clear && print_header change_klipper_repo_menu settings_ui;; - 3) + 2) switch_mainsail_releasetype settings_menu;; - 4) + 3) switch_fluidd_releasetype settings_menu;; - 5) + 4) toggle_backup_before_update settings_menu;; B|b) diff --git a/scripts/utilities.sh b/scripts/utilities.sh index cec0210..afad9e5 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -156,10 +156,6 @@ function init_ini() { echo -e "\nlogupload_accepted=false\c" >> "${INI_FILE}" fi - if ! grep -Eq "^custom_klipper_cfg_loc=" "${INI_FILE}"; then - echo -e "\ncustom_klipper_cfg_loc=\c" >> "${INI_FILE}" - fi - if ! grep -Eq "^custom_klipper_repo=" "${INI_FILE}"; then echo -e "\ncustom_klipper_repo=\c" >> "${INI_FILE}" fi @@ -184,157 +180,6 @@ function init_ini() { sed -i "/^[[:blank:]]*$/ d" "${INI_FILE}" } -function change_klipper_cfg_folder() { - local current_cfg_loc example_loc recommended_loc new_cfg_loc - current_cfg_loc="$(get_klipper_cfg_dir)" - example_loc=$(printf "%s/" "${HOME}") - recommended_loc=$(printf "%s/klipper_config" "${HOME}") - - local yn - while true; do - top_border - echo -e "| ${yellow}IMPORTANT:${white} |" - echo -e "| Please enter the new path in the following format: |" - printf "| ${cyan}%-51s${white} |\n" "${example_loc}" - blank_line - echo -e "| ${red}WARNING: ${white} |" - echo -e "| ${red}There will be no validation checks! Make sure to set${white} |" - echo -e "| ${red}a valid directory to prevent possible problems!${white} |" - blank_line - printf "| Recommended: ${cyan}%-38s${white} |\n" "${recommended_loc}" - bottom_border - echo - echo -e "${cyan}###### Please set the new Klipper config directory:${white} " - read -e -i "${current_cfg_loc}" -e new_cfg_loc - echo - read -p "${cyan}###### Set config directory to '${yellow}${new_cfg_loc}${cyan}' ? (Y/n):${white} " yn - case "${yn}" in - Y|y|Yes|yes|"") - select_msg "Yes" - set_klipper_cfg_path "${current_cfg_loc}" "${new_cfg_loc}" - print_confirm "New config directory set!" - break;; - N|n|No|no) - select_msg "No" - break;; - *) - print_error "Invalid command!";; - esac - done -} - -function set_klipper_cfg_path() { - local current_cfg_loc="${1}" new_cfg_loc="${2}" - local instance klipper_services moonraker_services moonraker_configs - - log_info "Function set_klipper_cfg_path invoked\nCurrent location: ${1}\nNew location: ${2}" - ### backup the old config dir - backup_klipper_config_dir - ### write new location to .kiauh.ini - sed -i "/^custom_klipper_cfg_loc=/d" "${INI_FILE}" - sed -i '$a'"custom_klipper_cfg_loc=${new_cfg_loc}" "${INI_FILE}" - status_msg "New directory was set to '${new_cfg_loc}'!" - - ### stop services - do_action_service "stop" "klipper" - do_action_service "stop" "moonraker" - - ### copy config files to new klipper config folder - if [[ -n ${current_cfg_loc} && -d ${current_cfg_loc} ]]; then - status_msg "Copy config files to '${new_cfg_loc}' ..." - - if [[ ! -d ${new_cfg_loc} ]]; then - log_info "Copy process started" - mkdir -p "${new_cfg_loc}" - cd "${current_cfg_loc}" - cp -r -v ./* "${new_cfg_loc}" - ok_msg "Done!" - else - log_warning "Copy process skipped, new config directory already exists and may not be empty!" - warn_msg "New config directory already exists! Copy process skipped!" - fi - fi - - klipper_services=$(find_klipper_systemd) - - if [[ -n ${klipper_services} ]]; then - status_msg "Re-writing Klipper services to use new config file location ..." - - for service in ${klipper_services}; do - if [[ ${service} = "/etc/systemd/system/klipper.service" ]]; then - - if grep -q "Environment=KLIPPER_CONFIG=" "${service}"; then - ### single instance klipper service installed by kiauh v4 / MainsailOS > 0.5.0 - sudo sed -i -r "/KLIPPER_CONFIG=/ s|CONFIG=(.+)\/printer\.cfg|CONFIG=${new_cfg_loc}/printer\.cfg|" "${service}" - else - ### single instance klipper service installed by kiauh v3 - sudo sed -i -r "/ExecStart=/ s|klippy\.py (.+)\/printer\.cfg|klippy\.py ${new_cfg_loc}\/printer\.cfg|" "${service}" - fi - - else - instance=$(echo "${service}" | cut -d"-" -f2 | cut -d"." -f1) - - if grep -q "Environment=KLIPPER_CONFIG=" "${service}"; then - ### multi instance klipper service installed by kiauh v4 / MainsailOS > 0.5.0 - sudo sed -i -r "/KLIPPER_CONFIG=/ s|CONFIG=(.+)\/printer_${instance}\/printer\.cfg|CONFIG=${new_cfg_loc}\/printer_${instance}\/printer\.cfg|" "${service}" - else - ### multi instance klipper service installed by kiauh v3 - sudo sed -i -r "/ExecStart=/ s|klippy\.py (.+)\/printer_${instance}\/printer\.cfg|klippy\.py ${new_cfg_loc}\/printer_${instance}\/printer\.cfg|" "${service}" - fi - fi - done - ok_msg "OK!" - fi - - moonraker_services=$(moonraker_systemd) - - if [[ -n ${moonraker_services} ]]; then - ### handle multi moonraker instance service file - status_msg "Re-writing Moonraker services to use new config file location ..." - - for service in ${moonraker_services}; do - if [[ ${service} = "/etc/systemd/system/moonraker.service" ]]; then - - if grep -q "Environment=MOONRAKER_CONF=" "${service}"; then - ### single instance moonraker service installed by kiauh v4 / MainsailOS > 0.5.0 - sudo sed -i -r "/MOONRAKER_CONF=/ s|_CONF=(.+)\/moonraker\.conf|_CONF=${new_cfg_loc}\/moonraker\.conf|" "${service}" - else - ### single instance moonraker service installed by kiauh v3 - sudo sed -i -r "/ExecStart=/ s| -c (.+)\/moonraker\.conf| -c ${new_cfg_loc}\/moonraker\.conf|" "${service}" - fi - - else - instance=$(echo "${service}" | cut -d"-" -f2 | cut -d"." -f1) - - if grep -q "Environment=MOONRAKER_CONF=" "${service}"; then - ### multi instance moonraker service installed by kiauh v4 / MainsailOS > 0.5.0 - sudo sed -i -r "/MOONRAKER_CONF=/ s|_CONF=(.+)\/printer_${instance}\/moonraker\.conf|_CONF=${new_cfg_loc}\/printer_${instance}\/moonraker\.conf|" "${service}" - else - ### multi instance moonraker service installed by kiauh v3 - sudo sed -i -r "/ExecStart=/ s| -c (.+)\/printer_${instance}\/moonraker\.conf| -c ${new_cfg_loc}\/printer_${instance}\/moonraker\.conf|" "${service}" - fi - fi - done - - moonraker_configs=$(find "${new_cfg_loc}" -type f -name "moonraker.conf" | sort) - - ### replace old file path with new one in moonraker.conf - local loc - for conf in ${moonraker_configs}; do - loc=$(echo "${conf}" | rev | cut -d"/" -f2- | rev) - sed -i -r "/config_path:/ s|config_path:.*|config_path: ${loc}|" "${conf}" - done - ok_msg "OK!" - fi - - ### reloading units - sudo systemctl daemon-reload - - ### restart services - do_action_service "restart" "klipper" - do_action_service "restart" "moonraker" -} - function switch_mainsail_releasetype() { read_kiauh_ini "${FUNCNAME[0]}" local state="${mainsail_install_unstable}"