From 7d5b4e7242eca2065d10ad32491a50da49c0a3f1 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 13 Aug 2022 16:01:18 +0200 Subject: [PATCH] refactor(obico.sh): refactor obico status initializes `is_linked` as true. switches it to false as soon as the first non linked instance is detected. status is then printed as non linked in the main menu. Signed-off-by: Dominik Willner --- scripts/obico.sh | 30 ++++++++++++++++++++---------- scripts/ui/main_menu.sh | 5 ++++- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/scripts/obico.sh b/scripts/obico.sh index 9113e62..f212345 100644 --- a/scripts/obico.sh +++ b/scripts/obico.sh @@ -365,23 +365,33 @@ function update_moonraker_obico() { #===================================================# function get_moonraker_obico_status() { - local moonraker_obico_services sf_count status - moonraker_obico_services=$(moonraker_obico_systemd) - sf_count=$(echo "${moonraker_obico_services}" | wc -w ) + local status + local service_count + local is_linked + local moonraker_obico_services - if (( sf_count == 0 )); then - status="Not installed!" - elif [[ ! -e "${MOONRAKER_OBICO_DIR}" ]]; then - status="Incomplete!" - else - status="Installed!" + moonraker_obico_services=$(moonraker_obico_systemd) + service_count=$(echo "${moonraker_obico_services}" | wc -w ) + + is_linked="true" + if [[ -n ${moonraker_obico_services} ]]; then for service in ${moonraker_obico_services}; do if ! is_moonraker_obico_linked "$(get_instance_name "${service}" moonraker-obico)"; then - status="Not linked!" + is_linked="false" fi done fi + if (( service_count == 0 )); then + status="Not installed!" + elif [[ ! -d "${MOONRAKER_OBICO_DIR}" ]]; then + status="Incomplete!" + elif [[ ${is_linked} == "false" ]]; then + status="Not linked!" + else + status="Installed!" + fi + echo "${status}" } diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh index 91092cc..925fca6 100755 --- a/scripts/ui/main_menu.sh +++ b/scripts/ui/main_menu.sh @@ -49,7 +49,10 @@ function print_status() { if [[ ${status} == "Not installed!" ]]; then status="${red}${status}${white}" - elif [[ ${status} == "Incomplete!" ]] || [[ ${status} == "Not linked!" ]]; then + elif [[ ${status} == "Incomplete!" ]]; then + status="${yellow}${status}${white}" + elif [[ ${status} == "Not linked!" ]]; then + ### "Not linked!" is only required for Moonraker-obico status="${yellow}${status}${white}" else status="${green}${status}${white}"