From 4c34245da05c780557bb4c8fde4b0c9bd53b40f0 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 11 Nov 2021 12:12:43 +0100 Subject: [PATCH 1/8] chore: refactor how klipper services are count --- scripts/install_moonraker.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh index b6d2d75..d0bf9f5 100755 --- a/scripts/install_moonraker.sh +++ b/scripts/install_moonraker.sh @@ -45,10 +45,10 @@ moonraker_setup_dialog(){ shopt -u extglob # disable extended globbing ### count amount of klipper services - if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ]; then + if ls /etc/systemd/system/klipper.service 2>/dev/null; then INSTANCE_COUNT=1 else - INSTANCE_COUNT=$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]]+.service" | wc -l) + INSTANCE_COUNT=$(ls /etc/systemd/system | grep -E "klipper-[[:digit:]]+.service" | wc -l) fi ### initial moonraker.conf path check From 22f705e06c37ed629d2e36f8af5d89f087f58a60 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 11 Nov 2021 12:28:20 +0100 Subject: [PATCH 2/8] chore: manage moonraker service enable/start with do_action_service method --- scripts/install_moonraker.sh | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh index d0bf9f5..bdae2c4 100755 --- a/scripts/install_moonraker.sh +++ b/scripts/install_moonraker.sh @@ -187,11 +187,10 @@ create_moonraker_service(){ ### write single instance service write_mr_service ### enable instance - sudo systemctl enable moonraker.service + do_action_service "enable" "moonraker" ok_msg "Single Moonraker instance created!" ### launching instance - status_msg "Launching Moonraker instance ..." - sudo systemctl start moonraker + do_action_service "start" "moonraker" else i=1 while [ $i -le $INSTANCE_COUNT ]; do @@ -203,12 +202,10 @@ create_moonraker_service(){ ### write multi instance service write_mr_service ### enable instance - sudo systemctl enable moonraker-$i.service + do_action_service "enable" "moonraker-$i" ok_msg "Moonraker instance #$i created!" ### launching instance - status_msg "Launching Moonraker instance #$i ..." - sudo systemctl start moonraker-$i - + do_action_service "start" "moonraker-$i" ### raise values by 1 i=$((i+1)) done From 0284a36e7f5a427af3f7b803bcb9673e9bf95b3d Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 11 Nov 2021 12:43:13 +0100 Subject: [PATCH 3/8] chore: use `ls` to look for nginx installation --- scripts/functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/functions.sh b/scripts/functions.sh index d4fa030..e4dcb9b 100755 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -225,7 +225,7 @@ restart_MoonrakerTelegramBot(){ } restart_nginx(){ - if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "nginx.service")" ]; then + if ls /lib/systemd/system/nginx.service 2>/dev/null 1>&2; then status_msg "Restarting NGINX Service ..." sudo systemctl restart nginx && ok_msg "NGINX Service restarted!" fi From ba888b1f97d07bcde374bf5b8811bf3f892ed2a9 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 11 Nov 2021 12:51:09 +0100 Subject: [PATCH 4/8] chore: use ls within remove_nginx method --- scripts/remove.sh | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/scripts/remove.sh b/scripts/remove.sh index 29af7d0..d53ebf1 100755 --- a/scripts/remove.sh +++ b/scripts/remove.sh @@ -364,12 +364,10 @@ remove_octoprint(){ ############################################################# remove_nginx(){ - if [[ $(dpkg-query -f'${Status}' --show nginx 2>/dev/null) = *\ installed ]] ; then - if systemctl is-active nginx -q; then - status_msg "Stopping Nginx service ..." - sudo service nginx stop && sudo systemctl disable nginx - ok_msg "Service stopped!" - fi + if ls /lib/systemd/system/nginx.service 2>/dev/null 1>&2; then + status_msg "Stopping Nginx service ..." + sudo systemctl stop nginx && sudo systemctl disable nginx + ok_msg "Service stopped and disabled!" status_msg "Purging Nginx from system ..." sudo apt-get purge nginx nginx-common -y sudo update-rc.d -f nginx remove From 19ddf3e023f07e71133d4df011021508b9f9817e Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 11 Nov 2021 13:02:36 +0100 Subject: [PATCH 5/8] fix: silence grep --- scripts/install_moonraker.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh index bdae2c4..ebc0a19 100755 --- a/scripts/install_moonraker.sh +++ b/scripts/install_moonraker.sh @@ -250,7 +250,7 @@ create_moonraker_conf(){ sed -i "s|%UDS%|$KLIPPY_UDS|" $MR_CONF # if host ip is not in the default ip ranges, replace placeholder # otherwise remove placeholder from config - if ! grep $LAN $MR_CONF; then + if ! grep -q $LAN $MR_CONF; then sed -i "s|%LAN%|$LAN|" $MR_CONF else sed -i "/%LAN%/d" $MR_CONF From fe4625d3e19198ccf42e82eca6db8267daa8369f Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 11 Nov 2021 13:21:57 +0100 Subject: [PATCH 6/8] chore: refactor how moonraker is detected --- scripts/install_klipper_webui.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/install_klipper_webui.sh b/scripts/install_klipper_webui.sh index 87cb486..7934b83 100755 --- a/scripts/install_klipper_webui.sh +++ b/scripts/install_klipper_webui.sh @@ -1,13 +1,13 @@ 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 + if ls /etc/systemd/system/moonraker.service 2>/dev/null || ls /etc/systemd/system | grep -q -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 + if sudo systemctl list-unit-files | grep -E "octoprint.*" | grep "enabled" &>/dev/null; then OCTOPRINT_ENABLED="true" fi From 36a8757cfd09c6ccbbd38f711773973d15219e2d Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 11 Nov 2021 13:26:01 +0100 Subject: [PATCH 7/8] chore: use ls to look for webcamd installation --- scripts/install_klipper_webui.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/install_klipper_webui.sh b/scripts/install_klipper_webui.sh index 7934b83..faff515 100755 --- a/scripts/install_klipper_webui.sh +++ b/scripts/install_klipper_webui.sh @@ -1,6 +1,6 @@ system_check_webui(){ ### check system for installed moonraker service - if ls /etc/systemd/system/moonraker.service 2>/dev/null || ls /etc/systemd/system | grep -q -E "moonraker-[[:digit:]]+.service"; then + if ls /etc/systemd/system/moonraker.service 2>/dev/null 1>&2 || ls /etc/systemd/system | grep -q -E "moonraker-[[:digit:]]+.service"; then moonraker_chk_ok="true" else moonraker_chk_ok="false" @@ -114,7 +114,7 @@ install_webui(){ $1_port_check ### ask user to install mjpg-streamer - if [[ ! "$(systemctl list-units --full -all -t service --no-legend | grep -F "webcamd.service")" ]]; then + if ls /etc/systemd/system/webcamd.service 2>/dev/null 1>&2; then get_user_selection_mjpg-streamer fi From 05a59e92610208e16ee4c90836d0b01a248f2925 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 11 Nov 2021 14:15:00 +0100 Subject: [PATCH 8/8] fix: correct ls command to find kiauh_macros.cfg --- scripts/install_klipper_webui.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install_klipper_webui.sh b/scripts/install_klipper_webui.sh index faff515..0756cc8 100755 --- a/scripts/install_klipper_webui.sh +++ b/scripts/install_klipper_webui.sh @@ -119,7 +119,7 @@ install_webui(){ fi ### ask user to install the recommended webinterface macros - if [[ ! -n $(ls $klipper_cfg_loc/kiauh_macros.cfg) ]] || [[ ! -n $(ls $klipper_cfg_loc/printer_*/kiauh_macros.cfg) ]]; then + if ! ls $klipper_cfg_loc/kiauh_macros.cfg 2>/dev/null 1>&2 || ! ls $klipper_cfg_loc/printer_*/kiauh_macros.cfg 2>/dev/null 1>&2; then get_user_selection_kiauh_macros "$IF_NAME2" fi ### create /etc/nginx/conf.d/upstreams.conf