summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2004-10-18 10:51:04 +0000
committerMarc Espie <espie@cvs.openbsd.org>2004-10-18 10:51:04 +0000
commit938d0a8021c4592b685840fe749be77fb305f4aa (patch)
tree4be2848a246587113e84b2db6e0c00f550cfa2d5 /usr.sbin
parent4264f44d231a8654ee4ea2b5d441378bc18fe7a6 (diff)
use OpenBSD::Getopt so that we can do -v -v.
Be much terser by default, start showing dependency information and various things only with at least one -v. Build a `flattened tree' of dependencies information in pkg_add, and show why we install a given package (idea from deraadt@).
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackingElement.pm3
-rw-r--r--usr.sbin/pkg_add/pkg_add72
-rw-r--r--usr.sbin/pkg_add/pkg_delete21
3 files changed, 62 insertions, 34 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PackingElement.pm b/usr.sbin/pkg_add/OpenBSD/PackingElement.pm
index 40f8de49f77..f24f006d705 100644
--- a/usr.sbin/pkg_add/OpenBSD/PackingElement.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PackingElement.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: PackingElement.pm,v 1.56 2004/10/16 11:01:29 espie Exp $
+# $OpenBSD: PackingElement.pm,v 1.57 2004/10/18 10:51:03 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -1125,7 +1125,6 @@ sub run
my ($self, $state, @args) = @_;
my $dir = $state->{dir};
- my $verbose = $state->{verbose};
my $not = $state->{not};
my $pkgname = $state->{pkgname};
my $name = $self->{name};
diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add
index 72b9d2fc386..8edbb11ef03 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.79 2004/10/18 09:38:35 espie Exp $
+# $OpenBSD: pkg_add,v 1.80 2004/10/18 10:51:03 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -27,7 +27,7 @@ use OpenBSD::PackageName;
use OpenBSD::PkgCfl;
use OpenBSD::PkgSpec;
use OpenBSD::Vstat;
-use Getopt::Std;
+use OpenBSD::Getopt;
use OpenBSD::Error;
use File::Copy;
@@ -40,7 +40,7 @@ sub ensure_ldconfig
return if $state->{not};
return if $state->{do_faked};
return unless defined $OpenBSD::PackingElement::Lib::todo;
- VSystem($state->{verbose},
+ VSystem($state->{very_verbose},
@OpenBSD::PackingElement::Lib::ldconfig, "-m",
keys %$OpenBSD::PackingElement::Lib::todo);
undef $OpenBSD::PackingElement::Lib::todo;
@@ -113,14 +113,14 @@ sub install
}
} else {
my $l=[];
- push(@$l, "-v") if $state->{verbose};
+ push(@$l, "-v") if $state->{very_verbose};
main::add_entry($l, '-u', $self->{uid});
main::add_entry($l, '-g', $self->{group});
main::add_entry($l, '-L', $self->{class});
main::add_entry($l, '-c', $self->{comment});
main::add_entry($l, '-d', $self->{home});
main::add_entry($l, '-s', $self->{shell});
- VSystem($state->{verbose}, '/usr/sbin/useradd', @$l, $user);
+ VSystem($state->{very_verbose}, '/usr/sbin/useradd', @$l, $user);
}
}
@@ -140,9 +140,9 @@ sub install
}
} else {
my $l=[];
- push(@$l, "-v") if $state->{verbose};
+ push(@$l, "-v") if $state->{very_verbose};
main::add_entry($l, '-g', $self->{gid});
- VSystem($state->{verbose}, '/usr/sbin/groupadd', @$l, $group);
+ VSystem($state->{very_verbose}, '/usr/sbin/groupadd', @$l, $group);
}
}
@@ -169,7 +169,7 @@ sub install
$self->{value}, "\n";
return;
}
- VSystem($state->{verbose}, '/sbin/sysctl', $name.'='.$self->{value});
+ VSystem($state->{very_verbose}, '/sbin/sysctl', $name.'='.$self->{value});
}
package OpenBSD::PackingElement::FileBase;
@@ -189,7 +189,7 @@ sub install
}
my $destdir = $state->{destdir};
- print "extracting $destdir$fullname\n" if $state->{verbose};
+ print "extracting $destdir$fullname\n" if $state->{very_verbose};
return if $state->{not};
$file->{name} = $fullname;
$file->{cwd} = $self->{cwd};
@@ -226,17 +226,19 @@ sub install
}
my $origname = $destdir.$orig->fullname();
if (-e $filename) {
- print "The existing file $filename has NOT been changed\n";
- if (defined $orig->{md5}) {
+ if ($state->{verbose}) {
+ print "The existing file $filename has NOT been changed\n";
+ if (defined $orig->{md5}) {
require OpenBSD::md5;
my $md5 = OpenBSD::md5::fromfile($filename);
if ($md5 eq $orig->{md5}) {
- print "\t(but it seems to match the sample file $origname)\n";
+ print "(but it seems to match the sample file $origname)\n";
} else {
- print "\tIt does not match the sample file $origname\n";
- print "You may wish to update it manually\n";
+ print "It does NOT match the sample file $origname\n";
+ print "You may wish to update it manually\n";
}
+ }
}
} else {
if ($state->{not}) {
@@ -246,7 +248,9 @@ sub install
Warn "File $filename could not be installed:\n\t$!\n";
}
$self->set_modes($filename);
- print "The file $filename has been installed from $origname\n";
+ if ($state->{verbose}) {
+ print "installed $filename from $origname\n";
+ }
}
}
}
@@ -286,7 +290,7 @@ sub install
$self->SUPER::install($state);
return if $state->{not};
my $fullname = $state->{destdir}.$self->fullname();
- VSystem($state->{verbose},
+ VSystem($state->{very_verbose},
"install-info", "--info-dir=".dirname($fullname), $fullname);
}
@@ -319,7 +323,7 @@ sub install
my $fullname = $self->fullname();
my $destdir = $state->{destdir};
- print "new directory ", $destdir, $fullname, "\n" if $state->{verbose};
+ print "new directory ", $destdir, $fullname, "\n" if $state->{very_verbose};
return if $state->{not};
File::Path::mkpath($destdir.$fullname);
$self->set_modes($destdir.$fullname);
@@ -392,7 +396,9 @@ sub fill_conflict_lists
my $errors = 0;
our ($opt_a, $opt_v, $opt_n, $opt_I, $opt_f, $opt_L, $opt_B, $opt_A, $opt_P, $opt_Q);
-getopts('avnIL:f:B:A:P:Q:');
+$opt_v = 0;
+getopts('avnIL:f:B:A:P:Q:',
+ {'v' => sub {++$opt_v;} });
if ($opt_f) {
%forced = map {($_, 1)} split(/,/, $opt_f);
}
@@ -412,6 +418,7 @@ $opt_L = '/usr/local' unless defined $opt_L;
my $state = {};
$state->{cache} = {};
+$state->{deptree} = {};
$state->{do_faked} = 0;
if (defined $opt_Q and defined $opt_B) {
Fatal "-Q and -B are incompatible options";
@@ -438,8 +445,9 @@ if ($< && !$forced{nonroot}) {
$state->{conflict_list} = {};
$state->{not} = $opt_n;
$state->{dont_run_scripts} = $opt_I;
+$state->{very_verbose} = $opt_v >= 2;
$state->{verbose} = $opt_v;
-$state->{beverbose} = $opt_n || $opt_v;
+$state->{beverbose} = $opt_n || ($opt_v >= 2);
fill_conflict_lists($state);
@@ -470,6 +478,9 @@ sub pre_add($$)
my ($pkg, $state) = @_;
my $pkgname1;
my $operation = $state->{not} ? "Pretending to add" : "Adding";
+ if (defined $state->{deptree}->{$pkg}) {
+ $operation = $state->{deptree}->{$pkg}.":$operation";
+ }
if ($pkg ne '-') {
my $more = "";
@@ -532,7 +543,7 @@ sub pre_add($$)
sub solve_dependencies
{
- my ($handle, @extra) = @_;
+ my ($verbose, $handle, @extra) = @_;
my $plist = $handle->{plist};
my $to_register = $handle->{solved_dependencies} = [];
my $to_install;
@@ -589,7 +600,7 @@ sub solve_dependencies
}
}
- if (@{$to_register} > 0) {
+ if ($verbose && @{$to_register} > 0) {
print "Dependencies for ", $plist->pkgname(), " resolve to: ",
join(',', @$to_register);
print " (todo: ", join(',', @deps), ")" if @deps > 0;
@@ -772,7 +783,6 @@ sub really_add($$)
{
my ($handle, $state) = @_;
my $destdir = $state->{destdir};
- my $verbose = $state->{verbose};
my $not = $state->{not};
my $plist = $handle->{plist};
my $dir = $handle->info();
@@ -846,6 +856,21 @@ sub really_add($$)
}
}
+# one-level dependencies tree, for nicer printouts
+sub build_deptree
+{
+ my ($state, $pkg, @deps) = @_;
+
+ my $tree = $state->{deptree};
+ $pkg = OpenBSD::PackageName::url2pkgname($pkg);
+ # flatten info
+ if (defined $tree->{$pkg}) {
+ $pkg = $tree->{$pkg};
+ }
+ for my $i (@deps) {
+ $tree->{$i} = $pkg unless defined $tree->{$i};
+ }
+}
sub install_package
{
@@ -876,8 +901,9 @@ sub install_package
}
}
if (!defined $handle->{solved_dependencies}) {
- my @deps = solve_dependencies($handle, @todo);
+ my @deps = solve_dependencies($state->{verbose}, $handle, @todo);
if (@deps > 0) {
+ build_deptree($state, $pkg, @deps);
return (@deps, $pkg);
}
}
diff --git a/usr.sbin/pkg_add/pkg_delete b/usr.sbin/pkg_add/pkg_delete
index bfa2afbad8e..92691e58d88 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.57 2004/10/17 09:32:21 espie Exp $
+# $OpenBSD: pkg_delete,v 1.58 2004/10/18 10:51:03 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -18,7 +18,7 @@
use strict;
use warnings;
-use Getopt::Std;
+use OpenBSD::Getopt;
use OpenBSD::PackingList;
use OpenBSD::PackingOld;
use OpenBSD::PackageInfo;
@@ -36,7 +36,7 @@ sub ensure_ldconfig
my $state = shift;
return if $state->{not};
return unless defined $OpenBSD::PackingElement::Lib::todo;
- VSystem($state->{verbose},
+ VSystem($state->{very_verbose},
@OpenBSD::PackingElement::Lib::ldconfig, "-R");
undef $OpenBSD::PackingElement::Lib::todo;
}
@@ -300,7 +300,7 @@ sub delete
} else {
my $md5 = OpenBSD::md5::fromfile($realname);
if ($md5 eq $orig->{md5}) {
- print "File $realname identical to sample\n";
+ print "File $realname identical to sample\n" if $state->{not} or $state->{verbose};
} else {
print "File $realname NOT identical to sample\n";
unless ($state->{extra}) {
@@ -310,7 +310,7 @@ sub delete
}
}
return if $state->{not};
- print "deleting $realname\n";
+ print "deleting $realname\n" if $state->{verbose};
if (!unlink $realname) {
print "Problem deleting $realname\n";
$self->log_pkgname($state);
@@ -328,7 +328,7 @@ sub delete
my ($self, $state) = @_;
unless ($state->{not}) {
my $fullname = $state->{destdir}.$self->fullname();
- VSystem($state->{verbose},
+ VSystem($state->{very_verbose},
"install-info", "--delete", "--info-dir=".dirname($fullname), $fullname);
}
$self->SUPER::delete($state);
@@ -473,6 +473,7 @@ package main;
our ($opt_v, $opt_D, $opt_d, $opt_n, $opt_f, $opt_q, $opt_p, $opt_c, $opt_L, $opt_B, $opt_I);
+$opt_v = 0;
sub remove_packing_info
{
my $dir = shift;
@@ -568,7 +569,8 @@ sub delete_package
remove_packing_info($dir) unless $opt_n;
}
-getopts('vcDdnf:qpS:L:B:I');
+getopts('vcDdnf:qpS:L:B:I',
+ {'v' => sub {++$opt_v;} });
if ($opt_D) {
$opt_I = 1;
}
@@ -602,8 +604,9 @@ my $removed;
my $state = {};
$state->{not} = $opt_n;
$state->{quick} = $opt_q;
-$state->{verbose} = $opt_v;
-$state->{beverbose} = $opt_n || $opt_v;
+$state->{verbose} = $opt_v >= 2;
+$state->{very_verbose} = $opt_v;
+$state->{beverbose} = $opt_n || ($opt_v >= 2);
$state->{extra} = $opt_c;
$state->{dont_run_scripts} = $opt_I;
$ENV{'PKG_DELETE_EXTRA'} = $state->{extra} ? "Yes" : "No";