remove-old-kernels: Simplify removal version selection logic

'rpmevrcmp' is not needed since we don't output epoch there, thus simple version
sort with `sort -V` is enough.

Signed-off-by: Vitaly Chikunov <vt@altlinux.org>
This commit is contained in:
Виталий Чикунов 2022-06-26 06:43:44 +03:00
parent 8d62291d77
commit 27e4f75969

View File

@ -107,38 +107,15 @@ else
flavours="${kernel_flavour:-$current_kernel_flavour}"
fi
echo "Checking for installed kernel packages..."
# Rewrite `uname -r's kernelrelease (V-F-R) to package's F-V-R format
tver=${uname_r%%-*}
trel=${uname_r##*-}
tflv=${uname_r#"$tver"-}
tflv=${tflv%-"$trel"}
flavour_version_release=$tflv-$tver-$trel
unset tver trel tflv
echo "For removing:"
for kernel_flavour in $flavours
do
old_kernels="$(rpm -qa | grep -F "kernel-image-$kernel_flavour" | grep -F -w -v "$flavour_version_release" | sort | tr '\n' ' ')"
if [ -n "$all" ] ; then
echo "$kernel_flavour:"
fi
for kernel in $old_kernels
do
if [ "$current_kernel_flavour" = "$kernel_flavour" ] ; then
comparever="$(rpmevrcmp "$current_kernel_package" "$kernel")"
[ "$comparever" -lt 0 ] && continue
else
# check if kernel is latest with given flavour
latest=1
for kernel2 in $old_kernels
do
comparever="$(rpmevrcmp "$kernel" "$kernel2")"
[ "$comparever" -lt 0 ] && latest=0
done
[ "$latest" -eq 1 ] && continue
fi
echo " $kernel"
for kernel_flavour in $flavours; do
# rpmevrcmp is not needed since we don't output epoch
# Output all kernels, sort by a version, skip last (highest version) one,
# then filter out kernels we want to keep (like booted one).
old_kernels="$(rpm -qa "kernel-image-$kernel_flavour" | sort -V | head -n-1)"
for kernel in $old_kernels; do
[ "$kernel" = "$current_kernel_package" ] && continue
echo " $kernel"
apt_args_list="$apt_args_list $(rpm -q --queryformat '%{NAME}=%{EPOCH}:%{VERSION}-%{RELEASE}\n' "$kernel" \
| sed -e "s,(none):,,g")"
done