| 1 |
#!/bin/sh |
| 2 |
# Copyright 2020-2021 Jonas Smedegaard <[email protected]> |
| 3 |
# Copyright 2020-2021 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 |
# Depends: |
| 20 |
# licensecheck, |
| 21 |
# libimage-exiftool-perl, |
| 22 |
# libipc-system-simple-perl, |
| 23 |
# perl, |
| 24 |
|
| 25 |
SKIPFILES='meta' |
| 26 |
|
| 27 |
# omit files not copyright protected nor stating copyright or licensing |
| 28 |
RE_omit='.*\.(ico)' |
| 29 |
|
| 30 |
# cleanup stray hint files from a previous run |
| 31 |
find -type f -regextype posix-egrep -regex "^.*:($SKIPFILES)$" -delete |
| 32 |
|
| 33 |
1>&2 echo 'extract metadata from binary files ...' |
| 34 |
RE_meta='.*\.png' |
| 35 |
exiftool '-textOut!' %d%f.%e:meta -short -short -recurse -ext png . |
| 36 |
|
| 37 |
RE_SKIP="$RE_omit|$RE_meta" |
| 38 |
|
| 39 |
# TODO: automate more of this manual cleanup: |
| 40 |
# * strip garbage copyright holders |
| 41 |
# * optionally merge equally licensed Files sections |
| 42 |
# * do "sort -k2 -k1,1 -u" on copyright holders |
| 43 |
# * merge copyright years for each copyright holder |
| 44 |
# TODO: strip files matching glob in current (only, no later) section |
| 45 |
_licensecheck() { |
| 46 |
SKIPFILES=$SKIPFILES perl -MGetopt::Long=:config,gnu_getopt -MIPC::System::Simple=capture -MList::Util=uniq \ |
| 47 |
-e 'GetOptions ( \%opt, "check=s", "ignore=s", "shortname=s", "subset=s", "merge-licenses" );'\ |
| 48 |
-e '@subset = split( " ", $opt{subset} );' \ |
| 49 |
-e '$subset_globs = join "\n ", @subset;' \ |
| 50 |
-E 'if ( $subset_globs =~ /^[*]$/ ) { say STDERR "check default section(s) ..." }' \ |
| 51 |
-E 'elsif ( @subset and $opt{shortname} ) { say STDERR "check $opt{shortname} section(s) @subset ..." }' \ |
| 52 |
-E 'elsif (@subset) { say STDERR "check section(s) @subset ..." }' \ |
| 53 |
-E 'elsif ($opt{shortname} ) { say STDERR "check $opt{shortname} section(s) @subset ..." }' \ |
| 54 |
-E 'else { say STDERR "check remaining upstream section(s) ..." };' \ |
| 55 |
-e '@cmd = ( qw(licensecheck --copyright --deb-machine --recursive --lines 0), "--check", $opt{check}, "--ignore", $opt{ignore}, $opt{"merge-licenses"} ? "--merge-licenses" : (), "--" );'\ |
| 56 |
-E 'say STDERR "@cmd *" if $ENV{DEBUG};'\ |
| 57 |
-e '$_ = $dump = capture( @cmd, glob "*" );'\ |
| 58 |
-e 'if ( !$ENV{NOGLOBMERGE} and grep /[*]/, @subset ) { s/^.*?\n\nFiles: \K.*?(?=\n\w)/$subset_globs/s }' \ |
| 59 |
-e 'elsif (@subset) { s/^.*?\n\nFiles: \K/$subset_globs\n /s };' \ |
| 60 |
-e 'if ( $subset[0] ne "*" ) { s/^.*?\n\n//s };' \ |
| 61 |
-e 's/^Files:\K /\n /mg;' \ |
| 62 |
-e 's/^Copyright:\K /\n /mg;' \ |
| 63 |
-e 's/(?:(?<=^ )|(?<=\d{4})),\K (?=\d{4})//mg;' \ |
| 64 |
-e 's/:(?:$ENV{SKIPFILES})$//mg;' \ |
| 65 |
-e 'if ($opt{shortname}) { s/^License: \K(.*)/ join " and\/or ", uniq sort grep( !m{\AUNKNOWN\Z}, split(" and\/or ",$1), $opt{shortname} ) /mge };' \ |
| 66 |
-e 'print $_;'\ |
| 67 |
-- "$@" \ |
| 68 |
>> debian/copyright_hints |
| 69 |
} |
| 70 |
|
| 71 |
rm -f debian/copyright_hints |
| 72 |
|
| 73 |
# initially, check all to know roughly what to group and in which order |
| 74 |
#rm -f debian/copyright_hints |
| 75 |
#_licensecheck --check '.*' --ignore "^($RE_SKIP|debian/.*)$" |
| 76 |
#exit 0 |
| 77 |
|
| 78 |
# check generally |
| 79 |
# * omit non-copyright-protected Debian files |
| 80 |
_licensecheck --subset '*' --check '.*' --ignore "^($RE_SKIP|debian/.*)$" |
| 81 |
_licensecheck --subset 'debian/*' --check '^debian/' --ignore '^debian/(changelog|copyright(_hints)?|source/lintian-overrides)$' |
| 82 |
|
| 83 |
# cleanup hint files |
| 84 |
find -type f -regextype posix-egrep -regex "^.*:($SKIPFILES)$" -delete |