tools: Fix shellcheck issues in build-static-clh.sh

Address shellcheck warnings including proper variable quoting,
use of [[ ]] over [ ], declaring and assigning variables separately,
and adding appropriate shellcheck disable directives where needed.

Signed-off-by: Fabiano Fidêncio <ffidencio@nvidia.com>
Made-with: Cursor
This commit is contained in:
Fabiano Fidêncio
2026-04-21 18:15:35 +02:00
parent cac4df8263
commit 5267823608

View File

@@ -11,12 +11,13 @@ set -o pipefail
ARCH=$(uname -m)
# Currently, Cloud Hypervisor only support arm64 and x86_64
[ "${ARCH}" != "aarch64" ] && [ "${ARCH}" != "x86_64" ] && exit
[[ "${ARCH}" != "aarch64" ]] && [[ "${ARCH}" != "x86_64" ]] && exit
script_dir=$(dirname $(readlink -f "$0"))
script_dir=$(dirname "$(readlink -f "$0")")
force_build_from_source="${force_build_from_source:-false}"
features="${features:-}"
# shellcheck source=/dev/null
source "${script_dir}/../../scripts/lib.sh"
cloud_hypervisor_repo="${cloud_hypervisor_repo:-}"
@@ -24,30 +25,30 @@ cloud_hypervisor_version="${cloud_hypervisor_version:-}"
cloud_hypervisor_pr="${cloud_hypervisor_pr:-}"
cloud_hypervisor_pull_ref_branch="${cloud_hypervisor_pull_ref_branch:-main}"
if [ -z "$cloud_hypervisor_repo" ]; then
if [[ -z "${cloud_hypervisor_repo}" ]]; then
info "Get cloud_hypervisor information from runtime versions.yaml"
cloud_hypervisor_url=$(get_from_kata_deps ".assets.hypervisor.cloud_hypervisor.url")
[ -n "$cloud_hypervisor_url" ] || die "failed to get cloud_hypervisor url"
[[ -n "${cloud_hypervisor_url}" ]] || die "failed to get cloud_hypervisor url"
cloud_hypervisor_repo="${cloud_hypervisor_url}.git"
fi
[ -n "$cloud_hypervisor_repo" ] || die "failed to get cloud_hypervisor repo"
[[ -n "${cloud_hypervisor_repo}" ]] || die "failed to get cloud_hypervisor repo"
if [ -n "$cloud_hypervisor_pr" ]; then
if [[ -n "${cloud_hypervisor_pr}" ]]; then
force_build_from_source=true
cloud_hypervisor_version="PR $cloud_hypervisor_pr"
cloud_hypervisor_version="PR ${cloud_hypervisor_pr}"
else
[ -n "$cloud_hypervisor_version" ] || cloud_hypervisor_version=$(get_from_kata_deps ".assets.hypervisor.cloud_hypervisor.version")
[ -n "$cloud_hypervisor_version" ] || die "failed to get cloud_hypervisor version"
[[ -n "${cloud_hypervisor_version}" ]] || cloud_hypervisor_version=$(get_from_kata_deps ".assets.hypervisor.cloud_hypervisor.version")
[[ -n "${cloud_hypervisor_version}" ]] || die "failed to get cloud_hypervisor version"
fi
pull_clh_released_binary() {
info "Download cloud-hypervisor version: ${cloud_hypervisor_version}"
cloud_hypervisor_binary="https://github.com/cloud-hypervisor/cloud-hypervisor/releases/download/${cloud_hypervisor_version}/cloud-hypervisor-static"
[ "${ARCH}" == "aarch64" ] && \
[[ "${ARCH}" == "aarch64" ]] && \
cloud_hypervisor_binary="${cloud_hypervisor_binary}-aarch64"
curl --fail -L ${cloud_hypervisor_binary} -o cloud-hypervisor-static || return 1
curl --fail -L "${cloud_hypervisor_binary}" -o cloud-hypervisor-static || return 1
mkdir -p cloud-hypervisor
mv -f cloud-hypervisor-static cloud-hypervisor/cloud-hypervisor
chmod +x cloud-hypervisor/cloud-hypervisor
@@ -61,7 +62,7 @@ build_clh_from_source() {
git clone "${cloud_hypervisor_repo}"
pushd "${repo_dir}"
if [ -n "${cloud_hypervisor_pr}" ]; then
if [[ -n "${cloud_hypervisor_pr}" ]]; then
local pr_branch="PR_${cloud_hypervisor_pr}"
git fetch origin "pull/${cloud_hypervisor_pr}/head:${pr_branch}" || return 1
git checkout "${pr_branch}"
@@ -73,23 +74,24 @@ build_clh_from_source() {
git checkout "${cloud_hypervisor_version}"
fi
if [ -n "${features}" ]; then
# shellcheck disable=SC2154
if [[ -n "${features}" ]]; then
info "Build cloud-hypervisor enabling the following features: ${features}"
./scripts/dev_cli.sh build --release --libc "${libc}" --features "${features}"
else
./scripts/dev_cli.sh build --release --libc "${libc}"
fi
rm -rf cloud-hypervisor
cp build/cargo_target/$(uname -m)-unknown-linux-${libc}/release/cloud-hypervisor .
cp "build/cargo_target/$(uname -m)-unknown-linux-${libc}/release/cloud-hypervisor" .
popd
}
if [ -n "${features}" ]; then
if [[ -n "${features}" ]]; then
info "As an extra build argument has been passed to the script, forcing to build from source"
force_build_from_source="true"
fi
if [ "${force_build_from_source}" == "true" ]; then
if [[ "${force_build_from_source}" == "true" ]]; then
info "Build cloud-hypervisor from source as it's been request via the force_build_from_source flag"
build_clh_from_source
else