#!/bin/sh
info() {
	printf "%b\n" "${1}"
}

SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
skip_regex="^(#.*)?$"

total=$(grep -cvP "$skip_regex" "${SCRIPT_DIR}/packages.txt")
tput sc
while read -r package; do
    echo "$package" | grep -qvP "$skip_regex" || continue
    n=$((n + 1))
    eval "info \"(${n}/${total}) Validating $package\""
    xbps-query -R "$package" >/dev/null 2>&1 || failed_packages="${failed_packages} ${package}"
    tput rc
    tput el
done <"${SCRIPT_DIR}/packages.txt"

echo "Failed packages:${failed_packages}"