Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 118 lines (95 sloc) 4.312 kb
a0b06fb @ctfliblime Prepare for perlbrew usage by changing all script magic to "#!/usr/bi…
ctfliblime authored
1 #!/usr/bin/env perl
b310be2 Win32 support: Adding a script to modify shebang lines per installati…
Chris Nighswonger authored
2 # This file is part of Koha.
3 #
4 # Koha is free software; you can redistribute it and/or modify it under the
5 # terms of the GNU General Public License as published by the Free Software
6 # Foundation; either version 2 of the License, or (at your option) any later
7 # version.
8 #
9 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
10 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License along with
14 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
15 # Suite 330, Boston, MA 02111-1307 USA
16 #
17
18 use strict;
19 use ExtUtils::MakeMaker::Config;
20 use Tie::File;
21
22 my $basedir = (shift);
06fb84f installer: made $DEBUG in fix-perl-path.pl contigent on DEBUG env var
Galen Charlton authored
23 my $DEBUG = exists $ENV{'DEBUG'} ? $ENV{'DEBUG'} : 0;
b310be2 Win32 support: Adding a script to modify shebang lines per installati…
Chris Nighswonger authored
24
25 $DEBUG = 1 if $basedir eq 'test';
26
27 my $bindir = $Config{installbin};
7fcfc09 Win32 support: Stripped ^M line endings and various other housekeeping.
Chris Nighswonger authored
28 $bindir =~ s!\\!/!g; # make all directory separators uniform since Win32 does not care and *nix does...
ffea1e0 Win32 support: Added differentiation between -w perl switch in sheban…
Chris Nighswonger authored
29 my $shebang = "#!$bindir\/perl";
b310be2 Win32 support: Adding a script to modify shebang lines per installati…
Chris Nighswonger authored
30
31 warn "Perl binary located in $bindir on this system.\n" if $DEBUG;
32 warn "The shebang line for this sytems should be $shebang\n\n" if $DEBUG;
33
34 die if $basedir eq 'test';
35
36 =head1 NAME
37
38 fix-perl-path.PL - A script to correct the shebang line to match the current platform
39
40 =head1 SYNOPSIS
41
42 =head2 BASIC USAGE
43
44 perl fix-perl-path.PL /absolute/path/to/foo
45
46 =head1 DESCRIPTION
47
48 This script should be run from the base of the directory
49 structure which contains the file(s) that need the
50 shebang line corrected. It will recurse through all
51 directories below the one called from and modify all
52 .pl files.
53
54 =head2 fixshebang
55
56 This sub will recurse through a given directory and its subdirectories checking for the existence of a shebang
57 line in .pl files and replacing it with the correct line for the current OS if needed. It should be called
58 in a manner similar to 'fixshebang (foodir)' but may be supplied with any directory.
59
60 =cut
61
62 sub fixshebang{
63 my $dir = shift;
64 opendir my $dh, $dir or die $!;
65 warn "Reading $dir contents.\n" if $DEBUG;
66 while( my $file = readdir($dh) ) {
67 # this may be used to exclude any desired files from the scan
ffea1e0 Win32 support: Added differentiation between -w perl switch in sheban…
Chris Nighswonger authored
68 # if ( $file =~ /foo/ ) { next; }
b310be2 Win32 support: Adding a script to modify shebang lines per installati…
Chris Nighswonger authored
69 # handle files... other extensions could be substituted/added if needed
70 if ( $file =~ /\.pl$/ ) {
71 my @filearray;
72 my $pathfile =$dir . '/' . $file;
73 warn "Found a perl script named $pathfile\n" if $DEBUG;
5b98031 installer: deal with permissions in fix-perl-path.PL
Galen Charlton authored
74
75 # At this point, file is in 'blib' and by default
76 # has mode a-w. Therefore, must change permission
abf5820 installer: improvements to fix-path-perl.PL on Win32
Galen Charlton authored
77 # to make it writable. Note that stat and chmod
78 # (the Perl functions) should work on Win32
5b98031 installer: deal with permissions in fix-perl-path.PL
Galen Charlton authored
79 my $old_perm;
abf5820 installer: improvements to fix-path-perl.PL on Win32
Galen Charlton authored
80 $old_perm = (stat $pathfile)[2] & 07777;
81 my $new_perm = $old_perm | 0200;
82 chmod $new_perm, $pathfile;
83
84 # tie the file -- note that we're explicitly setting the line (record)
85 # separator to hex 0A (the Unix newline) because that's what
86 # the files copied to blib are using, regardless of whether the install
87 # is under a Unix variant or Windows.
88 tie @filearray, 'Tie::File', $pathfile, recsep => "\x0a" or die $!;
89
42c9423 Win32 support: Switch DEBUG off and corrected warning bug.
Chris Nighswonger authored
90 warn "First line of $file is $filearray[0]\n\n" if $DEBUG;
ffea1e0 Win32 support: Added differentiation between -w perl switch in sheban…
Chris Nighswonger authored
91 if ( ( $filearray[0] =~ /#!.*perl/ ) && ( $filearray[0] !~ /$shebang|"$shebang -w"/ ) ) {
b310be2 Win32 support: Adding a script to modify shebang lines per installati…
Chris Nighswonger authored
92 warn "\n\tRe-writing shebang line for $pathfile\n" if $DEBUG;
93 warn "\tOriginal shebang line: $filearray[0]\n" if $DEBUG;
ffea1e0 Win32 support: Added differentiation between -w perl switch in sheban…
Chris Nighswonger authored
94 $filearray[0] =~ /-w$/ ? $filearray[0] = "$shebang -w" : $filearray[0] = $shebang;
b310be2 Win32 support: Adding a script to modify shebang lines per installati…
Chris Nighswonger authored
95 warn "\tNew shebang line is: $filearray[0]\n\n" if $DEBUG;
96 }
ffea1e0 Win32 support: Added differentiation between -w perl switch in sheban…
Chris Nighswonger authored
97 elsif ( $filearray[0] =~ /$shebang|"$shebang -w"/ ) {
b310be2 Win32 support: Adding a script to modify shebang lines per installati…
Chris Nighswonger authored
98 warn "\n\tShebang line is correct.\n\n" if $DEBUG;
99 }
100 else {
101 warn "\n\tNo shebang line found in $pathfile\n\n" if $DEBUG;
102 }
5b98031 installer: deal with permissions in fix-perl-path.PL
Galen Charlton authored
103 untie @filearray;
abf5820 installer: improvements to fix-path-perl.PL on Win32
Galen Charlton authored
104 chmod $old_perm, $pathfile;
b310be2 Win32 support: Adding a script to modify shebang lines per installati…
Chris Nighswonger authored
105 }
106 # handle directories
107 elsif ( -d ($dir . '/' . $file) && $file !~ /^\.{1,2}/ ) {
108 my $dirpath = $dir . '/' . $file;
109 warn "Found a subdir named $dirpath\n" if $DEBUG;
110 fixshebang ($dirpath);
111 }
112 }
113 closedir $dh;
114 }
115
116 fixshebang ($basedir);
117
Something went wrong with that request. Please try again.