afferify 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. use File::Find;
  17. $|=1;
  18. # Recurse into current or given directories
  19. find(\&wanted, $#ARGV >= 0 ? @ARGV : '.');
  20. print STDERR "\n";
  21. exit;
  22. sub wanted {
  23. my $name = $File::Find::name;
  24. ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime)
  25. = lstat;
  26. return $File::Find::prune = 1 if /^(CVS|\.git|\.svn)$/;
  27. # Nicer if you 'make distclean' first
  28. return if /\.(o|pdf)$/i;
  29. return if -d _ or -l _;
  30. return if /afferify/; # Don't apply this to itself ;)
  31. # No.. i didn't do it.. just being careful ;) ;)
  32. # return unless -T _; # We don't have binaries in the repo, do we?
  33. # We need the default variable '$_' for more important duties.
  34. my $f = $_;
  35. if (sysopen(I, $f, O_RDONLY)) {
  36. $_ = &slurp(*I);
  37. close I;
  38. # Debugging: What's inside the file we just read?
  39. # print STDERR '> ', $_;
  40. if (0) {
  41. # This code did the initial conversion. We ifdef it out.
  42. # Good idea to have the text start with "GNUnet" rather than "This program"
  43. 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# ) {
  44. # Whoever had the idea of reformatting the GPL license text...
  45. print STDERR "\nTrying wide style on $name\t";
  46. # Most important thing to know in order to be able
  47. # to read perl code: if regexps appear without any
  48. # context, it means they are applied to the default
  49. # variable being '$_'.
  50. return unless s#terms of the GNU General Public License as published by the Free Software#under the terms of the GNU Affero General Public License as published#;
  51. 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;
  52. 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#;
  53. return unless s#WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR#WITHOUT ANY WARRANTY; without even the implied warranty of#;
  54. 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;
  55. 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;
  56. } else {
  57. # If this string is not in the file, leave it alone.
  58. 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#;
  59. print STDERR "\nTrying regular style on $name\t";
  60. # Patterns are designed to also match some typos and substitutions.
  61. return unless s#it under the terms of the GNU General Public Lice\w+ as published#under the terms of the GNU Affero General Public License as published#;
  62. 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,#;
  63. return unless s#option\) any later version\.#or (at your option) any later version.#;
  64. return unless s#General Public Lice\w+ for more details\.#Affero General Public License for more details.#;
  65. 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;
  66. }
  67. print STDERR "OK";
  68. } else {
  69. # This is the code in actual & current use:
  70. return unless m#GNUnet is free software: you can redistribute it and/or modify it#;
  71. print STDERR "\nTrying $name\t";
  72. # There was a mistake in the replacement text!
  73. return unless s#under the terms of the GNU General Public License as published#under the terms of the GNU Affero General Public License as published#;
  74. # Don't apply this one twice!
  75. # return unless s#(\n\W*)(\s+)(Affero General Public License for more details\.)#\1\2\3\1\1\2You should have received a copy of the GNU Affero General Public License\1\2along with this program. If not, see <http://www.gnu.org/licenses/>.#;
  76. print STDERR "FIXED";
  77. }
  78. # We directly overwrite the original file in the
  79. # assumption that we're in a healthy revertible git.
  80. open(O, '>', $f) or die "Cannot overwrite $f";
  81. # Imagine, I could have left out $_ here... ;)
  82. print O $_;
  83. close O;
  84. } else {
  85. die "Cannot access $name";
  86. }
  87. }
  88. # Reads a file from a stream into a variable all at once:
  89. sub slurp {
  90. # Perl sure gets clunky here
  91. local(*IN) = @_;
  92. local($save) = $/;
  93. undef $/;
  94. local($data) = <IN>;
  95. $/ = $save;
  96. return $data;
  97. }