#!/bin/bash

# Detect CPU architecture and run the appropriate SystemCheck binary
ARCH=$(uname -m)

case "$ARCH" in
    i386 | i486 | i586 | i686)
        BINARY="Resources/Linux32Bit/SystemCheck"
        LABEL="32-bit x86"
        ;;
    x86_64)
        BINARY="Resources/Linux64/SystemCheck"
        LABEL="64-bit x86"
        ;;
    armv6l | armv7l)
        BINARY="Resources/RPi32bit/SystemCheck"
        LABEL="32-bit ARM"
        ;;
    aarch64 | arm64)
        BINARY="Resources/RPi64bit/SystemCheck"
        LABEL="64-bit ARM"
        ;;
    *)
        echo "No supported Operating System Found!"
        read -n 1 -s -r -p "Press any key to continue..."
        echo
        exit 1
        ;;
esac

# Verify the binary exists before attempting to run it
if [ ! -f "$BINARY" ]; then
    echo "Error: Binary not found at $BINARY"
    echo "Architecture detected: $LABEL ($ARCH)"
    read -n 1 -s -r -p "Press any key to continue..."
    echo
    exit 1
fi

# Ensure the binary is executable
chmod +x "$BINARY"

# Run the appropriate SystemCheck
exec "$BINARY"
