diff options
Diffstat (limited to 'pkgs/tools/misc/shebangfix/shebangfix.pl')
-rw-r--r-- | pkgs/tools/misc/shebangfix/shebangfix.pl | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/pkgs/tools/misc/shebangfix/shebangfix.pl b/pkgs/tools/misc/shebangfix/shebangfix.pl new file mode 100644 index 00000000000..53573f8d36d --- /dev/null +++ b/pkgs/tools/misc/shebangfix/shebangfix.pl @@ -0,0 +1,35 @@ +#!/bin/perl +use warnings; +use strict; + +#usage PATH=< : separated path list> perl <this script> file1 file2 + +print "TODO fix space trouble. This script won't work if your paths contain spaces"; + +sub findInPath{ + my $file = shift(@_); + foreach (split(/:/, $ENV{'PATH'})){ + my $f = "$_/$file"; + if (-x "$f"){ + return $f; + } + } + print "unable to find $file in on of ".$ENV{'PATH'}; + exit 1 +} + +foreach (@ARGV) +{ + my $file = $_; + open(FILE, $file); + my $content = do { local $/; <FILE> }; + + close(FILE); + + (my $name = $content) =~ /^#![^ ]*\/([^ \n\r]*)/; + my $fullpath = ($1 eq 'sh') ? "/bin/sh" : findInPath($1); + $content =~ s/^#![^ \n\r]*/#!$fullpath/; + open(FILE, ">$file"); + print FILE $content; + close($file); +} |