#!/usr/bin/env bash
. h-manifest.conf

# Dynamic miner/worker from CUSTOM_TEMPLATE with fallback to Hive worker name
if [[ -n "$CUSTOM_TEMPLATE" && "$CUSTOM_TEMPLATE" == *.* ]]; then
  MINER_NAME="${CUSTOM_TEMPLATE%%.*}"
  WORKER_NAME="${CUSTOM_TEMPLATE##*.}"
else
  MINER_NAME="${CUSTOM_TEMPLATE:-${HIVE_WORKER_NAME:-mcminer}}"
  WORKER_NAME="${HIVE_WORKER_NAME:-default}"
fi
[[ "$WORKER_NAME" == *"%WORKER_NAME%"* ]] && WORKER_NAME="$HIVE_WORKER_NAME"

echo "-miner $MINER_NAME -worker $WORKER_NAME -optimize-for cuda -pool-name moonclub -log-path $CUSTOM_LOG_BASENAME.log" > "$CUSTOM_CONFIG_FILENAME"
