FROM ghcr.io/benradey/silverblue-asrock-x570:latest

RUN dnf5 install -y \
      dkms \
      python3-pyusb \
      radeontop \
      xinput && \
    dnf5 clean all

RUN git clone https://github.com/johnfanv2/LenovoLegionLinux.git && \
    mkdir -p /usr/src/LenovoLegionLinux-1.0.0 && \
    cp /LenovoLegionLinux/kernel_module/* /usr/src/LenovoLegionLinux-1.0.0 -r && \
    dkms add -m LenovoLegionLinux -v 1.0.0 && \
    dkms build -m LenovoLegionLinux -v 1.0.0 -k $(rpm -qa kernel --queryformat '%{VERSION}-%{RELEASE}.%{ARCH}') && \
    dkms install -m LenovoLegionLinux -v 1.0.0 -k $(rpm -qa kernel --queryformat '%{VERSION}-%{RELEASE}.%{ARCH}') && \
    echo legion-laptop > /etc/modules-load.d/legion_laptop.conf && \
    rm -rf LenovoLegionLinux

# The first check makes sure that we have exactly 4 gpg pubkeys trusted in the rpmdb (the ones from the base image).
# Any more than that means that dnf automatically added a new one, which is shady!
# Then: cleanup image for linting
# Finally: verify image is good
RUN [[ 4 -eq $(rpm -qa gpg-pubkey* | wc -l) ]] && \
    rm -rf /var /boot && mkdir /var /boot && \
    bootc container lint --fatal-warnings --skip baseimage-composefs
