Skip to content

Commit 64ed658

Browse files
committed
CI: fix shellcheck issues in bash scripts
Replace exit code checking pattern from '\! cmd' to using variables for better code clarity. Wrap long command lines at 80 characters and ensure proper variable quoting to comply with shellcheck recommendations. - Use curl_exit_code, sed_exit_code, tar_exit_code variables - Fix SC2181 violations by avoiding $? checks - Fix SC2086 violations by adding quotes around variables - Improve readability with proper line wrapping
1 parent 9bdd58c commit 64ed658

File tree

3 files changed

+28
-17
lines changed

3 files changed

+28
-17
lines changed

frontend/docker/startup.sh

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ replace_signaling_url() {
1010
echo "Replacing signaling URL in $HTTPD_CONF..."
1111

1212
sed -i "s|$SIGNALING_URL|$OPENMINA_SIGNALING_URL|g" "$HTTPD_CONF"
13-
14-
if [[ $? -ne 0 ]]; then
13+
sed_exit_code=$?
14+
if [[ $sed_exit_code -ne 0 ]]; then
1515
echo "Failed to replace the signaling URL, exiting."
1616
exit 1
1717
else
18-
echo "Successfully replaced signaling URL with '$OPENMINA_SIGNALING_URL' in $HTTPD_CONF"
18+
echo "Successfully replaced signaling URL with" \
19+
"'$OPENMINA_SIGNALING_URL' in $HTTPD_CONF"
1920
fi
2021
else
2122
echo "OPENMINA_SIGNALING_URL is not set. No replacement performed."
@@ -63,8 +64,11 @@ download_circuit_files() {
6364
echo "$FILE already exists in $DOWNLOAD_DIR, skipping download."
6465
else
6566
echo "Downloading $FILE to $DOWNLOAD_DIR..."
66-
curl -s -L --retry 3 --retry-delay 5 -o "$DOWNLOAD_DIR/$FILE" "$CIRCUITS_BASE_URL/$CIRCUITS_VERSION/$FILE"
67-
if [[ $? -ne 0 ]]; then
67+
curl -s -L --retry 3 --retry-delay 5 \
68+
-o "$DOWNLOAD_DIR/$FILE" \
69+
"$CIRCUITS_BASE_URL/$CIRCUITS_VERSION/$FILE"
70+
curl_exit_code=$?
71+
if [[ $curl_exit_code -ne 0 ]]; then
6872
echo "Failed to download $FILE after 3 attempts, exiting."
6973
exit 1
7074
else
@@ -80,24 +84,28 @@ download_wasm_files() {
8084
exit 1
8185
fi
8286

83-
WASM_URL="$OPENMINA_BASE_URL/openmina/releases/download/$OPENMINA_WASM_VERSION/openmina-$OPENMINA_WASM_VERSION-webnode-wasm.tar.gz"
87+
WASM_URL="$OPENMINA_BASE_URL/openmina/releases/download/\
88+
$OPENMINA_WASM_VERSION/openmina-$OPENMINA_WASM_VERSION-webnode-wasm.tar.gz"
8489
TARGET_DIR="/usr/local/apache2/htdocs/assets/webnode/pkg"
8590

8691
mkdir -p "$TARGET_DIR"
8792

8893
echo "Downloading WASM files from $WASM_URL..."
89-
curl -s -L --retry 3 --retry-delay 5 -o "/tmp/openmina-$OPENMINA_WASM_VERSION-webnode-wasm.tar.gz" "$WASM_URL"
90-
91-
if [[ $? -ne 0 ]]; then
94+
curl -s -L --retry 3 --retry-delay 5 \
95+
-o "/tmp/openmina-$OPENMINA_WASM_VERSION-webnode-wasm.tar.gz" \
96+
"$WASM_URL"
97+
curl_exit_code=$?
98+
if [[ $curl_exit_code -ne 0 ]]; then
9299
echo "Failed to download the WASM file after 3 attempts, exiting."
93100
exit 1
94101
else
95102
echo "WASM file downloaded successfully. Extracting to $TARGET_DIR..."
96103

97-
tar -xzf "/tmp/openmina-$OPENMINA_WASM_VERSION-webnode-wasm.tar.gz" -C "$TARGET_DIR"
98-
99104
# Check if the extraction was successful
100-
if [[ $? -ne 0 ]]; then
105+
tar -xzf "/tmp/openmina-$OPENMINA_WASM_VERSION-webnode-wasm.tar.gz" \
106+
-C "$TARGET_DIR"
107+
tar_exit_code=$?
108+
if [[ $tar_exit_code -ne 0 ]]; then
101109
echo "Failed to extract the WASM file, exiting."
102110
exit 1
103111
else

frontend/scripts/download-webnode.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ download_circuit_files() {
4545
echo "$FILE already exists in $DOWNLOAD_DIR, skipping download."
4646
else
4747
echo "Downloading $FILE to $DOWNLOAD_DIR..."
48-
curl -s -L --retry 3 --retry-delay 5 -o "$DOWNLOAD_DIR/$FILE" "$CIRCUITS_BASE_URL/$CIRCUITS_VERSION/$FILE"
49-
if [[ $? -ne 0 ]]; then
48+
curl -s -L --retry 3 --retry-delay 5 \
49+
-o "$DOWNLOAD_DIR/$FILE" \
50+
"$CIRCUITS_BASE_URL/$CIRCUITS_VERSION/$FILE"
51+
curl_exit_code=$?
52+
if [[ $curl_exit_code -ne 0 ]]; then
5053
echo "Failed to download $FILE after 3 attempts, exiting."
5154
exit 1
5255
else

producer-dashboard/docker/init-db/init-db.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ PASSWORD=${POSTGRES_PASSWORD}
1010

1111
# Wait for PostgreSQL to become available
1212
echo "Waiting for postgres..."
13-
while ! pg_isready -h $HOST -p $PORT -U $USER; do
13+
while ! pg_isready -h "$HOST" -p "$PORT" -U "$USER"; do
1414
sleep 2;
1515
done
1616

1717
# Check if the database exists, and create it if it doesn't
18-
if ! PGPASSWORD=$PASSWORD psql -h $HOST -U $USER -lqt | cut -d \| -f 1 | grep -qw $DB; then
18+
if ! PGPASSWORD=$PASSWORD psql -h "$HOST" -U "$USER" -lqt | cut -d \| -f 1 | grep -qw "$DB"; then
1919
echo "Database $DB does not exist. Creating..."
2020
PGPASSWORD="$PASSWORD" createdb -h "$HOST" -U "$USER" "$DB"
2121
# Load the schema into the database
@@ -24,7 +24,7 @@ if ! PGPASSWORD=$PASSWORD psql -h $HOST -U $USER -lqt | cut -d \| -f 1 | grep -q
2424
# PGPASSWORD=$PASSWORD psql -h $HOST -U $USER -d $DB < create_schema.sql
2525
# TODO
2626
cd /dumps
27-
PGPASSWORD=$PASSWORD psql -h $HOST -U $USER -d $DB < dump.sql
27+
PGPASSWORD=$PASSWORD psql -h "$HOST" -U "$USER" -d "$DB" < dump.sql
2828
exit 1
2929
else
3030
echo "Database $DB already exists."

0 commit comments

Comments
 (0)