From a38b700627c099b505172ac77e7dbacfbd7ac53e Mon Sep 17 00:00:00 2001 From: Antoni Date: Fri, 22 Mar 2024 13:54:29 +0100 Subject: [PATCH] Add some small fixes suggested by shellcheck Some suggestions were ignored, for example if they made code less readable. Change-Id: I7063c5a192ea677e4d32628ca9160da32894d702 --- scripts/clone_partitions/clone_partitions.sh | 2 +- scripts/upgrade-support/upgrade-common.inc | 22 +++++++++---------- scripts/upgrade-support/upgrade-fota.sh | 4 ++-- scripts/upgrade-support/upgrade-partial.sh | 2 +- .../upgrade-prepare-partitions.sh | 2 +- scripts/upgrade-support/upgrade-trigger.sh | 10 ++++----- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/scripts/clone_partitions/clone_partitions.sh b/scripts/clone_partitions/clone_partitions.sh index dcce216..3682cff 100644 --- a/scripts/clone_partitions/clone_partitions.sh +++ b/scripts/clone_partitions/clone_partitions.sh @@ -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 diff --git a/scripts/upgrade-support/upgrade-common.inc b/scripts/upgrade-support/upgrade-common.inc index 9d8f959..d542590 100644 --- a/scripts/upgrade-support/upgrade-common.inc +++ b/scripts/upgrade-support/upgrade-common.inc @@ -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 diff --git a/scripts/upgrade-support/upgrade-fota.sh b/scripts/upgrade-support/upgrade-fota.sh index ac21c34..04c16d5 100755 --- a/scripts/upgrade-support/upgrade-fota.sh +++ b/scripts/upgrade-support/upgrade-fota.sh @@ -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 diff --git a/scripts/upgrade-support/upgrade-partial.sh b/scripts/upgrade-support/upgrade-partial.sh index 71ef97b..1b3d2d0 100755 --- a/scripts/upgrade-support/upgrade-partial.sh +++ b/scripts/upgrade-support/upgrade-partial.sh @@ -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 diff --git a/scripts/upgrade-support/upgrade-prepare-partitions.sh b/scripts/upgrade-support/upgrade-prepare-partitions.sh index 65db1c1..4926f7b 100755 --- a/scripts/upgrade-support/upgrade-prepare-partitions.sh +++ b/scripts/upgrade-support/upgrade-prepare-partitions.sh @@ -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 diff --git a/scripts/upgrade-support/upgrade-trigger.sh b/scripts/upgrade-support/upgrade-trigger.sh index 98c96a2..d36f89d 100644 --- a/scripts/upgrade-support/upgrade-trigger.sh +++ b/scripts/upgrade-support/upgrade-trigger.sh @@ -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" -- 2.34.1