1 1.1 christos #!/bin/sh 2 1.1 christos # SPDX-License-Identifier: 0BSD 3 1.1 christos 4 1.1 christos ############################################################################### 5 1.1 christos # 6 1.1 christos # Look for missing license info in xz.git 7 1.1 christos # 8 1.1 christos # The project doesn't conform to the FSFE REUSE specification for now. 9 1.1 christos # Instead, this script helps in finding files that lack license info. 10 1.1 christos # Pass -v as an argument to get license info from all files in xz.git or, 11 1.1 christos # when .git isn't available, from files extracted from a release tarball 12 1.1 christos # (in case of a release tarball, the tree must be clean of any extra files). 13 1.1 christos # 14 1.1 christos # NOTE: This relies on non-POSIX xargs -0. It's supported on GNU and *BSDs. 15 1.1 christos # 16 1.1 christos ############################################################################### 17 1.1 christos # 18 1.1 christos # Author: Lasse Collin 19 1.1 christos # 20 1.1 christos ############################################################################### 21 1.1 christos 22 1.1 christos # Print good files too if -v is passed as an argument. 23 1.1 christos VERBOSE=false 24 1.1 christos case $1 in 25 1.1 christos '') 26 1.1 christos ;; 27 1.1 christos -v) 28 1.1 christos VERBOSE=true 29 1.1 christos ;; 30 1.1 christos *) 31 1.1 christos echo "Usage: $0 [-v]" 32 1.1 christos exit 1 33 1.1 christos ;; 34 1.1 christos esac 35 1.1 christos 36 1.1 christos 37 1.1 christos # Use the C locale so that sorting is always the same. 38 1.1 christos LC_ALL=C 39 1.1 christos export LC_ALL 40 1.1 christos 41 1.1 christos 42 1.1 christos # String to match the SPDX license identifier tag. 43 1.1 christos # Spell it here in a way that doesn't match regular grep patterns. 44 1.1 christos SPDX_LI='SPDX''-License-''Identifier'':' 45 1.1 christos 46 1.1 christos # Pattern for files that don't contain SPDX tags but they are under 47 1.1 christos # a free license that isn't 0BSD. 48 1.1 christos PAT_UNTAGGED_MISC='^COPYING\. 49 1.1 christos ^INSTALL\.generic$' 50 1.1 christos 51 1.1 christos # Pattern for files that are 0BSD but don't contain SPDX tags. 52 1.1 christos # (The two file format specification files are public domain but 53 1.1 christos # they can be treated as 0BSD too.) 54 1.1 christos PAT_UNTAGGED_0BSD='^(.*/)?\.gitattributes$ 55 1.1 christos ^(.*/)?\.gitignore$ 56 1.1 christos ^\.github/SECURITY\.md$ 57 1.1 christos ^AUTHORS$ 58 1.1 christos ^COPYING$ 59 1.1 christos ^ChangeLog$ 60 1.1 christos ^INSTALL$ 61 1.1 christos ^NEWS$ 62 1.1 christos ^PACKAGERS$ 63 1.1 christos ^(.*/)?README$ 64 1.1 christos ^THANKS$ 65 1.1 christos ^TODO$ 66 1.1 christos ^(.*/)?[^/]+\.txt$ 67 1.1 christos ^doc/SHA256SUMS$ 68 1.1 christos ^po/LINGUAS$ 69 1.1 christos ^src/common/w32_application\.manifest$ 70 1.1 christos ^tests/xzgrep_expected_output$ 71 1.1 christos ^tests/files/[^/]+\.(lz|lzma|xz)$' 72 1.1 christos 73 1.1 christos # Pattern for files that must be ignored when Git isn't available. This is 74 1.1 christos # useful when this script is run right after extracting a release tarball. 75 1.1 christos PAT_TARBALL_IGNORE='^(m4/)?[^/]*\.m4$ 76 1.1 christos ^(.*/)?Makefile\.in(\.in)?$ 77 1.1 christos ^(po|po4a)/.*[^.]..$ 78 1.1 christos ^ABOUT-NLS$ 79 1.1 christos ^build-aux/(config\..*|ltmain\.sh|[^.]*)$ 80 1.1 christos ^config\.h\.in$ 81 1.1 christos ^configure$' 82 1.1 christos 83 1.1 christos 84 1.1 christos # Go to the top source dir. 85 1.1 christos cd "$(dirname "$0")/.." || exit 1 86 1.1 christos 87 1.1 christos # Get the list of files to check from git if possible. 88 1.1 christos # Otherwise list the whole source tree. This script should pass 89 1.1 christos # if it is run right after extracting a release tarball. 90 1.1 christos if test -d .git && type git > /dev/null 2>&1; then 91 1.1 christos FILES=$(git ls-files) || exit 1 92 1.1 christos IS_TARBALL=false 93 1.1 christos else 94 1.1 christos FILES=$(find . -type f) || exit 1 95 1.1 christos FILES=$(printf '%s\n' "$FILES" | sed 's,^\./,,') 96 1.1 christos IS_TARBALL=true 97 1.1 christos fi 98 1.1 christos 99 1.1 christos # Sort to keep the order consistent. 100 1.1 christos FILES=$(printf '%s\n' "$FILES" | sort) 101 1.1 christos 102 1.1 christos 103 1.1 christos # Find the tagged files. 104 1.1 christos TAGGED=$(printf '%s\n' "$FILES" \ 105 1.1 christos | tr '\n' '\000' | xargs -0r grep -l "$SPDX_LI" --) 106 1.1 christos 107 1.1 christos # Find the tagged 0BSD files. 108 1.1 christos TAGGED_0BSD=$(printf '%s\n' "$TAGGED" \ 109 1.1 christos | tr '\n' '\000' | xargs -0r grep -l "$SPDX_LI 0BSD" --) 110 1.1 christos 111 1.1 christos # Find the tagged non-0BSD files, that is, remove the 0BSD-tagged files 112 1.1 christos # from the list of tagged files. 113 1.1 christos TAGGED_MISC=$(printf '%s\n%s\n' "$TAGGED" "$TAGGED_0BSD" | sort | uniq -u) 114 1.1 christos 115 1.1 christos 116 1.1 christos # Remove the tagged files from the list. 117 1.1 christos FILES=$(printf '%s\n%s\n' "$FILES" "$TAGGED" | sort | uniq -u) 118 1.1 christos 119 1.1 christos # Find the intentionally-untagged files. 120 1.1 christos UNTAGGED_0BSD=$(printf '%s\n' "$FILES" | grep -E "$PAT_UNTAGGED_0BSD") 121 1.1 christos UNTAGGED_MISC=$(printf '%s\n' "$FILES" | grep -E "$PAT_UNTAGGED_MISC") 122 1.1 christos 123 1.1 christos # Remove the intentionally-untagged files from the list. 124 1.1 christos FILES=$(printf '%s\n' "$FILES" | grep -Ev \ 125 1.1 christos -e "$PAT_UNTAGGED_0BSD" -e "$PAT_UNTAGGED_MISC") 126 1.1 christos 127 1.1 christos 128 1.1 christos # FIXME: Allow untagged translations if they have a public domain notice. 129 1.1 christos # These are old translations that haven't been updated after 2024-02-14. 130 1.1 christos # Eventually these should go away. 131 1.1 christos PD_PO=$(printf '%s\n' "$FILES" | grep '\.po$' | tr '\n' '\000' \ 132 1.1 christos | xargs -0r grep -Fl '# This file is put in the public domain.' --) 133 1.1 christos 134 1.1 christos if test -n "$PD_PO"; then 135 1.1 christos # Remove the public domain .po files from the list. 136 1.1 christos FILES=$(printf '%s\n%s\n' "$FILES" "$PD_PO" | sort | uniq -u) 137 1.1 christos fi 138 1.1 christos 139 1.1 christos 140 1.1 christos # Remove generated files from the list which don't have SPDX tags but which 141 1.1 christos # can be present in release tarballs. This step is skipped when the file list 142 1.1 christos # is from "git ls-files". 143 1.1 christos GENERATED= 144 1.1 christos if $IS_TARBALL; then 145 1.1 christos GENERATED=$(printf '%s\n' "$FILES" | grep -E "$PAT_TARBALL_IGNORE") 146 1.1 christos FILES=$(printf '%s\n' "$FILES" | grep -Ev "$PAT_TARBALL_IGNORE") 147 1.1 christos fi 148 1.1 christos 149 1.1 christos 150 1.1 christos if $VERBOSE; then 151 1.1 christos printf '# Tagged 0BSD files:\n%s\n\n' "$TAGGED_0BSD" 152 1.1 christos printf '# Intentionally untagged 0BSD:\n%s\n\n' "$UNTAGGED_0BSD" 153 1.1 christos 154 1.1 christos # FIXME: Remove when no longer needed. 155 1.1 christos if test -n "$PD_PO"; then 156 1.1 christos printf '# Old public domain translations:\n%s\n\n' "$PD_PO" 157 1.1 christos fi 158 1.1 christos 159 1.1 christos printf '# Tagged non-0BSD files:\n%s\n\n' "$TAGGED_MISC" 160 1.1 christos printf '# Intentionally untagged miscellaneous: \n%s\n\n' \ 161 1.1 christos "$UNTAGGED_MISC" 162 1.1 christos 163 1.1 christos if test -n "$GENERATED"; then 164 1.1 christos printf '# Generated files whose license was NOT checked:\n%s\n\n' \ 165 1.1 christos "$GENERATED" 166 1.1 christos fi 167 1.1 christos fi 168 1.1 christos 169 1.1 christos 170 1.1 christos # Look for files with an unknown license and set the exit status accordingly. 171 1.1 christos STATUS=0 172 1.1 christos if test -n "$FILES"; then 173 1.1 christos printf '# ERROR: Licensing is unclear:\n%s\n' "$FILES" 174 1.1 christos STATUS=1 175 1.1 christos fi 176 1.1 christos 177 1.1 christos exit "$STATUS" 178