Skip to content

Commit 67b7ab1

Browse files
authored
fix: avoid potential bugs (#1999)
* fix: use double quotes * fix: use $(...) * fix: remove redundant 'cd -' * style: avoid using $? * style: avoid using $? * fix: revert changes * fix: use safe cd
1 parent 55d965e commit 67b7ab1

11 files changed

+38
-34
lines changed

apps/librelingo-standalone-server/build.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
DIRNAME=$(dirname "$0")
44
DEFAULT_OUTPUT_DIR="$DIRNAME/bin"
55
if [ -n "$1" ]; then
6-
WEBSITE_DIR="$1"
6+
WEBSITE_DIR="$1"
77
else
88
echo "This script packs the LibreLingo website into a single executable file"
99
echo "Usage: build.sh WEBSITE-DIR [OUTPUT-DIR]"
@@ -24,9 +24,9 @@ function cleanup {
2424
trap cleanup EXIT
2525

2626
# copy the website files to the build directory
27-
cp -r "$WEBSITE_DIR" "$BUILD_DIR/static"
27+
cp -r "$WEBSITE_DIR" "$BUILD_DIR/static"
2828
# copy the go files to the build directory
29-
cd $DIRNAME
29+
cd "$DIRNAME"
3030
cp -r ./* "$BUILD_DIR"
3131

3232
set -eux

apps/web/scripts/fetchPhoto.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env bash
22

3-
url=`echo $1 | cut -d',' -f2`
4-
image_name=`echo $1 | cut -d',' -f1`
5-
image_id=`echo $url | cut -d'/' -f5`
3+
url=$(echo "$1" | cut -d',' -f2)
4+
image_name=$(echo "$1" | cut -d',' -f1)
5+
image_id=$(echo "$url" | cut -d'/' -f5)
66
download_url="https://unsplash.com/photos/$image_id/download"
77

88
if [ -e "./static/images/$image_name.jpg" ]; then
@@ -11,7 +11,7 @@ fi
1111

1212
echo "Fetching URL $url"
1313
echo "Image ID $image_id"
14-
wget $download_url -O "/tmp/$image_id.jpg"
14+
wget "$download_url" -O "/tmp/$image_id.jpg"
1515
convert "/tmp/$image_id.jpg" -resize 512x -resize 'x512<' -gravity center -crop 512x512+0+0 +repage "/tmp/$image_id\_cropped.jpg"
1616
convert "/tmp/$image_id.jpg" -resize 240x -resize 'x240<' -gravity center -crop 240x240+0+0 +repage "/tmp/$image_id\_tiny.jpg"
1717
convert "/tmp/$image_id.jpg" -resize 100x -resize 'x100<' -gravity center -crop 100x100+0+0 +repage "/tmp/$image_id\_tinier.jpg"
@@ -21,4 +21,3 @@ jpegoptim "/tmp/$image_id\_tinier.jpg" -d "./static/images/" -s -m55
2121
mv "./static/images/$image_id\_cropped.jpg" "./static/images/$image_name.jpg"
2222
mv "./static/images/$image_id\_tiny.jpg" "./static/images/$image_name""_tiny.jpg"
2323
mv "./static/images/$image_id\_tinier.jpg" "./static/images/$image_name""_tinier.jpg"
24-

apps/web/scripts/fetchPhotos.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
22

33
tail -n +2 ../../docs/image_attributions.csv | while read -r photo_description; do \
4-
./scripts/fetchPhoto.sh $photo_description; \
4+
./scripts/fetchPhoto.sh "$photo_description"; \
55
done
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

33
wget "$1" -O temp.zip
4-
unzip temp.zip "*/course/*" -d ../../courses/$2
5-
mv ../../courses/$2/*/course/* ../../courses/$2
4+
unzip temp.zip "*/course/*" -d ../../courses/"$2"
5+
mv ../../courses/"$2"/*/course/* ../../courses/"$2"
66
rm temp.zip

scripts/exportAllYamlCourses.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
ANY_FAILED="0"
44
for d in ./courses/*/ ; do
5-
d=$(echo $d | sed 's/[^/]*\/[^/]*\///' | sed 's/\///')
6-
./scripts/exportYamlCourse.sh $d
5+
d=$(echo "$d" | sed 's/[^/]*\/[^/]*\///' | sed 's/\///')
6+
./scripts/exportYamlCourse.sh "$d"
77
if [ "$?" -eq "1" ]; then
88
ANY_FAILED="1"
99
fi
@@ -13,4 +13,3 @@ if [ "$ANY_FAILED" -eq "1" ]; then
1313
echo "😿 Could not export all yaml courses"
1414
exit 1
1515
fi
16-

scripts/exportYamlCourse.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
#!/bin/bash
22

33
echo -en "⏳ Exporting course $1"
4-
cd ./apps/librelingo_json_export/ > /dev/null
5-
poetry run export-cli ../../courses/$1 ../../apps/web/src/courses/$1
4+
cd ./apps/librelingo_json_export/ ||
5+
{
6+
echo -en "\r⚠️ Wrong folder structure"
7+
exit 1
8+
}
9+
poetry run export-cli ../../courses/"$1" ../../apps/web/src/courses/"$1"
610
if [ $? -eq 0 ]; then
711
echo -en "\r✅ Exported course $1"
812
else
913
echo -en "\r⚠️ Couldn't export course $1"
1014
exit 1
1115
fi
12-
cd - > /dev/null
1316
echo
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

33
for d in ./courses/*/ ; do
4-
d=$(echo $d | sed 's/[^/]*\/[^/]*\///' | sed 's/\///')
5-
./scripts/updateAudioForYamlCourse.sh $d "$@"
4+
d=$(echo "$d" | sed 's/[^/]*\/[^/]*\///' | sed 's/\///')
5+
./scripts/updateAudioForYamlCourse.sh "$d" "$@"
66
done

scripts/updateAudioForYamlCourse.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
#!/bin/bash
22

33
echo -en "⏳ Updating audio for course $1"
4-
cd ./apps/librelingo_audios/ > /dev/null
5-
poetry run python librelingo_audios/cli.py ../../courses/$1 ../../apps/web/static/voice $1 "${@:2}"
4+
cd ./apps/librelingo_audios/ ||
5+
{
6+
echo -en "\r⚠️ Wrong folder structure"
7+
exit 1
8+
}
9+
poetry run python librelingo_audios/cli.py ../../courses/"$1" ../../apps/web/static/voice "$1" "${@:2}"
610
if [ $? -eq 0 ]; then
711
echo -en "\r✅ Updated audio for course $1"
812
else
913
echo -en "\r⚠️ Couldn't update audio for course $1"
1014
fi
11-
cd - > /dev/null
1215
echo

scripts/updatePypiReadmeFiles.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
#!/bin/bash
22

33
for directory in $(find apps/ -name pyproject.toml | xargs -n1 dirname); do
4-
echo "Updating README.md for Python package '$(basename $directory)'..."
5-
cd $directory
4+
echo "Updating README.md for Python package '$(basename "$directory")'..."
5+
cd "$directory" ||
6+
{
7+
echo -en "\r⚠️ Could not enter $directory"
8+
exit 1
9+
}
610
poetry install
7-
make README.md -B $1
11+
make README.md -B "$1"
812
cd -
913
echo
1014
done
11-

scripts/verifyPypiReadmeFiles.sh

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@
22

33
./scripts/updatePypiReadmeFiles.sh -B
44

5-
git diff --exit-code --name-only
6-
7-
if [ "$?" -eq "0" ]; then
5+
if git diff --exit-code --name-only; then
86
echo "🎉 Amazing, PyPi readme files are up to date"
97
else
108
echo "😿 Outdated PyPi readme files detected."
119
echo "The following files were outdated:"
12-
git diff --name-only
10+
git diff --name-only
1311
echo
1412
echo "See the full list of changes:"
1513
git diff
1614
echo "Run the following script to automatically update the readme files:"
1715
echo
1816
echo "./scripts/updatePypiReadmeFiles.sh"
19-
exit 1
17+
exit 1
2018
fi

0 commit comments

Comments
 (0)