#!/bin/bash

BASEDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Source all *.sh files in checks/
for check_script in "$BASEDIR/checks"/*.sh; do
    [[ -f "$check_script" ]] && source "$check_script"
done

APP_NAME=redpesk-images-tester
REDPESK_BSP_FILE="/etc/dnf/vars/redpesk_bsp"

# Path where the script is installed
FULL_TEST_PATH="/usr/libexec/redtest/$APP_NAME"
FULL_LOGS_PATH="/var/log/redtest/$APP_NAME"

# Create the right logs path
mkdir -p "$FULL_LOGS_PATH"

echo ""
echo "***************************"
echo "Running common images tests"
echo "***************************"
echo ""

# Run the systemd services check
run_systemd_services_check "$FULL_LOGS_PATH"

# Run the helloworld-binding check
run_helloworld_binding_check "$FULL_LOGS_PATH"

# Adapt the following tests to the D.U.T. board
if grep -q 'solidrun-edge-gateways-bsp' "$REDPESK_BSP_FILE" 2>/dev/null; then
    
    echo ""
    echo "**************************************************"
    echo "Running additional tests for Solidrun Edge Gateway"
    echo "**************************************************"
    echo ""
    
    # Run the CAN check
    run_can_check "$FULL_LOGS_PATH"

    # Run the bluetooth check
    run_bluetooth_check "$FULL_LOGS_PATH"

    # Run the USB check
    run_usb_check "$FULL_LOGS_PATH"

    # Run the RTC check
    run_rtc_check "$FULL_LOGS_PATH"
fi

exit 0