remove-old-kernels: check only current flavour (or used with -t) (ALT bug #30717)
remove-old-kernels: do not delete current or newest kernel
This commit is contained in:
parent
edf7f6e6de
commit
027198d2b8
@ -27,13 +27,14 @@ Usage: $PROG [options]
|
|||||||
Valid options are:
|
Valid options are:
|
||||||
-f, --force non-interactive kernel removal (default is interactive)
|
-f, --force non-interactive kernel removal (default is interactive)
|
||||||
-n, --dry-run just simulate removal
|
-n, --dry-run just simulate removal
|
||||||
|
-t, --type remove kernels with specified flavour (ovz-smp, std-def, etc)
|
||||||
-h, --help show this text and exit
|
-h, --help show this text and exit
|
||||||
EOF
|
EOF
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
#parse command line options
|
#parse command line options
|
||||||
TEMP=`getopt -n $PROG -o f,n,h -l force,dry-run,help -- "$@"` || show_help
|
TEMP=`getopt -n $PROG -o f,n,t:,h -l force,dry-run,type:,help -- "$@"` || show_help
|
||||||
eval set -- "$TEMP"
|
eval set -- "$TEMP"
|
||||||
|
|
||||||
while :; do
|
while :; do
|
||||||
@ -44,6 +45,8 @@ while :; do
|
|||||||
;;
|
;;
|
||||||
-n|--dry-run) dryrun="--no-remove"
|
-n|--dry-run) dryrun="--no-remove"
|
||||||
;;
|
;;
|
||||||
|
-t|--type) shift ; kernel_flavour="$1"
|
||||||
|
;;
|
||||||
-h|--help) show_help
|
-h|--help) show_help
|
||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
@ -53,15 +56,39 @@ if [ -n "$force" -a -n "$dryrun" ]; then
|
|||||||
show_usage '--force and --dry-run are mutually exclusive options.'
|
show_usage '--force and --dry-run are mutually exclusive options.'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
flavour_version_release="$(uname -r | awk -F- '{print $2"-"$3"-"$1"-"$4}')"
|
###### copied from update-kernel
|
||||||
old_kernels="$(rpm -qa | fgrep kernel-image | fgrep -v $flavour_version_release | tr '\n' ' ')"
|
# 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}-%{SERIAL}:%{VERSION}-%{RELEASE}\n" -q $current_kernel_package)
|
||||||
|
echo $current_kernel_pkgname | grep -q "(none)" && current_kernel_pkgname=$(rpmquery --queryformat "%{NAME}-%{VERSION}-%{RELEASE}\n" -q $current_kernel_package)
|
||||||
|
else
|
||||||
|
current_kernel_pkgname="UNKNOWN"
|
||||||
|
fi
|
||||||
|
echo "Running kernel version: $current_kernel_pkgname"
|
||||||
|
#######
|
||||||
|
|
||||||
|
# set kernel flavour. if not defined with -t option, use current
|
||||||
|
current_kernel_flavour="$(uname -r | cut -d "-" -f2,3)"
|
||||||
|
kernel_flavour="${kernel_flavour:-$current_kernel_flavour}"
|
||||||
|
|
||||||
|
echo "Checking for installed kernel packages..."
|
||||||
|
flavour_version_release="$(uname -r | awk -F- '{print $2"-"$3"-"$1"-"$4}')"
|
||||||
|
old_kernels="$(rpm -qa | fgrep kernel-image-$kernel_flavour | fgrep -v $flavour_version_release | sort | tr '\n' ' ')"
|
||||||
|
|
||||||
|
echo "For removing:"
|
||||||
# calculate arguments for apt
|
# calculate arguments for apt
|
||||||
for kernel in $old_kernels
|
for kernel in $old_kernels
|
||||||
do
|
do
|
||||||
|
if [ "$current_kernel_flavour" = "$kernel_flavour" ] ; then
|
||||||
|
comparever="$(rpmevrcmp "$current_kernel_package" "$kernel")"
|
||||||
|
[ "$comparever" -lt 0 ] && 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
|
||||||
|
echo
|
||||||
|
|
||||||
# use sudo(1) if running as unprivileged user
|
# use sudo(1) if running as unprivileged user
|
||||||
[ "$UID" = "0" ] && SUDO= || SUDO=sudo
|
[ "$UID" = "0" ] && SUDO= || SUDO=sudo
|
||||||
|
Loading…
Reference in New Issue
Block a user