#!/bin/bash
# checkFilestoreAll — check the filestore of every active container.
# Runs checkFilestore for each UUID returned by activeContainers.
# Output: "<UUID> OK" or "<UUID> NOK" per container.

SBIN_DIR="$(cd "$(dirname "$(readlink -f "$0")")" && pwd)"

active_uuids() {
    "$SBIN_DIR/activeContainers" | awk 'NF && $1 != "uuid" && $1 !~ /^-/ {print $1}'
}

failed=0
while read -r UUID; do
    [[ -n "$UUID" ]] || continue
    if "$SBIN_DIR/checkFilestore" "$UUID" >/dev/null 2>&1; then
        echo "$UUID OK"
    else
        echo "$UUID NOK"
        failed=1
    fi
done < <(active_uuids)

exit "$failed"
