From 8fee15ec4e4774318120b0ffe8bd1ae9e4a84d85 Mon Sep 17 00:00:00 2001 From: Frederic Pillon Date: Mon, 1 Jul 2024 15:36:57 +0200 Subject: [PATCH] fix(stm32CubeProg): use BSD getopt for MacOS On MacOS getopt is the BSD based one while other using the gnu-based getopt. Then "-o" and long options are not supported Fixes #99 Signed-off-by: Frederic Pillon --- stm32CubeProg.sh | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/stm32CubeProg.sh b/stm32CubeProg.sh index 403d1a425..9e8a0bb38 100644 --- a/stm32CubeProg.sh +++ b/stm32CubeProg.sh @@ -2,6 +2,7 @@ set -o nounset # Treat unset variables as an error # set -o xtrace # Print command traces before executing command. +UNAME_OS="$(uname -s)" STM32CP_CLI= INTERFACE= PORT= @@ -55,11 +56,21 @@ aborting() { # parse command line arguments # options may be followed by one colon to indicate they have a required arg -if ! options=$(getopt -a -o hi:ef:o:c:r:d:v:p: --long help,interface:,erase,file:,offset:,com:,rts:,dtr:,vid:,pid: -- "$@"); then - echo "Terminating..." >&2 - exit 1 -fi - +case "${UNAME_OS}" in + Darwin*) + echo "Warning: long options not supported due to getopt from FreeBSD usage." + if ! options=$(getopt hi:ef:o:c:r:d:v:p: "$@"); then + echo "Terminating..." >&2 + exit 1 + fi + ;; + *) + if ! options=$(getopt -a -o hi:ef:o:c:r:d:v:p: --long help,interface:,erase,file:,offset:,com:,rts:,dtr:,vid:,pid: -- "$@"); then + echo "Terminating..." >&2 + exit 1 + fi + ;; +esac eval set -- "$options" while true; do @@ -109,10 +120,13 @@ while true; do shift break ;; + *) + echo "Unknown option $1" + usage 1 + ;; esac done -# Check STM32CubeProgrammer cli availability, fallback to dfu-util if protocol dfu -UNAME_OS="$(uname -s)" +# Check STM32CubeProgrammer cli availability case "${UNAME_OS}" in Linux*) STM32CP_CLI=STM32_Programmer.sh