remove-old-kernels: Better show to user what is happing
Also show what is not deleted and why. So user see decision about all the kernels in the system. Signed-off-by: Vitaly Chikunov <vt@altlinux.org>
This commit is contained in:
parent
27e4f75969
commit
7d47e9beb8
@ -85,13 +85,15 @@ else
|
||||
V() { "$@"; }
|
||||
fi
|
||||
|
||||
cr=$'\n'
|
||||
|
||||
uname_r=$(uname -r)
|
||||
|
||||
# get running kernel version
|
||||
current_kernel_package=$(rpmquery -qf "/lib/modules/$uname_r/kernel" 2>/dev/null)
|
||||
if [ -n "$current_kernel_package" ] ; then
|
||||
current_kernel_pkgname=$(rpmquery --queryformat "%{NAME}-%{VERSION}-%{RELEASE}\n" -q "$current_kernel_package")
|
||||
echo "Running kernel package: $current_kernel_pkgname (keeping)"
|
||||
echo "Currently booted kernel package: $current_kernel_pkgname"
|
||||
unset current_kernel_pkgname
|
||||
else
|
||||
echo "Running kernel version: $uname_r (package not found)"
|
||||
@ -107,20 +109,32 @@ else
|
||||
flavours="${kernel_flavour:-$current_kernel_flavour}"
|
||||
fi
|
||||
|
||||
echo "For removing:"
|
||||
# Sort the kernels
|
||||
keep_kernels=
|
||||
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")"
|
||||
all_kernels="$(rpm -qa "kernel-image-$kernel_flavour" | sort -V)"
|
||||
newest_kernel=$(echo "$all_kernels" | tail -1)
|
||||
for kernel in $all_kernels; do
|
||||
reason=
|
||||
if [ "$kernel" = "$newest_kernel" ]; then
|
||||
reason="$reason,latest for $kernel_flavour"
|
||||
fi
|
||||
if [ "$kernel" = "$current_kernel_package" ]; then
|
||||
reason="$reason,currently booted"
|
||||
fi
|
||||
if [ -n "$reason" ]; then
|
||||
keep_kernels="$keep_kernels $kernel (${reason#,})$cr"
|
||||
else
|
||||
remove_kernels="$remove_kernels $kernel$cr"
|
||||
apt_args_list="$apt_args_list $(rpm -q --queryformat '%{NAME}=%{EPOCH}:%{VERSION}-%{RELEASE}\n' "$kernel" \
|
||||
| sed -e "s,(none):,,g")"
|
||||
fi
|
||||
done
|
||||
done
|
||||
echo
|
||||
echo "Not removing these kernels (reason why keeping):"
|
||||
echo "$keep_kernels"
|
||||
echo "Removing these kernels:"
|
||||
echo "$remove_kernels"
|
||||
|
||||
if [ -z "$apt_args_list" ] ; then
|
||||
echo "Nothing to remove."
|
||||
|
Loading…
Reference in New Issue
Block a user