Skip to content

Commit 9ca6291

Browse files
authored
Revert Shell check fixes (#144)
1 parent be307fb commit 9ca6291

File tree

5 files changed

+48
-43
lines changed

5 files changed

+48
-43
lines changed

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

Lines changed: 24 additions & 22 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 -r password
116+
read password
117117
stty echo
118118
echo
119119

@@ -124,7 +124,7 @@ chmod 600 "$(pwd)/.psswd"
124124
# Validate the custom-cloud-init section
125125
if ! dpkg -s python3 > /dev/null 2>&1; then
126126
apt install -y python3 > /dev/null 2>&1
127-
if ! apt install -y python3 > /dev/null 2>&1; then
127+
if [ "$?" -ne 0 ]; then
128128
echo "Pyhon installation failed,please check!!"
129129
fi
130130
fi
@@ -136,7 +136,7 @@ START_MARKER="^services:"
136136
YAML_CONTENT=$(awk "/$START_MARKER/ {found=1} found" "$CONFIG_FILE")
137137

138138
# Validate using Python
139-
if ! echo "$YAML_CONTENT" | python3 -c '
139+
echo "$YAML_CONTENT" | python3 -c '
140140
import sys, yaml
141141
142142
try:
@@ -158,7 +158,9 @@ try:
158158
except yaml.YAMLError as e:
159159
print("Custom cloud-init YAML is invalid:\n", e)
160160
sys.exit(1)
161-
'; then
161+
'
162+
# Catch the Error
163+
if [ "$?" -ne 0 ]; then
162164
echo "Custome cloud-init file is not valiad,Please check!!"
163165
exit 1
164166
fi
@@ -338,7 +340,7 @@ copy_files() {
338340
echo "Custom files copied!"
339341
fi
340342
# Remove the hidden password file
341-
rm -rf "$(pwd)/.psswd"
343+
rm -rf $(pwd)/.psswd
342344
}
343345
copy_user_apps() {
344346
echo "Copying user-apps to USB device..."
@@ -347,30 +349,30 @@ copy_user_apps() {
347349
if [[ $USB_DEVICE == /dev/nbd* ]]; then
348350
USER_APPS_PART="p$USER_APPS_PART"
349351
fi
350-
check_mnt_mount_exist
351-
mount "${USB_DEVICE}${USER_APPS_PART}" /mnt
352+
check_mnt_mount_exist
353+
mount ${USB_DEVICE}${USER_APPS_PART} /mnt
352354
# Use rsync for fater copr
353-
if dpkg -s rsync; then
354-
rsync -ah --inplace user-apps /mnt/
355-
if rsync -ah --inplace user-apps /mnt/; then
356-
echo "user-apps data copied successfully"
357-
else
358-
echo "user-apps data failes to copy please check!!"
359-
umount /mnt
360-
exit 1
361-
fi
362-
else
363-
cp -r user-apps /mnt
364-
if cp -r user-apps /mnt; then
355+
if dpkg -s rsync; then
356+
rsync -ah --inplace user-apps /mnt/
357+
if [ "$?" -eq 0 ]; then
358+
echo "user-apps data copied successfully"
359+
else
360+
echo "user-apps data failes to copy please check!!"
361+
umount /mnt
362+
exit 1
363+
fi
364+
else
365+
cp -r user-apps /mnt
366+
if [ "$?" -eq 0 ]; then
365367
echo "user-apps data copied successfully"
366368
else
367369
echo "user-apps data failes to copy please check!!"
368370
umount /mnt
369371
exit 1
370372
fi
371-
fi
372-
umount /mnt
373-
sync
373+
fi
374+
umount /mnt
375+
sync
374376
fi
375377
}
376378

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

Lines changed: 9 additions & 7 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,7 +42,8 @@ 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-
if ! apt install -y qemu-system-x86 >/dev/null 2>&1; then
45+
apt install -y qemu-system-x86 >/dev/null 2>&1
46+
if [ "$?" -ne 0 ]; then
4647
echo "Qemu Installation Failed,Please check!!"
4748
exit 1
4849
fi
@@ -81,9 +82,10 @@ fi
8182
./bootable-usb-prepare.sh /dev/nbd0 usb-bootable-files.tar.gz config-file || { echo "USB device setup failed,please check"; exit 1; }
8283

8384
# Copy the new image if its provided
84-
if [ -n "$new_img" ]; then
85+
if [ ! -z "$new_img" ]; then
8586
mount /dev/nbd0p5 /mnt
86-
find /mnt -mindepth 1 -delete 2>/dev/null || true
87+
rm -rf /mnt/*
88+
cp $new_img /mnt
8789
cp "$new_img" /mnt
8890
umount /mnt
8991
sync
@@ -113,9 +115,9 @@ sudo -E qemu-system-x86_64 \
113115
-drive file=/dev/nbd0,format=raw,id=usb,if=none \
114116
-netdev user,id=net0,hostfwd=tcp::2222-:22 \
115117
-device e1000,netdev=net0
116-
117-
if ! qemu-system-x86_64 -accel kvm -m 4096 -drive file=emt-disk.img,format=raw,if=virtio -drive file=/dev/nbd0,format=raw,if=virtio -netdev user,id=net0,hostfwd=tcp::2222-:22 -device e1000,netdev=net0; then
118-
echo "Intallation VM lacunh Failed,Please check!!"
118+
119+
if [ "$?" -ne 0 ]; then
120+
echo "Intallation VM launch Failed,Please check!!"
119121
fi
120122

121123
trap 'killall --quiet standalone-vm-launch.sh || true' EXIT

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

Lines changed: 7 additions & 7 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 -r -p "Do you want to wipe all filesystem signatures from ${USB_DEVICE}? (yes/no): " user_input
47+
read -p "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
@@ -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 parition 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/k3s-configure.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if [ ! -f "/var/lib/rancher/k3s_status" ]; then
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/ || exit
15+
cd /etc/cloud/
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: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ else
5050
echo "Faild to mount the root file system for for swap entry update $disk"
5151
exit 1
5252
fi
53-
mount "$rootfs_partition_disk" /mnt
53+
mount $rootfs_partition_disk /mnt
5454
mount --bind /dev /mnt/dev
5555
mount --bind /dev/pts /mnt/dev/pts
5656
mount --bind /proc /mnt/proc
5757
mount --bind /sys /mnt/sys
5858
echo "UUID=$uuid swap swap default 0 2" >> /mnt/etc/fstab
59-
status=$(grep -c "swap" /mnt/etc/fstab)
59+
status=$(cat "/mnt/etc/fstab" | grep -c "swap")
6060
if [ "$status" -ge 1 ]; then
6161
echo "Successfuly created the swap partition for the disk $disk"
6262
else
@@ -94,7 +94,7 @@ else
9494
fi
9595

9696
#get the last partition end point
97-
data_part_end=$(parted -m "$disk" unit GB print | grep "^$data_part_number" | cut -d: -f3 | sed 's/GB//')
97+
data_part_end=$(parted -m $disk unit GB print | grep "^$data_part_number" | cut -d: -f3 | sed 's/GB//')
9898
if echo "$data_part_end" | grep -qE '^[0-9]+\.[0-9]+$'; then
9999
data_part_end=$(printf "%.0f" "$data_part_end")
100100
fi
@@ -107,7 +107,7 @@ secondary_rootfs_disk_end=$((data_part_end_size+secondary_rootfs_disk_size))
107107
parted ---pretend-input-tty "${disk}" \
108108
resizepart "$data_part_number" "${data_part_end_size}GB" \
109109
mkpart primary ext4 "${data_part_end_size}GB" "${secondary_rootfs_disk_end}GB"
110-
if ! parted ---pretend-input-tty "${disk}" resizepart "$data_part_number" "${data_part_end_size}GB" mkpart primary ext4 "${data_part_end_size}GB" "${secondary_rootfs_disk_end}GB"; then
110+
if [ $? -ne 0 ]; then
111111
echo "Partition resize for the disk ${disk} failed"
112112
exit 1
113113
else
@@ -116,7 +116,7 @@ fi
116116
partprobe "${disk}"
117117

118118
#get the end size of the last partition from the disk
119-
last_partition_end=$(parted -ms "$disk" print | tail -n 1 | awk -F: '{print $3}' | sed 's/GB$//')
119+
last_partition_end=$(parted -ms $disk print | tail -n 1 | awk -F: '{print $3}' | sed 's/GB$//')
120120
if echo "$last_partition_end" | grep -qE '^[0-9]+\.[0-9]+$'; then
121121
last_partition_end=$(printf "%.0f" "$last_partition_end")
122122
fi
@@ -127,7 +127,8 @@ create_swap_partition "${disk}" "${last_partition_end}" "${swap_partition_size_e
127127

128128
#finally expand the data partition using resize2fs
129129
e2fsck -f -y "$data_partition_disk"
130-
if ! resize2fs "$data_partition_disk"; then
130+
resize2fs "$data_partition_disk"
131+
if [ $? -ne 0 ]; then
131132
echo "Partition resize for the disk ${disk} failed"
132133
exit 1
133134
else

0 commit comments

Comments
 (0)