#!/bin/sh
# Scutarius pre-pkgsel hook (scutarius-tasks-udeb): queue the hardware
# profile task this machine calls for, with NO preseed value, so the
# installer stays general purpose.
#
# Why a hook and not the tasksel test: pkgsel runs tasksel with
# DEBIAN_TASKS_ONLY=1, and with that variable tasksel reads debian-tasks.desc
# ONLY -- the tasks in /usr/share/tasksel/descs/scutarius-tasks.desc and their
# Test- hooks are invisible during an install by construction (measured on
# brain-cell-g4, 2026-09-05; post-install `tasksel` shows them fine).
# pkgsel installs whatever pkgsel/include holds right after tasksel, so this
# hook appends the task there. Runs in the installer environment, where /sys
# is mounted; the detection is the same as tests/dgx-spark.
set -e
. /usr/share/debconf/confmodule

want=""
fam=$(cat /sys/class/dmi/id/product_family 2>/dev/null || true)
case "$fam" in
	"DGX Spark") want=task-scutarius-gb10 ;;
esac
[ -n "$want" ] || exit 0

# pkgsel/include may already carry preseeded packages (comma or space
# separated); keep them, add ours once.
db_get pkgsel/include || true
cur=$(printf '%s' "$RET" | sed 's/,/ /g')
case " $cur " in
	*" $want "*) exit 0 ;;
esac
db_set pkgsel/include "${cur:+$cur }$want"
logger -t scutarius-hwtasks "DMI product_family '$fam': $want added to pkgsel/include"
exit 0
