Vitaly Chikunov
a209e33861
Currently, 'latest' will select flavour with the highest kernel version, excluding release candidate kernels. Q: Aren't there is ambiguity? Is 6.10.0 a stable kernel or a mainline kernel? A: Yes. 'After each mainline kernel is released, it is considered "stable."'[1] 6.10 is marked 'mainline' or kernel.org page, and there is never 6.10.0 release in any (stable or mainline) tree. Link: https://kernel.org/category/releases.html Signed-off-by: Vitaly Chikunov <vt@altlinux.org>
57 lines
1.7 KiB
Bash
57 lines
1.7 KiB
Bash
# bash completion for update-kernel -*- shell-script -*-
|
|
# shellcheck disable=SC2207,SC2155
|
|
|
|
__update_kernel_flavours()
|
|
{
|
|
{
|
|
echo latest
|
|
apt-cache pkgnames 'kernel-image-' |
|
|
LC_ALL=C grep -Eo '^[^#]+' |
|
|
LC_ALL=C sed -E 's/^kernel-image-(domU-)?//;s/-(checkinstall|debuginfo)$//'
|
|
} | LC_ALL=C sort -u
|
|
}
|
|
|
|
_update_kernel()
|
|
{
|
|
# shellcheck disable=SC2034
|
|
local cur prev words cword
|
|
_init_completion || return
|
|
|
|
local cmd=${1##*/}
|
|
|
|
case $prev in
|
|
-t | --type)
|
|
# shellcheck disable=SC2034
|
|
local flavours=$(__update_kernel_flavours)
|
|
COMPREPLY=( $(compgen -W "\$flavours" -- "$cur") )
|
|
return
|
|
;;
|
|
-A)
|
|
return
|
|
;;
|
|
-r | --release)
|
|
return
|
|
;;
|
|
esac
|
|
|
|
if [[ $cur == -* ]]; then
|
|
local script="/usr/sbin/$cmd"
|
|
|
|
if [ -f "$script" ]; then
|
|
local short=$(LC_ALL=C grep -oP 'getopt.*-o \K[^\s]+' "$script" | LC_ALL=C sed -E 's/://g; s/(^|,)/\n-/g')
|
|
local long=$(LC_ALL=C grep -oP 'getopt.*-l \K[^\s]+' "$script" | LC_ALL=C sed -E 's/://g; s/(^|,)/\n--/g')
|
|
# shellcheck disable=SC2034
|
|
local opts=$(LC_ALL=C printf '%s' "$short" "$long" | LC_ALL=C sort)
|
|
COMPREPLY=( $(compgen -W "\$opts" -- "$cur") )
|
|
else
|
|
# Fallback to a buggy `_parse_help` which misses some short options.
|
|
# https://github.com/scop/bash-completion/issues/831
|
|
COMPREPLY=( $(compgen -W "\$(_parse_help $1)" -- "$cur") )
|
|
fi
|
|
fi
|
|
|
|
} &&
|
|
complete -F _update_kernel update-kernel remove-old-kernels debuginfo-kernel-install
|
|
|
|
# ex: filetype=sh sw=4 et
|