lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master c40f2f8 14/18: Routinely run shellcheck


From: Greg Chicares
Subject: [lmi-commits] [lmi] master c40f2f8 14/18: Routinely run shellcheck
Date: Wed, 29 May 2019 18:49:09 -0400 (EDT)

branch: master
commit c40f2f888e900be8278626c428adea03c7f2d95f
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Routinely run shellcheck
    
    Used 'xargs -P' in 'GNUmakefile' because it roughly quintuples the
    speed of the command in which it occurs.
---
 GNUmakefile     |  1 +
 check_script.sh | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)

diff --git a/GNUmakefile b/GNUmakefile
index 074fc46..b0766a4 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -454,6 +454,7 @@ check_concinnity: source_clean custom_tools
        @$(LS) --classify $(prefascicle_dir)/* \
          | $(SED) -e'/\*$$/!d' -e'/^\.\//!d' -e'/.sh\*$$/d' -e'/.sed\*$$/d' \
          | $(SED) -e's/^/Improperly executable: /'
+       @find $(prefascicle_dir) -executable -type f -print0 | xargs -0 -n 1 -P 
0 ./check_script.sh
        @$(ECHO) "  Problems detected by xmllint:"
        @for z in $(xml_files); \
          do \
diff --git a/check_script.sh b/check_script.sh
new file mode 100755
index 0000000..f0c4a09
--- /dev/null
+++ b/check_script.sh
@@ -0,0 +1,51 @@
+#!/bin/sh
+
+# Use 'shellcheck' to test a shell script.
+
+# Copyright (C) 2019 Gregory W. Chicares.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+#
+# http://savannah.nongnu.org/projects/lmi
+# email: <address@hidden>
+# snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA
+
+# Skip:
+#  - empty argument: no script to check
+#  - git's default hooks: the maintainers don't use shellcheck
+#  - tabs/ scripts: they're extraordinary
+
+case "$1" in
+    ("")                      exit 0 ;;
+    (*.git/hooks-orig*)       exit 0 ;;
+    (*tabs/*/startup_script*) exit 0 ;;
+esac
+
+# First line, truncated at its first blank:
+shebang="$(sed -e'1!d' -e's/ .*$//' "$1")"
+case $shebang  in
+    ("#!/bin/sh")
+        shellcheck --external-sources "$1"
+    ;;
+    ("#!/bin/zsh")
+        new_name="/tmp/$(basename "$1")$(date -u +'%s_%N').eraseme"
+        cp -a "$1" "$new_name"
+        sed -i "$new_name" -e'1s/zsh/sh/'
+        shellcheck --external-sources "$new_name"
+        rm "$new_name"
+    ;;
+    ("#!/usr/bin/make") ;;
+    ("#!/bin/sed") ;;
+    (*) printf '%s\n' "unknown shebang $shebang in file $1" ;;
+esac



reply via email to

[Prev in Thread] Current Thread [Next in Thread]