scripts: Fix ShellCheck diagnostics

Quote scalar arguments and use arrays for command option lists so paths
and options retain their boundaries. Preserve intentional version-field
splitting with narrow documented suppressions.

Also handle GNU getopt output without losing quoted arguments and
remove warnings about masked statuses, unused values and ambiguous test
expressions.
This commit is contained in:
Gleb Chesnokov
2026-08-21 19:58:59 +03:00
parent 055865e734
commit f788bfd0d6
4 changed files with 111 additions and 68 deletions
+18 -14
View File
@@ -84,9 +84,10 @@ function download_file {
# Make sure the kernel tarball and patch file are present in directory
# ${kernel_downloads}. Download any missing files from ${kernel_mirror}.
function download_kernel {
local kver="$(kernel_version "$1")"
local plevel="$(patchlevel "$1")"
local series="$1"
local kver plevel series="$1"
kver="$(kernel_version "$1")"
plevel="$(patchlevel "$1")"
series="${series/.*/}.x"
@@ -108,9 +109,10 @@ function download_kernel {
}
function extract_kernel_archive {
local kver="$(kernel_version "$1")"
local plevel="$(patchlevel "$1")"
local series="$1"
local kver plevel series="$1"
kver="$(kernel_version "$1")"
plevel="$(patchlevel "$1")"
if [ -e "${kernel_downloads}/linux-$1.tar.xz" ]; then
( set -o pipefail
@@ -134,10 +136,12 @@ function extract_kernel_archive {
# Create a linux-$1 tree in the current directory, where $1 is a kernel
# version number with either three or four components.
function extract_kernel_tree {
local kver="$(kernel_version "$1")"
local plevel="$(patchlevel "$1")"
local kver plevel
local tmpdir=kernel-tree-tmp-$$
kver="$(kernel_version "$1")"
plevel="$(patchlevel "$1")"
rm -rf "linux-$1" "${tmpdir}"
mkdir "${tmpdir}" || return $?
(
@@ -702,11 +706,9 @@ EOF
# After patch-v4.14.1[12] has been applied, the execute bit has to be
# set for sync-check.sh since patch can't do that.
for f in "tools/objtool/sync-check.sh"; do
if [ -e "$f" ]; then
chmod a+x "$f"
fi
done
if [ -e "tools/objtool/sync-check.sh" ]; then
chmod a+x "tools/objtool/sync-check.sh"
fi
}
function rpm_payload_is_readable {
@@ -770,7 +772,9 @@ function extract_rhel_kernel_archive {
}
function download_and_extract_distro_rpm {
[ -n "$1" ] || return $?
[ -n "$1" ] || return 1
# Split the kernel^distro^release triplet into positional parameters.
# shellcheck disable=SC2086
set -- ${1//^/ }
local kver=$1
local distro=$2