blob: c1110ec75d7567a33d45f723c8ec8c2990d13267 [file] [log] [blame]
Patrick Georgie8826302010-11-19 10:16:43 +00001#!/bin/sh
2# This file is part of the coreboot project.
3#
4# Copyright (C) 2010 coresystems GmbH
Martin Rothc4511e22016-01-12 10:25:49 -07005# Copyright (C) 2016 Google Inc.
Patrick Georgie8826302010-11-19 10:16:43 +00006#
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 Georgie8826302010-11-19 10:16:43 +000016#
Martin Rothc4511e22016-01-12 10:25:49 -070017# 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
21HEADER_EXCLUDED="\
Martin Rothbdad9a82018-05-26 19:47:07 -060022^src/lib/gnat/|\
Martin Rothc4511e22016-01-12 10:25:49 -070023^src/vendorcode/|\
Martin Rothbdad9a82018-05-26 19:47:07 -060024^util/amdtools/example_input/|\
25^util/cbfstool/lzma/|\
Martin Rothc4511e22016-01-12 10:25:49 -070026^util/kconfig/|\
Martin Rothc4511e22016-01-12 10:25:49 -070027Kconfig|\
28\<COPYING\>|\
29\<LICENSE\>|\
30\<README\>|\
31Changelog|\
32TODO|\
33EXAMPLE|\
Martin Rothbdad9a82018-05-26 19:47:07 -060034NEWS|\
35ChangeLog|\
36Dockerfile|\
37\.in$|\
38\.[18]$|\
39\.md$|\
40\.wiki$|\
41\.xxdump$|\
42\.spec$|\
Martin Rothc4511e22016-01-12 10:25:49 -070043\.txt$|\
44\.jpg$|\
45\.cksum$|\
46\.bin$|\
Martin Rothdea13332018-05-04 09:19:07 -060047\.vbt$|\
Martin Rothc4511e22016-01-12 10:25:49 -070048\.hex$|\
49\.patch$|\
50_shipped$|\
51/microcode-[^/]*.h$|\
52/sdram-.*\.inc$|\
Martin Roth84129b82016-04-11 13:35:59 -060053Makefile\.inc|\
54\.fmd|\
Naresh G Solanki358b2b32016-10-27 23:13:37 +053055\.cb|\
Martin Roth84129b82016-04-11 13:35:59 -060056\.cfg$|\
57\.spd|\
58config|\
59cmos\.layout|\
60cmos\.default\
Martin Rothc4511e22016-01-12 10:25:49 -070061"
62
Martin Rothe348eba2019-09-23 18:14:34 -060063HEADER_TEXT="license header"
64
Martin Rothc4511e22016-01-12 10:25:49 -070065#space separated list of directories to test
66if [ "$1" = "" ]; then
67 HEADER_DIRS="src util"
68else
69 HEADER_DIRS="$1"
70fi
Patrick Georgie8826302010-11-19 10:16:43 +000071
Martin Rothe348eba2019-09-23 18:14:34 -060072if [ "$2" = "SPDX_ONLY" ]; then
73 SPDX_ONLY=1
74 HEADER_TEXT="SPDX identifier"
75fi
76
Patrick Georgie8826302010-11-19 10:16:43 +000077LC_ALL=C export LC_ALL
Martin Rothc4511e22016-01-12 10:25:49 -070078
79#get initial list from git, removing HEADER_EXCLUDED files.
80#make a copy to check for the old style header later.
81headerlist=$(git ls-files $HEADER_DIRS | egrep -v "($HEADER_EXCLUDED)")
82
83#update headerlist by removing files that match the license string
84check_for_license() {
Martin Roth84129b82016-04-11 13:35:59 -060085 if [ -n "$headerlist" ] && [ -z "$2" ]; then
Martin Rothf8db0282016-01-21 13:20:39 -070086 headerlist="$(grep -iL "$1" $headerlist 2>/dev/null)"
Martin Roth84129b82016-04-11 13:35:59 -060087 elif [ -n "$headerlist" ]; then
88 p1list="$(grep -il "$1" $headerlist 2>/dev/null)"
89 p2list="$(grep -il "$2" $headerlist 2>/dev/null)"
Martin Rothf8db0282016-01-21 13:20:39 -070090
91 # Make list of files that were in both previous lists
Martin Roth84129b82016-04-11 13:35:59 -060092 pbothlist="$(echo $p1list $p2list | tr ' ' "\n" | \
Martin Rothf8db0282016-01-21 13:20:39 -070093 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 Rothc4511e22016-01-12 10:25:49 -0700101}
102
103#search the files for license headers
Martin Rothe348eba2019-09-23 18:14:34 -0600104check_for_license 'SPDX-License-Identifier: Apache-2.0'
105check_for_license 'SPDX-License-Identifier: BSD-3-Clause'
106check_for_license 'SPDX-License-Identifier: GPL-2.0-only'
107check_for_license 'SPDX-License-Identifier: GPL-2.0-or-later'
Rajat Jain99900112020-03-27 13:12:47 -0700108check_for_license 'SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note'
Martin Rothe348eba2019-09-23 18:14:34 -0600109check_for_license 'SPDX-License-Identifier: GPL-3.0-only'
110check_for_license 'SPDX-License-Identifier: GPL-3.0-or-later'
111check_for_license 'SPDX-License-Identifier: ISC'
112check_for_license 'SPDX-License-Identifier: MIT'
113check_for_license 'SPDX-License-Identifier: X11'
114
Patrick Georgie342cd32020-03-04 14:58:49 +0100115# 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.
120check_for_license 'SPDX-License-Identifier: BSD-4-Clause-UC'
121
Martin Rothe348eba2019-09-23 18:14:34 -0600122if [ ! "${SPDX_ONLY}" = "1" ]; then
Martin Rothf8db0282016-01-21 13:20:39 -0700123check_for_license "under the terms of the GNU General Public License" \
124 "WITHOUT ANY WARRANTY"
Martin Rothc4511e22016-01-12 10:25:49 -0700125check_for_license 'IS PROVIDED .*"AS IS"'
Martin Roth84129b82016-04-11 13:35:59 -0600126check_for_license 'IS DISTRIBUTED .*"AS IS"'
Martin Rothc4511e22016-01-12 10:25:49 -0700127check_for_license "IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE"
128check_for_license '"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES'
Martin Rothed0ee0a2017-04-04 14:35:42 -0600129check_for_license 'assumes any liability or responsibility for the use'
130check_for_license 'THE AUTHORS DISCLAIM.*ALL WARRANTIES WITH REGARD TO THIS SOFTWARE'
Martin Roth84129b82016-04-11 13:35:59 -0600131check_for_license 'No license required'
Martin Rothbdad9a82018-05-26 19:47:07 -0600132check_for_license 'GNU Lesser General Public'
Martin Rothe348eba2019-09-23 18:14:34 -0600133fi
Martin Rothc4511e22016-01-12 10:25:49 -0700134
135for file in $headerlist; do
Martin Roth03e9d6a2017-02-09 16:44:24 -0800136 # 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 Rothe348eba2019-09-23 18:14:34 -0600140 echo "$file has no recognized ${HEADER_TEXT}."
Martin Rothc4511e22016-01-12 10:25:49 -0700141 fi
142done