File indexing completed on 2024-06-09 04:20:04
0001 #!/bin/bash 0002 0003 # SPDX-FileCopyrightText: 2019-2023 Johannes Zarl-Zierl <johannes@zarl-zierl.at> 0004 # 0005 # SPDX-License-Identifier: BSD-2-Clause 0006 0007 ### 0008 # Check all added or modified files that have a copyright line 0009 # for an up-to-date copyright year. 0010 # e.g. "Copyright (C) 2018-2019 The KPhotoAlbum Development Team" 0011 ### 0012 0013 set -e 0014 0015 if [[ -z "$CHECK_COPYRIGHT_HEADER" ]] 0016 then 0017 CHECK_COPYRIGHT_HEADER=$(git config --bool --get kpa.checkCopyrightHeader || echo true) 0018 fi 0019 if [[ "$CHECK_COPYRIGHT_HEADER" == false ]] 0020 then 0021 exit 0 0022 fi 0023 0024 declare -a affected_files 0025 0026 year=$(date +%Y) 0027 IFS=$'\n' 0028 for line in $(git status --short) 0029 do 0030 # if the file is added or modified 0031 if [[ $line == A* || $line == M* ]] 0032 then 0033 filename="${line:3}" 0034 if grep -q SPDX-FileCopyrightText "${filename}" 0035 then 0036 if ! grep -q "SPDX-FileCopyrightText:.*$year" "${filename}" 0037 then 0038 if ! grep -iq "SPDX-FileCopyrightText: *none" "${filename}" 0039 then 0040 affected_files+=("${filename}") 0041 fi 0042 fi 0043 fi 0044 fi 0045 done 0046 0047 if [[ ${#affected_files[@]} -gt 0 ]] 0048 then 0049 printf "** Please update copyright year for the following files:\n\n%s\n" "${affected_files[*]}" 0050 # also check if the Copyright statement in main.cpp is ok: 0051 if ! grep -q -i "i18n(\"Copyright (C) 2003-$year " main.cpp 0052 then 0053 printf "...and also update the copyright statement in main.cpp!\n" 0054 fi 0055 copyright="$(git config --get user.name) <$(git config --get user.email)>" 0056 printf "\n" 0057 printf "** If you have the reuse tool installed and are the author (not just the committer),\n" 0058 printf "** you may use the following command as a starting point:\n" 0059 # whitespace in filenames is not handled 0060 IFS=" " fnames="${affected_files[*]}" 0061 printf "** reuse annotate --merge-copyrights --year %s --copyright '%s' %s\n" "$year " "$copyright" "${fnames}" 0062 if ! command -v reuse >/dev/null 0063 then 0064 printf "** You can usually install the reuse tool by running 'pip install --user reuse' or by following the instructions on https://reuse.software/\n" 0065 fi 0066 printf "** You can suppress this check by setting 'git config kpa.checkCopyrightHeader false'\n" 0067 printf "** or by setting the environment variable CHECK_COPYRIGHT_HEADER=false\n" 0068 exit 1 0069 fi