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 # omit files not copyright protected nor stating copyright or licensing
24 RE_omit='.*\.(ico)'
25
26 # cleanup stray hint files from a previous run
27 find -type f -regextype posix-egrep -regex "^.*:($SKIPFILES)$" -delete
28
29 1>&2 echo 'extract metadata from binary files ...'
30 RE_meta='.*\.png'
31 exiftool '-textOut!' %d%f.%e:meta -short -short -recurse -ext png .
32
33 RE_SKIP="$RE_omit|$RE_meta"
34
35 # TODO: automate more of this manual cleanup:
36 # * strip garbage copyright holders
37 # * optionally merge equally licensed Files sections
38 # * do "sort -k2 -k1,1 -u" on copyright holders
39 # * merge copyright years for each copyright holder
40 # TODO: strip files matching glob in current (only, no later) section
41 _licensecheck() {
42 GLOB=$1
43 shift
44 case "$GLOB" in
45 '*') 1>&2 echo "check default section(s) ...";;
46 '') 1>&2 echo "check remaining upstream section(s) ...";;
47 *) 1>&2 echo "check section(s) $GLOB ...";;
48 esac
49 licensecheck --copyright --deb-machine --recursive --lines 0 "$@" -- * \
50 | GLOB=$GLOB SKIPFILES=$SKIPFILES perl -0777 -p \
51 -e 'BEGIN { our $GLOB = join "\n ", split(" ",$ENV{GLOB}) }' \
52 -e 's/^.*?\n\nFiles: \K/$GLOB\n /s if $GLOB;' \
53 -e 's/^.*?\n\nFiles: \K.*?(?=\n\w)/$GLOB/s if $GLOB and $GLOB =~ /^[*]\//;' \
54 -e 's/^.*?\n\n//s unless $GLOB and $GLOB =~ /^[*]$/m;' \
55 -e 's/^Files:\K /\n /mg;' \
56 -e 's/^Copyright:\K /\n /mg;' \
57 -e 's/(?:(?<=^ )|(?<=\d{4})),\K (?=\d{4})//mg;' \
58 -e 's/:(?:$ENV{SKIPFILES})$//mg;' \
59 >> debian/copyright_hints
60 }
61
62 rm -f debian/copyright_hints
63
64 # initially, check all to know roughly what to group and in which order
65 #rm -f debian/copyright_hints
66 #_licensecheck '' --check '.*' --ignore "^($RE_SKIP|debian/.*)$"
67 #exit 0
68
69 # check generally
70 # * omit non-copyright-protected Debian files
71 _licensecheck '*' --check '.*' --ignore "^($RE_SKIP|debian/.*)$"
72 _licensecheck '*/debian' --check '^debian/' --ignore '^debian/(changelog|copyright(_hints)?|source/lintian-overrides)$'
73
74 # cleanup hint files
75 find -type f -regextype posix-egrep -regex "^.*:($SKIPFILES)$" -delete