#!/bin/bash -efu

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See LICENSE for more details.
#
# Copyright: Red Hat Inc. 2022
# Author: Michal Srb <michal@redhat.com>

# Prepare system for install, remove, downgrade, update tests

echo "Preparing the system for testing..."

if [ -n "$FIXREPO" ]; then
    # CentOS Stream composes don't have COMPOSE_ID (?)
    echo "Ignoring \"--fixrepo\" option as it has no effect on CentOS Stream profiles"
fi

# Replace system repositories with a profile repo
find "/etc/yum.repos.d/" -name "*.repo" -delete
cp -f "$PFILE" "$REPOFILE"

if [ -n "$ENABLE_BUILD_ROOT" ]; then
    echo "Enabling buildroot repository..."
    yum config-manager --set-enabled centos-stream-buildroot
fi

echo "Recreating the DNF cache..."
yum clean all
yum makecache

echo "Installing packages required for testing..."
yum -y install createrepo_c which procps-ng

echo "Updating the system..."
yum -y upgrade
