#!/bin/bash # SPDX-FileCopyrightText: 2022 Tillitis AB # SPDX-License-Identifier: BSD-2-Clause set -eu # Check for the SPDX tag in all files in the repo. Exit with a non-zero code if # some is missing. The missingok arrays below contain files and directories # with files where the the tag is not required. cd "${0%/*}" cd .. tag="SPDX-License-Identifier:" missingok_dirs=( .github/workflows/ LICENSES/ ) missingok_files=( .clang-format .editorconfig .gitignore LICENSE Makefile README.md README-DIST.txt RELEASE.md example-app/Makefile monocypher/LICENSE monocypher/README.md blake2s/* ) is_missingok() { item="$1" # ok for empty files [[ -f "$item" ]] && [[ ! -s "$item" ]] && return 0 for fileok in "${missingok_files[@]}"; do [[ "$item" = "$fileok" ]] && return 0 done for dirok in "${missingok_dirs[@]}"; do [[ "$item" =~ ^$dirok ]] && return 0 done return 1 } printf "* Checking for SPDX tags in %s\n" "$PWD" mapfile -t repofiles < <(git ls-files || true) if [[ -z "${repofiles[*]}" ]]; then printf "* No files in the repo?!\n" exit 1 fi failed=0 printed=0 for fileok in "${missingok_files[@]}"; do [[ -f "$fileok" ]] && continue if (( !printed )); then printf "* Some files in missingok_files are themselves missing:\n" printed=1 failed=1 fi printf "%s\n" "$fileok" done printed=0 for dirok in "${missingok_dirs[@]}"; do [[ -d "$dirok" ]] && continue if (( !printed )); then printf "* Some dirs in missingok_dirs are themselves missing:\n" printed=1 failed=1 fi printf "%s\n" "$dirok" done printed=0 for file in "${repofiles[@]}"; do is_missingok "$file" && continue if ! grep -q "$tag" "$file"; then if (( !printed )); then printf "* Files missing the SPDX tag:\n" printed=1 failed=1 fi printf "%s\n" "$file" fi done exit "$failed"