Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / rt / devel / tools / cmd-boilerplate
1 #!/usr/bin/env perl
2
3
4 # BEGIN BPS TAGGED BLOCK {{{
5 #
6 # COPYRIGHT:
7 #
8 # This software is Copyright (c) 1996-2015 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 use strict;
52 use warnings;
53 use File::Find;
54
55 File::Find::find({ no_chdir => 1, wanted => \&tag_it}, 'sbin', 'bin');
56
57 sub tag_it {
58         my $file = $_;
59         return unless (-f $file);
60         return if $file !~ /.in$/;
61         open( FILE, '<', $file ) or die "Failed to open $file";
62         my $content = (join "", <FILE>);
63         close (FILE);
64         my $new = q'BEGIN { # BEGIN RT CMD BOILERPLATE
65     require File::Spec;
66     require Cwd;
67     my @libs = ("@RT_LIB_PATH@", "@LOCAL_LIB_PATH@");
68     my $bin_path;
69
70     for my $lib (@libs) {
71         unless ( File::Spec->file_name_is_absolute($lib) ) {
72             $bin_path ||= ( File::Spec->splitpath(Cwd::abs_path(__FILE__)) )[1];
73             $lib = File::Spec->catfile( $bin_path, File::Spec->updir, $lib );
74         }
75         unshift @INC, $lib;
76     }
77
78 }';
79         unless ($content =~ s/^BEGIN \{ # BEGIN RT CMD BOILERPLATE.*?^\}$/$new/ms) {
80             return;
81         }
82
83         warn $file;
84  
85         open( FILE, '>', $file ) or die "couldn't write new file";
86         print FILE $content;
87         close FILE;
88
89 }