Whamcloud - gitweb
LU-16707 scripts: make license-status more flexible 28/55928/2
authorTimothy Day <timday@amazon.com>
Sat, 3 Aug 2024 20:02:43 +0000 (16:02 -0400)
committerOleg Drokin <green@whamcloud.com>
Fri, 16 Aug 2024 23:55:00 +0000 (23:55 +0000)
Accept a path argument to restrict the search to a sub-tree.
By default, use the current directory. Also, fix some shellcheck
errors.

Test-Parameters: trivial
Signed-off-by: Timothy Day <timday@amazon.com>
Change-Id: Iaddf0c22f8fed80947b0b511f9a56f6a35e0347b
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/55928
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
contrib/scripts/license-status

index 0001baa..7a60610 100755 (executable)
@@ -4,25 +4,28 @@
 #
 # Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
 #
+# Copyright (c) 2023-2024, Amazon and/or its affiliates. All rights reserved.
+# Use is subject to license terms.
+#
 
 #
 # This file is part of Lustre, http://www.lustre.org/
 #
-# contrib/scripts/license-status
-#
 # Display the license status of files in the current directory
 #
 # Author: Gordon Matzigkeit <gord@fig.org>, 2001-09-27
 # Author: Timothy Day <timday@amazon.com>, 2023-04-03
 #
 
-for file in $(git ls-tree -r HEAD --name-only); do
-       if head -20 "$file" | egrep -e 'SPDX' > /dev/null; then
-               license="$(grep SPDX $file | awk '{ print $3; exit; }')"
+export files="${1:-$(pwd)}"
+
+for file in $(git ls-files "$files"); do
+       if head -20 "$file" | grep -Ee 'SPDX' > /dev/null; then
+               license="$(grep SPDX "$file" | awk '{ print $3; exit; }')"
                printf "%-10s %-15s %-s\n" "SPDX" "$license" "$file"
-       elif head -20 "$file" | egrep -e 'GNU General Public License' > /dev/null; then
+       elif head -20 "$file" | grep -Ee 'GNU General Public License' > /dev/null; then
                printf "%-10s %-15s %-s\n" "guess" "gpled" "$file"
-       elif head -20 "$file" | egrep -e '\([Cc]\)' > /dev/null; then
+       elif head -20 "$file" | grep -Ee '\([Cc]\)' > /dev/null; then
                printf "%-10s %-15s %-s\n" "guess" "copyright" "$file"
        else
                printf "%-10s %-15s %-s\n" "guess" "unknown" "$file"