#!/bin/bash -eu

# shellcheck disable=SC2034  # used via process substitution below
tag="snap.$SNAP_INSTANCE_NAME.hook.install"

# Redirect stdout to stdout+syslog
exec 1> >(tee >(logger --tag="$tag"))
# Redirect stderr to stderr+syslog
exec 2> >(logger --stderr --priority error --tag="$tag")

#
# Set generic config
#

# The UbuSTT socket path, under the key modelctl's `status` reads for a
# ws+unix runtime server (runtimes/*/runtime.yaml) to report the entrypoint.
modelctl set --package ws.unix-socket="$SNAP_COMMON/run/ubustt.sock"
modelctl set --package verbose="false"
# Idle-unload: release the model after this many idle seconds (0 = never).
modelctl set --package sleep-idle-seconds="300"
# Emission mode. false = commit-on-finalize (one final at end of audio),
# true = progressive committed segments. A config key rather than a hardcoded
# flag so the same build can be measured both ways; the benchmark runner treats
# the presence of this key as the snap declaring it supports streaming at all.
modelctl set --package streaming="true"

#
# Activate the single engine.
#
# This snap ships exactly one engine and its daemon execs it directly, so
# nothing here needs hardware scoring. The activation still matters: without an
# active engine `modelctl show-engine` / `list-models` / `status` all fail, and
# those are meant to answer on every inference snap. Selecting by name rather
# than --auto keeps that true even where hardware-observe is
# unavailable - there is only one possible answer.
#
modelctl use-engine cpu --assume-yes --no-restart
