Clean up install & update shell scripts (#6839)

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>
This commit is contained in:
Mario Murphy
2025-06-07 21:04:31 -07:00
committed by GitHub
parent 8bd7adca47
commit e78033bb85
2 changed files with 140 additions and 140 deletions

View File

@@ -73,7 +73,7 @@ set -e
# Usage info
show_help() {
cat <<EOF
Usage: $(basename $0) [-h] [-p ESPTOOL_PORT] [-P PYTHON] [-f FILENAME] [--web] [--1200bps-reset]
Usage: $(basename "$0") [-h] [-p ESPTOOL_PORT] [-P PYTHON] [-f FILENAME] [--web] [--1200bps-reset]
Flash image file to device, but first erasing and writing system information.
-h Display this help and exit.
@@ -127,18 +127,18 @@ if [[ $BPS_RESET == true ]]; then
exit 0
fi
[ -z "$FILENAME" -a -n "$1" ] && {
FILENAME=$1
[ -z "$FILENAME" ] && [ -n "$1" ] && {
FILENAME="$1"
shift
}
if [[ $FILENAME != firmware-* ]]; then
if [[ "$FILENAME" != firmware-* ]]; then
echo "Filename must be a firmware-* file."
exit 1
fi
# Check if FILENAME contains "-tft-" and prevent web/mui comingling.
if [[ ${FILENAME//-tft-/} != "$FILENAME" ]]; then
if [[ "${FILENAME//-tft-/}" != "$FILENAME" ]]; then
TFT_BUILD=true
if [[ $WEB_APP == true ]] && [[ $TFT_BUILD == true ]]; then
echo "Cannot enable WebUI (--web) and MUI."
@@ -197,15 +197,15 @@ if [ -f "${FILENAME}" ] && [ -n "${FILENAME##*"update"*}" ]; then
SPIFFSFILE=littlefs-${BASENAME}
fi
if [[ ! -f $FILENAME ]]; then
if [[ ! -f "$FILENAME" ]]; then
echo "Error: file ${FILENAME} wasn't found. Terminating."
exit 1
fi
if [[ ! -f $OTAFILE ]]; then
if [[ ! -f "$OTAFILE" ]]; then
echo "Error: file ${OTAFILE} wasn't found. Terminating."
exit 1
fi
if [[ ! -f $SPIFFSFILE ]]; then
if [[ ! -f "$SPIFFSFILE" ]]; then
echo "Error: file ${SPIFFSFILE} wasn't found. Terminating."
exit 1
fi

View File

@@ -18,8 +18,8 @@ fi
# Usage info
show_help() {
cat << EOF
Usage: $(basename $0) [-h] [-p ESPTOOL_PORT] [-P PYTHON] [-f FILENAME|FILENAME] [--change-mode]
Flash image file to device, leave existing system intact.
Usage: $(basename "$0") [-h] [-p ESPTOOL_PORT] [-P PYTHON] [-f FILENAME|FILENAME] [--change-mode]
Flash image file to device, leave existing system intact."
-h Display this help and exit
-p ESPTOOL_PORT Set the environment variable for ESPTOOL_PORT. If not set, ESPTOOL iterates all ports (Dangerous).
@@ -60,14 +60,14 @@ if [[ $CHANGE_MODE == true ]]; then
exit 0
fi
[ -z "$FILENAME" -a -n "$1" ] && {
FILENAME=$1
[ -z "$FILENAME" ] && [ -n "$1" ] && {
FILENAME="$1"
shift
}
if [ -f "${FILENAME}" ] && [ -z "${FILENAME##*"update"*}" ]; then
printf "Trying to flash update ${FILENAME}"
$ESPTOOL_CMD --baud 115200 write_flash 0x10000 ${FILENAME}
echo "Trying to flash update ${FILENAME}"
$ESPTOOL_CMD --baud 115200 write_flash 0x10000 "${FILENAME}"
else
show_help
echo "Invalid file: ${FILENAME}"