From a89817cba8abb891de2e07cfee41e47a42604b70 Mon Sep 17 00:00:00 2001 From: Marc Weber Date: Wed, 14 Nov 2007 19:07:38 +0000 Subject: [PATCH] added small script fixing the shebang (#!/bin/...) path. It searches the PATH env variable for the same executable. svn path=/nixpkgs/trunk/; revision=9667 --- pkgs/tools/misc/shebangfix/default.nix | 20 ++++++++++++++ pkgs/tools/misc/shebangfix/shebangfix.pl | 35 ++++++++++++++++++++++++ pkgs/top-level/all-packages.nix | 5 ++++ 3 files changed, 60 insertions(+) create mode 100644 pkgs/tools/misc/shebangfix/default.nix create mode 100644 pkgs/tools/misc/shebangfix/shebangfix.pl 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 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 $/; }; + + 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); +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index eb747131bab1..dc848898bcf9 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -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; };