#!/bin/sh
# Flathub remote + Steam Link.
set -eu

. /etc/thinclient-agent/config.env

flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo

if [ "${ENABLE_STEAM_LINK}" != "true" ]; then
  echo "0400-flatpak-steamlink: ENABLE_STEAM_LINK is false, skipping Steam Link install."
  exit 0
fi

# VERIFY BEFORE THE FIRST REAL BUILD: confirm this application ID against the live
# Flathub listing (`flatpak search "Steam Link"`). It is believed correct but has not
# been checked against Flathub from this environment.
STEAM_LINK_APP_ID="com.valvesoftware.SteamLink"

if flatpak install -y --noninteractive flathub "$STEAM_LINK_APP_ID"; then
  echo "0400-flatpak-steamlink: installed ${STEAM_LINK_APP_ID}."
else
  echo "0400-flatpak-steamlink: WARNING — could not install ${STEAM_LINK_APP_ID} during the"
  echo "  build (no network in the chroot, or the app ID is wrong). Run this on the booted"
  echo "  image instead:  flatpak install -y flathub ${STEAM_LINK_APP_ID}"
fi
