#!/bin/bash
# Configure system for a specific bootc variant
set -xeuo pipefail

dn=$(dirname $0)

VARIANT="${1:-}"

if [ -z "$VARIANT" ]; then
  # No variant specified, nothing to do
  exit 0
fi

# Handle variant-specific configuration
case "${VARIANT}" in
  *-sdboot)
    # Install systemd-boot and remove bootupd;
    # We downloaded this in an earlier phase
    sdboot="usr/lib/systemd/boot/efi/systemd-bootx64.efi"
    sdboot_bn=$(basename ${sdboot})
    rpm -Uvh /run/sdboot-content/out/*.rpm
      # And override with our signed binary
    install -m 0644 /run/sdboot-signed/out/${sdboot_bn} /${sdboot}

    # Uninstall bootupd
    rpm -e bootupd
    rm -rf /usr/lib/bootupd/updates
    # Clean up package manager caches
    dnf clean all
    rm -rf /var/cache /var/lib/{dnf,rhsm} /var/log/*
  ;;
  # Future variants can be added here
  # For Debian support, this could check package manager type and use apt instead
esac
