From 202c1d4b0ecf4c352c0db937e676ec6af80b51af Mon Sep 17 00:00:00 2001 From: rusdacent <57439765+rusdacent@users.noreply.github.com> Date: Mon, 13 Sep 2021 04:44:02 +0300 Subject: [PATCH] Improved reliability of shell scripts (#699) * Add double quotes for shell variables * Added exit for cd command. Prevent run commands after incorrect change directory. --- docker/syntax_check.sh | 4 ++-- scripts/flash_core1_main_swd.sh | 8 ++++---- scripts/flash_core2_ble_swd.sh | 6 +++--- scripts/flash_otp_version_dfu.sh | 4 ++-- scripts/flash_otp_version_swd.sh | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docker/syntax_check.sh b/docker/syntax_check.sh index 0bd3466a..47fb095a 100755 --- a/docker/syntax_check.sh +++ b/docker/syntax_check.sh @@ -6,7 +6,7 @@ CLANG_FORMAT_BIN="/usr/bin/clang-format-12" PROJECT_DIR=$(pwd) -cd $PROJECT_DIR +cd "$PROJECT_DIR" || exit echo "RUN C\C++ SYNTAX CHECK" C_FILES=$(find . \ @@ -34,7 +34,7 @@ fi read -p "Do you want fix syntax? (y/n): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1 -cd $PROJECT_DIR +cd "$PROJECT_DIR" || exit # We use root in container and clang-format rewriting files. We'll need change owner to original local_user=$(stat -c '%u' .clang-format) diff --git a/scripts/flash_core1_main_swd.sh b/scripts/flash_core1_main_swd.sh index 9e54e6e9..8a159df9 100755 --- a/scripts/flash_core1_main_swd.sh +++ b/scripts/flash_core1_main_swd.sh @@ -5,8 +5,8 @@ set -x -e SCRIPT_DIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" PROJECT_DIR="$(dirname "$SCRIPT_DIR")" -rm $PROJECT_DIR/bootloader/.obj/f*/flash || true -make -C $PROJECT_DIR/bootloader -j9 flash +rm "$PROJECT_DIR"/bootloader/.obj/f*/flash || true +make -C "$PROJECT_DIR"/bootloader -j9 flash -rm $PROJECT_DIR/firmware/.obj/f*/flash || true -make -C $PROJECT_DIR/firmware -j9 flash +rm "$PROJECT_DIR"/firmware/.obj/f*/flash || true +make -C "$PROJECT_DIR"/firmware -j9 flash diff --git a/scripts/flash_core2_ble_swd.sh b/scripts/flash_core2_ble_swd.sh index 1f04ba81..71ea713f 100755 --- a/scripts/flash_core2_ble_swd.sh +++ b/scripts/flash_core2_ble_swd.sh @@ -6,15 +6,15 @@ SCRIPT_DIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" PROJECT_DIR="$(dirname "$SCRIPT_DIR")" COPRO_DIR="$PROJECT_DIR/lib/STM32CubeWB/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x" -STM32_Programmer_CLI -c port=swd -fwupgrade $COPRO_DIR/stm32wb5x_FUS_fw_for_fus_0_5_3.bin 0x080EC000 || true +STM32_Programmer_CLI -c port=swd -fwupgrade "$COPRO_DIR"/stm32wb5x_FUS_fw_for_fus_0_5_3.bin 0x080EC000 || true STM32_Programmer_CLI -c port=swd -STM32_Programmer_CLI -c port=swd -fwupgrade $COPRO_DIR/stm32wb5x_FUS_fw.bin 0x080EC000 || true +STM32_Programmer_CLI -c port=swd -fwupgrade "$COPRO_DIR"/stm32wb5x_FUS_fw.bin 0x080EC000 || true STM32_Programmer_CLI -c port=swd STM32_Programmer_CLI -c port=swd -fwdelete -STM32_Programmer_CLI -c port=swd -fwupgrade $COPRO_DIR/stm32wb5x_BLE_Stack_full_fw.bin 0x080CA000 firstinstall=0 +STM32_Programmer_CLI -c port=swd -fwupgrade "$COPRO_DIR"/stm32wb5x_BLE_Stack_full_fw.bin 0x080CA000 firstinstall=0 STM32_Programmer_CLI -c port=swd -ob nSWBOOT0=1 nBOOT0=1 diff --git a/scripts/flash_otp_version_dfu.sh b/scripts/flash_otp_version_dfu.sh index 0a9526d4..014f8883 100755 --- a/scripts/flash_otp_version_dfu.sh +++ b/scripts/flash_otp_version_dfu.sh @@ -7,11 +7,11 @@ if [ "$#" -ne 1 ]; then exit fi -if [ ! -f $1 ]; then +if [ ! -f "$1" ]; then echo "Unable to open OTP file" exit fi -STM32_Programmer_CLI -c port=usb1 -d $1 0x1FFF7000 +STM32_Programmer_CLI -c port=usb1 -d "$1" 0x1FFF7000 STM32_Programmer_CLI -c port=usb1 -r8 0x1FFF7000 8 diff --git a/scripts/flash_otp_version_swd.sh b/scripts/flash_otp_version_swd.sh index 1bfe1411..84e8dd71 100755 --- a/scripts/flash_otp_version_swd.sh +++ b/scripts/flash_otp_version_swd.sh @@ -7,11 +7,11 @@ if [ "$#" -ne 1 ]; then exit fi -if [ ! -f $1 ]; then +if [ ! -f "$1" ]; then echo "Unable to open OTP file" exit fi -STM32_Programmer_CLI -c port=swd -d $1 0x1FFF7000 +STM32_Programmer_CLI -c port=swd -d "$1" 0x1FFF7000 STM32_Programmer_CLI -c port=swd -r8 0x1FFF7000 8