#!/bin/bash
# Install bootc RPM and perform post-installation setup
set -xeuo pipefail

RPM_DIR="${1:-/tmp}"

# Install the RPM package
# Use rpm -Uvh with --oldpackage to allow replacing with dev version
rpm -Uvh --oldpackage "${RPM_DIR}"/*.rpm
rm -f "${RPM_DIR}"/*.rpm

# Regenerate initramfs if we have initramfs-setup
kver=$(cd /usr/lib/modules && echo *)
# DRACUT_NO_XATTR=1 is the default in newer base images, and
# we have --add bootc here until the change to add the module in base
# images lands.
env DRACUT_NO_XATTR=1 dracut --add bootc -vf /usr/lib/modules/$kver/initramfs.img $kver

# Only in this containerfile, inject a file which signifies
# this comes from this development image. This can be used in
# tests to know we're doing upstream CI.
touch /usr/lib/.bootc-dev-stamp

# Workaround for https://github.com/bootc-dev/bootc/issues/1546
rm -rf /root/buildinfo
