The previous method of removing `--change-mode` from the argument list used a
string (`NEW_ARGS`) and `eval set -- $NEW_ARGS` to reconstruct the positional
parameters. This was both unsafe and incorrect.
Because `NEW_ARGS` was built using quoted literal `$arg` strings instead of the
actual values, it resulted in all filtered arguments being set to the same last
value of `$arg`. This caused `getopts` to receive incorrect input and silently
fail to parse options like `-p` and `-f`, leading to broken behavior and unset
variables (e.g., `ESPTOOL_CMD` never got a port).
This patch rewrites the logic to use an array (`NEW_ARGS+=("$arg")`), and
resets positional parameters via `set -- "${NEW_ARGS[@]}"`. This preserves
argument integrity and avoids the unsafe use of `eval`.
Example of the broken behavior before this fix:
./device-update.sh -p /dev/ttyACM0 -f firmware.bin
Resulted in:
set -- firmware.bin firmware.bin firmware.bin firmware.bin
Now:
set -- -p /dev/ttyACM0 -f firmware.bin
as expected.
Signed-off-by: Neil Hanlon <neil@shrug.pw>
Fixed quoting of the `FILENAME` variable to work when the path of the
passed argument contains a space. Also fixed syntactical issues called
out by `shellcheck` in multi-condition `if` statements.
Also normalized indentation chars (was mix of tabs & spaces) and
trailing whitespace.
Co-authored-by: Tom Fifield <tom@tomfifield.net>
* add change-mode support
* add change-mode support
* tab to space
* fix if check
* change param name to 1200bps-reset
* update help section
* missed one in help seciton
---------
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>