Skip to content

Commit

Permalink
scripts: fix shellcheck error and warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Alice Khoudli <alice.khoudli@polytechnique.org>
  • Loading branch information
Synar committed Nov 8, 2024
1 parent c9daa1d commit 3e84506
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/check-commit-titles.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/bin/sh
# shellcheck disable=SC2317

# This script reads newline separated commit titles from stdin
# output an error message when titles are deemed invalid,
# and exits accordingly

if [ -z "$NOCOLOR" ]; then
RED=$(tput setaf 1 2>/dev/null)
YELLOW=$(tput setaf 3 2>/dev/null)
BLUE=$(tput setaf 4 2>/dev/null)
RESET=$(tput sgr0 2>/dev/null)
fi
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ jobs:

- name: Find and check all scripts using ShellCheck
uses: ludeeus/action-shellcheck@master
with:
ignore_names: gradlew

check_generated_railjson_sync:
runs-on: ubuntu-latest
Expand Down
7 changes: 4 additions & 3 deletions editoast/assets/signal_sprites/generate-atlas.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
# First add all your svg in a subfolder named to the signaling system (eg: `BAL`)
# Then run this script. You will need docker.

for signaling_system in $(ls); do
for signaling_system in *; do
# Skip files (like this file)
[ ! -d "${signaling_system}" ] && continue
[ -d "${signaling_system}" ] || continue

# Prepare the tmp directory
tmp_dir="$(mktemp -d)"
Expand All @@ -20,7 +20,8 @@ for signaling_system in $(ls); do
cp "${tmp_dir}"/sprites/sprites* "${signaling_system}"

# Add a linefeed to the json files
for json_file in $(ls "${signaling_system}"/*.json); do
for json_file in "${signaling_system}"/*.json; do
[ -f "$json_file" ] || continue
echo "" >> "${json_file}"
done

Expand Down
6 changes: 2 additions & 4 deletions front/scripts/generate-types.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#!/bin/sh
npx @rtk-query/codegen-openapi src/config/openapi-editoast-config.ts
if [ $? -ne 0 ]; then
if ! npx @rtk-query/codegen-openapi src/config/openapi-editoast-config.ts; then
echo "npx @rtk-query/codegen-openapi src/config/openapi-editoast-config.ts command failed. Exit the script"
exit 1
fi
yarn eslint --fix src/common/api/generatedEditoastApi.ts --no-ignore
npx @rtk-query/codegen-openapi src/config/openapi-gateway-config.ts
if [ $? -ne 0 ]; then
if ! npx @rtk-query/codegen-openapi src/config/openapi-gateway-config.ts; then
echo "npx @rtk-query/codegen-openapi src/config/openapi-gateway-config.ts command failed. Exit the script"
exit 1
fi
Expand Down
10 changes: 5 additions & 5 deletions scripts/cleanup-db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if [ "$#" -ne 0 ]; then
exit 1
fi

root_path="$(realpath $(dirname "$0")/..)"
root_path=$(realpath "$(dirname "$0")/..")

# These variables are necessary to load the infra on the correct instance (the pr-infra or the dev one)
OSRD_POSTGRES="osrd-postgres"
Expand All @@ -37,13 +37,13 @@ echo "Checking database exists..."
DB_EXISTS="$(docker exec $OSRD_POSTGRES psql -p $OSRD_POSTGRES_PORT -c "SELECT EXISTS (SELECT FROM pg_stat_database WHERE datname = 'osrd');")"
DB_EXISTS="$(echo "$DB_EXISTS" | grep -o -E '[tf]$')"

if [ $DB_EXISTS = 't' ]; then
if [ "$DB_EXISTS" = 't' ]; then
echo " Database 'osrd' found"
else
echo " Database 'osrd' not found"
fi

if [ $DB_EXISTS = 't' ]; then
if [ "$DB_EXISTS" = 't' ]; then
# Check that no service is connected to the database
echo "Checking database availability..."

Expand All @@ -56,7 +56,7 @@ if [ $DB_EXISTS = 't' ]; then
DB_CONN="$(docker exec "$OSRD_POSTGRES" psql -p "$OSRD_POSTGRES_PORT" -c "SELECT numbackends FROM pg_stat_database WHERE datname = 'osrd';")"
DB_CONN="$(echo "$DB_CONN" | grep -o -E '[0-9]+$')"

if [ $DB_CONN -ne 0 ]; then
if [ "$DB_CONN" -ne 0 ]; then
echo " The database can not be cleared."
echo " A process is connected to your database, please check it and close it."
echo " In doubt, you can shutdown the whole compose stack and only keep the database running."
Expand All @@ -77,6 +77,6 @@ docker exec "$OSRD_POSTGRES" psql -p "$OSRD_POSTGRES_PORT" -f //tmp/init.sql > /
echo "Deleting valkey cache..."
docker exec "$OSRD_VALKEY" valkey-cli -p "$OSRD_VALKEY_PORT" FLUSHALL > /dev/null 2>&1 || docker volume rm -f $OSRD_VALKEY_VOLUME > /dev/null

echo "Cleanup done!\n"
printf 'Cleanup done!\n'
echo "You may want to apply migrations if you don't load a backup:"
echo "'diesel migration run --migration-dir \"$root_path/editoast/migrations\"' # 'docker compose up editoast' does it automatically"
2 changes: 1 addition & 1 deletion scripts/create-backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set -e

OUTPUT_DIR="."
if [ "$#" -eq 1 ]; then
OUTPUT_DIR="$(readlink -f $1)/"
OUTPUT_DIR="$(readlink -f "$1")/"
fi

# Check output directory
Expand Down
4 changes: 2 additions & 2 deletions scripts/drop-core.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/sh

docker rm -f dyn-osrd-core-$1
docker rm -f "dyn-osrd-core-$1"

docker compose \
-p "osrd" \
-f "docker-compose.yml" \
exec rabbitmq rabbitmqctl delete_queue core-$1
exec rabbitmq rabbitmqctl delete_queue "core-$1"
2 changes: 1 addition & 1 deletion scripts/load-backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if [ "$#" -ne 1 ]; then
exit 1
fi

root_path="$(realpath $(dirname "$0")/..)"
root_path=$(realpath "$(dirname "$0")/..")

# Check sha1 is matching
echo "Checking backup integrity..."
Expand Down

0 comments on commit 3e84506

Please sign in to comment.