Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
# |
3 |
# Prepend copyright and license statements to Koha source files. |
4 |
# Only prepends statements if they are missing in the file. |
5 |
# Statements will be added at the beginning of the file. |
6 |
# |
7 |
# Copyright 2023 Koha development team |
8 |
# |
9 |
# This file is part of Koha. |
10 |
# |
11 |
# Koha is free software; you can redistribute it and/or modify it |
12 |
# under the terms of the GNU General Public License as published by |
13 |
# the Free Software Foundation; either version 3 of the License, or |
14 |
# (at your option) any later version. |
15 |
# |
16 |
# Koha is distributed in the hope that it will be useful, but |
17 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
18 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 |
# GNU General Public License for more details. |
20 |
# |
21 |
# You should have received a copy of the GNU General Public License |
22 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
23 |
|
24 |
use strict; |
25 |
use warnings; |
26 |
use Modern::Perl; |
27 |
use Path::Tiny; |
28 |
use File::Spec; |
29 |
use File::Find; |
30 |
|
31 |
my @files; |
32 |
my ( $hascopyright, $hasgpl, $hasv3, $hasorlater, $haslinktolicense, |
33 |
$hasfranklinst, $is_not_us, $needs_copyright ) = (0)x8; |
34 |
my $copyrightstatement = "# Copyright 2023 Koha development team\n"; |
35 |
my $licensestatement = "# Koha is free software; you can redistribute it and/or modify it\n |
36 |
# under the terms of the GNU General Public License as published by\n |
37 |
# the Free Software Foundation; either version 3 of the License, or\n |
38 |
# (at your option) any later version.\n |
39 |
#\n |
40 |
# Koha is distributed in the hope that it will be useful, but\n |
41 |
# WITHOUT ANY WARRANTY; without even the implied warranty of\n |
42 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n |
43 |
# GNU General Public License for more details.\n |
44 |
#\n |
45 |
# You should have received a copy of the GNU General Public License\n |
46 |
# along with Koha; if not, see <http://www.gnu.org/licenses>.\n"; |
47 |
|
48 |
sub wanted { |
49 |
my $name = $File::Find::name; |
50 |
push @files, $name |
51 |
unless $name =~ /\/(\.git|installer\/data\/mysql\/db_revs|koha-tmpl|node_modules|swagger-ui|Koha.Schema.Result)(\/.*)?$/ || |
52 |
$name =~ /\.(gif|jpg|odt|ogg|pdf|png|po|psd|svg|swf|zip|patch)$/ || |
53 |
$name =~ m[(xt/find-license-problems|xt/fix-old-fsf-address|misc/translator/po2json)] || |
54 |
! -f $name; |
55 |
} |
56 |
|
57 |
find({ wanted => \&wanted, no_chdir => 1 }, File::Spec->curdir()); |
58 |
|
59 |
foreach my $name (sort @files) { |
60 |
open( my $fh, '<', $name ) || die "cannot open file $name $!"; |
61 |
my ( $hascopyright, $hasgpl, $hasv3, $hasorlater, $haslinktolicense, |
62 |
$hasfranklinst, $is_not_us, $needs_copyright ) = (0)x8; |
63 |
while ( my $line = <$fh> ) { |
64 |
$hascopyright = 1 if ( $line =~ /^(#|--)?\s*Copyright.*\d\d/ ); |
65 |
$hasgpl = 1 if ( $line =~ /GNU General Public License/ ); |
66 |
$hasv3 = 1 if ( $line =~ /either version 3/ ); |
67 |
$hasorlater = 1 |
68 |
if ( $line =~ /any later version/ |
69 |
|| $line =~ /at your option/ ); |
70 |
$haslinktolicense = 1 if $line =~ m|http://www\.gnu\.org/licenses|; |
71 |
$hasfranklinst = 1 if ( $line =~ /51 Franklin Street/ ); |
72 |
$is_not_us = 1 if $line =~ m|This file is part of the Zebra server|; |
73 |
$needs_copyright = 1 if $line =~ m|This file is part of Koha| || $name =~ /\.(pl|pm)/; |
74 |
} |
75 |
close $fh; |
76 |
|
77 |
my $filecontent = path($name)->slurp_utf8; |
78 |
if ($hascopyright == 0 |
79 |
&& $hasgpl |
80 |
&& $hasv3 |
81 |
&& $hasorlater |
82 |
&& $haslinktolicense) { |
83 |
path($name)->spew_utf8($copyrightstatement, $filecontent); |
84 |
} |
85 |
elsif ($hascopyright == 0 |
86 |
&& $hasgpl == 0 |
87 |
&& $hasv3 == 0 |
88 |
&& $haslinktolicense == 0 |
89 |
&& $hasorlater == 0) { |
90 |
path($name)->spew_utf8($copyrightstatement, $licensestatement, $filecontent); |
91 |
} |
92 |
next unless $hascopyright || $needs_copyright; |
93 |
next if $is_not_us; |
94 |
} |