mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-25 00:12:56 +00:00
added small script fixing the shebang (#!/bin/...) path.
It searches the PATH env variable for the same executable. svn path=/nixpkgs/trunk/; revision=9667
This commit is contained in:
parent
076cc3a7d8
commit
a89817cba8
20
pkgs/tools/misc/shebangfix/default.nix
Normal file
20
pkgs/tools/misc/shebangfix/default.nix
Normal file
@ -0,0 +1,20 @@
|
||||
args:
|
||||
args.stdenv.mkDerivation {
|
||||
name = "shebangfix-0.0";
|
||||
|
||||
buildInputs = [args.perl];
|
||||
|
||||
file = ./shebangfix.pl;
|
||||
|
||||
phases = "buildPhase";
|
||||
|
||||
buildPhase = "
|
||||
ensureDir \$out/bin
|
||||
s=\$out/bin/shebangfix
|
||||
cp \$file \$s
|
||||
chmod +x \$s
|
||||
perl \$s \$s
|
||||
";
|
||||
|
||||
meta = { description = "replaces the #!executable with $#!correctpath/executable "; };
|
||||
}
|
35
pkgs/tools/misc/shebangfix/shebangfix.pl
Normal file
35
pkgs/tools/misc/shebangfix/shebangfix.pl
Normal file
@ -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);
|
||||
}
|
@ -659,6 +659,11 @@ rec {
|
||||
inherit fetchurl stdenv ncurses;
|
||||
};
|
||||
|
||||
shebangfix = import ../tools/misc/shebangfix {
|
||||
inherit perl;
|
||||
stdenv = overrideSetup stdenv ../stdenv/generic/setup-new-2.sh;
|
||||
};
|
||||
|
||||
smartmontools = import ../tools/system/smartmontools {
|
||||
inherit fetchurl stdenv;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user