diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2004-02-20 19:13:52 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2004-02-20 19:13:52 +0000 |
commit | 1204e10bf6cb87fa424624663421df07db02559a (patch) | |
tree | 4d1bc01934d083ad6d33ffee5a546d3cfb99c2ce | |
parent | 435c17a13e8f9d1812ab43949d16176ac349e7b5 (diff) |
PKG_DESTDIR / -B support in pkg_add.
-rw-r--r-- | usr.sbin/pkg_add/pkg_add | 43 | ||||
-rw-r--r-- | usr.sbin/pkg_add/pkg_add.1 | 20 |
2 files changed, 49 insertions, 14 deletions
diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add index acb30e0d48a..e6f22ebd56e 100644 --- a/usr.sbin/pkg_add/pkg_add +++ b/usr.sbin/pkg_add/pkg_add @@ -1,7 +1,7 @@ #! /usr/bin/perl # ex:ts=8 sw=4: -# $OpenBSD: pkg_add,v 1.26 2004/01/28 22:12:01 espie Exp $ +# $OpenBSD: pkg_add,v 1.27 2004/02/20 19:13:51 espie Exp $ # # Copyright (c) 2003 Marc Espie. # @@ -61,16 +61,17 @@ use File::Path; sub install { - my ($self, $archive, $verbose, $not) = @_; + my ($self, $archive, $destdir, $verbose, $not) = @_; my $file=$archive->next(); if ($file->{name} ne $self->{name}) { die "Error: archive does not match", $file->{name}, "!=", $self->{name}, "\n"; } - print "extracting ", $self->fullname(), "\n" if $verbose; + print "extracting ", $destdir, $self->fullname(), "\n" if $verbose; $file->{name} = $self->fullname(); $file->{cwd} = $self->{cwd}; + $file->{destdir} = $destdir; return if $not; $file->create(); if (defined $self->{owner} && defined $self->{group}) { @@ -89,7 +90,7 @@ package OpenBSD::PackingElement::Exec; sub install { - my ($self, $archive, $verbose, $not) = @_; + my ($self, $archive, $destdir, $verbose, $not) = @_; print "exec ", $self->{expanded}, "\n" if $verbose or $not; system('/bin/sh', '-c', $self->{expanded}) unless $not; @@ -120,13 +121,26 @@ package main; my $errors = 0; -our ($opt_v, $opt_n, $opt_I, $opt_f, $opt_L); -getopts('vnIL:f:'); +our ($opt_v, $opt_n, $opt_I, $opt_f, $opt_L, $opt_B); +getopts('vnIL:f:B:'); if ($opt_f) { %forced = map {($_, 1)} split(/,/, $opt_f); } $opt_L = '/usr/local' unless defined $opt_L; +my $destdir; +if (defined $opt_B) { + $destdir = $opt_B; +} elsif (defined $ENV{'PKG_PREFIX'}) { + $destdir = $ENV{'PKG_PREFIX'}; +} +if (defined $destdir) { + $destdir.='/'; + $ENV{'PKG_DESTDIR'} = $destdir; +} else { + $destdir = ''; +} + if ($< && !$forced{nonroot}) { die "$0 must be run as root"; } @@ -350,20 +364,21 @@ sub borked_script($) } } -sub really_add($) +sub really_add($$) { - my $handle = shift; + my ($handle, $destdir) = @_; my $plist = $handle->{plist}; my $dir = $handle->info(); my $pkgname = $plist->pkgname(); $ENV{'PKG_PREFIX'} = $plist->pkgbase(); # check for collisions with existing stuff my $problems = 0; + my $colliding = []; for my $item (@{$plist->{items}}) { next unless $item->IsFile(); - my $fname = $item->fullname(); + my $fname = $destdir.$item->fullname(); if (OpenBSD::Vstat::vexists($fname)) { - print "Collision: $fname already exists\n"; + push(@$colliding, $fname); $problems++; } my $s = OpenBSD::Vstat::add($fname, $item->{size}); @@ -377,6 +392,10 @@ sub really_add($) $problems++; } } + if (@$colliding > 0) { + print "Collision: the following files already exists\n\t", + join("\n\t", @$colliding), "\n"; + } die if $problems; my $interrupted; @@ -410,7 +429,7 @@ sub really_add($) $plist->{done} = []; for my $item (@{$plist->{items}}) { - $item->install($handle, $opt_v, $opt_n); + $item->install($handle, $destdir, $opt_v, $opt_n); push(@{$plist->{done}}, $item); last if $interrupted; } @@ -499,7 +518,7 @@ while (my $pkg = shift @todo) { for my $dep (@{$handle->{solved_dependencies}}) { OpenBSD::PackingElement::PkgDep->add($plist, $dep); } - really_add($handle); + really_add($handle, $destdir); $conflict_list->{$plist->pkgname()} = $handle->{conflicts}; } diff --git a/usr.sbin/pkg_add/pkg_add.1 b/usr.sbin/pkg_add/pkg_add.1 index 93b81faf99a..d0aca48181a 100644 --- a/usr.sbin/pkg_add/pkg_add.1 +++ b/usr.sbin/pkg_add/pkg_add.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: pkg_add.1,v 1.11 2004/01/28 22:12:01 espie Exp $ +.\" $OpenBSD: pkg_add.1,v 1.12 2004/02/20 19:13:51 espie Exp $ .\" .\" FreeBSD install - a package for the installation and maintenance .\" of non-core utilities. @@ -26,6 +26,7 @@ .Sh SYNOPSIS .Nm pkg_add .Op Fl Inv +.Op Fl B Ar pkg-destdir .Op Fl f Ar keys .Op Fl L Ar localbase .Ar pkg-name Op Ar ... @@ -120,6 +121,10 @@ If an installation script exists for a given package, do not execute it. .It Fl n Don't actually install a package, just report the steps that would be taken if it was. +.It Fl B Ar pkg-destdir +Set +.Ar pkg-destdir +as the prefix to prepend to any object extracted from the package. .It Fl f Ar keys Force installation of the package. .Ar keys @@ -300,7 +305,7 @@ through as it will safely record an interrupted install as .Pa borked.n . .Sh ENVIRONMENT -.Bl -tag -width PKG_TMPDIR +.Bl -tag -width PKG_DESTDIR .It Ev PKG_PATH If a given package name cannot be found, the directories named by @@ -315,6 +320,17 @@ period .It Ev PKG_DBDIR Where to register packages instead of .Pa /var/db/pkg . +.It Ev PKG_DESTDIR +Value for +.Ar pkg-destdir , +if no +.Fl B +option is specified; +value passed to any +.Cm INSTALL +or +.Cm REQUIRE +script invoked from the package. .It Ev PKG_TMPDIR Temporary area where package information files will be extracted, instead of .Pa /var/tmp . |