From 7f8ee7939c3f7524a71fe1b1f39096faaca2471d Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 1 Oct 2021 23:50:27 +0200 Subject: [PATCH] script: move nginx functions from install_moonraker.sh to install_klipper_webui.sh nginx was removed as a dependency from moonraker. moonraker didn't make use of it, only mainsail/fluidd do. so moving all nginx related functions to is reasonable --- scripts/install_klipper_webui.sh | 185 +++++++++++++++++++++++++++++-- scripts/install_moonraker.sh | 180 +----------------------------- 2 files changed, 180 insertions(+), 185 deletions(-) diff --git a/scripts/install_klipper_webui.sh b/scripts/install_klipper_webui.sh index b6b07ea..368fae8 100755 --- a/scripts/install_klipper_webui.sh +++ b/scripts/install_klipper_webui.sh @@ -1,10 +1,25 @@ -check_moonraker(){ - status_msg "Checking for Moonraker service ..." +system_check_webui(){ + ### check system for installed moonraker service if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "moonraker.service")" ] || [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "moonraker-[[:digit:]].service")" ]; then moonraker_chk_ok="true" else moonraker_chk_ok="false" fi + + ### check system for an installed and enabled octoprint service + if systemctl list-unit-files | grep -E "octoprint.*" | grep "enabled" &>/dev/null; then + OCTOPRINT_ENABLED="true" + fi + + ### check system for an installed haproxy service + if [[ $(dpkg-query -f'${Status}' --show haproxy 2>/dev/null) = *\ installed ]]; then + HAPROXY_FOUND="true" + fi + + ### check system for an installed lighttpd service + if [[ $(dpkg-query -f'${Status}' --show lighttpd 2>/dev/null) = *\ installed ]]; then + LIGHTTPD_FOUND="true" + fi } get_user_selection_mjpg-streamer(){ @@ -70,8 +85,16 @@ get_user_selection_kiauh_macros(){ install_webui(){ source_kiauh_ini + ### checking dependencies + dep=(nginx) + dependency_check ### check if moonraker is already installed - check_moonraker + system_check_webui + ### ask user how to handle OctoPrint, Haproxy and Lighttpd if found + process_octoprint_dialog + process_haproxy_lighttpd_dialog + ### process possible disruptive services + process_haproxy_lighttpd_services [ $1 == "mainsail" ] && IF_NAME1="Mainsail" && IF_NAME2="Mainsail " [ $1 == "fluidd" ] && IF_NAME1="Fluidd" && IF_NAME2="Fluidd " @@ -80,11 +103,9 @@ install_webui(){ if [ $moonraker_chk_ok = "false" ]; then ERROR_MSG="Moonraker service not found!\n Please install Moonraker first!" print_msg && clear_msg && return 0 - else - ok_msg "Moonraker service found!" - status_msg "Initializing $IF_NAME1 installation ..." fi + status_msg "Initializing $IF_NAME1 installation ..." ### check for other enabled web interfaces unset SET_LISTEN_PORT detect_enabled_sites @@ -335,6 +356,25 @@ fluidd_setup(){ rm -rf *.zip && ok_msg "Done!" } +set_upstream_nginx_cfg(){ + get_date + ### backup existing nginx configs + [ ! -d "$BACKUP_DIR/nginx_cfg" ] && mkdir -p "$BACKUP_DIR/nginx_cfg" + [ -f "$NGINX_CONFD/upstreams.conf" ] && sudo mv "$NGINX_CONFD/upstreams.conf" "$BACKUP_DIR/nginx_cfg/${current_date}_upstreams.conf" + [ -f "$NGINX_CONFD/common_vars.conf" ] && sudo mv "$NGINX_CONFD/common_vars.conf" "$BACKUP_DIR/nginx_cfg/${current_date}_common_vars.conf" + ### transfer ownership of backed up files from root to ${USER} + for log in $(ls "$BACKUP_DIR/nginx_cfg"); do + sudo chown ${USER} "$BACKUP_DIR/nginx_cfg/$log" + done + ### copy nginx configs to target destination + if [ ! -f "$NGINX_CONFD/upstreams.conf" ]; then + sudo cp "${SRCDIR}/kiauh/resources/upstreams.conf" "$NGINX_CONFD" + fi + if [ ! -f "$NGINX_CONFD/common_vars.conf" ]; then + sudo cp "${SRCDIR}/kiauh/resources/common_vars.conf" "$NGINX_CONFD" + fi +} + fetch_webui_ports(){ ### read listen ports from possible installed interfaces ### and write them to ~/.kiauh.ini @@ -371,7 +411,7 @@ match_nginx_configs(){ ### check for outdated upstreams.conf if [[ "$upstreams_webcams" -lt "$mainsail_webcams" ]] || [[ "$upstreams_webcams" -lt "$fluidd_webcams" ]]; then status_msg "Outdated upstreams.conf found! Updating ..." - setup_moonraker_nginx_cfg + set_upstream_nginx_cfg cfg_updated="true" fi ### check for outdated mainsail config @@ -404,4 +444,135 @@ match_nginx_configs(){ if [ "$cfg_updated" == "true" ]; then restart_nginx && unset cfg_updated fi +} + +process_octoprint_dialog(){ + #ask user to disable octoprint when its service was found + if [ "$OCTOPRINT_ENABLED" = "true" ]; then + while true; do + echo + top_border + echo -e "| ${red}!!! WARNING - OctoPrint service found !!!${default} |" + hr + echo -e "| You might consider disabling the OctoPrint service, |" + echo -e "| since an active OctoPrint service may lead to unex- |" + echo -e "| pected behavior of the Klipper Webinterfaces. |" + bottom_border + read -p "${cyan}###### Do you want to disable OctoPrint now? (Y/n):${default} " yn + case "$yn" in + Y|y|Yes|yes|"") + echo -e "###### > Yes" + status_msg "Stopping OctoPrint ..." + do_action_service "stop" "octoprint" && ok_msg "OctoPrint service stopped!" + status_msg "Disabling OctoPrint ..." + do_action_service "disable" "octoprint" && ok_msg "OctoPrint service disabled!" + break;; + N|n|No|no) + echo -e "###### > No" + break;; + *) + print_unkown_cmd + print_msg && clear_msg;; + esac + done + fi +} + +process_haproxy_lighttpd_services(){ + #handle haproxy service + if [ "$DISABLE_HAPROXY" = "true" ] || [ "$REMOVE_HAPROXY" = "true" ]; then + if systemctl is-active haproxy -q; then + status_msg "Stopping haproxy service ..." + sudo systemctl stop haproxy && ok_msg "Service stopped!" + fi + + ### disable haproxy + if [ "$DISABLE_HAPROXY" = "true" ]; then + status_msg "Disabling haproxy ..." + sudo systemctl disable haproxy && ok_msg "Haproxy service disabled!" + + ### remove haproxy + if [ "$REMOVE_HAPROXY" = "true" ]; then + status_msg "Removing haproxy ..." + sudo apt-get remove haproxy -y && sudo update-rc.d -f haproxy remove && ok_msg "Haproxy removed!" + fi + fi + fi + + ### handle lighttpd service + if [ "$DISABLE_LIGHTTPD" = "true" ] || [ "$REMOVE_LIGHTTPD" = "true" ]; then + if systemctl is-active lighttpd -q; then + status_msg "Stopping lighttpd service ..." + sudo systemctl stop lighttpd && ok_msg "Service stopped!" + fi + + ### disable lighttpd + if [ "$DISABLE_LIGHTTPD" = "true" ]; then + status_msg "Disabling lighttpd ..." + sudo systemctl disable lighttpd && ok_msg "Lighttpd service disabled!" + + ### remove lighttpd + if [ "$REMOVE_LIGHTTPD" = "true" ]; then + status_msg "Removing lighttpd ..." + sudo apt-get remove lighttpd -y && sudo update-rc.d -f lighttpd remove && ok_msg "Lighttpd removed!" + fi + fi + fi +} + +process_haproxy_lighttpd_dialog(){ + #notify user about haproxy or lighttpd services found and possible issues + if [ "$HAPROXY_FOUND" = "true" ] || [ "$LIGHTTPD_FOUND" = "true" ]; then + while true; do + echo + top_border + echo -e "| ${red}Possibly disruptive/incompatible services found!${default} |" + hr + if [ "$HAPROXY_FOUND" = "true" ]; then + echo -e "| ● haproxy |" + fi + if [ "$LIGHTTPD_FOUND" = "true" ]; then + echo -e "| ● lighttpd |" + fi + hr + echo -e "| Having those packages installed can lead to unwanted |" + echo -e "| behaviour. It is recommend to remove those packages. |" + echo -e "| |" + echo -e "| 1) Remove packages (recommend) |" + echo -e "| 2) Disable only (may cause issues) |" + echo -e "| ${red}3) Skip this step (not recommended)${default} |" + bottom_border + read -p "${cyan}###### Please choose:${default} " action + case "$action" in + 1) + echo -e "###### > Remove packages" + if [ "$HAPROXY_FOUND" = "true" ]; then + DISABLE_HAPROXY="true" + REMOVE_HAPROXY="true" + fi + if [ "$LIGHTTPD_FOUND" = "true" ]; then + DISABLE_LIGHTTPD="true" + REMOVE_LIGHTTPD="true" + fi + break;; + 2) + echo -e "###### > Disable only" + if [ "$HAPROXY_FOUND" = "true" ]; then + DISABLE_HAPROXY="true" + REMOVE_HAPROXY="false" + fi + if [ "$LIGHTTPD_FOUND" = "true" ]; then + DISABLE_LIGHTTPD="true" + REMOVE_LIGHTTPD="false" + fi + break;; + 3) + echo -e "###### > Skip" + break;; + *) + print_unkown_cmd + print_msg && clear_msg;; + esac + done + fi } \ No newline at end of file diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh index 7d5e9b8..4ad94e0 100755 --- a/scripts/install_moonraker.sh +++ b/scripts/install_moonraker.sh @@ -16,28 +16,12 @@ system_check_moonraker(){ warn_msg "Python version not ok!" py_chk_ok="false" fi - - ### check system for an installed and enabled octoprint service - if systemctl list-unit-files | grep -E "octoprint.*" | grep "enabled" &>/dev/null; then - OCTOPRINT_ENABLED="true" - fi - - ### check system for an installed haproxy service - if [[ $(dpkg-query -f'${Status}' --show haproxy 2>/dev/null) = *\ installed ]]; then - HAPROXY_FOUND="true" - fi - - ### check system for an installed lighttpd service - if [[ $(dpkg-query -f'${Status}' --show lighttpd 2>/dev/null) = *\ installed ]]; then - LIGHTTPD_FOUND="true" - fi - } moonraker_setup_dialog(){ status_msg "Initializing Moonraker installation ..." - ### check system for several requirements before initializing the moonraker installation + ### checking system for python3.7+ system_check_moonraker ### exit moonraker setup if python version is not ok @@ -70,10 +54,6 @@ moonraker_setup_dialog(){ ### initial moonraker.conf path check check_klipper_cfg_path - ### ask user how to handle OctoPrint, Haproxy and Lighttpd - process_octoprint_dialog - process_haproxy_lighttpd_dialog - ### instance confirmation dialog while true; do echo @@ -127,13 +107,7 @@ moonraker_setup(){ ### step 3: create moonraker.conf folder and moonraker.confs create_moonraker_conf - ### step 4: set up moonrakers nginx configs - setup_moonraker_nginx_cfg - - ### step 5: process possible disruptive services - process_haproxy_lighttpd_services - - # ### step 6: create final moonraker instances + ### step 4: create final moonraker instances create_moonraker_service ### confirm message @@ -324,153 +298,3 @@ print_mr_ip_list(){ i=$((i + 1)) done } - -setup_moonraker_nginx_cfg(){ - get_date - ### backup existing nginx configs - [ ! -d "$BACKUP_DIR/nginx_cfg" ] && mkdir -p "$BACKUP_DIR/nginx_cfg" - [ -f "$NGINX_CONFD/upstreams.conf" ] && sudo mv "$NGINX_CONFD/upstreams.conf" "$BACKUP_DIR/nginx_cfg/${current_date}_upstreams.conf" - [ -f "$NGINX_CONFD/common_vars.conf" ] && sudo mv "$NGINX_CONFD/common_vars.conf" "$BACKUP_DIR/nginx_cfg/${current_date}_common_vars.conf" - ### transfer ownership of backed up files from root to ${USER} - for log in $(ls "$BACKUP_DIR/nginx_cfg"); do - sudo chown ${USER} "$BACKUP_DIR/nginx_cfg/$log" - done - ### copy nginx configs to target destination - if [ ! -f "$NGINX_CONFD/upstreams.conf" ]; then - sudo cp "${SRCDIR}/kiauh/resources/upstreams.conf" "$NGINX_CONFD" - fi - if [ ! -f "$NGINX_CONFD/common_vars.conf" ]; then - sudo cp "${SRCDIR}/kiauh/resources/common_vars.conf" "$NGINX_CONFD" - fi -} - -process_octoprint_dialog(){ - #ask user to disable octoprint when its service was found - if [ "$OCTOPRINT_ENABLED" = "true" ]; then - while true; do - echo - top_border - echo -e "| ${red}!!! WARNING - OctoPrint service found !!!${default} |" - hr - echo -e "| You might consider disabling the OctoPrint service, |" - echo -e "| since an active OctoPrint service may lead to unex- |" - echo -e "| pected behavior of the Klipper Webinterfaces. |" - bottom_border - read -p "${cyan}###### Do you want to disable OctoPrint now? (Y/n):${default} " yn - case "$yn" in - Y|y|Yes|yes|"") - echo -e "###### > Yes" - status_msg "Stopping OctoPrint ..." - do_action_service "stop" "octoprint" && ok_msg "OctoPrint service stopped!" - status_msg "Disabling OctoPrint ..." - do_action_service "disable" "octoprint" && ok_msg "OctoPrint service disabled!" - break;; - N|n|No|no) - echo -e "###### > No" - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac - done - fi -} - -process_haproxy_lighttpd_services(){ - #handle haproxy service - if [ "$DISABLE_HAPROXY" = "true" ] || [ "$REMOVE_HAPROXY" = "true" ]; then - if systemctl is-active haproxy -q; then - status_msg "Stopping haproxy service ..." - sudo systemctl stop haproxy && ok_msg "Service stopped!" - fi - - ### disable haproxy - if [ "$DISABLE_HAPROXY" = "true" ]; then - status_msg "Disabling haproxy ..." - sudo systemctl disable haproxy && ok_msg "Haproxy service disabled!" - - ### remove haproxy - if [ "$REMOVE_HAPROXY" = "true" ]; then - status_msg "Removing haproxy ..." - sudo apt-get remove haproxy -y && sudo update-rc.d -f haproxy remove && ok_msg "Haproxy removed!" - fi - fi - fi - - ### handle lighttpd service - if [ "$DISABLE_LIGHTTPD" = "true" ] || [ "$REMOVE_LIGHTTPD" = "true" ]; then - if systemctl is-active lighttpd -q; then - status_msg "Stopping lighttpd service ..." - sudo systemctl stop lighttpd && ok_msg "Service stopped!" - fi - - ### disable lighttpd - if [ "$DISABLE_LIGHTTPD" = "true" ]; then - status_msg "Disabling lighttpd ..." - sudo systemctl disable lighttpd && ok_msg "Lighttpd service disabled!" - - ### remove lighttpd - if [ "$REMOVE_LIGHTTPD" = "true" ]; then - status_msg "Removing lighttpd ..." - sudo apt-get remove lighttpd -y && sudo update-rc.d -f lighttpd remove && ok_msg "Lighttpd removed!" - fi - fi - fi -} - -process_haproxy_lighttpd_dialog(){ - #notify user about haproxy or lighttpd services found and possible issues - if [ "$HAPROXY_FOUND" = "true" ] || [ "$LIGHTTPD_FOUND" = "true" ]; then - while true; do - echo - top_border - echo -e "| ${red}Possibly disruptive/incompatible services found!${default} |" - hr - if [ "$HAPROXY_FOUND" = "true" ]; then - echo -e "| ● haproxy |" - fi - if [ "$LIGHTTPD_FOUND" = "true" ]; then - echo -e "| ● lighttpd |" - fi - hr - echo -e "| Having those packages installed can lead to unwanted |" - echo -e "| behaviour. It is recommend to remove those packages. |" - echo -e "| |" - echo -e "| 1) Remove packages (recommend) |" - echo -e "| 2) Disable only (may cause issues) |" - echo -e "| ${red}3) Skip this step (not recommended)${default} |" - bottom_border - read -p "${cyan}###### Please choose:${default} " action - case "$action" in - 1) - echo -e "###### > Remove packages" - if [ "$HAPROXY_FOUND" = "true" ]; then - DISABLE_HAPROXY="true" - REMOVE_HAPROXY="true" - fi - if [ "$LIGHTTPD_FOUND" = "true" ]; then - DISABLE_LIGHTTPD="true" - REMOVE_LIGHTTPD="true" - fi - break;; - 2) - echo -e "###### > Disable only" - if [ "$HAPROXY_FOUND" = "true" ]; then - DISABLE_HAPROXY="true" - REMOVE_HAPROXY="false" - fi - if [ "$LIGHTTPD_FOUND" = "true" ]; then - DISABLE_LIGHTTPD="true" - REMOVE_LIGHTTPD="false" - fi - break;; - 3) - echo -e "###### > Skip" - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac - done - fi -}