import rt 3.8.10
[freeside.git] / rt / sbin / license_tag
1 #!/usr/bin/perl
2
3
4 # BEGIN BPS TAGGED BLOCK {{{
5 #
6 # COPYRIGHT:
7 #
8 # This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC
9 #                                          <sales@bestpractical.com>
10 #
11 # (Except where explicitly superseded by other copyright notices)
12 #
13 #
14 # LICENSE:
15 #
16 # This work is made available to you under the terms of Version 2 of
17 # the GNU General Public License. A copy of that license should have
18 # been provided with this software, but in any event can be snarfed
19 # from www.gnu.org.
20 #
21 # This work is distributed in the hope that it will be useful, but
22 # WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
24 # General Public License for more details.
25 #
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write to the Free Software
28 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
29 # 02110-1301 or visit their web page on the internet at
30 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
31 #
32 #
33 # CONTRIBUTION SUBMISSION POLICY:
34 #
35 # (The following paragraph is not intended to limit the rights granted
36 # to you to modify and distribute this software under the terms of
37 # the GNU General Public License and is only of importance to you if
38 # you choose to contribute your changes and enhancements to the
39 # community by submitting them to Best Practical Solutions, LLC.)
40 #
41 # By intentionally submitting any modifications, corrections or
42 # derivatives to this work, or any other work intended for use with
43 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
44 # you are the copyright holder for those contributions and you grant
45 # Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
46 # royalty-free, perpetual, license to use, copy, create derivative
47 # works based on those contributions, and sublicense and distribute
48 # those contributions and any derivatives thereof.
49 #
50 # END BPS TAGGED BLOCK }}}
51 my $LICENSE  = <<'EOL';
52
53 COPYRIGHT:
54
55 This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC
56                                          <sales@bestpractical.com>
57
58 (Except where explicitly superseded by other copyright notices)
59
60
61 LICENSE:
62
63 This work is made available to you under the terms of Version 2 of
64 the GNU General Public License. A copy of that license should have
65 been provided with this software, but in any event can be snarfed
66 from www.gnu.org.
67
68 This work is distributed in the hope that it will be useful, but
69 WITHOUT ANY WARRANTY; without even the implied warranty of
70 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
71 General Public License for more details.
72
73 You should have received a copy of the GNU General Public License
74 along with this program; if not, write to the Free Software
75 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
76 02110-1301 or visit their web page on the internet at
77 http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
78
79
80 CONTRIBUTION SUBMISSION POLICY:
81
82 (The following paragraph is not intended to limit the rights granted
83 to you to modify and distribute this software under the terms of
84 the GNU General Public License and is only of importance to you if
85 you choose to contribute your changes and enhancements to the
86 community by submitting them to Best Practical Solutions, LLC.)
87
88 By intentionally submitting any modifications, corrections or
89 derivatives to this work, or any other work intended for use with
90 Request Tracker, to Best Practical Solutions, LLC, you confirm that
91 you are the copyright holder for those contributions and you grant
92 Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
93 royalty-free, perpetual, license to use, copy, create derivative
94 works based on those contributions, and sublicense and distribute
95 those contributions and any derivatives thereof.
96
97 EOL
98
99 use File::Find;
100
101 my @MAKE = qw(Makefile);
102
103 File::Find::find({ no_chdir => 1, wanted => \&tag_pm}, 'lib');
104 File::Find::find({ no_chdir => 1, wanted => \&tag_mason}, 'share/html');
105 File::Find::find({ no_chdir => 1, wanted => \&tag_script}, 'sbin');
106 File::Find::find({ no_chdir => 1, wanted => \&tag_script}, 'bin');
107 File::Find::find({ no_chdir => 1, wanted => \&tag_script}, 'etc/upgrade');
108 tag_makefile ('Makefile.in');
109 tag_makefile ('README');
110
111
112 sub tag_mason {
113         my $pm = $_;
114         return unless (-f $pm);
115         return if $pm =~ /images/ || $pm =~ /\.(?:png|jpe?g|gif)$/;
116         open( FILE, '<', $pm ) or die "Failed to open $pm";
117         my $file = (join "", <FILE>);
118         close (FILE);
119         print "$pm - ";
120         return if another_license($pm => $file) && print "has different license\n";
121
122         my $pmlic = $LICENSE;
123         $pmlic =~ s/^/%# /mg;
124         $pmlic =~ s/\s*$//mg;
125         if ($file =~ /^%# BEGIN BPS TAGGED BLOCK {{{/ms) {
126                 print "has license section";
127              $file =~ s/^%# BEGIN BPS TAGGED BLOCK {{{(.*?)%# END BPS TAGGED BLOCK }}}/%# BEGIN BPS TAGGED BLOCK {{{\n$pmlic\n%# END BPS TAGGED BLOCK }}}/ms;
128
129
130         } else {
131                 print "no license section";
132              $file ="%# BEGIN BPS TAGGED BLOCK {{{\n$pmlic\n%# END BPS TAGGED BLOCK }}}\n". $file;
133         }
134         $file =~ s/%# END BPS TAGGED BLOCK }}}(\n+)/%# END BPS TAGGED BLOCK }}}\n/mg;
135         print "\n";
136
137
138
139
140         open( FILE, '>', $pm ) or die "couldn't write new file";
141         print FILE $file;
142         close FILE;
143
144 }
145
146
147 sub tag_makefile {
148         my $pm = shift;
149         open( FILE, '<', $pm ) or die "Failed to open $pm";
150         my $file = (join "", <FILE>);
151         close (FILE);
152         print "$pm - ";
153         return if another_license($pm => $file) && print "has different license\n";
154
155         my $pmlic = $LICENSE;
156         $pmlic =~ s/^/# /mg;
157         $pmlic =~ s/\s*$//mg;
158         if ($file =~ /^# BEGIN BPS TAGGED BLOCK {{{/ms) {
159                 print "has license section";
160              $file =~ s/^# BEGIN BPS TAGGED BLOCK {{{(.*?)# END BPS TAGGED BLOCK }}}/# BEGIN BPS TAGGED BLOCK {{{\n$pmlic\n# END BPS TAGGED BLOCK }}}/ms;
161
162
163         } else {
164                 print "no license section";
165              $file ="# BEGIN BPS TAGGED BLOCK {{{\n$pmlic\n# END BPS TAGGED BLOCK }}}\n". $file;
166         }
167         $file =~ s/# END BPS TAGGED BLOCK }}}(\n+)/# END BPS TAGGED BLOCK }}}\n/mg;
168         print "\n";
169
170
171
172
173         open( FILE, '>', $pm ) or die "couldn't write new file";
174         print FILE $file;
175         close FILE;
176
177 }
178
179
180 sub tag_pm {
181         my $pm = $_;
182         next unless $pm =~ /\.pm/s;
183         open( FILE, '<', $pm ) or die "Failed to open $pm";
184         my $file = (join "", <FILE>);
185         close (FILE);
186         print "$pm - ";
187         return if another_license($pm => $file) && print "has different license\n";
188
189         my $pmlic = $LICENSE;
190         $pmlic =~ s/^/# /mg;
191         $pmlic =~ s/\s*$//mg;
192         if ($file =~ /^# BEGIN BPS TAGGED BLOCK {{{/ms) {
193                 print "has license section";
194              $file =~ s/^# BEGIN BPS TAGGED BLOCK {{{(.*?)# END BPS TAGGED BLOCK }}}/# BEGIN BPS TAGGED BLOCK {{{\n$pmlic\n# END BPS TAGGED BLOCK }}}/ms;
195
196
197         } else {
198                 print "no license section";
199              $file ="# BEGIN BPS TAGGED BLOCK {{{\n$pmlic\n# END BPS TAGGED BLOCK }}}\n". $file;
200         }
201         $file =~ s/# END BPS TAGGED BLOCK }}}(\n+)/# END BPS TAGGED BLOCK }}}\n\n/mg;
202         print "\n";
203
204
205
206
207         open( FILE, '>', $pm ) or die "couldn't write new file $pm";
208         print FILE $file;
209         close FILE;
210
211 }
212
213
214 sub tag_script {
215         my $pm = $_;
216         return unless (-f $pm);
217         open( FILE, '<', $pm ) or die "Failed to open $pm";
218         my $file = (join "", <FILE>);
219         close (FILE);
220         print "$pm - ";
221         return if another_license($pm => $file) && print "has different license\n";
222
223         my $pmlic = $LICENSE;
224         $pmlic =~ s/^/# /msg;
225         $pmlic =~ s/\s*$//mg;
226         if ($file =~ /^# BEGIN BPS TAGGED BLOCK {{{/ms) {
227                 print "has license section";
228              $file =~ s/^# BEGIN BPS TAGGED BLOCK {{{(.*?)# END BPS TAGGED BLOCK }}}/# BEGIN BPS TAGGED BLOCK {{{\n$pmlic\n# END BPS TAGGED BLOCK }}}/ms;
229
230
231         } else {
232                 print "no license section";
233                 if ($file =~ /^(#!.*?)\n/) {
234
235             my  $lic ="# BEGIN BPS TAGGED BLOCK {{{\n$pmlic\n# END BPS TAGGED BLOCK }}}\n";
236                 $file =~ s/^(#!.*?)\n/$1\n$lic/;
237
238                 }
239         }
240         $file =~ s/# END BPS TAGGED BLOCK }}}(\n+)/# END BPS TAGGED BLOCK }}}\n/mg;
241         print "\n";
242
243
244         open( FILE, '>', $pm ) or die "couldn't write new file";
245         print FILE $file;
246         close FILE;
247
248 }
249
250 sub another_license {
251     my $name = shift;
252     my $file = shift;
253
254     return 1 if ($name =~ /(?:FCKEditor|scriptaculous)/i);
255
256     return 0 if $file =~ /Copyright\s+\(c\)\s+\d\d\d\d-\d\d\d\d Best Practical Solutions/i;
257     return 1 if $file =~ /\b(copyright|GPL|Public Domain)\b/i; # common
258     return 1 if $file =~ /\(c\)\s+\d\d\d\d(?:-\d\d\d\d)?/i; # prototype
259     return 0;
260 }
261