X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=fix-perl-path.PL;h=f81084015b762108ee8619a89534fd01a780b9e8;hb=3952c2028974d1e589b2d37d3a07aa38bc28a9c9;hp=222ff8d34f1afc083bb4abbb7e4fd92ca861c777;hpb=b310be2bab507630cbb4ea5d48fb9c6f0963fd64;p=koha.git diff --git a/fix-perl-path.PL b/fix-perl-path.PL index 222ff8d34f..f81084015b 100644 --- a/fix-perl-path.PL +++ b/fix-perl-path.PL @@ -1,4 +1,4 @@ -#!c:\strawberry-perl\perl\bin\perl +#!/usr/bin/perl # This file is part of Koha. # # Koha is free software; you can redistribute it and/or modify it under the @@ -20,13 +20,13 @@ use ExtUtils::MakeMaker::Config; use Tie::File; my $basedir = (shift); -my $DEBUG = 1; +my $DEBUG = exists $ENV{'DEBUG'} ? $ENV{'DEBUG'} : 0; $DEBUG = 1 if $basedir eq 'test'; my $bindir = $Config{installbin}; -$bindir =~ s!\\!/!g; # make all directory separators uniform... -my $shebang = "#!$bindir\/perl -w"; +$bindir =~ s!\\!/!g; # make all directory separators uniform since Win32 does not care and *nix does... +my $shebang = "#!$bindir\/perl"; warn "Perl binary located in $bindir on this system.\n" if $DEBUG; warn "The shebang line for this sytems should be $shebang\n\n" if $DEBUG; @@ -60,45 +60,54 @@ in a manner similar to 'fixshebang (foodir)' but may be supplied with any direct =cut sub fixshebang{ - # NOTE: this might be dressed up a bit with File::Spec since we're using it here already. my $dir = shift; opendir my $dh, $dir or die $!; warn "Reading $dir contents.\n" if $DEBUG; while( my $file = readdir($dh) ) { # this may be used to exclude any desired files from the scan - if ( $file =~ /shebang|wixgen/ ) { next; } + # if ( $file =~ /foo/ ) { next; } # handle files... other extensions could be substituted/added if needed if ( $file =~ /\.pl$/ ) { my @filearray; my $pathfile =$dir . '/' . $file; warn "Found a perl script named $pathfile\n" if $DEBUG; - tie @filearray, 'Tie::File', $pathfile or die $!; - print "First line of $file is $filearray[0]\n\n"; - if ( ( $filearray[0] =~ /#!.*perl/ ) && ( $filearray[0] !~ /$shebang/ ) ) { + + # At this point, file is in 'blib' and by default + # has mode a-w. Therefore, must change permission + # to make it writable. Note that stat and chmod + # (the Perl functions) should work on Win32 + my $old_perm; + $old_perm = (stat $pathfile)[2] & 07777; + my $new_perm = $old_perm | 0200; + chmod $new_perm, $pathfile; + + # tie the file -- note that we're explicitly setting the line (record) + # separator to hex 0A (the Unix newline) because that's what + # the files copied to blib are using, regardless of whether the install + # is under a Unix variant or Windows. + tie @filearray, 'Tie::File', $pathfile, recsep => "\x0a" or die $!; + + warn "First line of $file is $filearray[0]\n\n" if $DEBUG; + if ( ( $filearray[0] =~ /#!.*perl/ ) && ( $filearray[0] !~ /$shebang|"$shebang -w"/ ) ) { warn "\n\tRe-writing shebang line for $pathfile\n" if $DEBUG; warn "\tOriginal shebang line: $filearray[0]\n" if $DEBUG; - $filearray[0] = $shebang; + $filearray[0] =~ /-w$/ ? $filearray[0] = "$shebang -w" : $filearray[0] = $shebang; warn "\tNew shebang line is: $filearray[0]\n\n" if $DEBUG; - untie @filearray; - next; } - elsif ( $filearray[0] =~ /$shebang/ ) { + elsif ( $filearray[0] =~ /$shebang|"$shebang -w"/ ) { warn "\n\tShebang line is correct.\n\n" if $DEBUG; - untie @filearray; - next; } else { warn "\n\tNo shebang line found in $pathfile\n\n" if $DEBUG; - untie @filearray; - next; } + untie @filearray; + chmod $old_perm, $pathfile; } # handle directories elsif ( -d ($dir . '/' . $file) && $file !~ /^\.{1,2}/ ) { my $dirpath = $dir . '/' . $file; warn "Found a subdir named $dirpath\n" if $DEBUG; fixshebang ($dirpath); -# closedir $dh; # I'm not really sure if this is necessary } } closedir $dh; @@ -106,4 +115,3 @@ sub fixshebang{ fixshebang ($basedir); -