Skip to content

Commit a795ec9

Browse files
authored
Shell check test (#153)
1 parent 5435a74 commit a795ec9

File tree

8 files changed

+60
-54
lines changed

8 files changed

+60
-54
lines changed

standalone-node/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ all:
4141
configure:
4242

4343
#lint: license yamllint mdlint shellcheck #uncomment this line and remove next line after shellcheck is fixed
44-
lint: license yamllint mdlint
44+
lint: license shellcheck yamllint mdlint
4545

4646
build: configure
4747
@# Help: Runs build stage

standalone-node/installation_scripts/bootable-usb-prepare.sh

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ fi
113113
# Ask the password from cmd line
114114
echo -n "Please Set the Password for $user_name: "
115115
stty -echo
116-
read password
116+
read -r password
117117
stty echo
118118
echo
119119

@@ -123,16 +123,15 @@ chmod 600 "$(pwd)/.psswd"
123123

124124
# Validate the custom-cloud-init section
125125
if ! dpkg -s python3 > /dev/null 2>&1; then
126-
apt install -y python3 > /dev/null 2>&1
127-
if [ "$?" -ne 0 ]; then
126+
if ! apt install -y python3 > /dev/null 2>&1; then
128127
echo "Pyhon installation failed,please check!!"
129128
fi
130129
fi
131130
CONFIG_FILE="config-file"
132131
START_MARKER="^services:"
133132

134133
# Extract YAML content from custom cloud-init-section
135-
# if any error,throw the erros
134+
# if any error,throw the errors
136135
YAML_CONTENT=$(awk "/$START_MARKER/ {found=1} found" "$CONFIG_FILE")
137136

138137
# Validate using Python
@@ -154,14 +153,15 @@ try:
154153
print(f"Invalid runcmd item: {item!r}")
155154
sys.exit(1)
156155
else:
157-
print("")
156+
print("")
158157
except yaml.YAMLError as e:
159158
print("Custom cloud-init YAML is invalid:\n", e)
160159
sys.exit(1)
161160
'
162161
# Catch the Error
162+
# shellcheck disable=SC2181
163163
if [ "$?" -ne 0 ]; then
164-
echo "Custome cloud-init file is not valiad,Please check!!"
164+
echo "Custom cloud-init file is not valid,Please check!!"
165165
exit 1
166166
fi
167167

@@ -340,7 +340,7 @@ copy_files() {
340340
echo "Custom files copied!"
341341
fi
342342
# Remove the hidden password file
343-
rm -rf $(pwd)/.psswd
343+
rm -rf "$(pwd)/.psswd"
344344
}
345345
copy_user_apps() {
346346
echo "Copying user-apps to USB device..."
@@ -350,23 +350,21 @@ copy_user_apps() {
350350
USER_APPS_PART="p$USER_APPS_PART"
351351
fi
352352
check_mnt_mount_exist
353-
mount ${USB_DEVICE}${USER_APPS_PART} /mnt
353+
mount "${USB_DEVICE}${USER_APPS_PART}" /mnt
354354
# Use rsync for fater copr
355-
if dpkg -s rsync; then
356-
rsync -ah --inplace user-apps /mnt/
357-
if [ "$?" -eq 0 ]; then
355+
if dpkg -s rsync; then
356+
if rsync -ah --inplace user-apps /mnt/; then
358357
echo "user-apps data copied successfully"
359358
else
360-
echo "user-apps data failes to copy please check!!"
359+
echo "user-apps data fails to copy please check!!"
361360
umount /mnt
362361
exit 1
363362
fi
364-
else
365-
cp -r user-apps /mnt
366-
if [ "$?" -eq 0 ]; then
363+
else
364+
if cp -r user-apps /mnt; then
367365
echo "user-apps data copied successfully"
368366
else
369-
echo "user-apps data failes to copy please check!!"
367+
echo "user-apps data fails to copy please check!!"
370368
umount /mnt
371369
exit 1
372370
fi

standalone-node/installation_scripts/download_images.sh

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ manifests=(
6565
download_k3s_artifacts () {
6666
echo "Downloading k3s artifacts"
6767
mkdir -p ${OUT_DIR}/${ARTIFACT_DIR}
68-
cd ${OUT_DIR}/${ARTIFACT_DIR}
68+
cd ${OUT_DIR}/${ARTIFACT_DIR} || exit
6969
curl -OLs https://github.com/k3s-io/k3s/releases/download/v1.32.4%2Bk3s1/sha256sum-amd64.txt
7070
curl -sfL https://get.k3s.io --output install.sh
7171
curl -OLs https://github.com/k3s-io/k3s/releases/download/v1.32.4%2Bk3s1/k3s
@@ -76,18 +76,19 @@ download_k3s_artifacts () {
7676
download_airgap_images () {
7777
echo "Downloading kubernetes container images"
7878
mkdir -p ${OUT_DIR}/${IMG_DIR}
79-
cd ${OUT_DIR}/${IMG_DIR} && curl -OLs https://github.com/k3s-io/k3s/releases/download/v1.32.4%2Bk3s1/k3s-airgap-images-amd64.tar.zst && cd ../../
79+
cd ${OUT_DIR}/${IMG_DIR} || exit
80+
curl -OLs https://github.com/k3s-io/k3s/releases/download/v1.32.4%2Bk3s1/k3s-airgap-images-amd64.tar.zst
81+
cd ../../
8082
}
8183

8284
# Download extension manifests
8385
download_extension_manifests () {
8486
echo "Downloading addons manifests"
8587
mkdir -p ${OUT_DIR}/${MANIFEST_DIR}
86-
cd ${OUT_DIR}/${MANIFEST_DIR}
88+
cd ${OUT_DIR}/${MANIFEST_DIR} || exit
8789
for manifest in "${manifests[@]}" ; do
8890
name=$(basename "${manifest}")
89-
curl -OLs "${manifest}" -o "${OUT_DIR}/${MANIFEST_DIR}/${name}"
90-
if [ $? -ne 0 ]; then
91+
if ! curl -OLs "${manifest}" -o "${OUT_DIR}/${MANIFEST_DIR}/${name}"; then
9192
echo "Failed to download ${name}"
9293
exit 1
9394
fi
@@ -105,32 +106,32 @@ download_extension_images () {
105106
mkdir -p ${OUT_DIR}/${IMG_DIR}
106107
for image in "${images[@]}" ; do
107108
## check if image exists already in podman
108-
if docker image inspect ${image} > /dev/null 2>&1; then
109+
if docker image inspect "${image}" > /dev/null 2>&1; then
109110
echo "Image ${image} already exists, skipping download"
110111
else
111-
docker pull ${image}
112+
docker pull "${image}"
112113
fi
113-
img_name=$(echo ${image##*/} | tr ':' '-')
114+
img_name=$(echo "${image##*/}" | tr ':' '-')
114115
DEST=${OUT_DIR}/${IMG_DIR}/${TAR_PRX}-${img_name}.${TAR_SFX}
115-
docker save -o ${DEST}.tmp ${image}
116+
docker save -o "${DEST}.tmp" "${image}"
116117
# Create temp dirs for processing
117118
mkdir -p /tmp/image_repacking/{manifest,content}
118119

119120
# Extract only manifest.json and repositories first
120-
tar -xf ${DEST}.tmp -C /tmp/image_repacking/manifest manifest.json repositories 2>/dev/null
121+
tar -xf "${DEST}.tmp" -C /tmp/image_repacking/manifest manifest.json repositories 2>/dev/null
121122

122123
# Create initial tar with just the manifest files
123-
tar -cf ${DEST} -C /tmp/image_repacking/manifest .
124+
tar -cf "${DEST}" -C /tmp/image_repacking/manifest .
124125

125126
# Extract all remaining files (excluding manifest.json and repositories)
126-
tar -xf ${DEST}.tmp --exclude="manifest.json" --exclude="repositories" -C /tmp/image_repacking/content
127+
tar -xf "${DEST}.tmp" --exclude="manifest.json" --exclude="repositories" -C /tmp/image_repacking/content
127128

128129
# Append all other files to tar
129-
tar -rf ${DEST} -C /tmp/image_repacking/content .
130+
tar -rf "${DEST}" -C /tmp/image_repacking/content .
130131

131132
# Clean up
132133
rm -rf /tmp/image_repacking
133-
rm -f ${DEST}.tmp
134+
rm -f "${DEST}.tmp"
134135
done
135136
}
136137

@@ -139,7 +140,7 @@ download_idv_kubevirt_images_and_manifests () {
139140
echo "Downloading idv kubevirt artifacts"
140141
# download the artifacts
141142
mkdir -p ${OUT_DIR}/${ARTIFACT_DIR}
142-
cd ${OUT_DIR}/${ARTIFACT_DIR}
143+
cd ${OUT_DIR}/${ARTIFACT_DIR} || exit
143144
curl -OLs https://github.com/open-edge-platform/edge-desktop-virtualization/releases/download/1.0.0-rc2/intel-idv-kubevirt-1.0.0-rc2.tar.gz
144145
# untar
145146
tar -xzf intel-idv-kubevirt-1.0.0-rc2.tar.gz -C .
@@ -159,7 +160,7 @@ download_idv_device_plugins_images_and_manifests () {
159160
echo "Downloading idv device plugin artifacts"
160161
# download the artifacts
161162
mkdir -p ${OUT_DIR}/${ARTIFACT_DIR}
162-
cd ${OUT_DIR}/${ARTIFACT_DIR}
163+
cd ${OUT_DIR}/${ARTIFACT_DIR} || exit
163164
curl -OLs https://github.com/open-edge-platform/edge-desktop-virtualization/releases/download/1.0.0-rc2/intel-idv-device-plugin-1.0.0-rc2.tar.gz
164165
# untar
165166
tar -xzf intel-idv-device-plugin-1.0.0-rc2.tar.gz -C .
@@ -184,7 +185,7 @@ install_pkgs () {
184185
if [ "${BINARY_INSTALL}" = true ]; then
185186
download_k3s_artifacts
186187
fi
187-
if [ "${ARIGAP}" = true ]; then
188+
if [ "${AIRGAP}" = true ]; then
188189
download_airgap_images
189190
fi
190191
if [ "${IDV_EXTENSIONS}" = true ]; then

standalone-node/installation_scripts/standalone-vm-setup.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ deploy_mode=$(grep '^deploy_envmt=' "$CONFIG_FILE" | cut -d '=' -f2)
2525
deploy_mode=$(echo "$deploy_mode" | tr -d '"')
2626

2727
if [ "$deploy_mode" != "ven" ]; then
28-
echo "Please Make sure update the deploy_envmt="ven" in config-file"
28+
echo 'Please Make sure update the deploy_envmt="ven" in config-file'
2929
exit 1
3030
fi
3131

@@ -42,8 +42,7 @@ fi
4242
if ! dpkg -s qemu-system-x86 >/dev/null 2>&1; then
4343
echo "Installing qemu-system-x86.., Please Wait!!"
4444
apt update
45-
apt install -y qemu-system-x86 >/dev/null 2>&1
46-
if [ "$?" -ne 0 ]; then
45+
if ! apt install -y qemu-system-x86 >/dev/null 2>&1; then
4746
echo "Qemu Installation Failed,Please check!!"
4847
exit 1
4948
fi
@@ -82,10 +81,11 @@ fi
8281
./bootable-usb-prepare.sh /dev/nbd0 usb-bootable-files.tar.gz config-file || { echo "USB device setup failed,please check"; exit 1; }
8382

8483
# Copy the new image if its provided
84+
# shellcheck disable=SC2236
8585
if [ ! -z "$new_img" ]; then
8686
mount /dev/nbd0p5 /mnt
87+
# shellcheck disable=SC2115
8788
rm -rf /mnt/*
88-
cp $new_img /mnt
8989
cp "$new_img" /mnt
9090
umount /mnt
9191
sync
@@ -103,6 +103,7 @@ echo "Starting the Installation"
103103
echo ""
104104
echo "Please see the installation status on VNC viewer.Enter $host_ip:1 on vnc viewer"
105105
# Added -cpu host,+vms It will support nested VM configuration as well
106+
# shellcheck disable=SC2115
106107
sudo -E qemu-system-x86_64 \
107108
-m 4G -enable-kvm \
108109
-cpu host,+vmx \
@@ -115,7 +116,7 @@ sudo -E qemu-system-x86_64 \
115116
-drive file=/dev/nbd0,format=raw,id=usb,if=none \
116117
-netdev user,id=net0,hostfwd=tcp::2222-:22 \
117118
-device e1000,netdev=net0
118-
119+
# shellcheck disable=SC2181
119120
if [ "$?" -ne 0 ]; then
120121
echo "Intallation VM launch Failed,Please check!!"
121122
fi

standalone-node/installation_scripts/write-image-to-usb.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ fi
4040
# Function to wipe filesystem signatures
4141
wipe_partition() {
4242
# Check existing filesystem signatures
43-
echo "Checking existing filesystem signatures on "$USB_DEVICE"..."
43+
echo "Checking existing filesystem signatures on $USB_DEVICE..."
4444
wipefs --all --no-act "$USB_DEVICE"
4545

4646
# Prompt user for confirmation
47-
read -p "Do you want to wipe all filesystem signatures from "$USB_DEVICE"? (yes/no): " user_input
47+
read -rp "Do you want to wipe all filesystem signatures from $USB_DEVICE? (yes/no): " user_input
4848

4949
if [[ "$user_input" == "yes" ]]; then
5050
# Wipe filesystem signatures
51-
echo "Wiping filesystem signatures from "$USB_DEVICE"..."
51+
echo "Wiping filesystem signatures from $USB_DEVICE..."
5252
wipefs --all "$USB_DEVICE" || {
5353
echo "Error: Failed to wipe filesystem signatures from $USB_DEVICE"
5454
exit 1
@@ -83,7 +83,7 @@ wipe_partition
8383

8484
# Check for blockdev partprobe and ensure they are installed
8585
for cmd in blockdev partprobe; do
86-
if ! command -v $cmd &> /dev/null; then
86+
if ! command -v "$cmd" &> /dev/null; then
8787
echo "Error: $cmd is not installed. Please install it before proceeding."
8888
exit 1
8989
fi
@@ -93,7 +93,7 @@ sgdisk -e "$USB_DEVICE" >/dev/null 2>&1
9393
blockdev --rereadpt "${USB_DEVICE}"
9494

9595
# Create a new partition table
96-
echo "Creating a new parition table on "${USB_DEVICE}" "
96+
echo "Creating a new partition table on $USB_DEVICE"
9797
create_partition() {
9898
local start=$1
9999
local end=$2
@@ -128,17 +128,17 @@ copy_to_partition() {
128128
while [ $attempt -lt $retries ]; do
129129
if mount "${USB_DEVICE}${part}" "$mount_dir" && rsync --progress "$src" "$mount_dir"; then
130130
if umount "$mount_dir"; then
131-
echo "Successfully copied $src to "$mount_dir" on partition ${USB_DEVICE}${part}."
131+
echo "Successfully copied $src to $mount_dir on partition ${USB_DEVICE}${part}."
132132
break
133133
fi
134134
else
135-
echo "Error: Failed to copy $src to "$mount_dir" on attempt $((attempt + 1))/$retries. Retrying..."
135+
echo "Error: Failed to copy $src to $mount_dir on attempt $((attempt + 1))/$retries. Retrying..."
136136
umount "$mount_dir" || true
137137
sleep 2
138138
fi
139139
attempt=$((attempt + 1))
140140
if [ "$attempt" -eq 2 ]; then
141-
echo "Error: Failed to copy $src to "$mount_dir" after $retries attempts!"
141+
echo "Error: Failed to copy $src to $mount_dir after $retries attempts!"
142142
exit 1
143143
fi
144144
done

standalone-node/provisioning_scripts/install-os.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ check_mnt_mount_exist() {
7272
detect_usb() {
7373
for _ in {1..15}; do
7474
usb_devices=$(lsblk -dn -o NAME,TYPE,SIZE,RM | awk '$2 == "disk" && $4 == 1 && $3 != "0B" {print $1}')
75+
# shellcheck disable=SC2086
7576
for disk_name in $usb_devices; do
7677
# Bootable USB has 6 partitions,ignore other disks
7778
if [ "$(lsblk -l "/dev/$disk_name" | grep -c "^$(basename "/dev/$disk_name")[0-9]")" -eq 7 ]; then
@@ -148,6 +149,7 @@ get_block_device_details() {
148149
echo -e "${GREEN}Found the OS disk $os_disk${NC}"
149150

150151
# Clear the disk partitions
152+
# shellcheck disable=SC2086
151153
for disk_name in ${blk_devices}; do
152154
dd if=/dev/zero of="/dev/$disk_name" bs=100M count=20
153155
wipefs --all "/dev/$disk_name"
@@ -424,6 +426,7 @@ boot_order_chage_to_disk() {
424426

425427
efiboot=$(blkid | grep -Ei 'TYPE="vfat"' | grep -Ei 'LABEL="esp|uefi"' | awk -F: '{print $1}')
426428

429+
# shellcheck disable=SC2034
427430
if echo "$efiboot" | grep -q "nvme"; then
428431
osdisk=$(echo "$rootfs" | grep -oE 'nvme[0-9]+n[0-9]+' | head -n 1)
429432
elif echo "$efiboot" | grep -q "sd"; then
@@ -434,19 +437,18 @@ boot_order_chage_to_disk() {
434437
check_mnt_mount_exist
435438

436439
mount "${rootfs}" /mnt
437-
mount $efiboot /mnt/boot/efi
440+
mount "$efiboot" /mnt/boot/efi
438441
mount --bind /dev /mnt/dev
439442
mount --bind /dev/pts /mnt/dev/pts
440443
mount --bind /proc /mnt/proc
441444
mount --bind /sys /mnt/sys
442445
mount --bind /sys/firmware/efi/efivars /mnt/sys/firmware/efi/efivars
443446

444-
chroot /mnt /bin/bash <<EOT
447+
if chroot /mnt /bin/bash <<EOT
445448
set -e
446449
bootctl install
447450
EOT
448-
449-
if [ "$?" -eq 0 ]; then
451+
then
450452
success "Made Disk as first boot option"
451453
#unmount the partitions
452454
for mount in $(mount | grep '/mnt' | awk '{print $3}' | sort -nr); do
@@ -505,7 +507,7 @@ custom_cloud_init_updates() {
505507

506508
config_file="/mnt/config-file"
507509

508-
cp $config_file /etc/scripts
510+
cp "$config_file" /etc/scripts
509511
CONFIG_FILE="/etc/scripts/config-file"
510512

511513
umount /mnt

standalone-node/provisioning_scripts/k3s-configure.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55

66
# Start the cluster install scripts only once
77
if [ ! -f "/var/lib/rancher/k3s_status" ]; then
8-
cd /etc/cloud/
8+
cd /etc/cloud/ || exit
99

1010
chmod +x sen-k3s-installer.sh
1111

1212
bash sen-k3s-installer.sh
1313
else
1414
echo "k3s is already installed and running. Skipping installation." | sudo tee /var/log/cluster-init.log | sudo tee /dev/tty1
15-
cd /etc/cloud/
15+
cd /etc/cloud/ || exit
1616
chmod +x k3s-setup-post-reboot.sh
1717
bash k3s-setup-post-reboot.sh
1818
fi

standalone-node/provisioning_scripts/os-partition.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
# SPDX-FileCopyrightText: (C) 2025 Intel Corporation
44
# SPDX-License-Identifier: Apache-2.0
55

6+
# shellcheck disable=SC2086 # Double quote to prevent globbing and word splitting - intentionally not quoted for disk operations
7+
# shellcheck disable=SC2002 # Useless cat - using cat for readability and consistency
8+
# shellcheck disable=SC2181 # Check exit code directly - using $? for compatibility with sh
9+
610
set -x
711

812
##global variables#####

0 commit comments

Comments
 (0)