From 0bd5eb71a0a23b27a02af591ba46e4cf2c34aa04 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 21 Sep 2006 18:54:08 +0000 Subject: * `nix-install-package --url': install from a URL (NIX-12). * `nix-install-package --help' (NIX-9). * `nix-install-package --non-interactive': don't prompt or pause. * Tests for nix-install-package. * Security fixes: filter the values obtained from the nixpkg. --- scripts/nix-install-package.in | 124 ++++++++++++++++++++++++++++++++++------- 1 file changed, 105 insertions(+), 19 deletions(-) (limited to 'scripts/nix-install-package.in') diff --git a/scripts/nix-install-package.in b/scripts/nix-install-package.in index 7959070c0a66..4f5b0087fee3 100644 --- a/scripts/nix-install-package.in +++ b/scripts/nix-install-package.in @@ -3,28 +3,107 @@ use strict; use POSIX qw(tmpnam); -my $pkgFile = $ARGV[0]; -die unless defined $pkgFile; + +sub usageError { + print STDERR < if $interactive; + exit 1; +} + + +# Download the package description, if necessary. +my $pkgFile = $source; +if ($fromURL) { + $pkgFile = "$tmpDir/tmp.nixpkg"; + system ("@curl@", "--silent", $source, "-o", $pkgFile) == 0 + or barf "curl failed: $?"; +} + + # Read and parse the package file. -open PKGFILE, "<$pkgFile" or die "cannot open `$pkgFile': $!"; +open PKGFILE, "<$pkgFile" or barf "cannot open `$pkgFile': $!"; my $contents = ; close PKGFILE; -$contents =~ /^\s*(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/ or die "invalid package contents"; +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"; my $version = $1; my $manifestURL = $2; my $drvName = $3; @@ -32,22 +111,29 @@ my $system = $4; my $drvPath = $5; my $outPath = $6; -die "invalid package version `$version'" unless $version eq "NIXPKG1"; +barf "invalid package version `$version'" unless $version eq "NIXPKG1"; -# Ask confirmation. -print "Do you want to install `$drvName' (Y/N)? "; -my $reply = ; -chomp $reply; -exit if $reply ne "y" && $reply ne "Y"; +if ($interactive) { + # Ask confirmation. + print "Do you want to install `$drvName' (Y/N)? "; + my $reply = ; + chomp $reply; + exit if $reply ne "y" && $reply ne "Y"; +} + print "\nPulling manifests...\n"; -system "@bindir@/nix-pull '$manifestURL'"; -die if $? != 0; +system ("@bindir@/nix-pull", $manifestURL) == 0 + or barf "nix-pull failed: $?"; + print "\nInstalling package...\n"; -system "@bindir@/nix-env -i '$outPath'"; -die if $? != 0; +system ("@bindir@/nix-env", "--install", $outPath, @extraNixEnvArgs) == 0 + or barf "nix-env failed: $?"; + -print "\nInstallation succeeded! Press Enter to continue.\n"; -; +if ($interactive) { + print "\nInstallation succeeded! Press Enter to continue.\n"; + ; +} -- cgit 1.4.1