Add some small fixes suggested by shellcheck
authorAntoni <a.adaszkiewi@samsung.com>
Fri, 22 Mar 2024 12:54:29 +0000 (13:54 +0100)
committerChanwoo Choi <cw00.choi@samsung.com>
Wed, 24 Apr 2024 01:50:02 +0000 (10:50 +0900)
Some suggestions were ignored, for example if they made code less
readable.

Change-Id: I7063c5a192ea677e4d32628ca9160da32894d702

scripts/clone_partitions/clone_partitions.sh
scripts/upgrade-support/upgrade-common.inc
scripts/upgrade-support/upgrade-fota.sh
scripts/upgrade-support/upgrade-partial.sh
scripts/upgrade-support/upgrade-prepare-partitions.sh
scripts/upgrade-support/upgrade-trigger.sh

index dcce216..3682cff 100644 (file)
@@ -36,7 +36,7 @@ set -o errexit
 trap 'echo "Aborting due to errexit on ${0##*/}:$LINENO. Exit code: $?" >&2' ERR
 set -o errtrace -e -o pipefail
 
-if [ ! -z "${UPGRADE_DEBUG}" ]; then
+if [ -n "${UPGRADE_DEBUG}" ]; then
        set -x
 fi
 
index 9d8f959..d542590 100644 (file)
@@ -19,11 +19,11 @@ UPGRADE_LOG_FILE="$UPGRADE_LOG_DIR/upgrade.log"
 UPGRADE_SUPPORT_SCRIPT_NAMES=("upgrade-prepare-partitions.sh" "upgrade-trigger.sh" \
        "upgrade-partial.sh" "upgrade-fota.sh")
 
-if [ -z $BLKID_PRINT ]; then
+if [ -z "$BLKID_PRINT" ]; then
        BLKID_PRINT="/usr/bin/blkid-print"
 fi
 
-if [ -z $RESIZE_DYNPARTS ]; then
+if [ -z "$RESIZE_DYNPARTS" ]; then
        RESIZE_DYNPARTS="/bin/resize-dynparts"
 fi
 
@@ -177,7 +177,7 @@ map_from_super() {
 }
 
 check_if_super() {
-       if SUPERFS="$(("$BLKID_PRINT" "$EMMC_DEVICE" super a) 2>/dev/null)"; then
+       if SUPERFS="$( ("$BLKID_PRINT" "$EMMC_DEVICE" super a) 2>/dev/null)"; then
                local MAPPED_DEVICES=""
                MAPPED_DEVICES=$(dmsetup ls)
 
@@ -196,19 +196,19 @@ check_if_super() {
                                "${RESIZE_DYNPARTS}" "${SUPERFS}" "${NEXT_AB}"
                        fi
 
-                       PARSE_DYNPARTS=`/usr/sbin/parse-dynparts "$SUPERFS" --list-tables`
+                       PARSE_DYNPARTS=$(/usr/sbin/parse-dynparts "$SUPERFS" --list-tables)
 
                        while read -r part_name part_table; do
                                if [ "$part_name" = "rootfs_${NEXT_AB}" ]; then
                                        map_from_super "$part_name" "$part_table"
-                                       ROOTFS_CURR_SIZE="$(blockdev --getsize64 /dev/mapper/rootfs_${CURRENT_AB})"
-                                       ROOTFS_NEXT_SIZE="$(blockdev --getsize64 /dev/mapper/rootfs_${NEXT_AB})"
+                                       ROOTFS_CURR_SIZE="$(blockdev --getsize64 /dev/mapper/rootfs_"${CURRENT_AB}")"
+                                       ROOTFS_NEXT_SIZE="$(blockdev --getsize64 /dev/mapper/rootfs_"${NEXT_AB}")"
                                fi
 
                                if [ "$part_name" = "hal_${NEXT_AB}" ]; then
                                        map_from_super "$part_name" "$part_table"
-                                       HAL_CURR_SIZE="$(blockdev --getsize64 /dev/mapper/hal_${CURRENT_AB})"
-                                       HAL_NEXT_SIZE="$(blockdev --getsize64 /dev/mapper/hal_${NEXT_AB})"
+                                       HAL_CURR_SIZE="$(blockdev --getsize64 /dev/mapper/hal_"${CURRENT_AB}")"
+                                       HAL_NEXT_SIZE="$(blockdev --getsize64 /dev/mapper/hal_"${NEXT_AB}")"
                                fi
                        done <<< "$PARSE_DYNPARTS"
                fi
@@ -223,7 +223,7 @@ check_used_block_device() {
                MAPPER_DEVICE="${ROOTFS_DEVICE}"
                DM_NAME=$(basename "${MAPPER_DEVICE}")
                DM_N=$(dmsetup ls -o blkdevname | grep "${DM_NAME}" | sed -e 's/^.*(\([^)]\+\))/\1/')
-               ROOTFS_DEVICE="/dev/$(ls /sys/class/block/${DM_N}/slaves/)"
+               ROOTFS_DEVICE="/dev/$(ls /sys/class/block/"${DM_N}"/slaves/)"
        fi
 
        if ! EMMC_DEVICE="/dev/$(/bin/lsblk -ndo pkname "${ROOTFS_DEVICE}")" ||\
@@ -374,7 +374,7 @@ upgrade_images() {
                local CURR_PARTITION=""
                local NEXT_PARTITION=""
 
-               if { [ "$PART_NAME" == "rootfs" ] || [ "$PART_NAME" == "hal" ]; } && [ x$SUPERFS != "x" ]; then
+               if { [ "$PART_NAME" == "rootfs" ] || [ "$PART_NAME" == "hal" ]; } && [ x"$SUPERFS" != "x" ]; then
                        NEXT_PARTITION="/dev/mapper/${PART_NAME}_${NEXT_AB}"
                        CURR_PARTITION="/dev/mapper/${PART_NAME}_${CURRENT_AB}"
                else
@@ -470,7 +470,7 @@ write_version_info() {
 
 set_upgrade_status() {
        VALUE="$1"
-       ${SET_UPGRADE_STATUS} ${VALUE} &>/dev/null
+       ${SET_UPGRADE_STATUS} "${VALUE}" &>/dev/null
        if [ $? -eq 0 ]; then
                critical_log "[Info] set_upgrade_status success: status is ${VALUE}"
        else
index ac21c34..04c16d5 100755 (executable)
@@ -4,7 +4,7 @@ trap 'echo "Aborting due to errexit on ${0##*/}:$LINENO. Exit code: $?" >&2' ERR
 set -o errtrace -e -o pipefail
 
 
-if [ ! -z "${UPGRADE_DEBUG}" ]; then
+if [ -n "${UPGRADE_DEBUG}" ]; then
        set -x
 fi
 
@@ -48,7 +48,7 @@ reboot_to_fota() {
        log "[Info] calling sync"
 
        log "[Info] Switching board partition from $CURRENT_AB, to $NEXT_AB"
-       if ! device_board_switch_partition $NEXT_AB; then
+       if ! device_board_switch_partition "$NEXT_AB"; then
                critical_log "[Error] Failed to switch board slot to $NEXT_AB"
                exit 1
        fi
index 71ef97b..1b3d2d0 100755 (executable)
@@ -3,7 +3,7 @@ set -o errexit
 trap 'echo "Aborting due to errexit on ${0##*/}:$LINENO. Exit code: $?" >&2' ERR
 set -o errtrace -e -o pipefail
 
-if [ ! -z "${UPGRADE_DEBUG}" ]; then
+if [ -n "${UPGRADE_DEBUG}" ]; then
        set -x
 fi
 
index 65db1c1..4926f7b 100755 (executable)
@@ -3,7 +3,7 @@ set -o errexit
 trap 'echo "Aborting due to errexit on ${0##*/}:$LINENO. Exit code: $?" >&2' ERR
 set -o errtrace -e -o pipefail
 
-if [ ! -z "${UPGRADE_DEBUG}" ]; then
+if [ -n "${UPGRADE_DEBUG}" ]; then
        set -x
 fi
 
index 98c96a2..d36f89d 100644 (file)
@@ -4,7 +4,7 @@ set -o errexit
 trap 'echo "Aborting due to errexit on ${0##*/}:$LINENO. Exit code: $?" >&2' ERR
 set -o errtrace -e -o pipefail
 
-if [ ! -z "${UPGRADE_DEBUG}" ]; then
+if [ -n "${UPGRADE_DEBUG}" ]; then
        set -x
 fi
 
@@ -24,13 +24,13 @@ export RESIZE_DYNPARTS="$FOTA_DIR/$RESIZE_DYNPARTS_FILE"
 prepare_fota_dir() {
        if [ -d "$FOTA_DIR" ]; then
                # Cleanup FOTA_DIR
-               if [ "$(dirname $DOWNLOAD_DELTA)" = "$FOTA_DIR" ]; then
+               if [ "$(dirname "$DOWNLOAD_DELTA")" = "$FOTA_DIR" ]; then
                        # If provided delta is from inside the FOTA_DIR, delete everything else
-                       DELTA_FILE_NAME=$(basename $DOWNLOAD_DELTA)
+                       DELTA_FILE_NAME=$(basename "$DOWNLOAD_DELTA")
                        rm -rf -- "$FOTA_DIR/!($DELTA_FILE_NAME)"
                else
                        # If provided delta is from outside the FOTA_DIR delete everything
-                       rm -rf -- "$FOTA_DIR/*"
+                       rm -rf -- "${FOTA_DIR:?}/*"
                fi
        # `echo` commands below are intentional as upgrade-common.inc is not sourced yet (no access to logging functions)
        else
@@ -91,7 +91,7 @@ do_update() {
                unpack_file "${DOWNLOAD_DELTA}" "${SCRIPT_UPGRADE_PARTIAL}"
                unpack_file "${DOWNLOAD_DELTA}" "${SCRIPT_UPGRADE_FOTA}"
 
-               run_script ""${FOTA_DIR}/${SCRIPT_UPGRADE_PARTIAL}" "${DOWNLOAD_DELTA}""
+               run_script "${FOTA_DIR}/${SCRIPT_UPGRADE_PARTIAL} ${DOWNLOAD_DELTA}"
 
                if [ $RET -ne 0 ] ; then
                        log "[Error] Failed to run $SCRIPT_UPGRADE_PARTIAL ${DOWNLOAD_DELTA}" "$LOG_FILE"