From ccddb1ebdccb53b2daf1a4e30b037a3e3d38cfd6 Mon Sep 17 00:00:00 2001 From: slycordinator <68940237+slycordinator@users.noreply.github.com> Date: Mon, 27 Dec 2021 16:00:56 +0900 Subject: [PATCH 1/6] Update start_dev.sh Doesn't use anything bash-specific, so it can be /bin/sh --- start_dev.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/start_dev.sh b/start_dev.sh index 8f7bebc9..ef95947f 100755 --- a/start_dev.sh +++ b/start_dev.sh @@ -1,2 +1,2 @@ -#!/usr/bin/env bash -docker-compose run --rm builder \ No newline at end of file +#!/bin/sh +docker-compose run --rm builder From 82fdd74be7bc68e91e524b4fb2ab70960c334d2f Mon Sep 17 00:00:00 2001 From: slycordinator <68940237+slycordinator@users.noreply.github.com> Date: Mon, 27 Dec 2021 16:03:39 +0900 Subject: [PATCH 2/6] update setup.sh Doesn't use anything bash-specific, so it can be a /bin/sh script Added quotes to MDPATH variable, as recommended by shellcheck utility --- setup.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/setup.sh b/setup.sh index 6db08bed..00c460da 100644 --- a/setup.sh +++ b/setup.sh @@ -1,7 +1,7 @@ -#!/bin/bash +#!/bin/sh set -e # Setup shell file to setup the environment on an ubuntu machine -sudo apt-get update && sudo apt-get install -y make bzip2 git python3 python3-pip wget dfu-util +sudo apt-get update && sudo apt-get install -y make bzip2 git python3 python3-pip wget dfu-util python3 -m pip install bdflib black flake8 sudo mkdir -p /build cd /build @@ -12,7 +12,7 @@ cd /build MDPATH=${GITHUB_WORKSPACE:-/build/source/} sudo mkdir -p /build/cache cd /build/cache/ -if md5sum -c $MDPATH/ci/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2.md5; then +if md5sum -c "$MDPATH"/ci/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2.md5; then echo "Good MD5 ARM" else echo "ARM MD5 Mismatch, downloading fresh" @@ -20,7 +20,7 @@ else sudo wget -q "https://developer.arm.com/-/media/Files/downloads/gnu-rm/10-2020q4/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2" -O gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2 fi -if md5sum -c $MDPATH/ci/nuclei_riscv_newlibc_prebuilt_linux64_2020.08.tar.bz2.md5; then +if md5sum -c "$MDPATH"/ci/nuclei_riscv_newlibc_prebuilt_linux64_2020.08.tar.bz2.md5; then echo "Good MD5 RISCV" else echo "RISCV MD5 Mismatch, downloading fresh" From 6dfab0ae3cb594f6d9dd4c9ed7f9615ab7e0413f Mon Sep 17 00:00:00 2001 From: slycordinator <68940237+slycordinator@users.noreply.github.com> Date: Mon, 27 Dec 2021 16:04:51 +0900 Subject: [PATCH 3/6] update build.sh Doesn't use anything bash-specific, so can be a /bin/sh script --- build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index 10f26c0d..268abd28 100644 --- a/build.sh +++ b/build.sh @@ -1,2 +1,2 @@ -#!/usr/bin/env bash -docker-compose run --rm builder /bin/bash /build/ci/buildAll.sh \ No newline at end of file +#!/bin/sh +docker-compose run --rm builder /bin/bash /build/ci/buildAll.sh From 5aa30f2b054a77782e35ad3a873f4ca8914faa90 Mon Sep 17 00:00:00 2001 From: slycordinator <68940237+slycordinator@users.noreply.github.com> Date: Mon, 27 Dec 2021 16:07:55 +0900 Subject: [PATCH 4/6] update build.sh Modified quoting/variables as recommended by shellcheck --- source/build.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/build.sh b/source/build.sh index 8d3700fe..643af510 100755 --- a/source/build.sh +++ b/source/build.sh @@ -77,7 +77,7 @@ echo "*********************************************" # Calculate available languages for f in "$TRANSLATION_DIR"/translation_*.json; do - AVAILABLE_LANGUAGES+=($(echo $f | tr "[:lower:]" "[:upper:]" | sed "s/[^_]*_//" | sed "s/\.JSON//g")) + AVAILABLE_LANGUAGES+=("$(echo "$f" | tr "[:lower:]" "[:upper:]" | sed "s/[^_]*_//" | sed "s/\.JSON//g")") done # Checking requested language @@ -124,8 +124,8 @@ if [ ${#BUILD_LANGUAGES[@]} -gt 0 ] && [ ${#BUILD_MODELS[@]} -gt 0 ]; then checkLastCommand for model in "${BUILD_MODELS[@]}"; do - echo "Building firmware for $model in ${BUILD_LANGUAGES[@]}" - make -j$(nproc) model="$model" "${BUILD_LANGUAGES[@]/#/firmware-}" >/dev/null + echo "Building firmware for $model in ${BUILD_LANGUAGES[*]}" + make -j"$(nproc)" model="$model" "${BUILD_LANGUAGES[@]/#/firmware-}" >/dev/null checkLastCommand done else From 47b0d287bb793d86afb4032f0727bd9419df0a4f Mon Sep 17 00:00:00 2001 From: slycordinator <68940237+slycordinator@users.noreply.github.com> Date: Mon, 27 Dec 2021 16:10:55 +0900 Subject: [PATCH 5/6] update buildAll.sh Doesn't use anything bash-specific so it can be a /bin/sh script --- ci/buildAll.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/buildAll.sh b/ci/buildAll.sh index f285530a..566cfe72 100755 --- a/ci/buildAll.sh +++ b/ci/buildAll.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/sh set -e set -u From 48b9097c2c94a919651407dee04972ecf191391e Mon Sep 17 00:00:00 2001 From: slycordinator <68940237+slycordinator@users.noreply.github.com> Date: Mon, 27 Dec 2021 16:26:54 +0900 Subject: [PATCH 6/6] update flash_ts100_linux.sh Change to more generic /bin/sh script * added support for using on shells that don't have UID variable; uses UID if it's available and calls "id -u" when it's not * modified quoting as recommended by shellcheck * changed to not use "$?" to check for failure. Now uses "if ! (command); then (fail condition); fi" for when a command fails --- Flashing/flash_ts100_linux.sh | 42 +++++++++++++++-------------------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/Flashing/flash_ts100_linux.sh b/Flashing/flash_ts100_linux.sh index 943ebf2a..7c8aac06 100755 --- a/Flashing/flash_ts100_linux.sh +++ b/Flashing/flash_ts100_linux.sh @@ -1,9 +1,9 @@ -#!/bin/bash +#!/bin/sh # TS100 Flasher for Linux by Alex Wigen (https://github.com/awigen) DIR_TMP="/tmp/ts100" -function usage() { +usage() { echo echo "#################" echo "# TS100 Flasher #" @@ -18,36 +18,32 @@ function usage() { } GAUTOMOUNT=0 -function disable_gautomount { - GSETTINGS=$(which gsettings) - if [ $? -ne 0 ]; then +disable_gautomount() { + if ! GSETTINGS=$(which gsettings); then return 1 fi - gsettings get org.gnome.desktop.media-handling automount | grep true > /dev/null - if [ $? -eq 0 ]; then + if ! gsettings get org.gnome.desktop.media-handling automount | grep true > /dev/null; then GAUTOMOUNT=1 gsettings set org.gnome.desktop.media-handling automount false fi } -function enable_gautomount { +enable_gautomount() { if [ "$GAUTOMOUNT" -ne 0 ]; then gsettings set org.gnome.desktop.media-handling automount true fi } -function is_attached { - output=$(lsblk -b --raw --output NAME,MODEL | grep 'DFU.*Disk') - if [ $? -ne 0 ]; then +is_attached() { + if ! output=$(lsblk -b --raw --output NAME,MODEL | grep 'DFU.*Disk'); then return 1 fi - DEVICE=$(echo $output | awk '{print "/dev/"$1}') + DEVICE=$(echo "$output" | awk '{print "/dev/"$1}') } instructions="not printed" -function wait_for_ts100 { - is_attached - while [ $? -ne 0 ]; do +wait_for_ts100() { + while ! is_attached; do if [ "$instructions" = "not printed" ]; then echo echo "#####################################################" @@ -60,29 +56,27 @@ function wait_for_ts100 { instructions="printed" fi sleep 0.1 - is_attached done } -function mount_ts100 { +mount_ts100() { mkdir -p "$DIR_TMP" - sudo mount -t msdos -o uid=$UID "$DEVICE" "$DIR_TMP" - if [ $? -ne 0 ]; then + user="${UID:-$(id -u)}" + if ! sudo mount -t msdos -o uid=$user "$DEVICE" "$DIR_TMP"; then echo "Failed to mount $DEVICE on $DIR_TMP" exit 1 fi } -function umount_ts100 { - mountpoint "$DIR_TMP" > /dev/null && sudo umount "$DIR_TMP" - if [ $? -ne 0 ]; then +umount_ts100() { + if ! mountpoint "$DIR_TMP" > /dev/null && sudo umount "$DIR_TMP"; then echo "Failed to unmount $DIR_TMP" exit 1 fi rmdir "$DIR_TMP" } -function cleanup { +cleanup() { enable_gautomount if [ -d "$DIR_TMP" ]; then umount_ts100 @@ -102,7 +96,7 @@ if [ ! -f "$1" ]; then exit 1 fi -if [ $(head -c1 "$1") != ":" ] || [ $(tail -n1 "$1" | head -c1) != ":" ]; then +if [ "$(head -c1 "$1")" != ":" ] || [ "$(tail -n1 "$1" | head -c1)" != ":" ]; then echo "'$1' doesn't look like a valid HEX file. Please provide a HEX file to flash" usage exit 1