From ae63b453070f7cb5702981a4969880b0bbb617ec Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Mon, 13 Apr 2026 23:40:41 -0400 Subject: [PATCH] ci: add shellcheck lint workflow; fix 6 violations Removes unused drive_width variable (SC2034). Splits local+assign for emmc_size, host, drive (SC2155). Uses ${var#...} instead of sed for PCI desc parsing (SC2001). Pipes smartctl through sudo tee to fix redirect privilege (SC2024). Co-Authored-By: Claude Sonnet 4.6 --- .gitea/workflows/lint.yml | 20 ++++++++++++++++++++ driveAtlas.sh | 16 ++++++++-------- 2 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 .gitea/workflows/lint.yml diff --git a/.gitea/workflows/lint.yml b/.gitea/workflows/lint.yml new file mode 100644 index 0000000..a903146 --- /dev/null +++ b/.gitea/workflows/lint.yml @@ -0,0 +1,20 @@ +name: Lint + +on: + push: + branches: ["**"] + pull_request: + branches: ["**"] + +jobs: + shell-lint: + name: Shell (shellcheck) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Install shellcheck + run: apt-get update -qq && apt-get install -y -qq shellcheck + + - name: Run shellcheck + run: find . -name "*.sh" -exec shellcheck {} + diff --git a/driveAtlas.sh b/driveAtlas.sh index 62d957e..876b84a 100644 --- a/driveAtlas.sh +++ b/driveAtlas.sh @@ -410,9 +410,6 @@ generate_10bay_layout() { local hostname="$1" build_drive_map - # Fixed width for consistent box drawing (fits device names like "nvme0n1") - local drive_width=10 - # Box interior width = 136 (determined by 10 bay boxes: 4 + 10*13 + 2) # Total box width = 138 (136 interior + 2 for │ borders) @@ -493,7 +490,8 @@ generate_micro_layout() { # Show eMMC if present if [[ -n "$emmc_device" ]]; then - local emmc_size=$(lsblk -d -n -o SIZE "/dev/$emmc_device" 2>/dev/null | xargs) + local emmc_size + emmc_size=$(lsblk -d -n -o SIZE "/dev/$emmc_device" 2>/dev/null | xargs) printf "│ ┌─────────────────────────────────────────────────────┐ │\n" printf "│ │ Onboard eMMC: %-10s (%s) │ │\n" "$emmc_device" "$emmc_size" printf "│ └─────────────────────────────────────────────────────┘ │\n" @@ -689,7 +687,7 @@ get_storage_controllers() { [[ -z "$line" ]] && continue pci_addr="$(echo "$line" | awk '{print $1}')" # Get short description (strip PCI address) - desc="$(echo "$line" | sed 's/^[0-9a-f:.]\+ //')" + desc="${line#*[0-9a-f:.] }" echo " $pci_addr: $desc" done } @@ -709,7 +707,8 @@ get_storage_controllers() { # Values: PCI path strings (for --show-pci option) #------------------------------------------------------------------------------ build_drive_map() { - local host="$(hostname | tr -cd '[:alnum:]-_.')" + local host + host="$(hostname | tr -cd '[:alnum:]-_.')" local mapping="${SERVER_MAPPINGS[$host]}" # Declare global arrays directly @@ -728,7 +727,8 @@ build_drive_map() { BAY_TO_PCI_PATH[$slot]="$path" if [[ -L "${DISK_BY_PATH}/$path" ]]; then - local drive="$(readlink -f "${DISK_BY_PATH}/$path" | sed 's/.*\///')" + local drive + drive="$(readlink -f "${DISK_BY_PATH}/$path" | sed 's/.*\///')" DRIVE_MAP[$slot]="$drive" ((mapped_count++)) else @@ -1090,7 +1090,7 @@ if [[ "$SKIP_SMART" != true ]]; then device="${DRIVE_MAP[$bay]}" if [[ -n "$device" && "$device" != "EMPTY" && -b "/dev/$device" ]]; then # Launch background job to collect raw smartctl data - (sudo smartctl -A -i -H "/dev/$device" > "$SMART_CACHE_DIR/${device}.raw" 2>/dev/null) & + (sudo smartctl -A -i -H "/dev/$device" 2>/dev/null | sudo tee "$SMART_CACHE_DIR/${device}.raw" > /dev/null) & ((job_count++)) if ((job_count >= max_parallel_jobs)); then wait -n 2>/dev/null || wait # wait -n requires bash 4.3+, fall back to wait