Skip to content

Commit e00ca18

Browse files
committed
Make shell scripts ShellCheck compliant
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent 52b5a4a commit e00ca18

9 files changed

+100
-107
lines changed

linux/dfu-util.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
88

99
# Choose dfu program by arch
10-
if [ `uname -m` == "x86_64" ]; then
10+
if [ "$(uname -m)" == "x86_64" ]; then
1111
DFU_UTIL=${DIR}/dfu-util_x86_64/dfu-util
1212
else
1313
DFU_UTIL=${DIR}/dfu-util/dfu-util

linux/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if sudo [ -w /etc/udev/rules.d ]; then
88
echo "Reloading udev rules"
99
sudo udevadm control --reload-rules
1010
echo "Adding current user to dialout group"
11-
sudo adduser $USER dialout
11+
sudo adduser "$USER" dialout
1212
else
1313
echo "Couldn't copy to /etc/udev/rules.d/; you probably have to run this script as root? Or your distribution of Linux doesn't include udev; try running the IDE itself as root."
1414
fi

linux/maple_upload.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ if [ $# -lt 4 ]; then
66
echo "Usage: $0 $# <dummy_port> <altID> <usbID> <binfile>" >&2
77
exit 1
88
fi
9-
dummy_port="$1"; altID="$2"; usbID="$3"; binfile="$4"; dummy_port_fullpath="/dev/$1"
9+
altID="$2"; usbID="$3"; binfile="$4"; dummy_port_fullpath="/dev/$1"
1010
if [ $# -eq 5 ]; then
1111
dfuse_addr="--dfuse-address $5"
1212
else
@@ -24,14 +24,14 @@ DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
2424
# 750ms to 1500ms seems to work on my Mac
2525

2626

27-
"${DIR}/upload-reset" ${dummy_port_fullpath} 750
27+
"${DIR}/upload-reset" "${dummy_port_fullpath}" 750
2828

29-
"${DIR}/dfu-util.sh" -d ${usbID} -a ${altID} -D ${binfile} ${dfuse_addr} -R
29+
"${DIR}/dfu-util.sh" -d "${usbID}" -a "${altID}" -D "${binfile}" ${dfuse_addr} -R
3030

31-
echo -n Waiting for ${dummy_port_fullpath} serial...
31+
echo -n Waiting for "${dummy_port_fullpath}" serial...
3232

3333
COUNTER=0
34-
while [ ! -r ${dummy_port_fullpath} ] && ((COUNTER++ < 40)); do
34+
while [ ! -r "${dummy_port_fullpath}" ] && ((COUNTER++ < 40)); do
3535
sleep 0.1
3636
done
3737

linux/massStorageCopy.sh

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/bin/bash
22
set -o nounset # Treat unset variables as an error
3-
#set -x
4-
VERSION="0.1"
53

64
# List
75
bin_filepath=
@@ -14,7 +12,7 @@ usage()
1412
{
1513
echo "############################################################"
1614
echo "##"
17-
echo "## `basename $0` [-I <filepath>] [-O <mountpoint(s)> ]"
15+
echo "## $(basename "$0") [-I <filepath>] [-O <mountpoint(s)> ]"
1816
echo "##"
1917
echo "## Options:"
2018
echo "## -I: filepath binary to copy"
@@ -32,29 +30,29 @@ if [ $# -lt 2 ]; then
3230
fi
3331

3432
# Parsing options
35-
if [ $1 == "-I" ]; then
33+
if [ "$1" == "-I" ]; then
3634
shift 1
3735
fi
3836

3937
bin_filepath=$1
4038

41-
if [ $2 == "-O" ]; then
39+
if [ "$2" == "-O" ]; then
4240
shift 1
4341
fi
4442
# Strip first and last ""
4543
mountpoint_name="${2%\"}"
4644
mountpoint_name="${mountpoint_name#\"}"
4745

48-
if [ -z $bin_filepath ]; then
46+
if [ -z "$bin_filepath" ]; then
4947
echo "No binary file path provided!"
5048
exit 1
5149
fi
52-
if [ -z $mountpoint_name ]; then
50+
if [ -z "$mountpoint_name" ]; then
5351
echo "No mountpoint name provided!"
5452
exit 1
5553
fi
5654

57-
if [ ! -f $bin_filepath ]; then
55+
if [ ! -f "$bin_filepath" ]; then
5856
echo "$bin_filepath not found!"
5957
exit 2
6058
fi
@@ -63,11 +61,11 @@ fi
6361
IFS=',' read -ra mnt_list <<< "$mountpoint_name"
6462
for mnt in "${mnt_list[@]}"; do
6563
# mnt_path_list=(`cat /proc/mounts | cut -d' ' -f2 | sort -u | grep $mnt`)
66-
mnt_path_list=(`df -Hl | grep -v "Mounted on" | rev | cut -d' ' -f1 | rev | sort -u | grep $mnt`)
64+
mnt_path_list=($(df -Hl | grep -v "Mounted on" | rev | cut -d' ' -f1 | rev | sort -u | grep "$mnt"))
6765
if [ ${#mnt_path_list[@]} -ne 0 ]; then
6866
# Ensure to have exact match
6967
for mnt_path in "${mnt_path_list[@]}"; do
70-
mnt_name=`echo $mnt_path | rev | cut -d'/' -f1 | rev`
68+
mnt_name=$(echo "$mnt_path" | rev | cut -d'/' -f1 | rev)
7169
if [ "$mnt_name" = "$mnt" ]; then
7270
echo "Found '$mnt' at '$mnt_path'"
7371
mountpoint_path=$mnt_path
@@ -77,14 +75,14 @@ for mnt in "${mnt_list[@]}"; do
7775
fi
7876
done
7977

80-
if [ -z $mountpoint_path ] || [ ! -d $mountpoint_path ]; then
78+
if [ -z "$mountpoint_path" ] || [ ! -d "$mountpoint_path" ]; then
8179
echo "$mountpoint_name not found."
8280
echo "Please ensure the device is correctly connected and mounted."
8381
exit 3
8482
fi
8583

8684
# Copy the binary to the mountpoint
8785
echo "Copying $bin_filepath to $mountpoint_path..."
88-
cp $bin_filepath $mountpoint_path
86+
cp "$bin_filepath" "$mountpoint_path"
8987

9088
exit $?

linux/stm32CubeProg.sh

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
#!/bin/bash
22
set -o nounset # Treat unset variables as an error
3-
#set -x
43
STM32CP_CLI=STM32_Programmer.sh
54
ADDRESS=0x8000000
6-
ERASE=
7-
MODE=
8-
PORT=
9-
OPTS=
5+
ERASE=""
6+
MODE=""
7+
PORT=""
8+
OPTS=""
109

1110
###############################################################################
1211
## Help function
1312
usage()
1413
{
1514
echo "############################################################"
1615
echo "##"
17-
echo "## `basename $0` <protocol> <file_path> [OPTIONS]"
16+
echo "## $(basename "$0") <protocol> <file_path> [OPTIONS]"
1817
echo "##"
1918
echo "## protocol:"
2019
echo "## 0: SWD"
@@ -34,17 +33,16 @@ usage()
3433
echo "## -rst: Reset system"
3534
echo "## -s: start automatically (optional)"
3635
echo "############################################################"
37-
exit $1
36+
exit "$1"
3837
}
3938

40-
4139
check_tool() {
42-
command -v $STM32CP_CLI >/dev/null 2>&1
43-
if [ $? != 0 ]; then
40+
if ! command -v $STM32CP_CLI >/dev/null 2>&1
41+
then
4442
export PATH="$HOME/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin":$PATH
4543
fi
46-
command -v $STM32CP_CLI >/dev/null 2>&1
47-
if [ $? != 0 ]; then
44+
if ! command -v $STM32CP_CLI >/dev/null 2>&1
45+
then
4846
echo "$STM32CP_CLI not found."
4947
echo "Please install it or add '<STM32CubeProgrammer path>/bin' to your PATH environment:"
5048
echo "https://www.st.com/en/development-tools/stm32cubeprog.html"
@@ -65,8 +63,8 @@ PROTOCOL=$1
6563
FILEPATH=$2
6664
# Protocol $1
6765
# 1x: Erase all sectors
68-
if [ $1 -ge 10 ]; then
69-
ERASE='-e all'
66+
if [ "$1" -ge 10 ]; then
67+
ERASE="yes"
7068
PROTOCOL=$(($1 - 10))
7169
fi
7270
# Protocol $1
@@ -75,8 +73,8 @@ fi
7573
# 2: DFU
7674
case $PROTOCOL in
7775
0)
78-
PORT='SWD'
79-
MODE='mode=UR'
76+
PORT="SWD"
77+
MODE="mode=UR"
8078
shift 2;;
8179
1)
8280
if [ $# -lt 3 ]; then
@@ -86,18 +84,18 @@ case $PROTOCOL in
8684
shift 3
8785
fi;;
8886
2)
89-
PORT='USB1'
87+
PORT="USB1"
9088
shift 2;;
9189
*)
9290
echo "Protocol unknown!"
9391
usage 4;;
9492
esac
9593

9694
if [ $# -gt 0 ]; then
97-
OPTS="$@"
95+
OPTS="$*"
9896
fi
9997

100-
${STM32CP_CLI} -c port=${PORT} ${MODE} ${ERASE} -q -d ${FILEPATH} ${ADDRESS} ${OPTS}
98+
${STM32CP_CLI} -c port=${PORT} ${MODE} ${ERASE:+"-e all"} -q -d "${FILEPATH}" ${ADDRESS} "${OPTS}"
10199

102-
exit 0
100+
exit $?
103101

macosx/maple_upload.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ if [ $# -lt 4 ]; then
66
echo "Usage: $0 $# <dummy_port> <altID> <usbID> <binfile>" >&2
77
exit 1
88
fi
9-
dummy_port=$1; altID=$2; usbID=$3; binfile=$4;dummy_port_fullpath="/dev/$1"
9+
altID=$2; usbID=$3; binfile=$4;dummy_port_fullpath="/dev/$1"
1010

1111

1212
# Get the directory where the script is running.
@@ -31,7 +31,7 @@ DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
3131
# You may need to tune this to your system
3232
# 750ms to 1500ms seems to work on my Mac
3333

34-
${DIR}/upload-reset ${dummy_port_fullpath} 750
34+
"${DIR}"/upload-reset "${dummy_port_fullpath}" 750
3535

3636
if [ $# -eq 5 ]; then
3737
dfuse_addr="--dfuse-address $5"
@@ -41,7 +41,7 @@ fi
4141

4242
#DFU_UTIL=/usr/local/bin/dfu-util
4343
DFU_UTIL=${DIR}/dfu-util/dfu-util
44-
if [ ! -x ${DFU_UTIL} ]; then
44+
if [ ! -x "${DFU_UTIL}" ]; then
4545
DFU_UTIL=/opt/local/bin/dfu-util
4646
fi
4747

@@ -50,12 +50,12 @@ if [ ! -x ${DFU_UTIL} ]; then
5050
exit 2
5151
fi
5252

53-
${DFU_UTIL} -d ${usbID} -a ${altID} -D ${binfile} -R ${dfuse_addr} -R
53+
${DFU_UTIL} -d "${usbID}" -a "${altID}" -D "${binfile}" -R ${dfuse_addr} -R
5454

55-
echo -n Waiting for ${dummy_port_fullpath} serial...
55+
echo -n Waiting for "${dummy_port_fullpath}" serial...
5656

5757
COUNTER=0
58-
while [ ! -c ${dummy_port_fullpath} ] && ((COUNTER++ < 40)); do
58+
while [ ! -c "${dummy_port_fullpath}" ] && ((COUNTER++ < 40)); do
5959
sleep 0.1
6060
done
6161

macosx/massStorageCopy.sh

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/bin/bash
22
set -o nounset # Treat unset variables as an error
3-
#set -x
4-
VERSION="0.1"
53

64
# List
75
bin_filepath=
@@ -14,7 +12,7 @@ usage()
1412
{
1513
echo "############################################################"
1614
echo "##"
17-
echo "## `basename $0` [-I <filepath>] [-O <mountpoint(s)> ]"
15+
echo "## $(basename "$0") [-I <filepath>] [-O <mountpoint(s)> ]"
1816
echo "##"
1917
echo "## Options:"
2018
echo "## -I: filepath binary to copy"
@@ -32,41 +30,41 @@ if [ $# -lt 2 ]; then
3230
fi
3331

3432
# Parsing options
35-
if [ $1 == "-I" ]; then
33+
if [ "$1" == "-I" ]; then
3634
shift 1
3735
fi
3836

3937
bin_filepath=$1
4038

41-
if [ $2 == "-O" ]; then
39+
if [ "$2" == "-O" ]; then
4240
shift 1
4341
fi
4442
# Strip first and last ""
4543
mountpoint_name="${2%\"}"
4644
mountpoint_name="${mountpoint_name#\"}"
4745

48-
if [ -z $bin_filepath ]; then
46+
if [ -z "$bin_filepath" ]; then
4947
echo "No binary file path provided!"
5048
exit 1
5149
fi
52-
if [ -z $mountpoint_name ]; then
50+
if [ -z "$mountpoint_name" ]; then
5351
echo "No mountpoint name provided!"
5452
exit 1
5553
fi
5654

57-
if [ ! -f $bin_filepath ]; then
55+
if [ ! -f "$bin_filepath" ]; then
5856
echo "$bin_filepath not found!"
5957
exit 2
6058
fi
6159

6260
# Search the mountpoint
6361
IFS=',' read -ra mnt_list <<< "$mountpoint_name"
6462
for mnt in "${mnt_list[@]}"; do
65-
mnt_path_list=(`df -Hl | grep -v "Mounted on" | rev | cut -d' ' -f1 | rev | sort -u | grep $mnt`)
63+
mnt_path_list=($(df -Hl | grep -v "Mounted on" | rev | cut -d' ' -f1 | rev | sort -u | grep "$mnt"))
6664
if [ ${#mnt_path_list[@]} -ne 0 ]; then
6765
# Ensure to have exact match
6866
for mnt_path in "${mnt_path_list[@]}"; do
69-
mnt_name=`echo $mnt_path | rev | cut -d'/' -f1 | rev`
67+
mnt_name=$(echo "$mnt_path" | rev | cut -d'/' -f1 | rev)
7068
if [ "$mnt_name" = "$mnt" ]; then
7169
echo "Found '$mnt' at '$mnt_path'"
7270
mountpoint_path=$mnt_path
@@ -76,14 +74,14 @@ for mnt in "${mnt_list[@]}"; do
7674
fi
7775
done
7876

79-
if [ -z $mountpoint_path ] || [ ! -d $mountpoint_path ]; then
77+
if [ -z "$mountpoint_path" ] || [ ! -d "$mountpoint_path" ]; then
8078
echo "$mountpoint_name not found."
8179
echo "Please ensure the device is correctly connected and mounted."
8280
exit 3
8381
fi
8482

8583
# Copy the binary to the mountpoint
8684
echo "Copying $bin_filepath to $mountpoint_path..."
87-
cp $bin_filepath $mountpoint_path
85+
cp "$bin_filepath" "$mountpoint_path"
8886

8987
exit $?

0 commit comments

Comments
 (0)