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