#!/usr/bin/env bash

MODULE_HARDWARE_DETECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$MODULE_HARDWARE_DETECT_DIR/../../.." && pwd)"

# shellcheck source=lib/ui.sh
source "$PROJECT_ROOT/lib/ui.sh"
# shellcheck source=lib/log.sh
source "$PROJECT_ROOT/lib/log.sh"
# shellcheck source=lib/package.sh
source "$PROJECT_ROOT/lib/package.sh"
# shellcheck source=core/runtime.sh
source "$PROJECT_ROOT/core/runtime.sh"
# shellcheck source=modules/hardware/detect/module.sh
source "$MODULE_HARDWARE_DETECT_DIR/module.sh"

runtime_init "$PROJECT_ROOT"
log_init

if ! package_is_installed lshw; then
  printf 'hardware-detect test SKIPPED: lshw not installed\n'
  exit 0
fi

if ! test -f /var/log/postinstall-debian/hardware-report.txt; then
  printf 'hardware-detect test SKIPPED: report not generated\n'
  exit 0
fi

if module_detect_test; then
  printf 'hardware-detect test OK\n'
else
  printf 'hardware-detect test FAILED\n' >&2
  exit 1
fi
