Skip to content

Commit f9f5b25

Browse files
committed
Use shfmt to format shell scripts
Add the formatting options file Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent e00ca18 commit f9f5b25

10 files changed

+96
-94
lines changed

.editorconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[*.sh]
2+
# like -i=2
3+
indent_style = space
4+
indent_size = 2
5+
6+
#shell_variant = posix # like -ln=posix
7+
#binary_next_line = true # like -bn
8+
switch_case_indent = true # like -ci
9+
space_redirects = true # like -sr
10+
#keep_padding = true # like -kp

linux/dfu-util.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
#
55

66
# Get the directory where the script is running.
7-
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
7+
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: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
#!/bin/sh
22

33
if sudo [ -w /etc/udev/rules.d ]; then
4-
echo "Copying Maple-specific udev rules..."
5-
sudo cp -v 45-maple.rules /etc/udev/rules.d/45-maple.rules
6-
sudo chown root:root /etc/udev/rules.d/45-maple.rules
7-
sudo chmod 644 /etc/udev/rules.d/45-maple.rules
8-
echo "Reloading udev rules"
9-
sudo udevadm control --reload-rules
10-
echo "Adding current user to dialout group"
11-
sudo adduser "$USER" dialout
4+
echo "Copying Maple-specific udev rules..."
5+
sudo cp -v 45-maple.rules /etc/udev/rules.d/45-maple.rules
6+
sudo chown root:root /etc/udev/rules.d/45-maple.rules
7+
sudo chmod 644 /etc/udev/rules.d/45-maple.rules
8+
echo "Reloading udev rules"
9+
sudo udevadm control --reload-rules
10+
echo "Adding current user to dialout group"
11+
sudo adduser "$USER" dialout
1212
else
13-
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."
13+
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
15-

linux/maple_upload.sh

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,28 @@
33
#set -e
44

55
if [ $# -lt 4 ]; then
6-
echo "Usage: $0 $# <dummy_port> <altID> <usbID> <binfile>" >&2
7-
exit 1
6+
echo "Usage: $0 $# <dummy_port> <altID> <usbID> <binfile>" >&2
7+
exit 1
88
fi
9-
altID="$2"; usbID="$3"; binfile="$4"; dummy_port_fullpath="/dev/$1"
9+
altID="$2"
10+
usbID="$3"
11+
binfile="$4"
12+
dummy_port_fullpath="/dev/$1"
1013
if [ $# -eq 5 ]; then
11-
dfuse_addr="--dfuse-address $5"
14+
dfuse_addr="--dfuse-address $5"
1215
else
13-
dfuse_addr=""
16+
dfuse_addr=""
1417
fi
1518

16-
1719
# Get the directory where the script is running.
18-
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
20+
DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
1921

2022
# ----------------- IMPORTANT -----------------
2123
# The 2nd parameter to upload-reset is the delay after resetting before it exits
2224
# This value is in milliseonds
2325
# You may need to tune this to your system
2426
# 750ms to 1500ms seems to work on my Mac
2527

26-
2728
"${DIR}/upload-reset" "${dummy_port_fullpath}" 750
2829

2930
"${DIR}/dfu-util.sh" -d "${usbID}" -a "${altID}" -D "${binfile}" ${dfuse_addr} -R
@@ -32,7 +33,7 @@ echo -n Waiting for "${dummy_port_fullpath}" serial...
3233

3334
COUNTER=0
3435
while [ ! -r "${dummy_port_fullpath}" ] && ((COUNTER++ < 40)); do
35-
sleep 0.1
36+
sleep 0.1
3637
done
3738

3839
echo Done

linux/massStorageCopy.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
set -o nounset # Treat unset variables as an error
2+
set -o nounset # Treat unset variables as an error
33

44
# List
55
bin_filepath=
@@ -8,8 +8,7 @@ mountpoint_path=
88

99
###############################################################################
1010
## Help function
11-
usage()
12-
{
11+
usage() {
1312
echo "############################################################"
1413
echo "##"
1514
echo "## $(basename "$0") [-I <filepath>] [-O <mountpoint(s)> ]"
@@ -30,13 +29,13 @@ if [ $# -lt 2 ]; then
3029
fi
3130

3231
# Parsing options
33-
if [ "$1" == "-I" ]; then
32+
if [ "$1" == "-I" ]; then
3433
shift 1
3534
fi
3635

3736
bin_filepath=$1
3837

39-
if [ "$2" == "-O" ]; then
38+
if [ "$2" == "-O" ]; then
4039
shift 1
4140
fi
4241
# Strip first and last ""

linux/stm32CubeProg.sh

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
set -o nounset # Treat unset variables as an error
2+
set -o nounset # Treat unset variables as an error
33
STM32CP_CLI=STM32_Programmer.sh
44
ADDRESS=0x8000000
55
ERASE=""
@@ -9,8 +9,7 @@ OPTS=""
99

1010
###############################################################################
1111
## Help function
12-
usage()
13-
{
12+
usage() {
1413
echo "############################################################"
1514
echo "##"
1615
echo "## $(basename "$0") <protocol> <file_path> [OPTIONS]"
@@ -37,12 +36,10 @@ usage()
3736
}
3837

3938
check_tool() {
40-
if ! command -v $STM32CP_CLI >/dev/null 2>&1
41-
then
39+
if ! command -v $STM32CP_CLI > /dev/null 2>&1; then
4240
export PATH="$HOME/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin":$PATH
4341
fi
44-
if ! command -v $STM32CP_CLI >/dev/null 2>&1
45-
then
42+
if ! command -v $STM32CP_CLI > /dev/null 2>&1; then
4643
echo "$STM32CP_CLI not found."
4744
echo "Please install it or add '<STM32CubeProgrammer path>/bin' to your PATH environment:"
4845
echo "https://www.st.com/en/development-tools/stm32cubeprog.html"
@@ -54,8 +51,8 @@ check_tool() {
5451
check_tool
5552

5653
if [ $# -lt 2 ]; then
57-
echo "Not enough arguments!"
58-
usage 2
54+
echo "Not enough arguments!"
55+
usage 2
5956
fi
6057

6158
# Parse options
@@ -75,20 +72,24 @@ case $PROTOCOL in
7572
0)
7673
PORT="SWD"
7774
MODE="mode=UR"
78-
shift 2;;
75+
shift 2
76+
;;
7977
1)
8078
if [ $# -lt 3 ]; then
8179
usage 3
8280
else
8381
PORT=$3
8482
shift 3
85-
fi;;
83+
fi
84+
;;
8685
2)
8786
PORT="USB1"
88-
shift 2;;
87+
shift 2
88+
;;
8989
*)
9090
echo "Protocol unknown!"
91-
usage 4;;
91+
usage 4
92+
;;
9293
esac
9394

9495
if [ $# -gt 0 ]; then
@@ -98,4 +99,3 @@ fi
9899
${STM32CP_CLI} -c port=${PORT} ${MODE} ${ERASE:+"-e all"} -q -d "${FILEPATH}" ${ADDRESS} "${OPTS}"
99100

100101
exit $?
101-

macosx/maple_upload.sh

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
set -e
44

55
if [ $# -lt 4 ]; then
6-
echo "Usage: $0 $# <dummy_port> <altID> <usbID> <binfile>" >&2
7-
exit 1
6+
echo "Usage: $0 $# <dummy_port> <altID> <usbID> <binfile>" >&2
7+
exit 1
88
fi
9-
altID=$2; usbID=$3; binfile=$4;dummy_port_fullpath="/dev/$1"
10-
9+
altID=$2
10+
usbID=$3
11+
binfile=$4
12+
dummy_port_fullpath="/dev/$1"
1113

1214
# Get the directory where the script is running.
13-
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
14-
15+
DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
1516

1617
# ----------------- Old code to reset the USB - which doesn't seem to work --------
1718
#
@@ -34,20 +35,20 @@ DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
3435
"${DIR}"/upload-reset "${dummy_port_fullpath}" 750
3536

3637
if [ $# -eq 5 ]; then
37-
dfuse_addr="--dfuse-address $5"
38+
dfuse_addr="--dfuse-address $5"
3839
else
39-
dfuse_addr=""
40+
dfuse_addr=""
4041
fi
4142

4243
#DFU_UTIL=/usr/local/bin/dfu-util
4344
DFU_UTIL=${DIR}/dfu-util/dfu-util
4445
if [ ! -x "${DFU_UTIL}" ]; then
45-
DFU_UTIL=/opt/local/bin/dfu-util
46+
DFU_UTIL=/opt/local/bin/dfu-util
4647
fi
4748

4849
if [ ! -x ${DFU_UTIL} ]; then
49-
echo "$0: error: cannot find ${DFU_UTIL}" >&2
50-
exit 2
50+
echo "$0: error: cannot find ${DFU_UTIL}" >&2
51+
exit 2
5152
fi
5253

5354
${DFU_UTIL} -d "${usbID}" -a "${altID}" -D "${binfile}" -R ${dfuse_addr} -R
@@ -56,7 +57,7 @@ echo -n Waiting for "${dummy_port_fullpath}" serial...
5657

5758
COUNTER=0
5859
while [ ! -c "${dummy_port_fullpath}" ] && ((COUNTER++ < 40)); do
59-
sleep 0.1
60+
sleep 0.1
6061
done
6162

6263
echo Done

macosx/massStorageCopy.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
set -o nounset # Treat unset variables as an error
2+
set -o nounset # Treat unset variables as an error
33

44
# List
55
bin_filepath=
@@ -8,8 +8,7 @@ mountpoint_path=
88

99
###############################################################################
1010
## Help function
11-
usage()
12-
{
11+
usage() {
1312
echo "############################################################"
1413
echo "##"
1514
echo "## $(basename "$0") [-I <filepath>] [-O <mountpoint(s)> ]"
@@ -30,13 +29,13 @@ if [ $# -lt 2 ]; then
3029
fi
3130

3231
# Parsing options
33-
if [ "$1" == "-I" ]; then
32+
if [ "$1" == "-I" ]; then
3433
shift 1
3534
fi
3635

3736
bin_filepath=$1
3837

39-
if [ "$2" == "-O" ]; then
38+
if [ "$2" == "-O" ]; then
4039
shift 1
4140
fi
4241
# Strip first and last ""

macosx/stm32CubeProg.sh

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
set -o nounset # Treat unset variables as an error
2+
set -o nounset # Treat unset variables as an error
33
STM32CP_CLI=STM32_Programmer_CLI
44
ADDRESS=0x8000000
55
ERASE=""
@@ -9,8 +9,7 @@ OPTS=""
99

1010
###############################################################################
1111
## Help function
12-
usage()
13-
{
12+
usage() {
1413
echo "############################################################"
1514
echo "##"
1615
echo "## $(basename "$0") <protocol> <file_path> [OPTIONS]"
@@ -37,12 +36,10 @@ usage()
3736
}
3837

3938
check_tool() {
40-
if ! ommand -v $STM32CP_CLI >/dev/null 2>&1
41-
then
39+
if ! command -v $STM32CP_CLI > /dev/null 2>&1; then
4240
export PATH="/Applications/STMicroelectronics/STM32Cube/STM32CubeProgrammer/STM32CubeProgrammer.app/Contents/MacOs/bin":$PATH
4341
fi
44-
if ! command -v $STM32CP_CLI >/dev/null 2>&1
45-
then
42+
if ! command -v $STM32CP_CLI > /dev/null 2>&1; then
4643
echo "$STM32CP_CLI not found."
4744
echo "Please install it or add '<STM32CubeProgrammer path>/bin' to your PATH environment:"
4845
echo "https://www.st.com/en/development-tools/stm32cubeprog.html"
@@ -54,8 +51,8 @@ check_tool() {
5451
check_tool
5552

5653
if [ $# -lt 2 ]; then
57-
echo "Not enough arguments!"
58-
usage 2
54+
echo "Not enough arguments!"
55+
usage 2
5956
fi
6057

6158
# Parse options
@@ -75,20 +72,24 @@ case $PROTOCOL in
7572
0)
7673
PORT="SWD"
7774
MODE="mode=UR"
78-
shift 2;;
75+
shift 2
76+
;;
7977
1)
8078
if [ $# -lt 3 ]; then
8179
usage 3
8280
else
8381
PORT=$3
8482
shift 3
85-
fi;;
83+
fi
84+
;;
8685
2)
8786
PORT="USB1"
88-
shift 2;;
87+
shift 2
88+
;;
8989
*)
9090
echo "Protocol unknown!"
91-
usage 4;;
91+
usage 4
92+
;;
9293
esac
9394

9495
if [ $# -gt 0 ]; then
@@ -98,4 +99,3 @@ fi
9899
${STM32CP_CLI} -c port=${PORT} ${MODE} ${ERASE:+"-e all"} -q -d "${FILEPATH}" ${ADDRESS} "${OPTS}"
99100

100101
exit $?
101-

0 commit comments

Comments
 (0)