From fe77a45006b3e6a1928397fbe2001e2e4b873818 Mon Sep 17 00:00:00 2001 From: chrfranke <chrfranke@4ea69e1a-61f1-4043-bf83-b5c94c648137> Date: Wed, 24 Jan 2024 10:30:14 +0000 Subject: [PATCH] Fix or disable all warnings from shellcheck. git-svn-id: https://svn.code.sf.net/p/smartmontools/code/trunk@5597 4ea69e1a-61f1-4043-bf83-b5c94c648137 --- smartmontools/ChangeLog | 4 ++++ smartmontools/cppcheck.sh | 2 ++ smartmontools/do_release | 3 ++- smartmontools/getversion.sh | 6 +++--- smartmontools/os_win32/pe32edit.sh | 6 +++--- smartmontools/smartd_warning.sh.in | 4 ++++ smartmontools/update-smart-drivedb.in | 1 + 7 files changed, 19 insertions(+), 7 deletions(-) diff --git a/smartmontools/ChangeLog b/smartmontools/ChangeLog index 8a2c6968b..0617af088 100644 --- a/smartmontools/ChangeLog +++ b/smartmontools/ChangeLog @@ -1,5 +1,9 @@ $Id$ +2024-01-24 Christian Franke <franke@computer.org> + + Fix or disable all warnings from shellcheck. + 2024-01-23 Christian Franke <franke@computer.org> Makefile.am: Add target 'shellcheck'. diff --git a/smartmontools/cppcheck.sh b/smartmontools/cppcheck.sh index 1e928f81b..554cd38a5 100755 --- a/smartmontools/cppcheck.sh +++ b/smartmontools/cppcheck.sh @@ -109,6 +109,7 @@ for s in $sup_list; do suppress="${suppress}${suppress:+ }--suppress=${s%%#*}" done +# shellcheck disable=SC2089 defs="\ -U__KERNEL__ -U__LP64__ @@ -147,6 +148,7 @@ $(for s in $suppress; do echo " $s \\"; done) EOF # Run cppcheck with swapped stdout<>stderr +# shellcheck disable=SC2090 "$cppcheck" \ $v \ $jobs \ diff --git a/smartmontools/do_release b/smartmontools/do_release index a6ee6c96c..1894ea369 100755 --- a/smartmontools/do_release +++ b/smartmontools/do_release @@ -84,6 +84,7 @@ if [ -n "${REV//[0-9]/}" ]; then fi (cd $WDROOT && svn status) | while read s; do + # shellcheck disable=SC2254 case "`echo $s | tr -s ' '`" in "M "$DIRPAT/smartmontools/ChangeLog) echo "$s: OK";; "M "$DIRPAT/smartmontools/NEWS) echo "$s: OK";; @@ -161,7 +162,7 @@ fi set +v # Update configure.ac only after trunk releases -if [ -z "$RC" -a "$DIRPAT" = "trunk" ]; then +if [ -z "$RC" ] && [ "$DIRPAT" = "trunk" ]; then # Comment out timestamp sed -e "s|^smartmontools_release_date=\(.*\)$|smartmontools_release_date= # \1|" \ -e "s|^smartmontools_release_time=\(.*\)$|smartmontools_release_time= # \1|" \ diff --git a/smartmontools/getversion.sh b/smartmontools/getversion.sh index 10328172c..88c99336f 100755 --- a/smartmontools/getversion.sh +++ b/smartmontools/getversion.sh @@ -17,7 +17,7 @@ myname=$0 usage() { cat <<EOF -Usage: $myname [-i] [-p] [-r] [METHOD...] [> svnversion.h] +Usage: $myname [-i] [-pq] [-r] [METHOD...] [> svnversion.h] -i Print new contents of svnversion.h -p Print package version from configure.ac @@ -70,7 +70,7 @@ revision_from_svn() local r t r=$(cd "$srcdir" && svnversion 2>/dev/null) || return 1 case $r in [1-9][0-9]*) ;; *) return 1 ;; esac - t=$(cd "$srcdir" && TZ= LC_ALL=C svn info 2>/dev/null) || return 1 + t=$(cd "$srcdir" && TZ='' LC_ALL=C svn info 2>/dev/null) || return 1 t=$(echo "$t" | sed -n 's,^.* Date: *\(2[-0-9]*\) \([0-9][:0-9]*\) .*$,\1 \2,p') test -n "$t" || return 1 svnrev=$r; revdate=${t% *}; revtime=${t#* } @@ -91,7 +91,7 @@ revision_from_ids() revision_from_git() { local h r t x - x=$(cd "$srcdir" && TZ= LC_ALL=C git log -1 --date=iso 2>/dev/null) || return 1 + x=$(cd "$srcdir" && TZ='' LC_ALL=C git log -1 --date=iso 2>/dev/null) || return 1 h=$(echo "$x" | sed -n 's,^commit \([0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]\).*$,\1,p') t=$(echo "$x" | sed -n 's,^Date: *\(2[-0-9]*\) \([0-9][:0-9]*\) .*$,\1 \2,p') r=$(echo "$x" | sed -n 's,^.*git-svn-id: [.:/a-z]*/smartmontools/code/trunk@\([1-9][0-9]*\) 4ea69e.*$,\1,p') diff --git a/smartmontools/os_win32/pe32edit.sh b/smartmontools/os_win32/pe32edit.sh index fdb5e2585..08e83e44f 100755 --- a/smartmontools/os_win32/pe32edit.sh +++ b/smartmontools/os_win32/pe32edit.sh @@ -19,6 +19,7 @@ usage() { cat <<EOF Display or edit PE32 file header fields + Usage: $myname [-s SUBSYSTEM] [-t SECONDS_OR_FILE] [-v] FILE.exe -s SUBSYSTEM Set Subsystem: 2 = GUI, 3 = Console @@ -90,8 +91,7 @@ fi # Read first 512 bytes for quick access to header x=$(od -A n -N 512 -t u1 -v -w1 "$file") || exit 1 -declare -a header -header=( $x ) +mapfile header <<<"$x" test "${#header[*]}" == 512 || error "$file: Invalid file size" # get_uint16 OFFSET @@ -162,7 +162,7 @@ print_header() esac printf 'Magic: 0x%04x [%s]\n' $magic "$txt" - printf 'CheckSum: 0x%08x\n' $(get_uint32 $checksum_offs) + printf 'CheckSum: 0x%08x\n' "$(get_uint32 $checksum_offs)" val=$(get_uint16 $subsystem_offs) case $val in diff --git a/smartmontools/smartd_warning.sh.in b/smartmontools/smartd_warning.sh.in index a9c7495ac..e5a7c493e 100644 --- a/smartmontools/smartd_warning.sh.in +++ b/smartmontools/smartd_warning.sh.in @@ -15,6 +15,7 @@ set -e # Set by config.status @ENABLE_SCRIPTPATH_TRUE@export PATH="@scriptpath@" +# shellcheck disable=SC2034 PACKAGE="@PACKAGE@" VERSION="@VERSION@" prefix="@prefix@" @@ -67,6 +68,7 @@ if [ -z "${SMARTD_ADDRESS}${SMARTD_MAILER}" ]; then fi # Get host and domain names +# shellcheck disable=SC2041 for cmd in @os_hostname@ 'echo "[Unknown]"'; do hostname=`eval $cmd 2>/dev/null` || continue test -n "$hostname" || continue @@ -78,6 +80,7 @@ if [ "$dnsdomain" != "$hostname" ]; then # hostname command printed FQDN hostname=${hostname%%.*} else + # shellcheck disable=SC2041 for cmd in @os_dnsdomainname@ 'echo'; do dnsdomain=`eval $cmd 2>/dev/null` || continue break @@ -85,6 +88,7 @@ else test "$dnsdomain" != "(none)" || dnsdomain= fi +# shellcheck disable=SC2041 for cmd in @os_nisdomainname@ 'echo'; do nisdomain=`eval $cmd 2>/dev/null` || continue break diff --git a/smartmontools/update-smart-drivedb.in b/smartmontools/update-smart-drivedb.in index 276a41711..42fae716d 100644 --- a/smartmontools/update-smart-drivedb.in +++ b/smartmontools/update-smart-drivedb.in @@ -268,6 +268,7 @@ check_file() f=$1; firstchar=$2; minsize=$3; maxsize=$4 # Check first chars + # shellcheck disable=SC2254 case `dd if="$f" bs=1 count=1 2>/dev/null` in $firstchar) ;; \<) echo "HTML error message"; return 1 ;; -- GitLab