#!/bin/sh
cd "$(dirname "$0")"
echo "ZYL GPU miner -> 47.238.103.203:16102"
echo "Device id required: ZYL00001 .. ZYL10000"
lspci 2>/dev/null | grep -iE 'vga|3d|display' || true
BIN=""
for c in ./eid-opencl-miner ../build/opencl-miner/eid-opencl-miner ../miner-build/opencl-miner/eid-opencl-miner; do
  if [ -x "$c" ]; then BIN="$c"; break; fi
done
if [ -z "$BIN" ]; then
  echo "eid-opencl-miner not found. Build on a GPU machine:"
  echo "  cmake -DMARS_OPENCLMINER=ON -DCMAKE_BUILD_TYPE=Release .. && cmake --build . --target eid-opencl-miner"
  exit 1
fi
DEVICE_ID="$1"
if [ -z "$DEVICE_ID" ] && [ -f ./device-id.txt ]; then
  DEVICE_ID=$(tr -d ' \r\n' < ./device-id.txt)
fi
if [ -z "$DEVICE_ID" ]; then
  printf "Enter official device id [ZYL00001]: "
  read DEVICE_ID
fi
DEVICE_ID=$(echo "$DEVICE_ID" | tr '[:lower:]' '[:upper:]' | tr -d ' \r\n')
case "$DEVICE_ID" in
  ZYL[0-9][0-9][0-9][0-9][0-9]) ;;
  *)
    echo "device id must be ZYL + 5 digits, e.g. ZYL00001"
    echo "Wallet address is not accepted."
    exit 1
    ;;
esac
printf '%s\n' "$DEVICE_ID" > ./device-id.txt
exec "$BIN" --device-id "$DEVICE_ID" --server 47.238.103.203 --port 16102 --force3g
