Skip to content

Commit b239adc

Browse files
committed
Fix shellcheck findings and add shellcheck to CI
- Fix broken quoting in error messages (lines 205-206, 973) - Quote $TMP_OUTPUT and $SNAPRAID_CONF where unquoted - Separate local declaration from assignment in check_snapraid_status - Add SC2261 suppress directives for intentional exec redirections - Add SC2155 suppress for show_snapraid_info (display-only, exit code irrelevant) - Add shellcheck --severity=error step to CI
1 parent 1743feb commit b239adc

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

.github/workflows/tests.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ jobs:
1919
uses: actions/checkout@v5
2020

2121
- name: Install dependencies
22-
run: sudo apt-get update -qq && sudo apt-get install -y bats bc
22+
run: sudo apt-get update -qq && sudo apt-get install -y bats bc shellcheck
23+
24+
- name: ShellCheck
25+
run: shellcheck --severity=error snapraid-aio-script.sh
2326

2427
- name: Make mock snapraid executable
2528
run: chmod +x tests/mock/snapraid

snapraid-aio-script.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ fi
202202
if [ "$OMV_VERSION" -ge 7 ]; then
203203
pick_snapraid_conf_file
204204
else
205-
echo "SnapRAID configuration file not found. The script cannot be run! Please check your settings, because the specified file "$SNAPRAID_CONF" does not exist."
206-
mklog "WARN: SnapRAID configuration file not found. The script cannot be run! Please check your settings, because the specified file "$SNAPRAID_CONF" does not exist."
205+
echo "SnapRAID configuration file not found. The script cannot be run! Please check your settings, because the specified file \"$SNAPRAID_CONF\" does not exist."
206+
mklog "WARN: SnapRAID configuration file not found. The script cannot be run! Please check your settings, because the specified file \"$SNAPRAID_CONF\" does not exist."
207207
SUBJECT="[WARNING] - SnapRAID configuration file not found!"
208208
FORMATTED_CONF="\`$SNAPRAID_CONF\`"
209209
NOTIFY_OUTPUT="$SUBJECT The script cannot be run! Please check your settings, because the specified file $FORMATTED_CONF does not exist."
@@ -465,7 +465,7 @@ fi
465465
# Save and rotate logs if enabled
466466
if [ "$RETENTION_DAYS" -gt 0 ]; then
467467
find "$SNAPRAID_LOG_DIR"/SnapRAID-* -mtime +"$RETENTION_DAYS" -delete # delete old logs
468-
cp $TMP_OUTPUT "$SNAPRAID_LOG_DIR"/SnapRAID-"$(date +"%Y_%m_%d-%H%M")".txt
468+
cp "$TMP_OUTPUT" "$SNAPRAID_LOG_DIR"/SnapRAID-"$(date +"%Y_%m_%d-%H%M")".txt
469469
fi
470470

471471
# exit with success, letting the trap handle cleanup of file descriptors
@@ -557,6 +557,7 @@ sed_me(){
557557
# process and redirect output. We close stream because of the calls to new
558558
# wait function in between sed_me calls. If we do not do this we try to close
559559
# Processes which are not parents of the shell.
560+
# shellcheck disable=SC2261
560561
exec >& "$OUT" 2>& "$ERROR"
561562
sed -i "$1" "$2"
562563

@@ -676,7 +677,7 @@ chk_sync_warn(){
676677
chk_zero(){
677678
echo "### SnapRAID TOUCH [$(date)]"
678679
echo "Checking for zero sub-second files..."
679-
TIMESTATUS=$($SNAPRAID_BIN -c $SNAPRAID_CONF status | grep -E 'You have [1-9][0-9]* files with( a)? zero sub-second timestamp\.' | sed 's/^You have/Found/g')
680+
TIMESTATUS=$($SNAPRAID_BIN -c "$SNAPRAID_CONF" status | grep -E 'You have [1-9][0-9]* files with( a)? zero sub-second timestamp\.' | sed 's/^You have/Found/g')
680681
if [ -n "$TIMESTATUS" ]; then
681682
echo "$TIMESTATUS"
682683
echo "Running TOUCH job to timestamp. [$(date)]"
@@ -970,7 +971,7 @@ if [ "$APPRISE" -eq 1 ]; then
970971
APPRISE_EMAIL_ATTACH_DO=0
971972
fi
972973

973-
mklog "INFO: "$SUBJECT""
974+
mklog "INFO: $SUBJECT"
974975
}
975976

976977
notify_warning(){
@@ -1023,6 +1024,7 @@ if [ "$APPRISE_EMAIL" -eq 1 ]; then
10231024

10241025

10251026
show_snapraid_info() {
1027+
# shellcheck disable=SC2155
10261028
local command_output=$($1)
10271029
echo "$2"
10281030
echo "\`\`\`"
@@ -1168,6 +1170,7 @@ fi
11681170
# finish. Probably not the best way of 'fixing' this issue. Someone with more
11691171
# knowledge can provide better insight.
11701172
close_output_and_wait(){
1173+
# shellcheck disable=SC2261
11711174
exec >& "$OUT" 2>& "$ERROR"
11721175
CHILD_PID=$(pgrep -P $$)
11731176
if [ -n "$CHILD_PID" ]; then
@@ -1426,7 +1429,8 @@ extract_snapraid_info() {
14261429
# Run SnapRAID status to check for the previous sync
14271430
check_snapraid_status() {
14281431
# Run snapraid status command and capture the output
1429-
local snapraid_status_output=$("$SNAPRAID_BIN" status -c "$SNAPRAID_CONF")
1432+
local snapraid_status_output
1433+
snapraid_status_output=$("$SNAPRAID_BIN" status -c "$SNAPRAID_CONF")
14301434

14311435
# Check for the "No sync is in progress" message
14321436
if echo "$snapraid_status_output" | grep -q "No sync is in progress"; then

0 commit comments

Comments
 (0)