#!/usr/bin/env bash
#
# The `install-tools` machine action: put back the three programs the forge
# runs, from the channels this machine already trusts.
#
# `yt-dlp` fetches the recording, `ffmpeg` cuts and converts it, `fpcalc`
# fingerprints it. All three are hard dependencies of `archstar-web` - see its
# PKGBUILD - so pacman installed them with the service, and the `os` channel of
# repo.clem2k.com *is* the dependency closure of a full image build, so all
# three and everything they need are already published. Nothing had to be added
# to the repository for this to work, and that is worth knowing before reading
# any further: this is a repair, not an installer.
#
# What it repairs is the machine where a guaranteed program is nonetheless not
# there on the night - removed by hand, lost to an upgrade a power cut
# interrupted between unlinking the old file and writing the new one, or
# present and unable to start because a library went with a partial upgrade.
#
# The three names are written **here**, in a file that ships in the package,
# and never come from the request: the machine-action protocol carries a name
# and at most one word out of a closed list, and a request naming packages
# would be free text on its way to pacman.

set -euo pipefail

# shellcheck source=/dev/null
source "${ARCHSTAR_ACTIONS_LIB:-/usr/lib/archstar-actions/lib/common.sh}"

UPDATE="${ARCHSTAR_UPDATE:-/usr/bin/archstar-update}"

# The packages, not the programs. Two of the three share neither a name nor a
# package - `fpcalc` comes out of `chromaprint` - which is exactly the kind of
# thing that should be written down once rather than remembered.
PACKAGES=(yt-dlp ffmpeg chromaprint)

exec "${UPDATE}" --install "${PACKAGES[@]}"
