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 <th33xitus@gmail.com>
This commit is contained in:
th33xitus
2022-08-13 16:01:18 +02:00
parent d11323d55d
commit 7d5b4e7242
2 changed files with 24 additions and 11 deletions

View File

@@ -365,23 +365,33 @@ function update_moonraker_obico() {
#===================================================# #===================================================#
function get_moonraker_obico_status() { function get_moonraker_obico_status() {
local moonraker_obico_services sf_count status local status
moonraker_obico_services=$(moonraker_obico_systemd) local service_count
sf_count=$(echo "${moonraker_obico_services}" | wc -w ) local is_linked
local moonraker_obico_services
if (( sf_count == 0 )); then moonraker_obico_services=$(moonraker_obico_systemd)
status="Not installed!" service_count=$(echo "${moonraker_obico_services}" | wc -w )
elif [[ ! -e "${MOONRAKER_OBICO_DIR}" ]]; then
status="Incomplete!" is_linked="true"
else if [[ -n ${moonraker_obico_services} ]]; then
status="Installed!"
for service in ${moonraker_obico_services}; do for service in ${moonraker_obico_services}; do
if ! is_moonraker_obico_linked "$(get_instance_name "${service}" moonraker-obico)"; then if ! is_moonraker_obico_linked "$(get_instance_name "${service}" moonraker-obico)"; then
status="Not linked!" is_linked="false"
fi fi
done done
fi 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}" echo "${status}"
} }

View File

@@ -49,7 +49,10 @@ function print_status() {
if [[ ${status} == "Not installed!" ]]; then if [[ ${status} == "Not installed!" ]]; then
status="${red}${status}${white}" 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}" status="${yellow}${status}${white}"
else else
status="${green}${status}${white}" status="${green}${status}${white}"