Skip to content

Commit b63ef47

Browse files
committed
Protect variables from globbing and word splitting in deploy script
Stinginess with quoting in shell scripts is the most common cause of confusing bugs that usually only occur under specific uncommon conditions. For this reason, all variables must be quoted. More information: https://github.com/koalaman/shellcheck/wiki/SC2086
1 parent 35b3bda commit b63ef47

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

deploy.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash -xe
22
GIT_REV="$(git log --pretty=format:'%h' -n 1)"
33
BUILD_DATE="$(date +%Y-%m-%d:%H:%M:%S)"
4-
COMPILEINFO="$(echo +$GIT_REV+$BUILD_DATE | tr -d '"')"
4+
COMPILEINFO="$(echo "+${GIT_REV}+${BUILD_DATE}" | tr -d '"')"
55

66
VERSION="$(cat main.go| grep "const AppVersion" |cut -f4 -d " " | tr -d '"')"
77

@@ -19,9 +19,9 @@ mkdir distrib
1919
for folder in "${target_folders[@]}"
2020
do
2121

22-
IFS=_ read -a fields <<< $folder
23-
mkdir -p distrib/$folder/bin/
24-
GOOS=${fields[0]} GOARCH=${fields[1]} go build -o distrib/$folder/bin/arduinoOTA -ldflags "-X main.compileInfo=$COMPILEINFO" main.go
22+
IFS=_ read -a fields <<< "$folder"
23+
mkdir -p "distrib/${folder}/bin/"
24+
GOOS="${fields[0]}" GOARCH="${fields[1]}" go build -o "distrib/${folder}/bin/arduinoOTA" -ldflags "-X main.compileInfo=$COMPILEINFO" main.go
2525
done
2626

2727
#Fix windows binary extension
@@ -31,11 +31,11 @@ cd distrib
3131

3232
for folder in "${target_folders[@]}"
3333
do
34-
mv $folder arduinoOTA
34+
mv "$folder" arduinoOTA
3535
if [[ $folder == "windows_386" ]]; then
36-
zip -r arduinoOTA-$VERSION-$folder.zip arduinoOTA/
36+
zip -r "arduinoOTA-${VERSION}-${folder}.zip" arduinoOTA/
3737
else
38-
tar cjf arduinoOTA-$VERSION-$folder.tar.bz2 arduinoOTA/
38+
tar cjf "arduinoOTA-${VERSION}-${folder}.tar.bz2" arduinoOTA/
3939
fi
4040
rm -rf arduinoOTA
4141
done

0 commit comments

Comments
 (0)