From 3e742b0da73f8a51e29b9617fe35c6f285e1d8cf Mon Sep 17 00:00:00 2001 From: Tim Crawford Date: Mon, 22 Feb 2021 13:04:14 -0700 Subject: [PATCH] Add script to check for SPDX identifiers --- scripts/spdx.sh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 scripts/spdx.sh diff --git a/scripts/spdx.sh b/scripts/spdx.sh new file mode 100755 index 0000000..3ad4c84 --- /dev/null +++ b/scripts/spdx.sh @@ -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}