#!/bin/bash

/usr/bin/dnf upgrade -y

/usr/bin/dnf clean all

CURRENT_VERSION=$(uname -r | sed 's/\.x86_64//')

echo "Bezici verze kernelu: $CURRENT_VERSION"

OLD_VERSIONS=$(rpm -qa --queryformat '%{VERSION}-%{RELEASE}\n' kernel-uek-core | grep -v "$CURRENT_VERSION")

if [ -z "$OLD_VERSIONS" ]; then
    echo "Nenalezeny zadne starsi verze kernelu k odstraneni."
else
    echo "Nalezene stare verze k odstraneni:"
    echo "$OLD_VERSIONS"
    
    for VER in $OLD_VERSIONS; do
        echo "Mazu komplektni sadu pro verzi: $VER"
        /usr/bin/dnf remove "*$VER*" -y
    done
fi

/usr/sbin/grub2-mkconfig -o /boot/grub2/grub.cfg

/usr/bin/dnf autoremove -y
/usr/bin/dnf clean all
/usr/bin/dnf makecache
