#!/bin/bash
# This test ensures that we can install some common tools as OS extensions.
set -xeuo pipefail

## kola:
##   # This test only runs on FCOS as OS extensions are implemented differently on RHCOS.
##   distros: fcos
##   tags: needs-internet
##   # This test should pass everywhere if it passes anywhere.
##   platforms: qemu
##   # This is dependent on network and disk speed but we've seen the
##   # test take longer than 10 minutes in our aarch64 qemu tests.
##   timeoutMin: 15
##   minMemory: 1536

. $KOLA_EXT_DATA/commonlib.sh

# Note: This version must be kept up to date for now, since there currently is no 'latest' (or similar) stream
CRIO_VERSION=1.24

declare -A commands=(
  ["cri-o:${CRIO_VERSION}/default"]="crio"
  ["nginx:mainline"]="nginx"
)

rpm-ostree ex module install "${!commands[@]}"
rpm-ostree ex apply-live

failed=""

for m in "${!commands[@]}"; do
  if [[ -z "$(command -v "${commands[$m]}")" ]]; then
    echo "Could not find: ${commands[$m]}"
    failed+=" ${1}"
  fi
done

if [[ -n "${failed}" ]]; then
  fatal "could not install: ${failed}"
fi
ok "successfully installed os rpm module extensions"
