X-Git-Url: http://git.rot13.org/?p=koha.git;a=blobdiff_plain;f=fix-perl-path.PL;h=f81084015b762108ee8619a89534fd01a780b9e8;hp=dbe74037173549be47d9c6ffe0cc947ad2a83bae;hb=HEAD;hpb=7fcfc09669cb326b71f7faa2e1d012ff6690b640 diff --git a/fix-perl-path.PL b/fix-perl-path.PL index dbe7403717..f81084015b 100644 --- a/fix-perl-path.PL +++ b/fix-perl-path.PL @@ -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 since Win32 does not care and *nix does... -my $shebang = "#!$bindir\/perl -w"; +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; @@ -65,39 +65,49 @@ sub fixshebang{ 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;