diff options
author | Marc Weber <marco-oweber@gmx.de> | 2007-11-14 19:07:38 +0000 |
---|---|---|
committer | Marc Weber <marco-oweber@gmx.de> | 2007-11-14 19:07:38 +0000 |
commit | a89817cba8abb891de2e07cfee41e47a42604b70 (patch) | |
tree | 3a573052de2c6311db9ce65df8360cea0f696dd3 /pkgs/tools/misc/shebangfix | |
parent | 076cc3a7d8f68d4e612f042b8241a24cff5f37ee (diff) | |
download | nixlib-a89817cba8abb891de2e07cfee41e47a42604b70.tar nixlib-a89817cba8abb891de2e07cfee41e47a42604b70.tar.gz nixlib-a89817cba8abb891de2e07cfee41e47a42604b70.tar.bz2 nixlib-a89817cba8abb891de2e07cfee41e47a42604b70.tar.lz nixlib-a89817cba8abb891de2e07cfee41e47a42604b70.tar.xz nixlib-a89817cba8abb891de2e07cfee41e47a42604b70.tar.zst nixlib-a89817cba8abb891de2e07cfee41e47a42604b70.zip |
added small script fixing the shebang (#!/bin/...) path.
It searches the PATH env variable for the same executable. svn path=/nixpkgs/trunk/; revision=9667
Diffstat (limited to 'pkgs/tools/misc/shebangfix')
-rw-r--r-- | pkgs/tools/misc/shebangfix/default.nix | 20 | ||||
-rw-r--r-- | pkgs/tools/misc/shebangfix/shebangfix.pl | 35 |
2 files changed, 55 insertions, 0 deletions
diff --git a/pkgs/tools/misc/shebangfix/default.nix b/pkgs/tools/misc/shebangfix/default.nix new file mode 100644 index 000000000000..94ecc1e00f7b --- /dev/null +++ b/pkgs/tools/misc/shebangfix/default.nix @@ -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 "; }; +} diff --git a/pkgs/tools/misc/shebangfix/shebangfix.pl b/pkgs/tools/misc/shebangfix/shebangfix.pl new file mode 100644 index 000000000000..53573f8d36dd --- /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); +} |