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() {
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}"
}

View File

@@ -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}"