update-kernel: Fix and improve -r logic
- Allow setting release in old (backward compatibility) format (release or version-release). This was broken since `@buildtime' is added (few years ago) to the `apt-cache pkgnames' output. Then it did not become better when `:disttag' is added to the output recently. - Allow setting release in `uname -r' compatible format: version-flavour-release. - Allow setting release in package name format, RPM style: [kernel-image-]flavour-[epoch:]version-release or APT style: [kernel-image-]flavour=[epoch:]version-release, [kernel-image-]flavour#[epoch:]version-release. This is for future `--list' option. Fixes: Bug#39041.
This commit is contained in:
@ -34,7 +34,10 @@ Valid options are:
|
||||
-i, --interactive interactive modules install
|
||||
-f, -y, --force force kernel upgrade
|
||||
-t, --type install kernel with specified flavour (ovz-smp, std-def, etc)
|
||||
-r, --release install kernel with specified release (alt10, alt22, etc)
|
||||
-r, --release desired kernel release (allowed formats by example:
|
||||
old format: alt1, 5.7.19-alt1
|
||||
classic kernel release: 5.7.19-std-def-alt1
|
||||
package name: [kernel-image-]std-def-5.7.19-alt1)
|
||||
-n, --dry-run download packages, but don't install (--download-only)
|
||||
-h, --help show this text and exit
|
||||
EOF
|
||||
@ -103,10 +106,30 @@ else
|
||||
fi
|
||||
echo "Running kernel version: $current_kernel_pkgname"
|
||||
|
||||
|
||||
echo "Checking for available kernel packages..."
|
||||
# get list of all available kernel packages
|
||||
KERNEL_PKGS="$(apt-cache pkgnames kernel-image)"
|
||||
if [[ "$release" =~ ^[0-9]+\.[0-9.]+-.*-[^-]+$ ]]; then
|
||||
# Rewrite release in `uname -r` compatible 'kernel release' format
|
||||
ver="${release%-*}"
|
||||
flv="${ver#*-}"
|
||||
ver="${ver%%-*}"
|
||||
rel="${release##*-}"
|
||||
if [ -n "$kernel_flavour" ] && [ "$kernel_flavour" != "$flv" ]; then
|
||||
fatal "Kernel flavour from '-t $kernel_flavour' does not match flavour from '-r' ($flv)."
|
||||
fi
|
||||
kernel_flavour="$flv"
|
||||
release="$ver-$rel"
|
||||
ver= flv= rel=
|
||||
elif [[ "$release" =~ ^(kernel-image-)?.*[-=#][0-9:]+\.[0-9.]+-[^-]+$ ]]; then
|
||||
# Rewrite release in RPM, APT package format
|
||||
ver="${release#kernel-image-}"
|
||||
flv="${ver%[-=#]*-*}"
|
||||
rel="${ver#$flv[-=#]}"
|
||||
if [ -n "$kernel_flavour" ] && [ "$kernel_flavour" != "$flv" ]; then
|
||||
fatal "Kernel flavour from '-t $kernel_flavour' does not match flavour from '-r' ($flv)."
|
||||
fi
|
||||
kernel_flavour="$flv"
|
||||
release="$rel"
|
||||
ver= flv= rel=
|
||||
fi
|
||||
|
||||
# set kernel flavour. if not defined with -t option, use current
|
||||
current_kernel_flavour="$(uname -r)"
|
||||
@ -114,6 +137,10 @@ current_kernel_flavour="${current_kernel_flavour#*-}"
|
||||
current_kernel_flavour="${current_kernel_flavour%-*}"
|
||||
kernel_flavour="${kernel_flavour:-$current_kernel_flavour}"
|
||||
|
||||
echo "Checking for available $kernel_flavour kernel packages..."
|
||||
# get list of all available kernel packages
|
||||
KERNEL_PKGS="$(apt-cache pkgnames "kernel-image-$kernel_flavour#" | sort -V)"
|
||||
|
||||
# check that we have at least one kernel with defined kernel_flavour
|
||||
num_available_kernels="$(echo "$KERNEL_PKGS" | grep -c "$kernel_flavour")"
|
||||
[ "$num_available_kernels" != 0 ] || fatal "There are no available kernels with kernel flavour $kernel_flavour"
|
||||
@ -121,11 +148,11 @@ num_available_kernels="$(echo "$KERNEL_PKGS" | grep -c "$kernel_flavour")"
|
||||
# check that we have at least one kernel with defined kernel package release
|
||||
[ -z "$release" ] || {
|
||||
num_available_kernels="$(echo "$KERNEL_PKGS" | grep -c "$release")"
|
||||
[ "$num_available_kernels" != 0 ] || fatal "There are no available kernels with package release $release"
|
||||
[ "$num_available_kernels" != 0 ] || fatal "There are no available $kernel_flavour kernels with package release $release"
|
||||
}
|
||||
|
||||
# define how we must select available packages with needed flavour/release
|
||||
[ -z "$release" ] && pgkgrep="kernel-image-$kernel_flavour#" || pgkgrep="kernel-image-$kernel_flavour#.*$release$"
|
||||
[ -z "$release" ] && pgkgrep="kernel-image-$kernel_flavour#" || pgkgrep="kernel-image-$kernel_flavour#.*\b${release//./\\.}\([@:]\|\$\)"
|
||||
|
||||
# get the maximum available kernel package version
|
||||
kmaxver=
|
||||
|
Reference in New Issue
Block a user