From b1de7e0d2050bff409a76204d9cd5b254ffa58b6 Mon Sep 17 00:00:00 2001 From: Finlay Davidson Date: Mon, 20 Feb 2023 02:18:39 +0100 Subject: [PATCH 1/2] Apply changes suggested by shellcheck --- backup.sh | 13 ++++++------- build.sh | 8 +++----- download.sh | 11 +++++------ uart_log.sh | 5 ++--- 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/backup.sh b/backup.sh index bf16c33..f3e997e 100755 --- a/backup.sh +++ b/backup.sh @@ -1,21 +1,20 @@ -#! /bin/bash +#!/bin/bash BKPPATH="firmware-backups" -mkdir -p $BKPPATH +mkdir -p "$BKPPATH" NOW=$(date +%s) num=$(ls -l /dev/ttyACM* | rev | cut -c 1) -echo com is:$num -splitPorts=($num) +echo com is: "$num" +mapfile -t splitPorts <<< "$num" echo "This tool assumes your buds are the only thing connected and are enumerated {right,left} order. YMMV" echo "Right bud is at ${splitPorts[0]}" echo "Left bud is at ${splitPorts[1]}" echo "Please disconnect and reconnect the bud on the right" - -bestool read-image --port /dev/ttyACM${splitPorts[0]} $BKPPATH/firmware-$NOW-${splitPorts[0]}.bin.bkp +bestool read-image --port "/dev/ttyACM${splitPorts[0]}" "${BKPPATH}/firmware-${NOW}-${splitPorts[0]}.bin.bkp" echo "Please disconnect and reconnect the bud on the left" -bestool read-image --port /dev/ttyACM${splitPorts[1]} $BKPPATH/firmware-$NOW-${splitPorts[1]}.bin.bkp +bestool read-image --port "/dev/ttyACM${splitPorts[1]}" "${BKPPATH}/firmware-${NOW}-${splitPorts[1]}.bin.bkp" diff --git a/build.sh b/build.sh index 3211718..064cec6 100755 --- a/build.sh +++ b/build.sh @@ -1,10 +1,8 @@ -#!/bin/bash +#!/bin/sh -make -j T=open_source DEBUG=1 >log.txt 2>&1 - -if [ $? -eq 0 ]; then +if make -j "$(nproc)" T=open_source DEBUG=1 >log.txt 2>&1; then echo "build success" else echo "build failed and call log.txt" - cat log.txt | grep "error:*" + grep "error:" log.txt fi diff --git a/download.sh b/download.sh index 4b91953..4a1b365 100755 --- a/download.sh +++ b/download.sh @@ -1,15 +1,14 @@ -#! /bin/bash +#!/bin/bash num=$(ls -l /dev/ttyACM* | rev | cut -c 1) -echo com is:$num -splitPorts=($num) +echo com is: "$num" +mapfile -t splitPorts <<< "$num" echo "This tool assumes your buds are the only thing connected and are enumerated {right,left} order. YMMV" echo "Right bud is at ${splitPorts[0]}" echo "Left bud is at ${splitPorts[1]}" echo "Please disconnect and reconnect the bud on the right" - -bestool write-image out/open_source/open_source.bin --port /dev/ttyACM${splitPorts[0]} +bestool write-image out/open_source/open_source.bin --port "/dev/ttyACM${splitPorts[0]}" echo "Please disconnect and reconnect the bud on the left" -bestool write-image out/open_source/open_source.bin --port /dev/ttyACM${splitPorts[1]} +bestool write-image out/open_source/open_source.bin --port "/dev/ttyACM${splitPorts[1]}" diff --git a/uart_log.sh b/uart_log.sh index 1ce2513..be75958 100755 --- a/uart_log.sh +++ b/uart_log.sh @@ -1,6 +1,5 @@ #! /bin/bash num=$(ls -l /dev/ttyUSB* | rev | cut -c 1) -#num=1 -echo $num -sudo minicom port$num +echo "$num" +sudo minicom "port$num" From 49f3e2a10cfa830b0c680ccf0cd5ef4ed728424b Mon Sep 17 00:00:00 2001 From: Finlay Davidson Date: Mon, 20 Feb 2023 11:13:03 +0100 Subject: [PATCH 2/2] Switch to find over ls -l --- backup.sh | 2 +- clear.sh | 5 +++-- download.sh | 2 +- uart_log.sh | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/backup.sh b/backup.sh index f3e997e..e44b45c 100755 --- a/backup.sh +++ b/backup.sh @@ -6,7 +6,7 @@ mkdir -p "$BKPPATH" NOW=$(date +%s) -num=$(ls -l /dev/ttyACM* | rev | cut -c 1) +num=$(find /dev -name 'ttyACM*' | sort | rev | cut -c 1) echo com is: "$num" mapfile -t splitPorts <<< "$num" echo "This tool assumes your buds are the only thing connected and are enumerated {right,left} order. YMMV" diff --git a/clear.sh b/clear.sh index 21a648d..f51df0a 100755 --- a/clear.sh +++ b/clear.sh @@ -1,2 +1,3 @@ -#!/bin/bash -make T=open_source -j DEBUG=1 clean +#!/bin/sh + +make -j "$(nproc)" T=open_source DEBUG=1 clean diff --git a/download.sh b/download.sh index 4a1b365..7519f42 100755 --- a/download.sh +++ b/download.sh @@ -1,6 +1,6 @@ #!/bin/bash -num=$(ls -l /dev/ttyACM* | rev | cut -c 1) +num=$(find /dev -name 'ttyACM*' | sort | rev | cut -c 1) echo com is: "$num" mapfile -t splitPorts <<< "$num" echo "This tool assumes your buds are the only thing connected and are enumerated {right,left} order. YMMV" diff --git a/uart_log.sh b/uart_log.sh index be75958..93f16a0 100755 --- a/uart_log.sh +++ b/uart_log.sh @@ -1,5 +1,5 @@ -#! /bin/bash +#!/bin/sh -num=$(ls -l /dev/ttyUSB* | rev | cut -c 1) +num=$(find /dev -name 'ttyUSB*' | rev | cut -c 1) echo "$num" sudo minicom "port$num"