diff options
Diffstat (limited to 'contrib')
-rwxr-xr-x | contrib/scripts/afferify | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/contrib/scripts/afferify b/contrib/scripts/afferify new file mode 100755 index 000000000..188b66c64 --- /dev/null +++ b/contrib/scripts/afferify | |||
@@ -0,0 +1,95 @@ | |||
1 | #!/usr/bin/perl | ||
2 | # Catch all in-source GPL2/3 license declarations and convert | ||
3 | # them to AGPL. | ||
4 | # | ||
5 | # You expected this to be using diff & patch? Well, the source | ||
6 | # files have all sorts of different commenting and indentation | ||
7 | # styles, not speaking of typos and failed uses of search and | ||
8 | # replace, that an attempt in using the patch(1) tool would fail | ||
9 | # miserably. This script instead is based on my rgrep from 1998. | ||
10 | # Keeping it here as it may be useful to other projects under- | ||
11 | # going the same pains. It is forbidden to use this script to | ||
12 | # convert AGPL code back to less strict licensing. Haha, just | ||
13 | # kidding. | ||
14 | # | ||
15 | # -symlynX | ||
16 | |||
17 | use File::Find; | ||
18 | $|=1; | ||
19 | # Recurse into current or given directories | ||
20 | find(\&wanted, $#ARGV >= 0 ? @ARGV : '.'); | ||
21 | print STDERR "\n"; | ||
22 | exit; | ||
23 | |||
24 | |||
25 | sub wanted { | ||
26 | my $name = $File::Find::name; | ||
27 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime) | ||
28 | = lstat; | ||
29 | return $File::Find::prune = 1 if /^(CVS|\.git|\.svn)$/; | ||
30 | # Nicer if you 'make distclean' first | ||
31 | return if /\.(o|pdf)$/i; | ||
32 | return if -d _ or -l _; | ||
33 | return if /afferify/; # Don't apply this to itself ;) | ||
34 | # No.. i didn't do it.. just being careful ;) ;) | ||
35 | # return unless -T _; # We don't have binaries in the repo, do we? | ||
36 | |||
37 | # We need the default variable '$_' for more important duties. | ||
38 | my $f = $_; | ||
39 | |||
40 | if (sysopen(I, $f, O_RDONLY)) { | ||
41 | $_ = &slurp(*I); | ||
42 | close I; | ||
43 | # Debugging: What's inside the file we just read? | ||
44 | # print STDERR '> ', $_; | ||
45 | |||
46 | # Good idea to have the text start with "GNUnet" rather than "This program" | ||
47 | if ( s#GNUnet is free software; you can redistribute it and/or modify it under the#GNUnet is free software: you can redistribute it and/or modify it# ) { | ||
48 | # Whoever had the idea of reformatting the GPL license text... | ||
49 | print STDERR "\nTrying wide style on $name\t"; | ||
50 | |||
51 | # Most important thing to know in order to be able | ||
52 | # to read perl code: if regexps appear without any | ||
53 | # context, it means they are applied to the default | ||
54 | # variable being '$_'. | ||
55 | return unless s#terms of the GNU General Public License as published by the Free Software#under the terms of the GNU General Public License as published#; | ||
56 | return unless s#^(\W*\s+)Foundation; either version \d, or \(at your option\) any later version\.#\1by the Free Software Foundation, either version 3 of the License,\n\1or (at your option) any later version.#m; | ||
57 | return unless s#GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY#GNUnet is distributed in the hope that it will be useful, but#; | ||
58 | return unless s#WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR#WITHOUT ANY WARRANTY; without even the implied warranty of#; | ||
59 | return unless s#^(\W*\s+)A PARTICULAR PURPOSE. See the GNU General Public License for more details.#\1MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n\1Affero General Public License for more details.#m; | ||
60 | return unless s#^\W*\n\W*\s+You should have received a copy of the GNU General Public License along with\n\W*\s+GNUnet. see the file COPYING\. If not, .* see\s*\W*\s+<http://www.gnu.org/licenses/>\n##m; | ||
61 | } else { | ||
62 | # If this string is not in the file, leave it alone. | ||
63 | return unless s#GNUnet is free software; you can redistribute it and/or modify#GNUnet is free software: you can redistribute it and/or modify it#; | ||
64 | print STDERR "\nTrying regular style on $name\t"; | ||
65 | |||
66 | # Patterns are designed to also match some typos and substitutions. | ||
67 | return unless s#it under the terms of the GNU General Public Lice\w+ as published#under the terms of the GNU General Public License as published#; | ||
68 | return unless s#by the Free Software Foundation; either version \d, or \(at your#by the Free Software Foundation, either version 3 of the License,#; | ||
69 | return unless s#option\) any later version\.#or (at your option) any later version.#; | ||
70 | return unless s#General Public Lice\w+ for more details\.#Affero General Public License for more details.#; | ||
71 | return unless s#^\W*\n\W*\s+You should have received a copy of the GNU General Public Lice\w+\n\W*\s+along with GNUnet. see the file COPYING\. If not, write to the\n\W*\s+Free Software Foundation, Inc\., (51 Franklin Street, Fifth Floor|59 Tem ?ple Place - Suite 330),\n\W*\s+Boston, MA 0211\d-130\d, USA\.\n##m; | ||
72 | } | ||
73 | print STDERR "OK"; | ||
74 | |||
75 | # We directly overwrite the original file in the | ||
76 | # assumption that we're in a healthy revertible git. | ||
77 | open(O, '>', $f) or die "Cannot overwrite $f"; | ||
78 | # Imagine, I could have left out $_ here... ;) | ||
79 | print O $_; | ||
80 | close O; | ||
81 | } else { | ||
82 | die "Cannot access $name"; | ||
83 | } | ||
84 | } | ||
85 | |||
86 | # Reads a file from a stream into a variable all at once: | ||
87 | sub slurp { | ||
88 | # Perl sure gets clunky here | ||
89 | local(*IN) = @_; | ||
90 | local($save) = $/; | ||
91 | undef $/; | ||
92 | local($data) = <IN>; | ||
93 | $/ = $save; | ||
94 | return $data; | ||
95 | } | ||