1#!/usr/bin/env sh 2# 3# SPDX-License-Identifier: GPL-2.0-only 4 5# DESCR: Check that files in have valid license headers 6# $1 is an optional command line parameter containing directories to check 7 8 9LINTDIR="$( 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 17# regex list of files and directories to exclude from the search 18HEADER_EXCLUDED="\ 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/|\ 24^src/drivers/net/ne2k.c\$|\ 25^src/drivers/xgi/common/initdef.h\$|\ 26^src/drivers/xgi/common/vstruct.h\$|\ 27^src/lib/gnat/|\ 28^src/lib/lzmadecode.[ch]\$|\ 29^src/lib/stack.c\$|\ 30^src/sbom/TAGS|\ 31^src/vendorcode/|\ 32^tests/data/|\ 33^util/amdtools/example_input/|\ 34^util/cbfstool/lzma/|\ 35^util/cbfstool/lz4/|\ 36^util/kconfig/|\ 37Kconfig|\ 38\<COPYING\>|\ 39\<LICENSE\>|\ 40\<README\>|\ 41Changelog|\ 42AUTHORS|\ 43TODO|\ 44EXAMPLE|\ 45NEWS|\ 46ChangeLog|\ 47Dockerfile|\ 48\.gitignore$|\ 49\.in$|\ 50\.[18]$|\ 51\.md$|\ 52\.wiki$|\ 53\.xxdump$|\ 54\.spec$|\ 55\.txt$|\ 56\.jpg$|\ 57\.cksum$|\ 58\.bin$|\ 59\.vbt$|\ 60\.hex$|\ 61\.patch$|\ 62_shipped$|\ 63/microcode-[^/]*.h$|\ 64/sdram-.*\.inc$|\ 65\.fmd|\ 66\.cb|\ 67\.cfg$|\ 68\.spd|\ 69config|\ 70cmos\.layout|\ 71cmos\.default|\ 72\.apcb$\ 73" 74 75#space separated list of directories to test 76if [ "$1" = "" ]; then 77 HEADER_DIRS="src util" 78else 79 HEADER_DIRS="$1" 80fi 81 82 83#get initial list from git, removing HEADER_EXCLUDED files. 84#make a copy to check for the old style header later. 85headerlist=$(${FIND_FILES} $HEADER_DIRS | grep -E -v "($HEADER_EXCLUDED)") 86 87LICENSE_ID_STRING="SPDX-License-Identifier" 88 89#update headerlist by removing files that match the license string 90check_for_license() { 91 if [ -n "$headerlist" ] && [ -z "$2" ]; then 92 headerlist="$(grep -iL "${LICENSE_ID_STRING}: $1" $headerlist 2>/dev/null)" 93 elif [ -n "$headerlist" ]; then 94 p1list="$(grep -il "${LICENSE_ID_STRING}: $1" $headerlist 2>/dev/null)" 95 p2list="$(grep -il "${LICENSE_ID_STRING}: $2" $headerlist 2>/dev/null)" 96 97 # Make list of files that were in both previous lists 98 pbothlist="$(echo $p1list $p2list | tr ' ' "\n" | \ 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 107} 108 109#search the files for license headers 110check_for_license 'Apache-2.0' 111check_for_license 'BSD-2-Clause' 112check_for_license 'BSD-3-Clause' 113check_for_license 'GPL-2.0-only' 114check_for_license 'GPL-2.0-or-later' 115check_for_license 'GPL-2.0-only WITH Linux-syscall-note' 116check_for_license 'GPL-3.0-only' 117check_for_license 'GPL-3.0-only WITH GCC-exception-3.1' 118check_for_license 'GPL-3.0-or-later' 119check_for_license 'HPND' 120check_for_license 'HPND-sell-variant' 121check_for_license 'ISC' 122check_for_license 'MIT' 123check_for_license 'X11' 124 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. 130check_for_license 'BSD-4-Clause-UC' 131 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. 136check_for_license 'CC-PDDC' 137 138for file in $headerlist; do 139 # Verify the file actually exists 140 if [ -f "$file" ]; then 141 echo "$file has no recognized SPDX identifier." 142 fi 143done 144