Skip to content

Commit

Permalink
fix: avoid potential bugs (#1999)
Browse files Browse the repository at this point in the history
* fix: use double quotes

* fix: use $(...)

* fix: remove redundant 'cd -'

* style: avoid using $?

* style: avoid using $?

* fix: revert changes

* fix: use safe cd
  • Loading branch information
vil02 committed Jan 16, 2022
1 parent 55d965e commit 67b7ab1
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 34 deletions.
6 changes: 3 additions & 3 deletions apps/librelingo-standalone-server/build.sh
Expand Up @@ -3,7 +3,7 @@
DIRNAME=$(dirname "$0")
DEFAULT_OUTPUT_DIR="$DIRNAME/bin"
if [ -n "$1" ]; then
WEBSITE_DIR="$1"
WEBSITE_DIR="$1"
else
echo "This script packs the LibreLingo website into a single executable file"
echo "Usage: build.sh WEBSITE-DIR [OUTPUT-DIR]"
Expand All @@ -24,9 +24,9 @@ function cleanup {
trap cleanup EXIT

# copy the website files to the build directory
cp -r "$WEBSITE_DIR" "$BUILD_DIR/static"
cp -r "$WEBSITE_DIR" "$BUILD_DIR/static"
# copy the go files to the build directory
cd $DIRNAME
cd "$DIRNAME"
cp -r ./* "$BUILD_DIR"

set -eux
Expand Down
9 changes: 4 additions & 5 deletions apps/web/scripts/fetchPhoto.sh
@@ -1,8 +1,8 @@
#!/usr/bin/env bash

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

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

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

2 changes: 1 addition & 1 deletion apps/web/scripts/fetchPhotos.sh
@@ -1,5 +1,5 @@
#!/usr/bin/env bash

tail -n +2 ../../docs/image_attributions.csv | while read -r photo_description; do \
./scripts/fetchPhoto.sh $photo_description; \
./scripts/fetchPhoto.sh "$photo_description"; \
done
4 changes: 2 additions & 2 deletions apps/web/scripts/installExternalCourse.sh
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

wget "$1" -O temp.zip
unzip temp.zip "*/course/*" -d ../../courses/$2
mv ../../courses/$2/*/course/* ../../courses/$2
unzip temp.zip "*/course/*" -d ../../courses/"$2"
mv ../../courses/"$2"/*/course/* ../../courses/"$2"
rm temp.zip
5 changes: 2 additions & 3 deletions scripts/exportAllYamlCourses.sh
Expand Up @@ -2,8 +2,8 @@

ANY_FAILED="0"
for d in ./courses/*/ ; do
d=$(echo $d | sed 's/[^/]*\/[^/]*\///' | sed 's/\///')
./scripts/exportYamlCourse.sh $d
d=$(echo "$d" | sed 's/[^/]*\/[^/]*\///' | sed 's/\///')
./scripts/exportYamlCourse.sh "$d"
if [ "$?" -eq "1" ]; then
ANY_FAILED="1"
fi
Expand All @@ -13,4 +13,3 @@ if [ "$ANY_FAILED" -eq "1" ]; then
echo "😿 Could not export all yaml courses"
exit 1
fi

9 changes: 6 additions & 3 deletions scripts/exportYamlCourse.sh
@@ -1,13 +1,16 @@
#!/bin/bash

echo -en "⏳ Exporting course $1"
cd ./apps/librelingo_json_export/ > /dev/null
poetry run export-cli ../../courses/$1 ../../apps/web/src/courses/$1
cd ./apps/librelingo_json_export/ ||
{
echo -en "\r⚠️ Wrong folder structure"
exit 1
}
poetry run export-cli ../../courses/"$1" ../../apps/web/src/courses/"$1"
if [ $? -eq 0 ]; then
echo -en "\r✅ Exported course $1"
else
echo -en "\r⚠️ Couldn't export course $1"
exit 1
fi
cd - > /dev/null
echo
4 changes: 2 additions & 2 deletions scripts/updateAudioForAllYamlCourses.sh
@@ -1,6 +1,6 @@
#!/bin/bash

for d in ./courses/*/ ; do
d=$(echo $d | sed 's/[^/]*\/[^/]*\///' | sed 's/\///')
./scripts/updateAudioForYamlCourse.sh $d "$@"
d=$(echo "$d" | sed 's/[^/]*\/[^/]*\///' | sed 's/\///')
./scripts/updateAudioForYamlCourse.sh "$d" "$@"
done
9 changes: 6 additions & 3 deletions scripts/updateAudioForYamlCourse.sh
@@ -1,12 +1,15 @@
#!/bin/bash

echo -en "⏳ Updating audio for course $1"
cd ./apps/librelingo_audios/ > /dev/null
poetry run python librelingo_audios/cli.py ../../courses/$1 ../../apps/web/static/voice $1 "${@:2}"
cd ./apps/librelingo_audios/ ||
{
echo -en "\r⚠️ Wrong folder structure"
exit 1
}
poetry run python librelingo_audios/cli.py ../../courses/"$1" ../../apps/web/static/voice "$1" "${@:2}"
if [ $? -eq 0 ]; then
echo -en "\r✅ Updated audio for course $1"
else
echo -en "\r⚠️ Couldn't update audio for course $1"
fi
cd - > /dev/null
echo
11 changes: 7 additions & 4 deletions scripts/updatePypiReadmeFiles.sh
@@ -1,11 +1,14 @@
#!/bin/bash

for directory in $(find apps/ -name pyproject.toml | xargs -n1 dirname); do
echo "Updating README.md for Python package '$(basename $directory)'..."
cd $directory
echo "Updating README.md for Python package '$(basename "$directory")'..."
cd "$directory" ||
{
echo -en "\r⚠️ Could not enter $directory"
exit 1
}
poetry install
make README.md -B $1
make README.md -B "$1"
cd -
echo
done

8 changes: 3 additions & 5 deletions scripts/verifyPypiReadmeFiles.sh
Expand Up @@ -2,19 +2,17 @@

./scripts/updatePypiReadmeFiles.sh -B

git diff --exit-code --name-only

if [ "$?" -eq "0" ]; then
if git diff --exit-code --name-only; then
echo "🎉 Amazing, PyPi readme files are up to date"
else
echo "😿 Outdated PyPi readme files detected."
echo "The following files were outdated:"
git diff --name-only
git diff --name-only
echo
echo "See the full list of changes:"
git diff
echo "Run the following script to automatically update the readme files:"
echo
echo "./scripts/updatePypiReadmeFiles.sh"
exit 1
exit 1
fi
5 changes: 2 additions & 3 deletions scripts/verifyTestCourseJsonFiles.sh
@@ -1,9 +1,8 @@
#!/bin/bash

yarn exportCourse test
git diff --exit-code --name-only

if [ "$?" -eq "0" ]; then
if git diff --exit-code --name-only; then
echo "🎉 Amazing, test course JSON files are up to date"
else
echo "😿 Outdated test course JSON files detected."
Expand All @@ -13,7 +12,7 @@ else
echo "See the full list of changes:"
git diff
echo "Run the following script to automatically update the JSON files:"
echo
echo
echo "yarn exportAllCourses"
exit 1
fi

1 comment on commit 67b7ab1

@vercel
Copy link

@vercel vercel bot commented on 67b7ab1 Jan 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.