summaryrefslogtreecommitdiff
path: root/usr.sbin/pkg_add
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/pkg_add')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Logger.pm12
-rw-r--r--usr.sbin/pkg_add/pkg_delete68
-rw-r--r--usr.sbin/pkg_add/pkg_delete.126
3 files changed, 80 insertions, 26 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Logger.pm b/usr.sbin/pkg_add/OpenBSD/Logger.pm
index 3e59f86557c..8943271e112 100644
--- a/usr.sbin/pkg_add/OpenBSD/Logger.pm
+++ b/usr.sbin/pkg_add/OpenBSD/Logger.pm
@@ -1,4 +1,4 @@
-# $OpenBSD: Logger.pm,v 1.1 2003/11/04 17:54:21 espie Exp $
+# $OpenBSD: Logger.pm,v 1.2 2004/02/25 21:56:12 espie Exp $
#
# Copyright (c) 2003 Marc Espie.
#
@@ -33,6 +33,7 @@ use File::Temp;
my $log_handle;
my $log_base;
my $log_name;
+my @annotations=();
sub log_as($)
{
@@ -53,9 +54,18 @@ sub logfile()
return $log_handle;
}
+sub annotate
+{
+ push(@annotations, @_);
+}
+
sub log(@)
{
my $fh = logfile();
+ if (@annotations > 0) {
+ print $fh @annotations;
+ @annotations = ();
+ }
print $fh @_;
}
diff --git a/usr.sbin/pkg_add/pkg_delete b/usr.sbin/pkg_add/pkg_delete
index 20a0bd2147b..6ef5070ae13 100644
--- a/usr.sbin/pkg_add/pkg_delete
+++ b/usr.sbin/pkg_add/pkg_delete
@@ -1,6 +1,6 @@
#!/usr/bin/perl
# ex:ts=8 sw=4:
-# $OpenBSD: pkg_delete,v 1.22 2004/01/28 22:12:01 espie Exp $
+# $OpenBSD: pkg_delete,v 1.23 2004/02/25 21:56:12 espie Exp $
#
# Copyright (c) 2003 Marc Espie.
#
@@ -83,6 +83,7 @@ sub delete
{
my ($self, $state) = @_;
my $name = $self->fullname();
+ my $realname = $state->{destdir}.$name;
if ($state->{verbose} or $state->{not}) {
print "dirrm: $name\n";
@@ -101,10 +102,10 @@ sub delete
}
elsif (@$entry == 1) {
if ($entry->[0] eq $state->{pkgname}) {
- if (!rmdir $name) {
- print "Error deleting directory $name\n";
+ if (!rmdir $realname) {
+ print "Error deleting directory $realname\n";
$self->log_pkgname($state);
- OpenBSD::Logger::log "rmdir $name\n";
+ OpenBSD::Logger::log "rmdir $state->{destdirname}$name\n";
}
$state->{dirrms}->{$name} = undef;
} else {
@@ -137,41 +138,42 @@ sub delete
{
my ($self, $state) = @_;
my $name = $self->fullname();
- if (-l $name) {
+ my $realname = $state->{destdir}.$name;
+ if (-l $realname) {
if ($state->{verbose} or $state->{not}) {
- print "deleting symlink: $name\n";
+ print "deleting symlink: $realname\n";
}
} else {
unless ($self->{nochecksum} or $state->{quick}) {
if (!defined $self->{md5}) {
print "Problem: $name does not have an md5 checksum\n";
- print "NOT deleting: $name\n";
+ print "NOT deleting: $realname\n";
$self->log_pkgname($state);
- OpenBSD::Logger::log "rm $name\n";
+ OpenBSD::Logger::log "rm $state->{destdirname}$name\n";
return;
}
- if (! -f $name) {
- print "File $name does not exist\n";
+ if (! -f $realname) {
+ print "File $realname does not exist\n";
return;
}
- my $md5 = OpenBSD::md5::fromfile($name);
+ my $md5 = OpenBSD::md5::fromfile($realname);
if ($md5 ne $self->{md5}) {
print "Problem: md5 doesn't match for $name\n";
- print "NOT deleting: $name\n";
+ print "NOT deleting: $realname\n";
$self->log_pkgname($state);
- OpenBSD::Logger::log "rm $name #MD5\n";
+ OpenBSD::Logger::log "rm $state->{destdirname}$name #MD5\n";
return;
}
}
if ($state->{verbose} or $state->{not}) {
- print "deleting: $name\n";
+ print "deleting: $realname\n";
}
}
return if $state->{not};
- if (!unlink $name) {
- print "problem deleting $name\n";
+ if (!unlink $realname) {
+ print "Problem deleting $realname\n";
$self->log_pkgname($state);
- OpenBSD::Logger::log "rm $name\n";
+ OpenBSD::Logger::log "rm $state->{destdirname}$name\n";
}
}
@@ -181,17 +183,23 @@ sub delete
my ($self, $state) = @_;
return unless $state->{extra};
my $name = $self->fullname();
+ my $realname = $state->{destdir}.$name;
if ($self->{name} =~ m|/$|) {
if ($state->{verbose} or $state->{not}) {
- print "deleting extra directory: $name\n";
+ print "deleting extra directory: $realname\n";
}
- rmdir($name) unless $state->{not};
+ return if $state->{not};
+ return unless -e $realname;
+ rmdir($realname) or
+ print "problem deleting extra directory $realname\n";
} else {
if ($state->{verbose} or $state->{not}) {
- print "deleting extra file: $name\n";
+ print "deleting extra file: $realname\n";
}
return if $state->{not};
- unlink($name) or print "problem deleting $name\n";
+ return unless -e $realname;
+ unlink($realname) or
+ print "problem deleting extra file $realname\n";
}
}
@@ -248,7 +256,7 @@ sub delete
package main;
-our ($opt_v, $opt_D, $opt_d, $opt_n, $opt_f, $opt_q, $opt_p, $opt_c, $opt_L);
+our ($opt_v, $opt_D, $opt_d, $opt_n, $opt_f, $opt_q, $opt_p, $opt_c, $opt_L, $opt_B);
sub remove_packing_info
{
@@ -314,7 +322,13 @@ sub delete_package
remove_packing_info($dir) unless $opt_n;
}
-getopts('vcDdnf:qpS:L:');
+getopts('vcDdnf:qpS:L:B:');
+$opt_B = $ENV{'PKG_DESTDIR'} unless defined $opt_B;
+$opt_B = '' unless defined $opt_B;
+if ($opt_B ne '') {
+ $opt_B.='/' unless $opt_B =~ m/\/$/;
+}
+$ENV{'PKG_DESTDIR'} = $opt_B;
$opt_L = '/usr/local' unless defined $opt_L;
@@ -412,6 +426,14 @@ if ($bad) {
exit(1);
}
+$state->{destdir} = $opt_B;
+if ($opt_B eq '') {
+ $state->{destdirname} = '';
+} else {
+ OpenBSD::Logger::annotate("PKG_DESTDIR=\"$opt_B\"; export PKG_DESTDIR\n");
+ $state->{destdirname} = '${PKG_DESTDIR}';
+}
+
# and finally, handle the removal
{ do {
$removed = 0;
diff --git a/usr.sbin/pkg_add/pkg_delete.1 b/usr.sbin/pkg_add/pkg_delete.1
index 0cef5043e4c..f1041577d6b 100644
--- a/usr.sbin/pkg_add/pkg_delete.1
+++ b/usr.sbin/pkg_add/pkg_delete.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: pkg_delete.1,v 1.6 2004/01/27 15:34:31 espie Exp $
+.\" $OpenBSD: pkg_delete.1,v 1.7 2004/02/25 21:56:12 espie Exp $
.\"
.\" FreeBSD install - a package for the installation and maintenance
.\" of non-core utilities.
@@ -26,6 +26,7 @@
.Sh SYNOPSIS
.Nm pkg_delete
.Op Fl cDnqv
+.Op Fl B Ar pkg-destdir
.Op Fl f Ar keys
.Ar pkgname Op Ar ...
.Sh DESCRIPTION
@@ -51,7 +52,11 @@ see
can be omitted, unless the resulting specification is ambiguous.
.Pp
The options are as follows:
-.Bl -tag -width keyword
+.Bl -tag -width BB-pkg-destdir
+.It Fl B Ar pkg-destdir
+Set
+.Ar pkg-destdir
+as the prefix to prepend to any object deleted.
.It Fl v
Turn on verbose output.
.It Fl D
@@ -138,6 +143,23 @@ Passing the keyword
lets you potentially write only one program/script that handles all
aspects of installation and deletion.
.Pp
+.Sh ENVIRONMENT
+.Bl -tag -width PKG_DESTDIR
+.It Ev PKG_DBDIR
+Where to look for installed 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 DEINSTALL
+or
+.Cm REQUIRE
+script invoked from the package.
+.El
.Sh SEE ALSO
.Xr pkg_add 1 ,
.Xr pkg_create 1 ,