From 68a02ad3f53226ba495e4a6058b7e9891ab9e4a2 Mon Sep 17 00:00:00 2001 From: Michael Bravo Date: Sat, 25 Feb 2023 13:59:31 +0200 Subject: [PATCH 1/7] fix(mainsail): set increased read timeout on API endpoint (#294) --- resources/fluidd | 1 + resources/mainsail | 1 + 2 files changed, 2 insertions(+) diff --git a/resources/fluidd b/resources/fluidd index f25e487..468fad4 100644 --- a/resources/fluidd +++ b/resources/fluidd @@ -55,6 +55,7 @@ server { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Scheme $scheme; + proxy_read_timeout 600; } location /webcam/ { diff --git a/resources/mainsail b/resources/mainsail index efabb63..6d63b07 100644 --- a/resources/mainsail +++ b/resources/mainsail @@ -55,6 +55,7 @@ server { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Scheme $scheme; + proxy_read_timeout 600; } location /webcam/ { From fd27db28d46ca5ff2f76a234ba0e9c429198dc3f Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 26 Feb 2023 16:29:01 +0100 Subject: [PATCH 2/7] feat(mainsail): use mainsail-config repo for downloading mainsail macros (#301) --- scripts/mainsail.sh | 164 ++++++++++++++++++++++++-------------- scripts/ui/remove_menu.sh | 36 +++++---- 2 files changed, 122 insertions(+), 78 deletions(-) diff --git a/scripts/mainsail.sh b/scripts/mainsail.sh index 38fc4d2..b778946 100644 --- a/scripts/mainsail.sh +++ b/scripts/mainsail.sh @@ -30,7 +30,7 @@ function install_mainsail() { status_msg "Initializing Mainsail installation ..." ### first, we create a backup of the full klipper_config dir - safety first! - backup_klipper_config_dir + #backup_klipper_config_dir ### check for other enabled web interfaces unset SET_LISTEN_PORT @@ -39,30 +39,6 @@ function install_mainsail() { ### check if another site already listens to port 80 mainsail_port_check -# ### ask user to install mjpg-streamer -# local install_mjpg_streamer -# if [[ ! -f "${SYSTEMD}/webcamd.service" ]]; then -# while true; do -# echo -# top_border -# echo -e "| Install MJPG-Streamer for webcam support? |" -# bottom_border -# read -p "${cyan}###### Please select (y/N):${white} " yn -# case "${yn}" in -# Y|y|Yes|yes) -# select_msg "Yes" -# install_mjpg_streamer="true" -# break;; -# N|n|No|no|"") -# select_msg "No" -# install_mjpg_streamer="false" -# break;; -# *) -# error_msg "Invalid command!";; -# esac -# done -# fi - ### download mainsail download_mainsail @@ -82,9 +58,6 @@ function install_mainsail() { ### add mainsail to the update manager in moonraker.conf patch_mainsail_update_manager - ### install mjpg-streamer -# [[ ${install_mjpg_streamer} == "true" ]] && install_mjpg-streamer - fetch_webui_ports #WIP ### confirm message @@ -92,22 +65,21 @@ function install_mainsail() { } function install_mainsail_macros() { + local yn while true; do echo top_border - echo -e "| It is recommended to have some important macros in |" - echo -e "| your printer configuration to have Mainsail fully |" - echo -e "| functional and working. |" + echo -e "| It is recommended to use special macros in order to |" + echo -e "| have Mainsail fully functional and working. |" blank_line echo -e "| The recommended macros for Mainsail can be seen here: |" - echo -e "| https://docs.mainsail.xyz/configuration#macros |" + echo -e "| https://github.com/mainsail-crew/mainsail-config |" blank_line - echo -e "| If you already have these macros in your config file, |" - echo -e "| skip this step and answer with 'no'. |" + echo -e "| If you already use these macros skip this step. |" echo -e "| Otherwise you should consider to answer with 'yes' to |" - echo -e "| add the recommended example macros to your config. |" + echo -e "| download the recommended macros. |" bottom_border - read -p "${cyan}###### Add the recommended macros? (Y/n):${white} " yn + read -p "${cyan}###### Download the recommended macros? (Y/n):${white} " yn case "${yn}" in Y|y|Yes|yes|"") select_msg "Yes" @@ -124,36 +96,64 @@ function install_mainsail_macros() { } function download_mainsail_macros() { - local ms_cfg path configs regex + local ms_cfg_repo path configs regex line gcode_dir - ms_cfg="https://raw.githubusercontent.com/mainsail-crew/mainsail-config/master/mainsail.cfg" + ms_cfg_repo="https://github.com/mainsail-crew/mainsail-config.git" regex="\/home\/${USER}\/([A-Za-z0-9_]+)\/config\/printer\.cfg" configs=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${regex}" | sort) - if [[ -n ${configs} ]]; then - for config in ${configs}; do - path=$(echo "${config}" | rev | cut -d"/" -f2- | rev) - if [[ ! -f "${path}/mainsail.cfg" ]]; then - status_msg "Downloading mainsail.cfg to ${path} ..." - log_info "downloading mainsail.cfg to: ${path}" - wget "${ms_cfg}" -O "${path}/mainsail.cfg" - - ### replace user 'pi' with current username to prevent issues in cases where the user is not called 'pi' - log_info "modify mainsail.cfg" - sed -i "/^path: \/home\/pi\/gcode_files/ s/\/home\/pi/\/home\/${USER}/" "${path}/mainsail.cfg" - - ### write include to the very first line of the printer.cfg - if ! grep -Eq "^[include mainsail.cfg]$" "${path}/printer.cfg"; then - log_info "modify printer.cfg" - sed -i "1 i [include mainsail.cfg]" "${path}/printer.cfg" - fi - ok_msg "Done!" - fi - done - else + if [[ -z ${configs} ]]; then + print_error "No printer.cfg found! Installation of Macros will be skipped ..." log_error "execution stopped! reason: no printer.cfg found" return fi + + status_msg "Cloning mainsail-config ..." + [[ -d "${HOME}/mainsail-config" ]] && rm -rf "${HOME}/mainsail-config" + if git clone "${ms_cfg_repo}" "${HOME}/mainsail-config"; then + for config in ${configs}; do + path=$(echo "${config}" | rev | cut -d"/" -f2- | rev) + + if [[ -e "${path}/mainsail.cfg" && ! -h "${path}/mainsail.cfg" ]]; then + warn_msg "Attention! Existing mainsail.cfg detected!" + warn_msg "The file will be renamed to 'mainsail.bak.cfg' to be able to continue with the installation." + if ! mv "${path}/mainsail.cfg" "${path}/mainsail.bak.cfg"; then + error_msg "Renaming mainsail.cfg failed! Aborting installation ..." + return + fi + fi + + if [[ -h "${path}/mainsail.cfg" ]]; then + warn_msg "Recreating symlink in ${path} ..." + rm -rf "${path}/mainsail.cfg" + fi + + if ! ln -sf "${HOME}/mainsail-config/client.cfg" "${path}/mainsail.cfg"; then + error_msg "Creating symlink failed! Aborting installation ..." + return + fi + + if ! grep -Eq "^\[include mainsail.cfg\]$" "${path}/printer.cfg"; then + log_info "${path}/printer.cfg" + sed -i "1 i [include mainsail.cfg]" "${path}/printer.cfg" + fi + + line=$(($(grep -n "\[include mainsail.cfg\]" "${path}/printer.cfg" | tail -1 | cut -d: -f1) + 1)) + gcode_dir=${path/config/gcodes} + if ! grep -Eq "^\[virtual_sdcard\]$" "${path}/printer.cfg"; then + log_info "${path}/printer.cfg" + sed -i "${line} i \[virtual_sdcard]\npath: ${gcode_dir}\non_error_gcode: CANCEL_PRINT\n" "${path}/printer.cfg" + fi + done + else + print_error "Cloning failed! Aborting installation ..." + log_error "execution stopped! reason: cloning failed" + return + fi + + patch_mainsail_config_update_manager + + ok_msg "Done!" } function download_mainsail() { @@ -196,7 +196,7 @@ function remove_mainsail_dir() { rm -rf "${MAINSAIL_DIR}" && ok_msg "Directory removed!" } -function remove_mainsail_config() { +function remove_mainsail_nginx_config() { if [[ -e "/etc/nginx/sites-available/mainsail" ]]; then status_msg "Removing Mainsail configuration for Nginx ..." sudo rm "/etc/nginx/sites-available/mainsail" && ok_msg "File removed!" @@ -248,9 +248,18 @@ function remove_legacy_mainsail_log_symlinks() { fi } +function remove_mainsail_config() { + if [[ -d "${HOME}/mainsail-config" ]]; then + status_msg "Removing ${HOME}/mainsail-config ..." + rm -rf "${HOME}/mainsail-config" + ok_msg "${HOME}/mainsail-config removed!" + print_confirm "Mainsail-Config successfully removed!" + fi +} + function remove_mainsail() { remove_mainsail_dir - remove_mainsail_config + remove_mainsail_nginx_config remove_mainsail_logs remove_mainsail_log_symlinks remove_legacy_mainsail_log_symlinks @@ -623,3 +632,36 @@ MOONRAKER_CONF do_action_service "restart" "moonraker" fi } + +function patch_mainsail_config_update_manager() { + local patched moonraker_configs regex + regex="\/home\/${USER}\/([A-Za-z0-9_]+)\/config\/moonraker\.conf" + moonraker_configs=$(find "${HOME}" -maxdepth 3 -type f -regextype posix-extended -regex "${regex}" | sort) + + patched="false" + for conf in ${moonraker_configs}; do + if ! grep -Eq "^\[update_manager mainsail-config\]\s*$" "${conf}"; then + ### add new line to conf if it doesn't end with one + [[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}" + + ### add Mainsails update manager section to moonraker.conf + status_msg "Adding Mainsail-Config to update manager in file:\n ${conf}" + /bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF + +[update_manager mainsail-config] +type: git_repo +primary_branch: master +path: ~/mainsail-config +origin: https://github.com/mainsail-crew/mainsail-config.git +managed_services: klipper +MOONRAKER_CONF + + fi + + patched="true" + done + + if [[ ${patched} == "true" ]]; then + do_action_service "restart" "moonraker" + fi +} diff --git a/scripts/ui/remove_menu.sh b/scripts/ui/remove_menu.sh index 0e6dca2..da36388 100755 --- a/scripts/ui/remove_menu.sh +++ b/scripts/ui/remove_menu.sh @@ -18,17 +18,17 @@ function remove_ui() { echo -e "| ${yellow}INFO: Configurations and/or any backups will be kept!${white} |" hr echo -e "| Firmware & API: | 3rd Party Webinterface: |" - echo -e "| 1) [Klipper] | 6) [OctoPrint] |" + echo -e "| 1) [Klipper] | 7) [OctoPrint] |" echo -e "| 2) [Moonraker] | |" echo -e "| | Webcam Streamer: |" - echo -e "| Klipper Webinterface: | 7) [Crowsnest] |" - echo -e "| 3) [Mainsail] | 8) [MJPG-Streamer] |" - echo -e "| 4) [Fluidd] | |" - echo -e "| | Other: |" - echo -e "| Touchscreen GUI: | 9) [PrettyGCode] |" - echo -e "| 5) [KlipperScreen] | 10) [Telegram Bot] |" - echo -e "| | 11) [Obico for Klipper] |" - echo -e "| | 12) [NGINX] |" + echo -e "| Klipper Webinterface: | 8) [Crowsnest] |" + echo -e "| 3) [Mainsail] | 9) [MJPG-Streamer] |" + echo -e "| 4) [Mainsail-Config] | |" + echo -e "| 5) [Fluidd] | Other: |" + echo -e "| | 10) [PrettyGCode] |" + echo -e "| Touchscreen GUI: | 11) [Telegram Bot] |" + echo -e "| 6) [KlipperScreen] | 12) [Obico for Klipper] |" + echo -e "| | 13) [NGINX] |" back_footer } @@ -46,22 +46,24 @@ function remove_menu() { 3) do_action "remove_mainsail" "remove_ui";; 4) - do_action "remove_fluidd" "remove_ui";; + do_action "remove_mainsail_config" "remove_ui";; 5) - do_action "remove_klipperscreen" "remove_ui";; + do_action "remove_fluidd" "remove_ui";; 6) - do_action "remove_octoprint" "remove_ui";; + do_action "remove_klipperscreen" "remove_ui";; 7) - do_action "remove_crowsnest" "remove_ui";; + do_action "remove_octoprint" "remove_ui";; 8) - do_action "remove_mjpg-streamer" "remove_ui";; + do_action "remove_crowsnest" "remove_ui";; 9) - do_action "remove_prettygcode" "remove_ui";; + do_action "remove_mjpg-streamer" "remove_ui";; 10) - do_action "remove_telegram_bot" "remove_ui";; + do_action "remove_prettygcode" "remove_ui";; 11) - do_action "remove_moonraker_obico" "remove_ui";; + do_action "remove_telegram_bot" "remove_ui";; 12) + do_action "remove_moonraker_obico" "remove_ui";; + 13) do_action "remove_nginx" "remove_ui";; B|b) clear; main_menu; break;; From e3ed223b5c41bdcf06befeddfebbee27b2bd0b3b Mon Sep 17 00:00:00 2001 From: Pedro Lamas Date: Tue, 28 Feb 2023 14:30:42 +0000 Subject: [PATCH 3/7] fix: always use system home directory (#303) --- scripts/fluidd.sh | 8 ++++---- scripts/gcode_shell_command.sh | 2 +- scripts/mainsail.sh | 10 +++++----- scripts/moonraker-telegram-bot.sh | 6 +++--- scripts/moonraker.sh | 4 ++-- scripts/nginx.sh | 2 +- scripts/obico.sh | 2 +- scripts/pretty_gcode.sh | 2 +- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/scripts/fluidd.sh b/scripts/fluidd.sh index 81f1aa7..0c020c6 100644 --- a/scripts/fluidd.sh +++ b/scripts/fluidd.sh @@ -127,7 +127,7 @@ function download_fluidd_macros() { local fluidd_cfg path configs regex fluidd_cfg="https://raw.githubusercontent.com/fluidd-core/FluiddPI/master/src/modules/fluidd/filesystem/home/pi/klipper_config/fluidd.cfg" - regex="\/home\/${USER}\/([A-Za-z0-9_]+)\/config\/printer\.cfg" + regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/printer\.cfg" configs=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${regex}" | sort) if [[ -n ${configs} ]]; then @@ -140,7 +140,7 @@ function download_fluidd_macros() { ### replace user 'pi' with current username to prevent issues in cases where the user is not called 'pi' log_info "modify fluidd.cfg" - sed -i "/^path: \/home\/pi\/gcode_files/ s/\/home\/pi/\/home\/${USER}/" "${path}/fluidd.cfg" + sed -i "/^path: \/home\/pi\/gcode_files/ s/\/home\/pi/${HOME//\//\\/}/" "${path}/fluidd.cfg" ### write include to the very first line of the printer.cfg if ! grep -Eq "^[include fluidd.cfg]$" "${path}/printer.cfg"; then @@ -218,7 +218,7 @@ function remove_fluidd_logs() { function remove_fluidd_log_symlinks() { local files regex - regex="\/home\/${USER}\/([A-Za-z0-9_]+)\/logs\/fluidd-.*" + regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/logs\/fluidd-.*" files=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${regex}" 2> /dev/null | sort) if [[ -n ${files} ]]; then @@ -416,7 +416,7 @@ function select_fluidd_port() { function patch_fluidd_update_manager() { local patched moonraker_configs regex - regex="\/home\/${USER}\/([A-Za-z0-9_]+)\/config\/moonraker\.conf" + regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/moonraker\.conf" moonraker_configs=$(find "${HOME}" -maxdepth 3 -type f -regextype posix-extended -regex "${regex}" | sort) patched="false" diff --git a/scripts/gcode_shell_command.sh b/scripts/gcode_shell_command.sh index 3ddb3f3..f07747f 100644 --- a/scripts/gcode_shell_command.sh +++ b/scripts/gcode_shell_command.sh @@ -106,7 +106,7 @@ function create_example_shell_command() { backup_klipper_config_dir local configs regex path - regex="\/home\/${USER}\/([A-Za-z0-9_]+)\/config\/printer\.cfg" + regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/printer\.cfg" configs=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${regex}" | sort) for cfg in ${configs}; do diff --git a/scripts/mainsail.sh b/scripts/mainsail.sh index b778946..216fa58 100644 --- a/scripts/mainsail.sh +++ b/scripts/mainsail.sh @@ -99,7 +99,7 @@ function download_mainsail_macros() { local ms_cfg_repo path configs regex line gcode_dir ms_cfg_repo="https://github.com/mainsail-crew/mainsail-config.git" - regex="\/home\/${USER}\/([A-Za-z0-9_]+)\/config\/printer\.cfg" + regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/printer\.cfg" configs=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${regex}" | sort) if [[ -z ${configs} ]]; then @@ -223,7 +223,7 @@ function remove_mainsail_logs() { function remove_mainsail_log_symlinks() { local files regex - regex="\/home\/${USER}\/([A-Za-z0-9_]+)\/logs\/mainsail-.*" + regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/logs\/mainsail-.*" files=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${regex}" 2> /dev/null | sort) if [[ -n ${files} ]]; then @@ -469,7 +469,7 @@ function ms_theme_install() { function ms_theme_delete() { local regex theme_folders target_folders=() - regex="\/home\/${USER}\/([A-Za-z0-9_]+)\/config\/\.theme" + regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/\.theme" theme_folders=$(find "${HOME}" -maxdepth 3 -type d -regextype posix-extended -regex "${regex}" | sort) # theme_folders=$(find "${KLIPPER_CONFIG}" -mindepth 1 -type d -name ".theme" | sort) @@ -603,7 +603,7 @@ function enable_mainsail_remotemode() { function patch_mainsail_update_manager() { local patched moonraker_configs regex - regex="\/home\/${USER}\/([A-Za-z0-9_]+)\/config\/moonraker\.conf" + regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/moonraker\.conf" moonraker_configs=$(find "${HOME}" -maxdepth 3 -type f -regextype posix-extended -regex "${regex}" | sort) patched="false" @@ -635,7 +635,7 @@ MOONRAKER_CONF function patch_mainsail_config_update_manager() { local patched moonraker_configs regex - regex="\/home\/${USER}\/([A-Za-z0-9_]+)\/config\/moonraker\.conf" + regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/moonraker\.conf" moonraker_configs=$(find "${HOME}" -maxdepth 3 -type f -regextype posix-extended -regex "${regex}" | sort) patched="false" diff --git a/scripts/moonraker-telegram-bot.sh b/scripts/moonraker-telegram-bot.sh index 423e8a3..3ad92bf 100644 --- a/scripts/moonraker-telegram-bot.sh +++ b/scripts/moonraker-telegram-bot.sh @@ -376,7 +376,7 @@ function remove_telegram_bot_env() { } function remove_telegram_bot_env_file() { - local files regex="\/home\/${USER}\/([A-Za-z0-9_]+)\/systemd\/moonraker-telegram-bot\.env" + local files regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/systemd\/moonraker-telegram-bot\.env" files=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${regex}" | sort) if [[ -n ${files} ]]; then @@ -389,7 +389,7 @@ function remove_telegram_bot_env_file() { } function remove_telegram_bot_logs() { - local files regex="\/home\/${USER}\/([A-Za-z0-9_]+)\/logs\/telegram\.log.*" + local files regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/logs\/telegram\.log.*" files=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${regex}" | sort) if [[ -n ${files} ]]; then @@ -519,7 +519,7 @@ function compare_telegram_bot_versions() { function patch_telegram_bot_update_manager() { local patched moonraker_configs regex - regex="\/home\/${USER}\/([A-Za-z0-9_]+)\/config\/moonraker\.conf" + regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/moonraker\.conf" moonraker_configs=$(find "${HOME}" -maxdepth 3 -type f -regextype posix-extended -regex "${regex}" | sort) patched="false" diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index 707b27d..4ab5598 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -465,7 +465,7 @@ function remove_moonraker_systemd() { } function remove_moonraker_env_file() { - local files regex="\/home\/${USER}\/([A-Za-z0-9_]+)\/systemd\/moonraker\.env" + local files regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/systemd\/moonraker\.env" files=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${regex}" | sort) if [[ -n ${files} ]]; then @@ -478,7 +478,7 @@ function remove_moonraker_env_file() { } function remove_moonraker_logs() { - local files regex="\/home\/${USER}\/([A-Za-z0-9_]+)\/logs\/moonraker\.log.*" + local files regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/logs\/moonraker\.log.*" files=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${regex}" | sort) if [[ -n ${files} ]]; then diff --git a/scripts/nginx.sh b/scripts/nginx.sh index 3a9215f..15eaab6 100644 --- a/scripts/nginx.sh +++ b/scripts/nginx.sh @@ -79,7 +79,7 @@ function symlink_webui_nginx_log() { interface=${1} access_log="/var/log/nginx/${interface}-access.log" error_log="/var/log/nginx/${interface}-error.log" - regex="\/home\/${USER}\/([A-Za-z0-9_]+)\/logs" + regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/logs" logpaths=$(find "${HOME}" -maxdepth 2 -type d -regextype posix-extended -regex "${regex}" | sort) for path in ${logpaths}; do diff --git a/scripts/obico.sh b/scripts/obico.sh index b002130..92d5b3f 100644 --- a/scripts/obico.sh +++ b/scripts/obico.sh @@ -311,7 +311,7 @@ function remove_moonraker_obico_systemd() { } function remove_moonraker_obico_logs() { - local files regex="\/home\/${USER}\/([A-Za-z0-9_]+)\/logs\/moonraker-obico(-[0-9a-zA-Z]+)?\.log(.*)?" + local files regex="${HOME//\//\\/}\/([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 diff --git a/scripts/pretty_gcode.sh b/scripts/pretty_gcode.sh index 8ab9494..8d27bb5 100644 --- a/scripts/pretty_gcode.sh +++ b/scripts/pretty_gcode.sh @@ -38,7 +38,7 @@ function install_pgc_for_klipper() { fi sudo cp "${pgconfsrc}" "${pgconf}" - sudo sed -i "s|/home/pi/pgcode;|/home/${USER}/pgcode;|" "${pgconf}" + sudo sed -i "s|/home/pi/pgcode;|${HOME}/pgcode;|" "${pgconf}" ### replace default port if (( pgc_custom_port != pgc_default_port )); then From afe6f7499a53b037af5b234f445d700b372e6292 Mon Sep 17 00:00:00 2001 From: Pedro Lamas Date: Tue, 28 Feb 2023 15:33:32 +0000 Subject: [PATCH 4/7] feat(fluidd): use fluidd-config repo for downloading fluidd macros (#305) --- scripts/fluidd.sh | 164 ++++++++++++++++++++++++-------------- scripts/ui/remove_menu.sh | 30 +++---- 2 files changed, 119 insertions(+), 75 deletions(-) diff --git a/scripts/fluidd.sh b/scripts/fluidd.sh index 0c020c6..c6188c6 100644 --- a/scripts/fluidd.sh +++ b/scripts/fluidd.sh @@ -39,30 +39,6 @@ function install_fluidd() { ### check if another site already listens to port 80 fluidd_port_check -# ### ask user to install mjpg-streamer -# local install_mjpg_streamer -# if [[ ! -f "${SYSTEMD}/webcamd.service" ]]; then -# while true; do -# echo -# top_border -# echo -e "| Install MJPG-Streamer for webcam support? |" -# bottom_border -# read -p "${cyan}###### Please select (y/N):${white} " yn -# case "${yn}" in -# Y|y|Yes|yes) -# select_msg "Yes" -# install_mjpg_streamer="true" -# break;; -# N|n|No|no|"") -# select_msg "No" -# install_mjpg_streamer="false" -# break;; -# *) -# error_msg "Invalid command!";; -# esac -# done -# fi - ### download fluidd download_fluidd @@ -82,9 +58,6 @@ function install_fluidd() { ### add fluidd to the update manager in moonraker.conf patch_fluidd_update_manager - ### install mjpg-streamer -# [[ ${install_mjpg_streamer} == "true" ]] && install_mjpg-streamer - fetch_webui_ports #WIP ### confirm message @@ -92,22 +65,21 @@ function install_fluidd() { } function install_fluidd_macros() { + local yn while true; do echo top_border - echo -e "| It is recommended to have some important macros in |" - echo -e "| your printer configuration to have Fluidd fully |" - echo -e "| functional and working. |" + echo -e "| It is recommended to use special macros in order to |" + echo -e "| have Fluidd fully functional and working. |" blank_line echo -e "| The recommended macros for Fluidd can be found here: |" - echo -e "| https://docs.fluidd.xyz/configuration/initial_setup |" + echo -e "| https://github.com/fluidd-core/fluidd-config |" blank_line - echo -e "| If you already have these macros in your config file, |" - echo -e "| skip this step and answer with 'no'. |" + echo -e "| If you already use these macros skip this step. |" echo -e "| Otherwise you should consider to answer with 'yes' to |" - echo -e "| add the recommended example macros to your config. |" + echo -e "| download the recommended macros. |" bottom_border - read -p "${cyan}###### Add the recommended macros? (Y/n):${white} " yn + read -p "${cyan}###### Download the recommended macros? (Y/n):${white} " yn case "${yn}" in Y|y|Yes|yes|"") select_msg "Yes" @@ -124,36 +96,64 @@ function install_fluidd_macros() { } function download_fluidd_macros() { - local fluidd_cfg path configs regex + local ms_cfg_repo path configs regex line gcode_dir - fluidd_cfg="https://raw.githubusercontent.com/fluidd-core/FluiddPI/master/src/modules/fluidd/filesystem/home/pi/klipper_config/fluidd.cfg" + ms_cfg_repo="https://github.com/fluidd-core/fluidd-config.git" regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/printer\.cfg" configs=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${regex}" | sort) - if [[ -n ${configs} ]]; then - for config in ${configs}; do - path=$(echo "${config}" | rev | cut -d"/" -f2- | rev) - if [[ ! -f "${path}/fluidd.cfg" ]]; then - status_msg "Downloading fluidd.cfg to ${path} ..." - log_info "downloading fluidd.cfg to: ${path}" - wget "${fluidd_cfg}" -O "${path}/fluidd.cfg" - - ### replace user 'pi' with current username to prevent issues in cases where the user is not called 'pi' - log_info "modify fluidd.cfg" - sed -i "/^path: \/home\/pi\/gcode_files/ s/\/home\/pi/${HOME//\//\\/}/" "${path}/fluidd.cfg" - - ### write include to the very first line of the printer.cfg - if ! grep -Eq "^[include fluidd.cfg]$" "${path}/printer.cfg"; then - log_info "modify printer.cfg" - sed -i "1 i [include fluidd.cfg]" "${path}/printer.cfg" - fi - ok_msg "Done!" - fi - done - else + if [[ -z ${configs} ]]; then + print_error "No printer.cfg found! Installation of Macros will be skipped ..." log_error "execution stopped! reason: no printer.cfg found" return fi + + status_msg "Cloning fluidd-config ..." + [[ -d "${HOME}/fluidd-config" ]] && rm -rf "${HOME}/fluidd-config" + if git clone --recurse-submodules "${ms_cfg_repo}" "${HOME}/fluidd-config"; then + for config in ${configs}; do + path=$(echo "${config}" | rev | cut -d"/" -f2- | rev) + + if [[ -e "${path}/fluidd.cfg" && ! -h "${path}/fluidd.cfg" ]]; then + warn_msg "Attention! Existing fluidd.cfg detected!" + warn_msg "The file will be renamed to 'fluidd.bak.cfg' to be able to continue with the installation." + if ! mv "${path}/fluidd.cfg" "${path}/fluidd.bak.cfg"; then + error_msg "Renaming fluidd.cfg failed! Aborting installation ..." + return + fi + fi + + if [[ -h "${path}/fluidd.cfg" ]]; then + warn_msg "Recreating symlink in ${path} ..." + rm -rf "${path}/fluidd.cfg" + fi + + if ! ln -sf "${HOME}/fluidd-config/client.cfg" "${path}/fluidd.cfg"; then + error_msg "Creating symlink failed! Aborting installation ..." + return + fi + + if ! grep -Eq "^\[include fluidd.cfg\]$" "${path}/printer.cfg"; then + log_info "${path}/printer.cfg" + sed -i "1 i [include fluidd.cfg]" "${path}/printer.cfg" + fi + + line=$(($(grep -n "\[include fluidd.cfg\]" "${path}/printer.cfg" | tail -1 | cut -d: -f1) + 1)) + gcode_dir=${path/config/gcodes} + if ! grep -Eq "^\[virtual_sdcard\]$" "${path}/printer.cfg"; then + log_info "${path}/printer.cfg" + sed -i "${line} i \[virtual_sdcard]\npath: ${gcode_dir}\non_error_gcode: CANCEL_PRINT\n" "${path}/printer.cfg" + fi + done + else + print_error "Cloning failed! Aborting installation ..." + log_error "execution stopped! reason: cloning failed" + return + fi + + patch_fluidd_config_update_manager + + ok_msg "Done!" } function download_fluidd() { @@ -191,7 +191,7 @@ function remove_fluidd_dir() { rm -rf "${FLUIDD_DIR}" && ok_msg "Directory removed!" } -function remove_fluidd_config() { +function remove_fluidd_nginx_config() { if [[ -e "/etc/nginx/sites-available/fluidd" ]]; then status_msg "Removing Fluidd configuration for Nginx ..." sudo rm "/etc/nginx/sites-available/fluidd" && ok_msg "File removed!" @@ -243,9 +243,18 @@ function remove_legacy_fluidd_log_symlinks() { fi } +function remove_fluidd_config() { + if [[ -d "${HOME}/fluidd-config" ]]; then + status_msg "Removing ${HOME}/fluidd-config ..." + rm -rf "${HOME}/fluidd-config" + ok_msg "${HOME}/fluidd-config removed!" + print_confirm "Fluidd-Config successfully removed!" + fi +} + function remove_fluidd() { remove_fluidd_dir - remove_fluidd_config + remove_fluidd_nginx_config remove_fluidd_logs remove_fluidd_log_symlinks remove_legacy_fluidd_log_symlinks @@ -389,7 +398,7 @@ function select_fluidd_port() { blank_line [[ ${MAINSAIL_PORT} == "80" ]] && echo "| ● Mainsail |" blank_line - echo -e "| Make sure you don't choose a port which is already |" + echo -e "| Make sure you don't choose a port which was already |" echo -e "| assigned to another webinterface! |" blank_line echo -e "| Be aware: there is ${red}NO${white} sanity check for the following |" @@ -445,3 +454,36 @@ MOONRAKER_CONF do_action_service "restart" "moonraker" fi } + +function patch_fluidd_config_update_manager() { + local patched moonraker_configs regex + regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/moonraker\.conf" + moonraker_configs=$(find "${HOME}" -maxdepth 3 -type f -regextype posix-extended -regex "${regex}" | sort) + + patched="false" + for conf in ${moonraker_configs}; do + if ! grep -Eq "^\[update_manager fluidd-config\]\s*$" "${conf}"; then + ### add new line to conf if it doesn't end with one + [[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}" + + ### add Fluidds update manager section to moonraker.conf + status_msg "Adding Fluidd-Config to update manager in file:\n ${conf}" + /bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF + +[update_manager fluidd-config] +type: git_repo +primary_branch: master +path: ~/fluidd-config +origin: https://github.com/fluidd-core/fluidd-config.git +managed_services: klipper +MOONRAKER_CONF + + fi + + patched="true" + done + + if [[ ${patched} == "true" ]]; then + do_action_service "restart" "moonraker" + fi +} diff --git a/scripts/ui/remove_menu.sh b/scripts/ui/remove_menu.sh index da36388..d7408d0 100755 --- a/scripts/ui/remove_menu.sh +++ b/scripts/ui/remove_menu.sh @@ -18,17 +18,17 @@ function remove_ui() { echo -e "| ${yellow}INFO: Configurations and/or any backups will be kept!${white} |" hr echo -e "| Firmware & API: | 3rd Party Webinterface: |" - echo -e "| 1) [Klipper] | 7) [OctoPrint] |" + echo -e "| 1) [Klipper] | 8) [OctoPrint] |" echo -e "| 2) [Moonraker] | |" echo -e "| | Webcam Streamer: |" - echo -e "| Klipper Webinterface: | 8) [Crowsnest] |" - echo -e "| 3) [Mainsail] | 9) [MJPG-Streamer] |" + echo -e "| Klipper Webinterface: | 9) [Crowsnest] |" + echo -e "| 3) [Mainsail] | 10) [MJPG-Streamer] |" echo -e "| 4) [Mainsail-Config] | |" echo -e "| 5) [Fluidd] | Other: |" - echo -e "| | 10) [PrettyGCode] |" - echo -e "| Touchscreen GUI: | 11) [Telegram Bot] |" - echo -e "| 6) [KlipperScreen] | 12) [Obico for Klipper] |" - echo -e "| | 13) [NGINX] |" + echo -e "| 6) [Fluidd-Config] | 11) [PrettyGCode] |" + echo -e "| | 12) [Telegram Bot] |" + echo -e "| Touchscreen GUI: | 13) [Obico for Klipper] |" + echo -e "| 7) [KlipperScreen] | 14) [NGINX] |" back_footer } @@ -50,20 +50,22 @@ function remove_menu() { 5) do_action "remove_fluidd" "remove_ui";; 6) - do_action "remove_klipperscreen" "remove_ui";; + do_action "remove_fluidd_config" "remove_ui";; 7) - do_action "remove_octoprint" "remove_ui";; + do_action "remove_klipperscreen" "remove_ui";; 8) - do_action "remove_crowsnest" "remove_ui";; + do_action "remove_octoprint" "remove_ui";; 9) - do_action "remove_mjpg-streamer" "remove_ui";; + do_action "remove_crowsnest" "remove_ui";; 10) - do_action "remove_prettygcode" "remove_ui";; + do_action "remove_mjpg-streamer" "remove_ui";; 11) - do_action "remove_telegram_bot" "remove_ui";; + do_action "remove_prettygcode" "remove_ui";; 12) - do_action "remove_moonraker_obico" "remove_ui";; + do_action "remove_telegram_bot" "remove_ui";; 13) + do_action "remove_moonraker_obico" "remove_ui";; + 14) do_action "remove_nginx" "remove_ui";; B|b) clear; main_menu; break;; From d6837af2a2140f18c789cb8e493eeb7965e88cad Mon Sep 17 00:00:00 2001 From: th33xitus Date: Tue, 28 Feb 2023 18:29:21 +0100 Subject: [PATCH 5/7] refactor(klipper): implement blacklisted service names (#304) --- scripts/klipper.sh | 78 ++++++++++++++++++++++++-------------------- scripts/moonraker.sh | 2 +- scripts/octoprint.sh | 2 +- scripts/utilities.sh | 18 ++-------- 4 files changed, 48 insertions(+), 52 deletions(-) diff --git a/scripts/klipper.sh b/scripts/klipper.sh index 1381e31..afe4332 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -19,8 +19,30 @@ set -e #================ INSTALL KLIPPER ================# #=================================================# +### +# this function detects all installed klipper +# systemd instances and returns their absolute path +function klipper_systemd() { + local services + local blacklist + local ignore + local match + + ### + # any service that uses "klipper" in its own name but isn't a full klipper service must be blacklisted using + # this variable, otherwise they will be falsely recognized as klipper instances. E.g. "klipper-mcu.service" + # is not a klipper service, but related to klippers linux mcu, which also requires its own service file, hence + # it must be blacklisted. + blacklist="mcu" + + ignore="${SYSTEMD}/klipper-(${blacklist}).service" + match="${SYSTEMD}/klipper(-[0-9a-zA-Z]+)?.service" + + services=$(find "${SYSTEMD}" -maxdepth 1 -regextype awk ! -regex "${ignore}" -regex "${match}" | sort) + echo "${services}" +} + function start_klipper_setup() { - local klipper_initd_service local klipper_systemd_services local python_version local instance_count @@ -28,20 +50,15 @@ function start_klipper_setup() { local use_custom_names local input local regex + local blacklist local error status_msg "Initializing Klipper installation ...\n" ### return early if klipper already exists - klipper_initd_service=$(find_klipper_initd) - klipper_systemd_services=$(find_klipper_systemd) + klipper_systemd_services=$(klipper_systemd) - if [[ -n ${klipper_initd_service} ]]; then - error="Unsupported Klipper SysVinit service detected:" - error="${error}\n ➔ ${klipper_initd_service}" - error="${error}\n Please re-install Klipper with KIAUH!" - log_info "Unsupported Klipper SysVinit service detected: ${klipper_initd_service}" - elif [[ -n ${klipper_systemd_services} ]]; then + if [[ -n ${klipper_systemd_services} ]]; then error="At least one Klipper service is already installed:" for s in ${klipper_systemd_services}; do @@ -113,15 +130,19 @@ function start_klipper_setup() { fi ### user selection for setting the actual custom names + shopt -s nocasematch if (( instance_count > 1 )) && [[ ${use_custom_names} == "true" ]]; then local i i=1 regex="^[0-9a-zA-Z]+$" - while [[ ! ${input} =~ ${regex} || ${i} -le ${instance_count} ]]; do + blacklist="mcu" + while [[ ! ${input} =~ ${regex} || ${input} =~ ${blacklist} || ${i} -le ${instance_count} ]]; do read -p "${cyan}###### Name for instance #${i}:${white} " input - if [[ ${input} =~ ${regex} ]]; then + if [[ ${input} =~ ${blacklist} ]]; then + error_msg "Name not allowed! You are trying to use a reserved name." + elif [[ ${input} =~ ${regex} && ! ${input} =~ ${blacklist} ]]; then select_msg "Name: ${input}\n" if [[ ${input} =~ ^[0-9]+$ ]]; then instance_names+=("printer_${input}") @@ -138,6 +159,7 @@ function start_klipper_setup() { instance_names+=("printer_${i}") done fi + shopt -u nocasematch (( instance_count > 1 )) && status_msg "Installing ${instance_count} Klipper instances ..." (( instance_count == 1 )) && status_msg "Installing single Klipper instance ..." @@ -386,26 +408,18 @@ function write_example_printer_cfg() { #================================================# function remove_klipper_service() { - if [[ ! -e "${INITD}/klipper" ]] && [[ -z $(find_klipper_systemd) ]]; then - return - fi + [[ -z $(klipper_systemd) ]] && return status_msg "Removing Klipper services ..." - if [[ -e "${INITD}/klipper" ]]; then - sudo systemctl stop klipper - sudo update-rc.d -f klipper remove - sudo rm -f "${INITD}/klipper" "${ETCDEF}/klipper" - else - for service in $(find_klipper_systemd | cut -d"/" -f5); do - status_msg "Removing ${service} ..." - sudo systemctl stop "${service}" - sudo systemctl disable "${service}" - sudo rm -f "${SYSTEMD}/${service}" - sudo systemctl daemon-reload - sudo systemctl reset-failed - done - fi + for service in $(klipper_systemd | cut -d"/" -f5); do + status_msg "Removing ${service} ..." + sudo systemctl stop "${service}" + sudo systemctl disable "${service}" + sudo rm -f "${SYSTEMD}/${service}" + sudo systemctl daemon-reload + sudo systemctl reset-failed + done ok_msg "All Klipper services removed!" } @@ -534,13 +548,7 @@ function update_klipper() { function get_klipper_status() { local sf_count status py_ver - sf_count="$(find_klipper_systemd | wc -w)" - - ### detect an existing "legacy" klipper init.d installation - if [[ $(find_klipper_systemd | wc -w) -eq 0 ]] \ - && [[ $(find_klipper_initd | wc -w) -ge 1 ]]; then - sf_count=1 - fi + sf_count="$(klipper_systemd | wc -w)" py_ver=$(get_klipper_python_ver) diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index 4ab5598..3baac95 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -60,7 +60,7 @@ function moonraker_setup_dialog() { ### return early if klipper is not installed local klipper_services - klipper_services=$(find_klipper_systemd) + klipper_services=$(klipper_systemd) if [[ -z ${klipper_services} ]]; then local error="Klipper not installed! Please install Klipper first!" log_error "Moonraker setup started without Klipper being installed. Aborting setup." diff --git a/scripts/octoprint.sh b/scripts/octoprint.sh index dee4851..b819373 100644 --- a/scripts/octoprint.sh +++ b/scripts/octoprint.sh @@ -25,7 +25,7 @@ function octoprint_setup_dialog() { status_msg "Initializing OctoPrint installation ..." local klipper_services - klipper_services=$(find_klipper_systemd) + klipper_services=$(klipper_systemd) if [[ -z ${klipper_services} ]]; then local error="Klipper not installed! Please install Klipper first!" log_error "OctoPrint setup started without Klipper being installed. Aborting setup." diff --git a/scripts/utilities.sh b/scripts/utilities.sh index 5c3a6ed..8490634 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -338,18 +338,6 @@ function fetch_webui_ports() { #=================== SYSTEM =====================# #================================================# -function find_klipper_initd() { - local services - services=$(find "${INITD}" -maxdepth 1 -regextype posix-extended -regex "${INITD}/klipper(-[^0])?[0-9]*" | sort) - echo "${services}" -} - -function find_klipper_systemd() { - local services - services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/klipper(-[0-9a-zA-Z]+)?.service" | sort) - echo "${services}" -} - function create_required_folders() { local printer_data=${1} folders folders=("backup" "certs" "config" "database" "gcodes" "comms" "logs" "systemd") @@ -599,7 +587,7 @@ function set_multi_instance_names() { local names="" local services - services=$(find_klipper_systemd) + services=$(klipper_systemd) ### # if value of 'multi_instance_names' is not an empty @@ -664,7 +652,7 @@ function get_config_folders() { cfg_dirs+=("${HOME}/${name}_data/config") fi done - elif [[ -z ${instance_names} && $(find_klipper_systemd | wc -w) -gt 0 ]]; then + elif [[ -z ${instance_names} && $(klipper_systemd | wc -w) -gt 0 ]]; then cfg_dirs+=("${HOME}/printer_data/config") else cfg_dirs=() @@ -707,7 +695,7 @@ function get_instance_folder_path() { fi fi done - elif [[ -z ${instance_names} && $(find_klipper_systemd | wc -w) -gt 0 ]]; then + elif [[ -z ${instance_names} && $(klipper_systemd | wc -w) -gt 0 ]]; then path="${HOME}/printer_data/${folder_name}" if [[ -d ${path} ]]; then folder_paths+=("${path}") From faf56ed1b18008ccc410f8449ee02788b29f94e3 Mon Sep 17 00:00:00 2001 From: Stephan Wendel <43513802+KwadFan@users.noreply.github.com> Date: Tue, 28 Feb 2023 18:37:43 +0100 Subject: [PATCH 6/7] refactor(crowsnest): improve performance in crowsnest.sh (#306) --- scripts/crowsnest.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/crowsnest.sh b/scripts/crowsnest.sh index f8ed048..4733a29 100644 --- a/scripts/crowsnest.sh +++ b/scripts/crowsnest.sh @@ -134,15 +134,15 @@ function remove_crowsnest(){ # Status funcs get_crowsnest_status(){ local -a files + local env_file + env_file="$(grep "EnvironmentFile" /etc/systemd/system/crowsnest.service | cut -d "=" -f2)" files=( "${CROWSNEST_DIR}" "/usr/local/bin/crowsnest" "/etc/logrotate.d/crowsnest" "/etc/systemd/system/crowsnest.service" - "$(find "${HOME}" -name 'crowsnest.env' 2> /dev/null || - echo "${HOME}/printer_data/systemd/crowsnest.env")" + "${env_file}" ) - # Contains ugly hackaround for multi instance... :( local count count=0 From 31616ebad55febba7d53782371f16bd54b73798f Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 4 Mar 2023 16:01:06 +0100 Subject: [PATCH 7/7] fix(crowsnest): silence grep error output in main menu fixes #308 Signed-off-by: Dominik Willner --- scripts/crowsnest.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/crowsnest.sh b/scripts/crowsnest.sh index 4733a29..2915e55 100644 --- a/scripts/crowsnest.sh +++ b/scripts/crowsnest.sh @@ -135,7 +135,7 @@ function remove_crowsnest(){ get_crowsnest_status(){ local -a files local env_file - env_file="$(grep "EnvironmentFile" /etc/systemd/system/crowsnest.service | cut -d "=" -f2)" + env_file="$(grep "EnvironmentFile" /etc/systemd/system/crowsnest.service 2>/dev/null | cut -d "=" -f2)" files=( "${CROWSNEST_DIR}" "/usr/local/bin/crowsnest"