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:
parent
8d62291d77
commit
27e4f75969
@ -107,38 +107,15 @@ else
|
|||||||
flavours="${kernel_flavour:-$current_kernel_flavour}"
|
flavours="${kernel_flavour:-$current_kernel_flavour}"
|
||||||
fi
|
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:"
|
echo "For removing:"
|
||||||
for kernel_flavour in $flavours
|
for kernel_flavour in $flavours; do
|
||||||
do
|
# rpmevrcmp is not needed since we don't output epoch
|
||||||
old_kernels="$(rpm -qa | grep -F "kernel-image-$kernel_flavour" | grep -F -w -v "$flavour_version_release" | sort | tr '\n' ' ')"
|
# Output all kernels, sort by a version, skip last (highest version) one,
|
||||||
if [ -n "$all" ] ; then
|
# then filter out kernels we want to keep (like booted one).
|
||||||
echo "$kernel_flavour:"
|
old_kernels="$(rpm -qa "kernel-image-$kernel_flavour" | sort -V | head -n-1)"
|
||||||
fi
|
for kernel in $old_kernels; do
|
||||||
for kernel in $old_kernels
|
[ "$kernel" = "$current_kernel_package" ] && continue
|
||||||
do
|
echo " $kernel"
|
||||||
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"
|
|
||||||
apt_args_list="$apt_args_list $(rpm -q --queryformat '%{NAME}=%{EPOCH}:%{VERSION}-%{RELEASE}\n' "$kernel" \
|
apt_args_list="$apt_args_list $(rpm -q --queryformat '%{NAME}=%{EPOCH}:%{VERSION}-%{RELEASE}\n' "$kernel" \
|
||||||
| sed -e "s,(none):,,g")"
|
| sed -e "s,(none):,,g")"
|
||||||
done
|
done
|
||||||
|
Loading…
x
Reference in New Issue
Block a user