import rt 3.6.4
[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-2007 Best Practical Solutions, LLC 
9 #                                          <jesse@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/copyleft/gpl.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-2007 Best Practical Solutions, LLC 
56                                          <jesse@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/copyleft/gpl.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}, 'html');
105 File::Find::find({ no_chdir => 1, wanted => \&tag_script}, 'sbin');
106 File::Find::find({ no_chdir => 1, wanted => \&tag_script}, 'bin');
107 tag_makefile ('Makefile.in');
108 tag_makefile ('README');
109
110
111 sub tag_mason {
112         my $pm = $_;
113         next unless (-f $pm);
114         next if ($pm =~ /images/);
115         open(FILE,"<$pm") || die "Failed to open $pm";
116         my $file = (join "", <FILE>); 
117         close (FILE);
118         my $pmlic = $LICENSE;
119         $pmlic =~ s/^/%# /mg;
120
121
122         print "$pm - ";
123         if ($file =~ /^%# BEGIN BPS TAGGED BLOCK {{{/ms) {
124                 print "has license section";
125              $file =~ s/^%# BEGIN BPS TAGGED BLOCK {{{(.*?)%# END BPS TAGGED BLOCK }}}/%# BEGIN BPS TAGGED BLOCK {{{\n$pmlic%# END BPS TAGGED BLOCK }}}/ms;
126              
127
128         } else {
129                 print "no license section";
130              $file ="%# BEGIN BPS TAGGED BLOCK {{{\n$pmlic%# END BPS TAGGED BLOCK }}}\n". $file;
131         }
132         $file =~ s/%# END BPS TAGGED BLOCK }}}(\n+)/%# END BPS TAGGED BLOCK }}}\n/mg;
133         print "\n";
134         
135         
136
137
138         open (FILE, ">$pm") || die "couldn't write new file";
139         print FILE $file;
140         close FILE;
141
142 }
143
144
145 sub tag_makefile {
146         my $pm = shift;
147         open(FILE,"<$pm") || die "Failed to open $pm";
148         my $file = (join "", <FILE>); 
149         close (FILE);
150         my $pmlic = $LICENSE;
151         $pmlic =~ s/^/# /mg;
152
153
154         print "$pm - ";
155         if ($file =~ /^# BEGIN BPS TAGGED BLOCK {{{/ms) {
156                 print "has license section";
157              $file =~ s/^# BEGIN BPS TAGGED BLOCK {{{(.*?)# END BPS TAGGED BLOCK }}}/# BEGIN BPS TAGGED BLOCK {{{\n$pmlic# END BPS TAGGED BLOCK }}}/ms;
158              
159
160         } else {
161                 print "no license section";
162              $file ="# BEGIN BPS TAGGED BLOCK {{{\n$pmlic# END BPS TAGGED BLOCK }}}\n". $file;
163         }
164         $file =~ s/# END BPS TAGGED BLOCK }}}(\n+)/# END BPS TAGGED BLOCK }}}\n/mg;
165         print "\n";
166         
167         
168
169
170         open (FILE, ">$pm") || die "couldn't write new file";
171         print FILE $file;
172         close FILE;
173
174 }
175
176
177 sub tag_pm {
178         my $pm = $_;
179         next unless $pm =~ /\.pm/s;
180         open(FILE,"<$pm") || die "Failed to open $pm";
181         my $file = (join "", <FILE>); 
182         close (FILE);
183         my $pmlic = $LICENSE;
184         $pmlic =~ s/^/# /mg;
185
186
187         print "$pm - ";
188         if ($file =~ /^# BEGIN BPS TAGGED BLOCK {{{/ms) {
189                 print "has license section";
190              $file =~ s/^# BEGIN BPS TAGGED BLOCK {{{(.*?)# END BPS TAGGED BLOCK }}}/# BEGIN BPS TAGGED BLOCK {{{\n$pmlic# END BPS TAGGED BLOCK }}}/ms;
191              
192
193         } else {
194                 print "no license section";
195              $file ="# BEGIN BPS TAGGED BLOCK {{{\n$pmlic# END BPS TAGGED BLOCK }}}\n". $file;
196         }
197         $file =~ s/# END BPS TAGGED BLOCK }}}(\n+)/# END BPS TAGGED BLOCK }}}\n/mg;
198         print "\n";
199         
200         
201
202
203         open (FILE, ">$pm") || die "couldn't write new file $pm";
204         print FILE $file;
205         close FILE;
206
207 }
208
209
210 sub tag_script {
211         my $pm = $_;
212         return unless (-f $pm);
213         open(FILE,"<$pm") || die "Failed to open $pm";
214         my $file = (join "", <FILE>); 
215         close (FILE);
216         my $pmlic = $LICENSE;
217         $pmlic =~ s/^/# /msg;
218
219         print "$pm - ";
220         if ($file =~ /^# BEGIN BPS TAGGED BLOCK {{{/ms) {
221                 print "has license section";
222              $file =~ s/^# BEGIN BPS TAGGED BLOCK {{{(.*?)# END BPS TAGGED BLOCK }}}/# BEGIN BPS TAGGED BLOCK {{{\n$pmlic# END BPS TAGGED BLOCK }}}/ms;
223              
224
225         } else {
226                 print "no license section";
227                 if ($file =~ /^(#!.*?)\n/) {
228
229             my  $lic ="# BEGIN BPS TAGGED BLOCK {{{\n$pmlic# END BPS TAGGED BLOCK }}}\n";
230                 $file =~ s/^(#!.*?)\n/$1\n$lic/; 
231
232                 } 
233         }
234         $file =~ s/# END BPS TAGGED BLOCK }}}(\n+)/# END BPS TAGGED BLOCK }}}\n/mg;
235         print "\n";
236         
237
238         open (FILE, ">$pm") || die "couldn't write new file";
239         print FILE $file;
240         close FILE;
241
242 }
243