Skip to content

Commit cb6d1e9

Browse files
authored
fix(ci): resolve all ShellCheck warnings and errors
- fix(gc-cleanup): SC1128 move shebang to line 1 (was after comment) - fix(auto-deployment): SC2181 check git pull exit code directly in if - fix(rsync-backup): SC2181 inline rsync into if condition - fix(backup): SC2086 quote variables; convert backup_files to array - fix(backup-size-trend): SC2038 use -print0/-0 for non-alphanumeric filenames - fix(check-ssl-expiry): SC2004 remove unnecessary $/{} in arithmetic - fix(disk-inode-monitor): SC2034 remove unused ALERT variable in subshell - fix(disk-usage-monitor): SC2162 add -r to read; SC2086 quote $output - fix(file-integrity-snapshot): SC2094 write to tempfile then mv to manifest - fix(git-repo-stats): SC2006 replace backticks with $(); SC2126 use grep -c - fix(k8s-pod-restart-report): SC2054 quote custom-columns arg; SC2034 remove unused findings - fix(kubectl-namespace-cleanup): SC2162 add -r to read -p - fix(system-resource-reporter): SC2155 declare then assign all local vars - fix(ci): set --severity=warning so warnings and errors fail the build - fix(shellcheckrc): align severity with CI (warning)
1 parent ed3cae7 commit cb6d1e9

15 files changed

Lines changed: 43 additions & 47 deletions

β€Ž.github/workflows/ci.ymlβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: Lint all scripts
2424
run: |
2525
echo "Running ShellCheck on all scripts..."
26-
find scripts/ -name "*.sh" -type f | sort | xargs shellcheck
26+
find scripts/ -name "*.sh" -type f | sort | xargs shellcheck --severity=warning
2727
2828
test:
2929
name: BATS Test Suite

β€Ž.shellcheckrcβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# All scripts in this repo target bash
55
shell=bash
66

7-
# Only fail on actual errors (not style warnings) β€” tighten to 'warning' over time
8-
severity=error
7+
# Only fail on warnings and above (not style/info notes) β€” tighten to 'style' over time
8+
severity=warning
99

1010
# SC1091: Not following source β€” external files can't be statically analysed
1111
disable=SC1091

β€Žscripts/auto-deployment.shβ€Ž

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ cd "$REPO_DIR" || { echo "Repository directory not found."; exit 1; }
99

1010
# Pull the latest code
1111
echo "Pulling latest code from repository."
12-
git pull origin main
1312

1413
# Check if the pull was successful
15-
if [ $? -eq 0 ]; then
14+
if git pull origin main; then
1615
echo "Code updated successfully."
1716
# Restart the application service
1817
echo "Restarting $SERVICE service."

β€Žscripts/backup-size-trend.shβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ if [[ ! -d "$BACKUP_DIR" ]]; then
2929
fi
3030

3131
echo "Largest backup files in $BACKUP_DIR"
32-
find "$BACKUP_DIR" -maxdepth 1 -type f | xargs -r du -h 2>/dev/null | sort -hr | head -n "$TOP_N"
32+
find "$BACKUP_DIR" -maxdepth 1 -type f -print0 | xargs -r0 du -h 2>/dev/null | sort -hr | head -n "$TOP_N"

β€Žscripts/backup.shβ€Ž

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33

44
# Set backup directories and files
55
backup_dir="/var/backups"
6-
backup_files="/etc /var/www /home /var/lib /var/mail /opt"
6+
backup_files=(/etc /var/www /home /var/lib /var/mail /opt)
77

88
# Set the date and time for the backup
99
day=$(date +%Y-%m-%d)
1010
hostname=$(hostname -s)
1111
archive_file="$hostname-$day.tgz"
1212

1313
# Create the backup directory if it does not exist
14-
if [ ! -d $backup_dir ]; then
15-
mkdir -p $backup_dir
14+
if [ ! -d "$backup_dir" ]; then
15+
mkdir -p "$backup_dir"
1616
fi
1717

1818
# Create the backup archive
19-
tar czf $backup_dir/$archive_file $backup_files
19+
tar czf "$backup_dir/$archive_file" "${backup_files[@]}"
2020

2121
# Print the backup status
22-
echo "Backup of $backup_files completed! Details about the output backup file:"
23-
ls -lh $backup_dir/$archive_file
22+
echo "Backup of ${backup_files[*]} completed! Details about the output backup file:"
23+
ls -lh "$backup_dir/$archive_file"
2424
echo "Backup completed on $(date)"
2525
echo "Backup script completed"

β€Žscripts/check-ssl-expiry.shβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ EXPIRY_EPOCH=$(date -d "$EXPIRY_DATE" +%s 2>/dev/null || date -j -f "%b %d %T %Y
3232
CURRENT_EPOCH=$(date +%s)
3333

3434
# Calculate days until expiration
35-
DAYS_UNTIL_EXPIRY=$(( ($EXPIRY_EPOCH - $CURRENT_EPOCH) / 86400 ))
35+
DAYS_UNTIL_EXPIRY=$(( (EXPIRY_EPOCH - CURRENT_EPOCH) / 86400 ))
3636

3737
# Display results
3838
echo "Certificate expiration date: $EXPIRY_DATE"

β€Žscripts/disk-inode-monitor.shβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ df -Pi | awk 'NR>1 {print $1, $5, $6}' | while read -r fs usage mount; do
3838
used_percent=${usage%%%}
3939
if (( used_percent >= THRESHOLD )); then
4040
echo "ALERT: $fs at $mount inode usage ${usage}"
41-
ALERT=1
4241
else
4342
echo "OK: $fs at $mount inode usage ${usage}"
4443
fi

β€Žscripts/disk-usage-monitor.shβ€Ž

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ THRESHOLD=80
55
ALERT_EMAIL="admin@example.com"
66

77
# Check disk usage for each mounted file system
8-
df -h | awk '{if(NR>1) print $5 " " $6}' | while read output; do
9-
usage=$(echo $output | awk '{print $1}' | sed 's/%//')
10-
mount_point=$(echo $output | awk '{print $2}')
8+
df -h | awk '{if(NR>1) print $5 " " $6}' | while read -r output; do
9+
usage=$(echo "$output" | awk '{print $1}' | sed 's/%//')
10+
mount_point=$(echo "$output" | awk '{print $2}')
1111
if [ "$usage" -ge "$THRESHOLD" ]; then
1212
echo "Disk usage on $mount_point has reached $usage%." | mail -s "Disk Usage Alert" "$ALERT_EMAIL"
1313
fi

β€Žscripts/file-integrity-snapshot.shβ€Ž

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ if [[ "$MODE" == "create" ]]; then
4141
fi
4242

4343
if [[ -d "$TARGET_PATH" ]]; then
44-
find "$TARGET_PATH" -type f ! -name "$(basename "$MANIFEST_FILE")" -print0 | sort -z | xargs -0 sha256sum > "$MANIFEST_FILE"
44+
_tmpfile=$(mktemp)
45+
find "$TARGET_PATH" -type f ! -name "$(basename "$MANIFEST_FILE")" -print0 | sort -z | xargs -0 sha256sum > "$_tmpfile"
46+
mv "$_tmpfile" "$MANIFEST_FILE"
4547
else
4648
sha256sum "$TARGET_PATH" > "$MANIFEST_FILE"
4749
fi

β€Žscripts/gc-cleanup.shβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Script run garbage collection
21
#!/bin/bash
2+
# Script run garbage collection
33

44
# Run git gc prune - remove objects that are no longer pointed to by any object
55
git gc --prune=now

0 commit comments

Comments
Β (0)