From 734952ca65410958f702fafe788f790652f45d72 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 2 Apr 2022 01:36:20 +0200 Subject: [PATCH] refactor: octoprint Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/octoprint.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/scripts/octoprint.sh b/scripts/octoprint.sh index 7d5913f..7807c29 100644 --- a/scripts/octoprint.sh +++ b/scripts/octoprint.sh @@ -371,3 +371,35 @@ octoprint_status(){ OCTOPRINT_STATUS="${yellow}Incomplete!${default} " fi } + +read_octoprint_service_status(){ + unset OPRINT_SERVICE_STATUS + if [ ! -f "/etc/systemd/system/octoprint.service" ]; then + return 0 + fi + if systemctl list-unit-files | grep -E "octoprint*" | grep "enabled" &>/dev/null; then + OPRINT_SERVICE_STATUS="${red}[Disable]${white} OctoPrint Service " + else + OPRINT_SERVICE_STATUS="${green}[Enable]${white} OctoPrint Service " + fi +} + +#================================================# +#=================== HELPERS ====================# +#================================================# + +toggle_octoprint_service(){ + if systemctl list-unit-files | grep -E "octoprint.*" | grep "enabled" &>/dev/null; then + do_action_service "stop" "octoprint" + do_action_service "disable" "octoprint" + sleep 2 + CONFIRM_MSG=" OctoPrint Service is now >>> DISABLED <<< !" + elif systemctl list-unit-files | grep -E "octoprint.*" | grep "disabled" &>/dev/null; then + do_action_service "enable" "octoprint" + do_action_service "start" "octoprint" + sleep 2 + CONFIRM_MSG=" OctoPrint Service is now >>> ENABLED <<< !" + else + ERROR_MSG=" You cannot activate a service that does not exist!" + fi +}