summary refs log tree commit diff
path: root/pkgs/tools
diff options
context:
space:
mode:
authorMarc Weber <marco-oweber@gmx.de>2007-11-14 19:07:38 +0000
committerMarc Weber <marco-oweber@gmx.de>2007-11-14 19:07:38 +0000
commita89817cba8abb891de2e07cfee41e47a42604b70 (patch)
tree3a573052de2c6311db9ce65df8360cea0f696dd3 /pkgs/tools
parent076cc3a7d8f68d4e612f042b8241a24cff5f37ee (diff)
downloadnixpkgs-a89817cba8abb891de2e07cfee41e47a42604b70.tar
nixpkgs-a89817cba8abb891de2e07cfee41e47a42604b70.tar.gz
nixpkgs-a89817cba8abb891de2e07cfee41e47a42604b70.tar.bz2
nixpkgs-a89817cba8abb891de2e07cfee41e47a42604b70.tar.lz
nixpkgs-a89817cba8abb891de2e07cfee41e47a42604b70.tar.xz
nixpkgs-a89817cba8abb891de2e07cfee41e47a42604b70.tar.zst
nixpkgs-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')
-rw-r--r--pkgs/tools/misc/shebangfix/default.nix20
-rw-r--r--pkgs/tools/misc/shebangfix/shebangfix.pl35
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 00000000000..94ecc1e00f7
--- /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 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);
+}