#!/usr/bin/env bash
# QuantOS Machine Fingerprint Generator
# Run this on the target deployment machine and send the output to QuantOS support
# to receive your license file.

set -euo pipefail

echo "=== QuantOS Machine Fingerprint ==="
echo ""

# CPU model
if [ -f /proc/cpuinfo ]; then
    CPU=$(grep "model name" /proc/cpuinfo | head -1 | cut -d: -f2 | xargs)
elif command -v sysctl &>/dev/null; then
    CPU=$(sysctl -n machdep.cpu.brand_string 2>/dev/null || echo "unknown")
else
    CPU="unknown"
fi

# MAC address
if [ -f /sys/class/net/eth0/address ]; then
    MAC=$(cat /sys/class/net/eth0/address)
elif [ -f /sys/class/net/ens3/address ]; then
    MAC=$(cat /sys/class/net/ens3/address)
elif [ -f /sys/class/net/ens5/address ]; then
    MAC=$(cat /sys/class/net/ens5/address)
elif command -v ifconfig &>/dev/null; then
    MAC=$(ifconfig en0 2>/dev/null | grep ether | awk '{print $2}' || echo "00:00:00:00:00:00")
else
    MAC="00:00:00:00:00:00"
fi

HOSTNAME=$(hostname)

echo "CPU:         $CPU"
echo "MAC:         $MAC"
echo "Hostname:    $HOSTNAME"
echo ""

INPUT="${CPU}|${MAC}|${HOSTNAME}"
FINGERPRINT=$(echo -n "$INPUT" | sha256sum | cut -d' ' -f1)

echo "Fingerprint: $FINGERPRINT"
echo ""
echo "Paste this fingerprint into the QuantOS Console to apply for your license."
