2004-03-15 17:23:53 +02:00
|
|
|
#! @perl@ -w
|
2003-11-24 13:11:40 +02:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use POSIX qw(tmpnam);
|
|
|
|
|
2006-09-21 21:54:08 +03:00
|
|
|
|
|
|
|
sub usageError {
|
|
|
|
print STDERR <<EOF;
|
|
|
|
Usage: nix-install-package (FILE | --url URL)
|
|
|
|
|
|
|
|
Install a Nix Package (.nixpkg) either directly from FILE or by
|
|
|
|
downloading it from URL.
|
|
|
|
|
|
|
|
Flags:
|
|
|
|
--profile / -p LINK: install into the specified profile
|
|
|
|
--non-interactive: don't run inside a new terminal XXX
|
|
|
|
EOF
|
|
|
|
; # '
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Parse the command line arguments.
|
|
|
|
my @args = @ARGV;
|
|
|
|
usageError if scalar @args == 0;
|
|
|
|
|
|
|
|
my $source;
|
|
|
|
my $fromURL = 0;
|
|
|
|
my @extraNixEnvArgs = ();
|
|
|
|
my $interactive = 1;
|
|
|
|
|
|
|
|
while (scalar @args) {
|
|
|
|
my $arg = shift @args;
|
|
|
|
if ($arg eq "--help") {
|
|
|
|
usageError;
|
|
|
|
}
|
|
|
|
elsif ($arg eq "--url") {
|
|
|
|
$fromURL = 1;
|
|
|
|
}
|
|
|
|
elsif ($arg eq "--profile" || $arg eq "-p") {
|
|
|
|
my $profile = shift @args;
|
|
|
|
usageError if !defined $profile;
|
|
|
|
push @extraNixEnvArgs, "-p", $profile;
|
|
|
|
}
|
|
|
|
elsif ($arg eq "--non-interactive") {
|
|
|
|
$interactive = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$source = $arg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
usageError unless defined $source;
|
2003-11-24 13:11:40 +02:00
|
|
|
|
|
|
|
|
2005-02-25 17:42:52 +02:00
|
|
|
# Re-execute in a terminal, if necessary, so that if we're executed
|
|
|
|
# from a web browser, the user gets to see us.
|
2006-09-21 21:54:08 +03:00
|
|
|
if ($interactive && !defined $ENV{"NIX_HAVE_TERMINAL"}) {
|
2005-02-25 17:42:52 +02:00
|
|
|
$ENV{"NIX_HAVE_TERMINAL"} = "1";
|
2005-03-11 17:27:37 +02:00
|
|
|
$ENV{"LD_LIBRARY_PATH"} = "";
|
2006-09-21 21:54:08 +03:00
|
|
|
foreach my $term ("xterm", "konsole", "gnome-terminal", "xterm") {
|
|
|
|
exec($term, "-e", "@bindir@/nix-install-package", @ARGV);
|
2006-09-21 14:29:14 +03:00
|
|
|
}
|
2005-02-25 17:42:52 +02:00
|
|
|
die "cannot execute `xterm'";
|
|
|
|
}
|
2003-11-24 13:11:40 +02:00
|
|
|
|
|
|
|
|
2006-09-21 21:54:08 +03:00
|
|
|
my $tmpDir;
|
|
|
|
do { $tmpDir = tmpnam(); }
|
|
|
|
until mkdir $tmpDir, 0777;
|
2006-09-25 13:44:27 +03:00
|
|
|
END { if (defined $tmpDir) { my $x = $?; system("@coreutils@/rm", "-rf", $tmpDir); $? = $x; } }
|
2006-09-21 21:54:08 +03:00
|
|
|
|
|
|
|
|
|
|
|
sub barf {
|
|
|
|
my $msg = shift;
|
|
|
|
print "$msg\n";
|
|
|
|
<STDIN> if $interactive;
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Download the package description, if necessary.
|
|
|
|
my $pkgFile = $source;
|
|
|
|
if ($fromURL) {
|
|
|
|
$pkgFile = "$tmpDir/tmp.nixpkg";
|
2006-09-25 13:44:27 +03:00
|
|
|
system("@curl@", "--silent", $source, "-o", $pkgFile) == 0
|
2006-09-21 21:54:08 +03:00
|
|
|
or barf "curl failed: $?";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-25 17:42:52 +02:00
|
|
|
# Read and parse the package file.
|
2006-09-21 21:54:08 +03:00
|
|
|
open PKGFILE, "<$pkgFile" or barf "cannot open `$pkgFile': $!";
|
2005-02-25 17:42:52 +02:00
|
|
|
my $contents = <PKGFILE>;
|
|
|
|
close PKGFILE;
|
2003-11-24 13:11:40 +02:00
|
|
|
|
2006-09-21 21:54:08 +03:00
|
|
|
my $urlRE = "(?: [a-zA-Z][a-zA-Z0-9\+\-\.]*\:[a-zA-Z0-9\%\/\?\:\@\&\=\+\$\,\-\_\.\!\~\*\']+ )";
|
|
|
|
my $nameRE = "(?: [A-Za-z0-9\+\-\.\_\?\=]+ )"; # see checkStoreName()
|
|
|
|
my $systemRE = "(?: [A-Za-z0-9\+\-\_]+ )";
|
|
|
|
my $pathRE = "(?: \/ [\/A-Za-z0-9\+\-\.\_\?\=]* )";
|
|
|
|
|
|
|
|
# Note: $pathRE doesn't check that whether we're looking at a valid
|
|
|
|
# store path. We'll let nix-env do that.
|
|
|
|
|
|
|
|
$contents =~
|
|
|
|
/ ^ \s* (\S+) \s+ ($urlRE) \s+ ($nameRE) \s+ ($systemRE) \s+ ($pathRE) \s+ ($pathRE) /x
|
|
|
|
or barf "invalid package contents";
|
2005-02-25 17:42:52 +02:00
|
|
|
my $version = $1;
|
|
|
|
my $manifestURL = $2;
|
|
|
|
my $drvName = $3;
|
|
|
|
my $system = $4;
|
|
|
|
my $drvPath = $5;
|
|
|
|
my $outPath = $6;
|
|
|
|
|
2006-09-21 21:54:08 +03:00
|
|
|
barf "invalid package version `$version'" unless $version eq "NIXPKG1";
|
2005-02-25 17:42:52 +02:00
|
|
|
|
|
|
|
|
2006-09-21 21:54:08 +03:00
|
|
|
if ($interactive) {
|
|
|
|
# Ask confirmation.
|
|
|
|
print "Do you want to install `$drvName' (Y/N)? ";
|
|
|
|
my $reply = <STDIN>;
|
|
|
|
chomp $reply;
|
|
|
|
exit if $reply ne "y" && $reply ne "Y";
|
|
|
|
}
|
|
|
|
|
2003-11-24 13:11:40 +02:00
|
|
|
|
2005-02-25 17:42:52 +02:00
|
|
|
print "\nPulling manifests...\n";
|
2006-09-25 13:44:27 +03:00
|
|
|
system("@bindir@/nix-pull", $manifestURL) == 0
|
2006-09-21 21:54:08 +03:00
|
|
|
or barf "nix-pull failed: $?";
|
|
|
|
|
2003-11-24 13:11:40 +02:00
|
|
|
|
2005-02-25 17:42:52 +02:00
|
|
|
print "\nInstalling package...\n";
|
2006-09-25 17:00:59 +03:00
|
|
|
system("@bindir@/nix-env", "--install", $outPath, "--force-name", $drvName, @extraNixEnvArgs) == 0
|
2006-09-21 21:54:08 +03:00
|
|
|
or barf "nix-env failed: $?";
|
|
|
|
|
2003-11-24 13:11:40 +02:00
|
|
|
|
2006-09-21 21:54:08 +03:00
|
|
|
if ($interactive) {
|
|
|
|
print "\nInstallation succeeded! Press Enter to continue.\n";
|
|
|
|
<STDIN>;
|
|
|
|
}
|