Debian Codegraph @

debian/copyright-check

raw
1 #!/bin/sh
2 # Copyright 2020 Jonas Smedegaard <[email protected]>
3 # Copyright 2020 Purism, SPC
4 # Description: helper script to update copyright_hints
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3, or (at your option)
9 # any later version.
10 #
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19 set -eu
20
21 SKIPFILES='meta'
22
23 # cleanup stray hint files from a previous run
24 find -type f -regextype posix-egrep -regex "^.*:($SKIPFILES)$" -delete
25
26 1>&2 echo 'omit files unlikely to contain copyright or license info ...'
27 RE_omit='FAQ-KR\.md'
28
29 1>&2 echo 'extract metadata from binary files ...'
30 RE_meta='.*\.(gif|jpg|otf|png|ttc|ttf)'
31 exiftool '-textOut!' %d%f.%e:meta -short -short -recurse -ext gif -ext jpg -ext otf -ext png -ext ttc -ext ttf .
32
33 RE_SKIP="$RE_omit|$RE_meta"
34
35 # directories more closely aligned
36 RE_cmap='Resource/CMap/.*'
37
38 # licensing patterns misdetected by licensecheck
39 RE_ghostscript=$(grep --files-with-matches --recursive --null \
40 --regexp='license contained in the file LICENSE in this distribution' \
41 | tr '\0' '|' | sed -e 's/|$//')
42
43 RE_artifex=$(grep --files-with-matches --recursive --null \
44 --regexp='Refer to licensing information at http://www.artifex.com' \
45 | tr '\0' '|' | sed -e 's/|$//')
46
47 # TODO: automate more of this manual cleanup:
48 # * strip garbage copyright holders
49 # * optionally merge equally licensed Files sections
50 # * do "sort -k2 -k1,1 -u" on copyright holders
51 # * merge copyright years for each copyright holder
52 # TODO: strip files matching glob in current (only, no later) section
53 _licensecheck() {
54 GLOB=$1
55 shift
56 case "$GLOB" in
57 '*') 1>&2 echo "check default section(s) ...";;
58 '') 1>&2 echo "check remaining upstream section(s) ...";;
59 *) 1>&2 echo "check section(s) $GLOB ...";;
60 esac
61 licensecheck --copyright --deb-machine --recursive --lines 0 "$@" -- * \
62 | GLOB=$GLOB SKIPFILES=$SKIPFILES perl -0777 -p \
63 -e 'BEGIN { our $GLOB = join "\n ", split(" ",$ENV{GLOB}) }' \
64 -e 's/^.*?\n\nFiles: \K/$GLOB\n /s if $GLOB;' \
65 -e 's/^.*?\n\nFiles: \K.*?(?=\n\w)/$GLOB/s if $GLOB and $GLOB =~ /^[*]\//;' \
66 -e 's/^.*?\n\n//s unless $GLOB and $GLOB =~ /^[*]$/m;' \
67 -e 's/^Files:\K /\n /mg;' \
68 -e 's/^Copyright:\K /\n /mg;' \
69 -e 's/(?:(?<=^ )|(?<=\d{4})),\K (?=\d{4})//mg;' \
70 -e 's/:(?:$ENV{SKIPFILES})$//mg;' \
71 >> debian/copyright_hints
72 }
73
74 rm -f debian/copyright_hints
75
76 # initially, check all to know roughly what to group and in which order
77 #rm -f debian/copyright_hints
78 #_licensecheck '' --check '.*' --ignore "^($RE_SKIP|debian/.*)$"
79 #exit 0
80
81 # check generally
82 # * omit non-copyright-protected Debian files
83 _licensecheck '*' --check '.*' --ignore "^($RE_SKIP|debian/.*)$"
84 _licensecheck '*/debian' --check '^debian/' --ignore "^($RE_SKIP|debian/(changelog|copyright(_hints)?|source/lintian-overrides))$"
85
86 # cleanup hint files
87 find -type f -regextype posix-egrep -regex "^.*:($SKIPFILES)$" -delete