From e30dd56d4a95fa94367f659ab0f4935b50c86ab9 Mon Sep 17 00:00:00 2001 From: jarppiko <23549925+jarppiko@users.noreply.github.com> Date: Wed, 25 May 2022 20:46:03 +0300 Subject: [PATCH 1/5] Add support for version filtering --- ubuntu-mainline-kernel.sh | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/ubuntu-mainline-kernel.sh b/ubuntu-mainline-kernel.sh index 3286ca1..6efac17 100755 --- a/ubuntu-mainline-kernel.sh +++ b/ubuntu-mainline-kernel.sh @@ -274,6 +274,14 @@ containsElement () { return 1 } +filterArray () { + local filter=$1 + shift + local -a all=( "$@" ) + local -a filtered=($(printf '%s\n' "${all[@]}" | grep "v${filter#v}")) + echo "${filtered[@]}" +} + download () { host=$1 uri=$2 @@ -581,14 +589,23 @@ Optional: version="v"${action_data[0]#v} fi + if [ -z "$version" ]; then + FILTERED_VERSIONS=($(filterArray "v${action_data[0]#v}" "${REMOTE_VERSIONS[@]}")) + version="${FILTERED_VERSIONS[-1]}" + fi + [[ -z "$version" ]] && { err "Version '${action_data[0]}' not found" exit 2 } shift - if [ $do_install -gt 0 ] && containsElement "$version" "${LOCAL_VERSIONS[@]}" && [ $assume_yes -eq 0 ]; then - logn "It seems version $version is already installed, continue? (y/N) " + if [ $do_install -gt 0 ] && [ $assume_yes -eq 0 ]; then + if containsElement "$version" "${LOCAL_VERSIONS[@]}"; then + logn "It seems version $version is already installed, continue? (y/N) " + else + logn "Installing version $version, continue? (y/N) " + fi [ $quiet -eq 0 ] && read -rsn1 continue log From 4c315c2ea0f462517f743c2caf677ed6732219e4 Mon Sep 17 00:00:00 2001 From: jarppiko <23549925+jarppiko@users.noreply.github.com> Date: Wed, 25 May 2022 20:55:35 +0300 Subject: [PATCH 2/5] Update README.md Mention support for version filtering. E.g. `-i v5.17` will install the latest v5.17.x kernel --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 19c021b..1eacc03 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,9 @@ Arguments: -c Check if a newer kernel version is available -i [VERSION] Install kernel VERSION, see -l for list. You don't have to prefix with v. E.g. -i 4.9 is the same as -i v4.9. If version is - omitted the latest available version will be installed + omitted the latest available version will be installed. Supports + version filtering. E.g. -i v.5.17 will install the latest v5.17.x + kernel. -l [SEARCH] List locally installedkernel versions. If an argument to this option is supplied it will search for that -r [SEARCH] List available kernel versions. If an argument to this option From a056990d0616c3a83cb65d455bbe4b0d732a2809 Mon Sep 17 00:00:00 2001 From: jarppiko <23549925+jarppiko@users.noreply.github.com> Date: Wed, 8 Jun 2022 16:41:33 +0300 Subject: [PATCH 3/5] Fix error when no versions matching filter specified is found --- ubuntu-mainline-kernel.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ubuntu-mainline-kernel.sh b/ubuntu-mainline-kernel.sh index 6efac17..c8cb62e 100755 --- a/ubuntu-mainline-kernel.sh +++ b/ubuntu-mainline-kernel.sh @@ -591,6 +591,10 @@ Optional: if [ -z "$version" ]; then FILTERED_VERSIONS=($(filterArray "v${action_data[0]#v}" "${REMOTE_VERSIONS[@]}")) + if [ ${#FILTERED_VERSIONS[@]} -eq 0 ]; then + err "No versions found matching filter: v${action_data[0]#v}" + exit 3 + fi version="${FILTERED_VERSIONS[-1]}" fi From ae287a1dc5139946aed556456d96031bf1bfea3e Mon Sep 17 00:00:00 2001 From: jarppiko <23549925+jarppiko@users.noreply.github.com> Date: Thu, 30 Jun 2022 21:48:05 +0300 Subject: [PATCH 4/5] -c version filter --- ubuntu-mainline-kernel.sh | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/ubuntu-mainline-kernel.sh b/ubuntu-mainline-kernel.sh index c8cb62e..141a6f0 100755 --- a/ubuntu-mainline-kernel.sh +++ b/ubuntu-mainline-kernel.sh @@ -145,6 +145,7 @@ while (( "$#" )); do -c|--check) single_action run_action="check" + argarg_required=1 ;; -l|--local-list) single_action @@ -415,7 +416,7 @@ load_remote_versions () { [[ $use_rc -eq 0 ]] && continue line="${BASH_REMATCH[1]}-${BASH_REMATCH[2]}" fi - [[ -n "$2" ]] && [[ ! "$line" =~ $2 ]] && continue + [[ -n "$2" ]] && [[ ! "$line" =~ "$2" ]] && continue REMOTE_VERSIONS+=("$line") done < <(parse_remote_versions | sort -V) unset IFS @@ -482,9 +483,17 @@ Optional: check) check_environment - logn "Finding latest version available on $ppa_host" - latest_version=$(latest_remote_version) - log ": $latest_version" + if [ -z "${action_data[0]}" ]; then + logn "Finding latest version available on $ppa_host" + latest_version=$(latest_remote_version) + log ": $latest_version" + else + version_filter="v"${action_data[0]#v} + logn "Finding latest version matching '${version_filter}' available on $ppa_host" + latest_version=$(latest_remote_version "${version_filter}") + log ": $latest_version" + + fi logn "Finding latest installed version" installed_version=$(latest_local_version) From b97057805f473f3884282fce3c9c28d435bd1939 Mon Sep 17 00:00:00 2001 From: jarppiko <23549925+jarppiko@users.noreply.github.com> Date: Thu, 30 Jun 2022 21:53:24 +0300 Subject: [PATCH 5/5] -c version filter: update help --- ubuntu-mainline-kernel.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ubuntu-mainline-kernel.sh b/ubuntu-mainline-kernel.sh index 141a6f0..e0375de 100755 --- a/ubuntu-mainline-kernel.sh +++ b/ubuntu-mainline-kernel.sh @@ -450,7 +450,7 @@ case $run_action in Download & install the latest kernel available from $ppa_host$ppa_uri Arguments: - -c Check if a newer kernel version is available + -c [VERSION] Check if a newer kernel version is available. Optional VERSION filter -i [VERSION] Install kernel VERSION, see -l for list. You don't have to prefix with v. E.g. -i 4.9 is the same as -i v4.9. If version is omitted the latest available version will be installed