From e94775f1c41a459c42609b9d496c648fd47e4716 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer <mschiffer@universe-factory.net> Date: Mon, 7 Apr 2025 19:16:54 +0200 Subject: [PATCH] lint: sh: add checking for initscripts Detect initscripts by their shebang line. SC2034 is ignored additionally for these scripts, to avoid needing to override it for setting START, USE_PROCD, ... in every single script. --- scripts/lint-sh.sh | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/lint-sh.sh b/scripts/lint-sh.sh index e6cf28498..1cb16c71e 100755 --- a/scripts/lint-sh.sh +++ b/scripts/lint-sh.sh @@ -6,6 +6,10 @@ is_scriptfile() { echo "$1" | grep -q '\.sh$' || head -n1 "$1" | grep -qE '^#!(.*\<bash|/bin/sh)$' } +is_initscript() { + head -n1 "$1" | grep -qxF '#!/bin/sh /etc/rc.common' +} + find contrib -type f | while read -r file; do is_scriptfile "$file" || continue @@ -14,10 +18,13 @@ find contrib -type f | while read -r file; do done find package -type f | while read -r file; do - is_scriptfile "$file" || continue - - echo "Checking $file" - shellcheck -f gcc -x -s sh -e SC2039,SC3043,SC3037,SC3057 "$file" + if is_scriptfile "$file"; then + echo "Checking $file" + shellcheck -f gcc -x -s sh -e SC2039,SC3043,SC3037,SC3057 "$file" + elif is_initscript "$file"; then + echo "Checking $file (initscript)" + shellcheck -f gcc -x -s sh -e SC2034,SC2039,SC3043,SC3037,SC3057 "$file" + fi done find scripts -type f | while read -r file; do -- GitLab