#!/usr/bin/env bash
set -e

GPU_IDS="${1:-}"
TIMEOUT="${2:-3600}"
TEMP_ABORT="${3:-95}"

if ! command -v hashcat >/dev/null 2>&1; then
  echo "[INFO] hashcat 未安装，开始安装..."

  export DEBIAN_FRONTEND=noninteractive
  apt-get install -y hashcat

  echo "[INFO] hashcat 安装完成"
fi

printf "2b576acbe6bcfda7294d6bd18041b8fe" > hashes.ntlm

DEVICE_ARG=""
if [ -n "$GPU_IDS" ]; then
  DEVICE_ARG="-d $GPU_IDS"
fi

hashcat -m 1000 -a 3 hashes.ntlm '?1?1?1?1?1?1?1?1?1' -1 '?l?u?d' \
  -D 2 $DEVICE_ARG \
  -w 4 --status --status-timer 5 \
  -O --keep-guessing --runtime "$TIMEOUT" \
  --hwmon-temp-abort="$TEMP_ABORT"
