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