Patrick Georgi | e882630 | 2010-11-19 10:16:43 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # This file is part of the coreboot project. |
| 3 | # |
| 4 | # Copyright (C) 2010 coresystems GmbH |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 5 | # Copyright (C) 2016 Google Inc. |
Patrick Georgi | e882630 | 2010-11-19 10:16:43 +0000 | [diff] [blame] | 6 | # |
| 7 | # This program is free software; you can redistribute it and/or modify |
| 8 | # it under the terms of the GNU General Public License as published by |
| 9 | # the Free Software Foundation; version 2 of the License. |
| 10 | # |
| 11 | # This program is distributed in the hope that it will be useful, |
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | # GNU General Public License for more details. |
| 15 | # |
Patrick Georgi | e882630 | 2010-11-19 10:16:43 +0000 | [diff] [blame] | 16 | # |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 17 | # DESCR: Check that files in have valid license headers |
| 18 | # $1 is an optional command line parameter containing directories to check |
| 19 | |
| 20 | # regex list of files and directories to exclude from the search |
| 21 | HEADER_EXCLUDED="\ |
Martin Roth | bdad9a8 | 2018-05-26 19:47:07 -0600 | [diff] [blame] | 22 | ^src/lib/gnat/|\ |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 23 | ^src/vendorcode/|\ |
Martin Roth | bdad9a8 | 2018-05-26 19:47:07 -0600 | [diff] [blame] | 24 | ^util/amdtools/example_input/|\ |
| 25 | ^util/cbfstool/lzma/|\ |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 26 | ^util/kconfig/|\ |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 27 | Kconfig|\ |
| 28 | \<COPYING\>|\ |
| 29 | \<LICENSE\>|\ |
| 30 | \<README\>|\ |
| 31 | Changelog|\ |
| 32 | TODO|\ |
| 33 | EXAMPLE|\ |
Martin Roth | bdad9a8 | 2018-05-26 19:47:07 -0600 | [diff] [blame] | 34 | NEWS|\ |
| 35 | ChangeLog|\ |
| 36 | Dockerfile|\ |
| 37 | \.in$|\ |
| 38 | \.[18]$|\ |
| 39 | \.md$|\ |
| 40 | \.wiki$|\ |
| 41 | \.xxdump$|\ |
| 42 | \.spec$|\ |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 43 | \.txt$|\ |
| 44 | \.jpg$|\ |
| 45 | \.cksum$|\ |
| 46 | \.bin$|\ |
Martin Roth | dea1333 | 2018-05-04 09:19:07 -0600 | [diff] [blame] | 47 | \.vbt$|\ |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 48 | \.hex$|\ |
| 49 | \.patch$|\ |
| 50 | _shipped$|\ |
| 51 | /microcode-[^/]*.h$|\ |
| 52 | /sdram-.*\.inc$|\ |
Martin Roth | 84129b8 | 2016-04-11 13:35:59 -0600 | [diff] [blame] | 53 | Makefile\.inc|\ |
| 54 | \.fmd|\ |
Naresh G Solanki | 358b2b3 | 2016-10-27 23:13:37 +0530 | [diff] [blame] | 55 | \.cb|\ |
Martin Roth | 84129b8 | 2016-04-11 13:35:59 -0600 | [diff] [blame] | 56 | \.cfg$|\ |
| 57 | \.spd|\ |
| 58 | config|\ |
| 59 | cmos\.layout|\ |
| 60 | cmos\.default\ |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 61 | " |
| 62 | |
Martin Roth | e348eba | 2019-09-23 18:14:34 -0600 | [diff] [blame] | 63 | HEADER_TEXT="license header" |
| 64 | |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 65 | #space separated list of directories to test |
| 66 | if [ "$1" = "" ]; then |
| 67 | HEADER_DIRS="src util" |
| 68 | else |
| 69 | HEADER_DIRS="$1" |
| 70 | fi |
Patrick Georgi | e882630 | 2010-11-19 10:16:43 +0000 | [diff] [blame] | 71 | |
Martin Roth | e348eba | 2019-09-23 18:14:34 -0600 | [diff] [blame] | 72 | if [ "$2" = "SPDX_ONLY" ]; then |
| 73 | SPDX_ONLY=1 |
| 74 | HEADER_TEXT="SPDX identifier" |
| 75 | fi |
| 76 | |
Patrick Georgi | e882630 | 2010-11-19 10:16:43 +0000 | [diff] [blame] | 77 | LC_ALL=C export LC_ALL |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 78 | |
| 79 | #get initial list from git, removing HEADER_EXCLUDED files. |
| 80 | #make a copy to check for the old style header later. |
| 81 | headerlist=$(git ls-files $HEADER_DIRS | egrep -v "($HEADER_EXCLUDED)") |
| 82 | |
| 83 | #update headerlist by removing files that match the license string |
| 84 | check_for_license() { |
Martin Roth | 84129b8 | 2016-04-11 13:35:59 -0600 | [diff] [blame] | 85 | if [ -n "$headerlist" ] && [ -z "$2" ]; then |
Martin Roth | f8db028 | 2016-01-21 13:20:39 -0700 | [diff] [blame] | 86 | headerlist="$(grep -iL "$1" $headerlist 2>/dev/null)" |
Martin Roth | 84129b8 | 2016-04-11 13:35:59 -0600 | [diff] [blame] | 87 | elif [ -n "$headerlist" ]; then |
| 88 | p1list="$(grep -il "$1" $headerlist 2>/dev/null)" |
| 89 | p2list="$(grep -il "$2" $headerlist 2>/dev/null)" |
Martin Roth | f8db028 | 2016-01-21 13:20:39 -0700 | [diff] [blame] | 90 | |
| 91 | # Make list of files that were in both previous lists |
Martin Roth | 84129b8 | 2016-04-11 13:35:59 -0600 | [diff] [blame] | 92 | pbothlist="$(echo $p1list $p2list | tr ' ' "\n" | \ |
Martin Roth | f8db028 | 2016-01-21 13:20:39 -0700 | [diff] [blame] | 93 | sort | uniq -d)" |
| 94 | |
| 95 | # Remove all files that were in both of the previous lists |
| 96 | # Note that this is unstable if we ever get any filenames |
| 97 | # with spaces. |
| 98 | headerlist="$(echo $headerlist $pbothlist | tr ' ' "\n" | \ |
| 99 | sort | uniq -u)" |
| 100 | fi |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | #search the files for license headers |
Martin Roth | e348eba | 2019-09-23 18:14:34 -0600 | [diff] [blame] | 104 | check_for_license 'SPDX-License-Identifier: Apache-2.0' |
| 105 | check_for_license 'SPDX-License-Identifier: BSD-3-Clause' |
| 106 | check_for_license 'SPDX-License-Identifier: GPL-2.0-only' |
| 107 | check_for_license 'SPDX-License-Identifier: GPL-2.0-or-later' |
Rajat Jain | 9990011 | 2020-03-27 13:12:47 -0700 | [diff] [blame] | 108 | 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] | 109 | check_for_license 'SPDX-License-Identifier: GPL-3.0-only' |
| 110 | check_for_license 'SPDX-License-Identifier: GPL-3.0-or-later' |
| 111 | check_for_license 'SPDX-License-Identifier: ISC' |
| 112 | check_for_license 'SPDX-License-Identifier: MIT' |
| 113 | check_for_license 'SPDX-License-Identifier: X11' |
| 114 | |
Patrick Georgi | e342cd3 | 2020-03-04 14:58:49 +0100 | [diff] [blame] | 115 | # This is 4 clause ("with advertising") but the University of Berkeley |
| 116 | # declared that 4th clause void, see |
| 117 | # ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change |
| 118 | # With this, BSD-4-Clause-UC becomes GPLv2 compatible, and so SPDX doesn't |
| 119 | # differentiate between this license with or without advertising. |
| 120 | check_for_license 'SPDX-License-Identifier: BSD-4-Clause-UC' |
| 121 | |
Martin Roth | e348eba | 2019-09-23 18:14:34 -0600 | [diff] [blame] | 122 | if [ ! "${SPDX_ONLY}" = "1" ]; then |
Martin Roth | f8db028 | 2016-01-21 13:20:39 -0700 | [diff] [blame] | 123 | check_for_license "under the terms of the GNU General Public License" \ |
| 124 | "WITHOUT ANY WARRANTY" |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 125 | check_for_license 'IS PROVIDED .*"AS IS"' |
Martin Roth | 84129b8 | 2016-04-11 13:35:59 -0600 | [diff] [blame] | 126 | check_for_license 'IS DISTRIBUTED .*"AS IS"' |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 127 | check_for_license "IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE" |
| 128 | check_for_license '"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES' |
Martin Roth | ed0ee0a | 2017-04-04 14:35:42 -0600 | [diff] [blame] | 129 | check_for_license 'assumes any liability or responsibility for the use' |
| 130 | check_for_license 'THE AUTHORS DISCLAIM.*ALL WARRANTIES WITH REGARD TO THIS SOFTWARE' |
Martin Roth | 84129b8 | 2016-04-11 13:35:59 -0600 | [diff] [blame] | 131 | check_for_license 'No license required' |
Martin Roth | bdad9a8 | 2018-05-26 19:47:07 -0600 | [diff] [blame] | 132 | check_for_license 'GNU Lesser General Public' |
Martin Roth | e348eba | 2019-09-23 18:14:34 -0600 | [diff] [blame] | 133 | fi |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 134 | |
| 135 | for file in $headerlist; do |
Martin Roth | 03e9d6a | 2017-02-09 16:44:24 -0800 | [diff] [blame] | 136 | # Verify the file exists, and has content that requires a header |
| 137 | # This assumes that a file that has 4 lines or fewer is not notable |
| 138 | # enough to require a license. |
| 139 | if [ -f "$file" ] && [ "$(wc -l < "$file")" -gt 4 ]; then |
Martin Roth | e348eba | 2019-09-23 18:14:34 -0600 | [diff] [blame] | 140 | echo "$file has no recognized ${HEADER_TEXT}." |
Martin Roth | c4511e2 | 2016-01-12 10:25:49 -0700 | [diff] [blame] | 141 | fi |
| 142 | done |