#!/bin/bash
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

# This test ensures that we can install some common tools as OS extensions.

. $KOLA_EXT_DATA/commonlib.sh

commands=(
  'gdb'
  'htop'
  'strace'
  'tcpdump'
  'tree'
)

# Also try some OS extensions which have host bindings. These can only
# work on streams that are sure to have the archive repo available
# (mostly streams based on Fedora stable releases). Since `next`
# rebases early to the next major Fedora and the other streams operate
# continuously on non-stable Fedora we'll just limit this to
# `stable`/`testing`/`testing-devel`. It's possible that this test will
# fail on one of those streams if we fast track VIM and it's not
# availabe in any repo, but we can just snooze the entire test in that
# case.
case "$(get_fcos_stream)" in
    "stable"|"testing"|"testing-devel") commands+=('vim') ;;
    *) ;;
esac

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

failed=""

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

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