Martin Roth | 0ad5fbd | 2020-12-24 12:06:38 -0700 | [diff] [blame] | 1 | #!/usr/bin/env sh |
Patrick Georgi | e882630 | 2010-11-19 10:16:43 +0000 | [diff] [blame] | 2 | # |
Patrick Georgi | 7333a11 | 2020-05-08 20:48:04 +0200 | [diff] [blame] | 3 | # SPDX-License-Identifier: GPL-2.0-only |
| 4 | |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 5 | # DESCR: Check that files in have valid license headers |
| 6 | # $1 is an optional command line parameter containing directories to check |
| 7 | |
Martin Roth | d81debd | 2022-06-03 00:06:57 -0600 | [diff] [blame] | 8 | |
| 9 | LINTDIR="$( |
| 10 | cd -- "$(dirname "$0")" > /dev/null 2>&1 || return |
| 11 | pwd -P |
| 12 | )" |
| 13 | |
| 14 | # shellcheck source=helper_functions.sh |
| 15 | . "${LINTDIR}/helper_functions.sh" |
| 16 | |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 17 | # regex list of files and directories to exclude from the search |
| 18 | HEADER_EXCLUDED="\ |
Patrick Georgi | deea25b | 2020-05-10 16:34:10 +0200 | [diff] [blame] | 19 | ^src/commonlib/bsd/lz4.c.inc\$|\ |
| 20 | ^src/cpu/x86/16bit/entry16.inc\$|\ |
| 21 | ^src/device/oprom/x86emu/|\ |
| 22 | ^src/device/oprom/include/x86emu/|\ |
| 23 | ^src/device/oprom/yabel/|\ |
Jacob Garber | 10999ea6 | 2020-05-18 13:36:58 -0600 | [diff] [blame] | 24 | ^src/drivers/net/ne2k.c\$|\ |
Patrick Georgi | deea25b | 2020-05-10 16:34:10 +0200 | [diff] [blame] | 25 | ^src/drivers/xgi/common/initdef.h\$|\ |
| 26 | ^src/drivers/xgi/common/vstruct.h\$|\ |
Martin Roth | bdad9a8 | 2018-05-26 19:47:07 -0600 | [diff] [blame] | 27 | ^src/lib/gnat/|\ |
Patrick Georgi | deea25b | 2020-05-10 16:34:10 +0200 | [diff] [blame] | 28 | ^src/lib/lzmadecode.[ch]\$|\ |
| 29 | ^src/lib/stack.c\$|\ |
Felix Singer | bbe0a99 | 2022-08-22 20:08:40 +0200 | [diff] [blame] | 30 | ^src/sbom/TAGS|\ |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 31 | ^src/vendorcode/|\ |
Maximilian Brune | 33079b8 | 2024-03-04 15:34:41 +0100 | [diff] [blame] | 32 | ^tests/data/|\ |
Martin Roth | bdad9a8 | 2018-05-26 19:47:07 -0600 | [diff] [blame] | 33 | ^util/amdtools/example_input/|\ |
| 34 | ^util/cbfstool/lzma/|\ |
Patrick Georgi | deea25b | 2020-05-10 16:34:10 +0200 | [diff] [blame] | 35 | ^util/cbfstool/lz4/|\ |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 36 | ^util/kconfig/|\ |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 37 | Kconfig|\ |
| 38 | \<COPYING\>|\ |
| 39 | \<LICENSE\>|\ |
| 40 | \<README\>|\ |
| 41 | Changelog|\ |
Jacob Garber | 07201d7 | 2020-09-08 12:25:44 -0600 | [diff] [blame] | 42 | AUTHORS|\ |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 43 | TODO|\ |
| 44 | EXAMPLE|\ |
Martin Roth | bdad9a8 | 2018-05-26 19:47:07 -0600 | [diff] [blame] | 45 | NEWS|\ |
| 46 | ChangeLog|\ |
| 47 | Dockerfile|\ |
Martin Roth | 251e266 | 2022-08-07 17:17:41 -0600 | [diff] [blame] | 48 | \.gitignore$|\ |
Martin Roth | bdad9a8 | 2018-05-26 19:47:07 -0600 | [diff] [blame] | 49 | \.in$|\ |
| 50 | \.[18]$|\ |
| 51 | \.md$|\ |
| 52 | \.wiki$|\ |
| 53 | \.xxdump$|\ |
| 54 | \.spec$|\ |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 55 | \.txt$|\ |
| 56 | \.jpg$|\ |
| 57 | \.cksum$|\ |
| 58 | \.bin$|\ |
Martin Roth | dea1333 | 2018-05-04 09:19:07 -0600 | [diff] [blame] | 59 | \.vbt$|\ |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 60 | \.hex$|\ |
| 61 | \.patch$|\ |
| 62 | _shipped$|\ |
| 63 | /microcode-[^/]*.h$|\ |
| 64 | /sdram-.*\.inc$|\ |
Martin Roth | 84129b8 | 2016-04-11 13:35:59 -0600 | [diff] [blame] | 65 | \.fmd|\ |
Naresh G Solanki | 358b2b3 | 2016-10-27 23:13:37 +0530 | [diff] [blame] | 66 | \.cb|\ |
Martin Roth | 84129b8 | 2016-04-11 13:35:59 -0600 | [diff] [blame] | 67 | \.cfg$|\ |
| 68 | \.spd|\ |
| 69 | config|\ |
| 70 | cmos\.layout|\ |
Nicholas Chin | 4ff23a2 | 2024-03-21 11:27:50 -0600 | [diff] [blame] | 71 | cmos\.default|\ |
| 72 | \.apcb$\ |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 73 | " |
| 74 | |
| 75 | #space separated list of directories to test |
| 76 | if [ "$1" = "" ]; then |
| 77 | HEADER_DIRS="src util" |
| 78 | else |
| 79 | HEADER_DIRS="$1" |
| 80 | fi |
Patrick Georgi | e882630 | 2010-11-19 10:16:43 +0000 | [diff] [blame] | 81 | |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 82 | |
| 83 | #get initial list from git, removing HEADER_EXCLUDED files. |
| 84 | #make a copy to check for the old style header later. |
Felix Singer | 74b4bd0 | 2023-04-01 14:42:54 +0200 | [diff] [blame] | 85 | headerlist=$(${FIND_FILES} $HEADER_DIRS | grep -E -v "($HEADER_EXCLUDED)") |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 86 | |
Martin Roth | 1eccf77 | 2024-02-16 10:19:07 -0700 | [diff] [blame^] | 87 | LICENSE_ID_STRING="SPDX-License-Identifier" |
| 88 | |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 89 | #update headerlist by removing files that match the license string |
| 90 | check_for_license() { |
Martin Roth | 84129b8 | 2016-04-11 13:35:59 -0600 | [diff] [blame] | 91 | if [ -n "$headerlist" ] && [ -z "$2" ]; then |
Martin Roth | 1eccf77 | 2024-02-16 10:19:07 -0700 | [diff] [blame^] | 92 | headerlist="$(grep -iL "${LICENSE_ID_STRING}: $1" $headerlist 2>/dev/null)" |
Martin Roth | 84129b8 | 2016-04-11 13:35:59 -0600 | [diff] [blame] | 93 | elif [ -n "$headerlist" ]; then |
Martin Roth | 1eccf77 | 2024-02-16 10:19:07 -0700 | [diff] [blame^] | 94 | p1list="$(grep -il "${LICENSE_ID_STRING}: $1" $headerlist 2>/dev/null)" |
| 95 | p2list="$(grep -il "${LICENSE_ID_STRING}: $2" $headerlist 2>/dev/null)" |
Martin Roth | f8db028 | 2016-01-21 13:20:39 -0700 | [diff] [blame] | 96 | |
| 97 | # Make list of files that were in both previous lists |
Martin Roth | 84129b8 | 2016-04-11 13:35:59 -0600 | [diff] [blame] | 98 | pbothlist="$(echo $p1list $p2list | tr ' ' "\n" | \ |
Martin Roth | f8db028 | 2016-01-21 13:20:39 -0700 | [diff] [blame] | 99 | sort | uniq -d)" |
| 100 | |
| 101 | # Remove all files that were in both of the previous lists |
| 102 | # Note that this is unstable if we ever get any filenames |
| 103 | # with spaces. |
| 104 | headerlist="$(echo $headerlist $pbothlist | tr ' ' "\n" | \ |
| 105 | sort | uniq -u)" |
| 106 | fi |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | #search the files for license headers |
Martin Roth | 1eccf77 | 2024-02-16 10:19:07 -0700 | [diff] [blame^] | 110 | check_for_license 'Apache-2.0' |
| 111 | check_for_license 'BSD-2-Clause' |
| 112 | check_for_license 'BSD-3-Clause' |
| 113 | check_for_license 'GPL-2.0-only' |
| 114 | check_for_license 'GPL-2.0-or-later' |
| 115 | check_for_license 'GPL-2.0-only WITH Linux-syscall-note' |
| 116 | check_for_license 'GPL-3.0-only' |
| 117 | check_for_license 'GPL-3.0-only WITH GCC-exception-3.1' |
| 118 | check_for_license 'GPL-3.0-or-later' |
| 119 | check_for_license 'HPND' |
| 120 | check_for_license 'HPND-sell-variant' |
| 121 | check_for_license 'ISC' |
| 122 | check_for_license 'MIT' |
| 123 | check_for_license 'X11' |
Martin Roth | e348eba | 2019-09-23 18:14:34 -0600 | [diff] [blame] | 124 | |
Patrick Georgi | e342cd3 | 2020-03-04 14:58:49 +0100 | [diff] [blame] | 125 | # This is 4 clause ("with advertising") but the University of Berkeley |
| 126 | # declared that 4th clause void, see |
| 127 | # ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change |
| 128 | # With this, BSD-4-Clause-UC becomes GPLv2 compatible, and so SPDX doesn't |
| 129 | # differentiate between this license with or without advertising. |
Martin Roth | 1eccf77 | 2024-02-16 10:19:07 -0700 | [diff] [blame^] | 130 | check_for_license 'BSD-4-Clause-UC' |
Patrick Georgi | e342cd3 | 2020-03-04 14:58:49 +0100 | [diff] [blame] | 131 | |
Martin Roth | f67a1aa | 2022-08-04 12:20:29 -0600 | [diff] [blame] | 132 | # This is the Creative Commons Public Domain Dedication and Certification |
| 133 | # for files that are already in the public domain. This includes files |
| 134 | # that cannot be licensed such as blank files or files with no "creative" |
| 135 | # content. |
Martin Roth | 1eccf77 | 2024-02-16 10:19:07 -0700 | [diff] [blame^] | 136 | check_for_license 'CC-PDDC' |
Martin Roth | f67a1aa | 2022-08-04 12:20:29 -0600 | [diff] [blame] | 137 | |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 138 | for file in $headerlist; do |
Martin Roth | 957fde6 | 2022-08-07 17:21:17 -0600 | [diff] [blame] | 139 | # Verify the file actually exists |
| 140 | if [ -f "$file" ]; then |
Jacob Garber | d2fea1a | 2020-05-18 13:25:18 -0600 | [diff] [blame] | 141 | echo "$file has no recognized SPDX identifier." |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 142 | fi |
| 143 | done |