Add script to check for SPDX identifiers

This commit is contained in:
Tim Crawford 2021-02-22 13:04:14 -07:00 committed by Jeremy Soller
parent 9ef191edff
commit 3e742b0da7

35
scripts/spdx.sh Executable file
View File

@ -0,0 +1,35 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: GPL-3.0-only
# Check that all files have a SPDX license identifier
set -e
# File patterns to check
FILE_TYPES=(
'*.c'
'*.h'
'*.mk'
'*.rs'
'*.sh'
'Makefile'
)
ret=0
for ft in "${FILE_TYPES[@]}"; do
files=$(git ls-files "$ft")
for f in ${files}; do
# Skip empty files
if [[ "$(wc -l < "$f")" = "0" ]]; then
continue
fi
# SPDX must appear at head of file
if ! head "$f" | grep -q 'SPDX-License-Identifier:'; then
echo "$f: Missing SPDX identifier"
ret=1
fi
done
done
exit ${ret}