summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/pkg_add/Makefile21
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Add.pm4
-rw-r--r--usr.sbin/pkg_add/OpenBSD/AddCreateDelete.pm116
-rw-r--r--usr.sbin/pkg_add/OpenBSD/AddDelete.pm167
-rw-r--r--usr.sbin/pkg_add/OpenBSD/CollisionReport.pm8
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Delete.pm2
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Dependencies.pm8
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackageInfo.pm4
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackingElement.pm4
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PkgAdd.pm (renamed from usr.sbin/pkg_add/pkg_add)219
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PkgCreate.pm (renamed from usr.sbin/pkg_add/pkg_create)596
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PkgDelete.pm (renamed from usr.sbin/pkg_add/pkg_delete)78
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PkgInfo.pm (renamed from usr.sbin/pkg_add/pkg_info)238
-rw-r--r--usr.sbin/pkg_add/OpenBSD/ProgressMeter.pm6
-rw-r--r--usr.sbin/pkg_add/OpenBSD/ProgressMeter/Term.pm5
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Replace.pm6
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Update.pm10
-rw-r--r--usr.sbin/pkg_add/OpenBSD/UpdateSet.pm4
-rw-r--r--usr.sbin/pkg_add/pkg53
19 files changed, 815 insertions, 734 deletions
diff --git a/usr.sbin/pkg_add/Makefile b/usr.sbin/pkg_add/Makefile
index c392998bddd..06e31691b53 100644
--- a/usr.sbin/pkg_add/Makefile
+++ b/usr.sbin/pkg_add/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.61 2010/04/24 14:33:12 espie Exp $
+# $OpenBSD: Makefile,v 1.62 2010/06/04 13:19:39 espie Exp $
.include <bsd.own.mk>
@@ -12,6 +12,7 @@ POD2MAN=/usr/bin/pod2man
PACKAGES= \
OpenBSD/Add.pm \
+ OpenBSD/AddCreateDelete.pm \
OpenBSD/AddDelete.pm \
OpenBSD/ArcCheck.pm \
OpenBSD/CollisionReport.pm \
@@ -39,8 +40,12 @@ PACKAGES= \
OpenBSD/PackingElement.pm \
OpenBSD/PackingList.pm \
OpenBSD/Paths.pm \
+ OpenBSD/PkgAdd.pm \
OpenBSD/PkgCfl.pm \
OpenBSD/PkgConfig.pm \
+ OpenBSD/PkgCreate.pm \
+ OpenBSD/PkgDelete.pm \
+ OpenBSD/PkgInfo.pm \
OpenBSD/PkgSpec.pm \
OpenBSD/ProgressMeter/Term.pm \
OpenBSD/ProgressMeter.pm \
@@ -64,14 +69,16 @@ PACKAGEDIRS=OpenBSD OpenBSD/PackageRepository OpenBSD/ProgressMeter \
OpenBSD/LibSpec
SCRIPTS= \
- pkg_add \
- pkg_info \
- pkg_create \
- pkg_delete \
pkg_merge \
pkg_mklocatedb \
pkg
+SCRIPTS_LNK = \
+ pkg pkg_add \
+ pkg pkg_create \
+ pkg pkg_delete \
+ pkg pkg_info
+
LIBBASE=/usr/libdata/perl5
PODS= \
@@ -142,7 +149,9 @@ realinstall:
${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
${.CURDIR}/$i ${DESTDIR}${BINDIR}/$i
.endfor
-
+.for i j in ${SCRIPTS_LNK}
+ cd ${DESTDIR}${BINDIR} && ln -f $i $j
+.endfor
.include <bsd.prog.mk>
.PHONY: mansrc.build
diff --git a/usr.sbin/pkg_add/OpenBSD/Add.pm b/usr.sbin/pkg_add/OpenBSD/Add.pm
index d74c313113d..169f8c42774 100644
--- a/usr.sbin/pkg_add/OpenBSD/Add.pm
+++ b/usr.sbin/pkg_add/OpenBSD/Add.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Add.pm,v 1.108 2010/05/10 09:17:55 espie Exp $
+# $OpenBSD: Add.pm,v 1.109 2010/06/04 13:19:39 espie Exp $
#
# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
@@ -698,7 +698,7 @@ sub prepare_for_addition
my @old = $set->older_names;
if ($self->spec->match_ref(\@old) > 0) {
my $key = "update_".OpenBSD::PackageName::splitstem($pkgname);
- return if $state->{defines}->{$key};
+ return if $state->defines($key);
if ($state->{interactive}) {
if ($state->confirm($self->{message}."\n".
"Do you want to update now", 0)) {
diff --git a/usr.sbin/pkg_add/OpenBSD/AddCreateDelete.pm b/usr.sbin/pkg_add/OpenBSD/AddCreateDelete.pm
new file mode 100644
index 00000000000..249ebb59adf
--- /dev/null
+++ b/usr.sbin/pkg_add/OpenBSD/AddCreateDelete.pm
@@ -0,0 +1,116 @@
+# ex:ts=8 sw=4:
+# $OpenBSD: AddCreateDelete.pm,v 1.1 2010/06/04 13:19:39 espie Exp $
+#
+# Copyright (c) 2007-2010 Marc Espie <espie@openbsd.org>
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+#
+
+use strict;
+use warnings;
+
+# common framework, let's place most everything in there
+
+package OpenBSD::AddCreateDelete::State;
+
+sub new
+{
+ my $class = shift;
+ my $o = bless {}, $class;
+ $o->init(@_);
+ return $o;
+}
+
+sub init
+{
+ my $self = shift;
+
+ $self->{subst} = OpenBSD::Subst->new;
+ $self->{progressmeter} = OpenBSD::ProgressMeter->new;
+ $self->{bad} = 0;
+}
+
+sub progress
+{
+ my $self = shift;
+ return $self->{progressmeter};
+}
+
+sub verbose
+{
+ my $self = shift;
+ return $self->{v};
+}
+
+sub not
+{
+ my $self = shift;
+ return $self->{not};
+}
+
+sub opt
+{
+ my ($self, $k) = @_;
+ return $self->{opt}{$k};
+}
+
+sub print
+{
+ my $self = shift;
+ $self->progress->print(@_);
+}
+
+sub say
+{
+ my $self = shift;
+ $self->progress->print(@_, "\n");
+}
+
+sub errprint
+{
+ my $self = shift;
+ $self->progress->errprint(@_);
+}
+
+sub errsay
+{
+ my $self = shift;
+ $self->progress->errprint(@_, "\n");
+}
+
+package OpenBSD::AddCreateDelete;
+use OpenBSD::Getopt;
+use OpenBSD::Error;
+
+sub handle_options
+{
+ my ($self, $opt_string, $state, @usage) = @_;
+
+
+ $state->{opt}{v} = 0;
+ $state->{opt}{h} = sub { Usage(); };
+ $state->{opt}{D} = sub {
+ $state->{subst}->parse_option(shift);
+ };
+ set_usage(@usage);
+ try {
+ getopts('hmnvxD:'.$opt_string, $state->{opt});
+ } catchall {
+ Usage($_);
+ };
+ $state->progress->setup($state->opt('x'), $state->opt('m'));
+ $state->{v} = $state->opt('v');
+ $state->{not} = $state->opt('n');
+}
+
+1;
diff --git a/usr.sbin/pkg_add/OpenBSD/AddDelete.pm b/usr.sbin/pkg_add/OpenBSD/AddDelete.pm
index 0409f5e9919..ecf151b91be 100644
--- a/usr.sbin/pkg_add/OpenBSD/AddDelete.pm
+++ b/usr.sbin/pkg_add/OpenBSD/AddDelete.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: AddDelete.pm,v 1.20 2010/05/10 09:17:55 espie Exp $
+# $OpenBSD: AddDelete.pm,v 1.21 2010/06/04 13:19:39 espie Exp $
#
# Copyright (c) 2007-2010 Marc Espie <espie@openbsd.org>
#
@@ -24,67 +24,49 @@ package main;
our $not;
package OpenBSD::AddDelete;
-use OpenBSD::Getopt;
use OpenBSD::Error;
use OpenBSD::Paths;
use OpenBSD::ProgressMeter;
+use OpenBSD::PackageInfo;
+use OpenBSD::Subst;
+use OpenBSD::AddCreateDelete;
-our $bad = 0;
-our %defines = ();
-our $state;
-
-our ($opt_n, $opt_x, $opt_v, $opt_B, $opt_L, $opt_i, $opt_q, $opt_c, $opt_I, $opt_s);
-$opt_v = 0;
+our @ISA = qw(OpenBSD::AddCreateDelete);
sub handle_options
{
- my ($opt_string, $hash, @usage) = @_;
+ my ($self, $opt_string, $hash, @usage) = @_;
- set_usage(@usage);
- $state = OpenBSD::State->new;
- $hash->{h} = sub { Usage(); };
+ my $state = $self->new_state;
+ $state->{opt} = $hash;
$hash->{F} = sub {
for my $o (split /\,/o, shift) {
- $defines{$o} = 1;
- }
- };
- $hash->{D} = sub {
- my $_ = shift;
- if (m/^(.*?)=(.*)/) {
- $defines{$1} = $2;
- } else {
- $defines{$_} = 1;
+ $state->{subst}->add($o, 1);
}
};
- try {
- getopts('hciInqvsxB:D:F:L:'.$opt_string, $hash);
- } catchall {
- Usage($_);
- };
+ $self->SUPER::handle_options($opt_string.'ciInqsB:F:',
+ $state, @usage);
- $opt_L = OpenBSD::Paths->localbase unless defined $opt_L;
-
- if ($opt_s) {
- $opt_n = 1;
+ if ($state->opt('s')) {
+ $state->{not} = 1;
}
- $state->{not} = $opt_n;
# XXX RequiredBy
- $main::not = $opt_n;
- $state->{defines} = \%defines;
- $state->{interactive} = $opt_i;
- $state->{v} = $opt_v;
- $state->{localbase} = $opt_L;
- $state->{size_only} = $opt_s;
- $state->{quick} = $opt_q;
- $state->{extra} = $opt_c;
- $state->{dont_run_scripts} = $opt_I;
+ $main::not = $state->{not};
+ $state->{interactive} = $state->opt('i');
+ $state->{localbase} = $state->opt('L') // OpenBSD::Paths->localbase;
+ $state->{size_only} = $state->opt('s');
+ $state->{quick} = $state->opt('q');
+ $state->{extra} = $state->opt('c');
+ $state->{dont_run_scripts} = $state->opt('I');
+ $ENV{'PKG_DELETE_EXTRA'} = $state->{extra} ? "Yes" : "No";
+ return $state;
}
sub do_the_main_work
{
- my $code = shift;
+ my ($self, $state) = @_;
- if ($bad) {
+ if ($state->{bad}) {
exit(1);
}
@@ -95,10 +77,10 @@ sub do_the_main_work
local $SIG{'KILL'} = $handler;
local $SIG{'TERM'} = $handler;
- if ($state->{defines}->{debug}) {
- &$code;
+ if ($state->defines('debug')) {
+ $self->main($state);
} else {
- eval { &$code; };
+ eval { $self->main($state); };
}
my $dielater = $@;
return $dielater;
@@ -106,22 +88,21 @@ sub do_the_main_work
sub framework
{
- my $code = shift;
+ my ($self, $state) = @_;
try {
- lock_db($opt_n) unless $state->{defines}->{nolock};
- $state->progress->setup($opt_x);
+ lock_db($state->{not}) unless $state->defines('nolock');
$state->check_root;
- process_parameters();
- my $dielater = do_the_main_work($code);
+ $self->process_parameters($state);
+ my $dielater = $self->do_the_main_work($state);
# cleanup various things
$state->{recorder}->cleanup($state);
OpenBSD::PackingElement::Lib::ensure_ldconfig($state);
OpenBSD::PackingElement::Fontdir::finish_fontdirs($state);
$state->progress->clear;
$state->log->dump;
- finish_display();
- if ($state->verbose >= 2 || $opt_s ||
- $state->{defines}->{tally}) {
+ $self->finish_display($state);
+ if ($state->verbose >= 2 || $state->{size_only} ||
+ $state->defines('tally')) {
$state->vstat->tally;
}
# show any error, and show why we died...
@@ -135,11 +116,20 @@ sub framework
exit(1);
};
- if ($bad) {
+ if ($state->{bad}) {
exit(1);
}
}
+sub parse_and_run
+{
+ my $self = shift;
+
+ my $state = $self->handle_options;
+ local $SIG{'INFO'} = sub { $state->status->print($state); };
+
+ $self->framework($state);
+}
package OpenBSD::SharedItemsRecorder;
sub new
@@ -179,41 +169,34 @@ sub dump
}
-package OpenBSD::UI;
+package OpenBSD::AddDelete::State;
use OpenBSD::Error;
use OpenBSD::Vstat;
-
-sub new
-{
- my $class = shift;
- my $o = bless {}, $class;
- $o->init(@_);
- return $o;
-}
+our @ISA = qw(OpenBSD::AddCreateDelete::State);
sub init
{
my $self = shift;
$self->{l} = OpenBSD::Log->new;
$self->{vstat} = OpenBSD::Vstat->new($self);
- $self->{progressmeter} = OpenBSD::ProgressMeter->new;
$self->{status} = OpenBSD::Status->new;
$self->{recorder} = OpenBSD::SharedItemsRecorder->new;
$self->{v} = 0;
+ $self->SUPER::init(@_);
}
sub ntogo
{
my ($self, $offset) = @_;
- return $self->progress->ntogo($self->todo, $offset);
+ return $self->progress->ntogo($self, $offset);
}
sub ntogo_string
{
- my ($self, $todo, $offset) = @_;
+ my ($self, $offset) = @_;
- $todo //= 0;
+ my $todo = $self->{todo} // 0;
$offset //= 0;
$todo += $offset;
@@ -224,14 +207,10 @@ sub ntogo_string
}
}
-sub verbose
-{
- return shift->{v};
-}
-
sub vstat
{
- return shift->{vstat};
+ my $self = shift;
+ return $self->{vstat};
}
sub log
@@ -244,36 +223,6 @@ sub log
}
}
-sub print
-{
- my $self = shift;
- $self->progress->print(@_);
-}
-
-sub say
-{
- my $self = shift;
- $self->progress->print(@_, "\n");
-}
-
-sub errprint
-{
- my $self = shift;
- $self->progress->errprint(@_);
-}
-
-sub errsay
-{
- my $self = shift;
- $self->progress->errprint(@_, "\n");
-}
-
-sub progress
-{
- my $self = shift;
- return $self->{progressmeter};
-}
-
sub vsystem
{
my $self = shift;
@@ -298,7 +247,7 @@ sub unlink
sub check_root
{
my $state = shift;
- if ($< && !$state->{defines}->{nonroot}) {
+ if ($< && !$state->defines('nonroot')) {
if ($state->{not}) {
$state->errsay("$0 should be run as root") if $state->verbose;
} else {
@@ -347,6 +296,12 @@ sub status
return $self->{status};
}
+sub defines
+{
+ my ($self, $k) = @_;
+ return $self->{subst}->value($k);
+}
+
# the object that gets displayed during status updates
package OpenBSD::Status;
@@ -365,8 +320,8 @@ sub print
$object = "Parameters";
}
- $state->say($what." ".$object.$state->ntogo_string($state->todo));
- if ($state->{defines}->{carp}) {
+ $state->say($what." ".$object.$state->ntogo_string);
+ if ($state->defines('carp')) {
require Carp;
Carp::cluck("currently here");
}
diff --git a/usr.sbin/pkg_add/OpenBSD/CollisionReport.pm b/usr.sbin/pkg_add/OpenBSD/CollisionReport.pm
index 5deeb7a0838..ad71c847688 100644
--- a/usr.sbin/pkg_add/OpenBSD/CollisionReport.pm
+++ b/usr.sbin/pkg_add/OpenBSD/CollisionReport.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: CollisionReport.pm,v 1.33 2010/05/10 09:17:55 espie Exp $
+# $OpenBSD: CollisionReport.pm,v 1.34 2010/06/04 13:19:39 espie Exp $
#
# Copyright (c) 2003-2006 Marc Espie <espie@openbsd.org>
#
@@ -62,7 +62,7 @@ sub collision_report($$)
my $destdir = $state->{destdir};
- if ($state->{defines}->{removecollisions}) {
+ if ($state->defines('removecollisions')) {
require OpenBSD::Error;
for my $f (@$list) {
$state->unlink(1, $destdir.$f->fullname);
@@ -75,7 +75,7 @@ sub collision_report($$)
my $found = 0;
$state->errsay("Collision: the following files already exist");
- if (!$state->{defines}->{dontfindcollisions}) {
+ if (!$state->defines('dontfindcollisions')) {
my $bypkg = find_collisions(\%todo, $state);
for my $pkg (sort keys %$bypkg) {
for my $item (sort @{$bypkg->{$pkg}}) {
@@ -122,7 +122,7 @@ sub collision_report($$)
}
my $dorepair = 0;
if ($found == 0) {
- if ($state->{defines}->{repair}) {
+ if ($state->defines('repair')) {
$dorepair = 1;
} elsif ($state->{interactive}) {
if ($state->confirm("It seems to be a missing package registration\nRepair", 0)) {
diff --git a/usr.sbin/pkg_add/OpenBSD/Delete.pm b/usr.sbin/pkg_add/OpenBSD/Delete.pm
index ff93a9119f0..bdd558fee0d 100644
--- a/usr.sbin/pkg_add/OpenBSD/Delete.pm
+++ b/usr.sbin/pkg_add/OpenBSD/Delete.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Delete.pm,v 1.100 2010/05/10 09:17:55 espie Exp $
+# $OpenBSD: Delete.pm,v 1.101 2010/06/04 13:19:39 espie Exp $
#
# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
diff --git a/usr.sbin/pkg_add/OpenBSD/Dependencies.pm b/usr.sbin/pkg_add/OpenBSD/Dependencies.pm
index 535e385d013..29c1ea51faa 100644
--- a/usr.sbin/pkg_add/OpenBSD/Dependencies.pm
+++ b/usr.sbin/pkg_add/OpenBSD/Dependencies.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Dependencies.pm,v 1.126 2010/05/10 09:17:55 espie Exp $
+# $OpenBSD: Dependencies.pm,v 1.127 2010/06/04 13:19:39 espie Exp $
#
# Copyright (c) 2005-2010 Marc Espie <espie@openbsd.org>
#
@@ -405,7 +405,7 @@ sub find_dep_in_repositories
return unless $dep->spec->is_valid;
my $candidates = $self->{set}->match_locations($dep->spec);
- if (!$state->{defines}->{allversions}) {
+ if (!$state->defines('allversions')) {
require OpenBSD::Search;
$candidates = OpenBSD::Search::FilterLocation->
keep_most_recent->filter_locations($candidates);
@@ -509,7 +509,7 @@ sub solve_dependency
my $v;
if (defined $self->cached($dep)) {
- if ($state->{defines}->{stat_cache}) {
+ if ($state->defines('stat_cache')) {
if (defined $global_cache->{$dep->{pattern}}) {
$state->print("Global ");
}
@@ -519,7 +519,7 @@ sub solve_dependency
$v = $self->cached($dep)->do($self, $state, $dep, $package);
return $v if $v;
}
- if ($state->{defines}->{stat_cache}) {
+ if ($state->defines('stat_cache')) {
$state->say("No cache hit on $dep->{pattern}");
}
diff --git a/usr.sbin/pkg_add/OpenBSD/PackageInfo.pm b/usr.sbin/pkg_add/OpenBSD/PackageInfo.pm
index 1e84024c4a8..6515ad2b1a2 100644
--- a/usr.sbin/pkg_add/OpenBSD/PackageInfo.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PackageInfo.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: PackageInfo.pm,v 1.45 2010/05/10 09:17:55 espie Exp $
+# $OpenBSD: PackageInfo.pm,v 1.46 2010/06/04 13:19:39 espie Exp $
#
# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
@@ -255,7 +255,7 @@ sub solve_installed_names
}
next if $found;
- if ($state->{defines}->{ambiguous}) {
+ if ($state->defines('ambiguous')) {
my @l = map {$_->name} @$r;
$state->say("Ambiguous: $pkgname could be ",
join(' ', @l));
diff --git a/usr.sbin/pkg_add/OpenBSD/PackingElement.pm b/usr.sbin/pkg_add/OpenBSD/PackingElement.pm
index 78424881ba9..92bcc24f830 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.176 2010/05/10 09:17:55 espie Exp $
+# $OpenBSD: PackingElement.pm,v 1.177 2010/06/04 13:19:39 espie Exp $
#
# Copyright (c) 2003-2010 Marc Espie <espie@openbsd.org>
#
@@ -1569,7 +1569,7 @@ sub run
return if $state->{not};
chmod 0755, $name;
return if $state->log->system($name, $pkgname, @args) == 0;
- if ($state->{defines}->{scripts}) {
+ if ($state->defines('scripts')) {
$state->log->warn($self->beautify, " script failed\n");
} else {
$state->log->fatal($self->beautify." script failed");
diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/OpenBSD/PkgAdd.pm
index 09ac8fcb993..5201d296393 100644
--- a/usr.sbin/pkg_add/pkg_add
+++ b/usr.sbin/pkg_add/OpenBSD/PkgAdd.pm
@@ -1,7 +1,7 @@
#! /usr/bin/perl
# ex:ts=8 sw=4:
-# $OpenBSD: pkg_add,v 1.478 2010/05/10 09:17:54 espie Exp $
+# $OpenBSD: PkgAdd.pm,v 1.1 2010/06/04 13:19:39 espie Exp $
#
# Copyright (c) 2003-2010 Marc Espie <espie@openbsd.org>
#
@@ -22,20 +22,6 @@ use warnings;
use OpenBSD::AddDelete;
-package OpenBSD::AddDelete;
-use OpenBSD::Dependencies;
-use OpenBSD::PackingList;
-use OpenBSD::PackageInfo;
-use OpenBSD::PackageLocator;
-use OpenBSD::PackageName;
-use OpenBSD::PkgCfl;
-use OpenBSD::Add;
-use OpenBSD::SharedLibs;
-use OpenBSD::UpdateSet;
-use OpenBSD::Handle;
-
-our ($state, %defines, $bad, $opt_B);
-
package OpenBSD::PackingList;
sub uses_old_libs
@@ -77,8 +63,8 @@ sub has_different_sig
return $plist->{different_sig};
}
-package OpenBSD::State;
-our @ISA=(qw(OpenBSD::UI));
+package OpenBSD::PkgAdd::State;
+our @ISA = qw(OpenBSD::AddDelete::State);
# one-level dependencies tree, for nicer printouts
sub build_deptree
@@ -150,7 +136,7 @@ sub new
sub add
{
- my ($self, $handle) = @_;
+ my ($self, $handle, $state) = @_;
return if $self->{done}{$handle};
$self->{done}{$handle} = 1;
for my $conflict (OpenBSD::PkgCfl::find_all($handle->plist, $state)) {
@@ -174,6 +160,7 @@ sub merge
package OpenBSD::UpdateSet;
use OpenBSD::PackageInfo;
use OpenBSD::Error;
+use OpenBSD::Handle;
OpenBSD::Auto::cache(solver,
sub {
@@ -229,7 +216,7 @@ sub complete
return 1 if !defined $plist;
if (is_installed($pkgname) &&
(!$state->{allow_replacing} ||
- !$state->{defines}->{installed} &&
+ !$state->defines('installed') &&
!$plist->has_different_sig($state) &&
!$plist->uses_old_libs)) {
my $o = $set->{older}->{$pkgname};
@@ -255,7 +242,7 @@ sub complete
return 0 if !defined $check;
if ($check) {
- $bad++;
+ $state->{bad}++;
$set->cleanup(OpenBSD::Handle::CANT_INSTALL, $check);
$state->tracker->cant($set);
}
@@ -269,7 +256,7 @@ sub find_conflicts
my $c = $set->conflict_cache;
for my $handle ($set->newer) {
- $c->add($handle);
+ $c->add($handle, $state);
}
return $c->list;
}
@@ -327,7 +314,7 @@ sub install_issues
my @conflicts = $set->find_conflicts($state);
if (@conflicts == 0) {
- if ($state->{defines}{update_only}) {
+ if ($state->defines('update_only')) {
return "only update, no install";
} else {
return 0;
@@ -420,7 +407,7 @@ sub check_forward_dependencies
if (%$bad) {
my $no_merge = 1;
- if (!$state->{defines}->{dontmerge}) {
+ if (!$state->defines('dontmerge')) {
my $okay = 1;
for my $m (keys %$bad) {
if ($set->try_merging($m, $state)) {
@@ -431,7 +418,7 @@ sub check_forward_dependencies
}
return 0 if $okay == 1;
}
- if ($state->{defines}->{updatedepends}) {
+ if ($state->defines('updatedepends')) {
$state->errsay("Forcing update");
return $no_merge;
} elsif ($state->{interactive}) {
@@ -465,7 +452,19 @@ sub recheck_conflicts
return 1;
}
-package OpenBSD::AddDelete;
+package OpenBSD::PkgAdd;
+our @ISA = qw(OpenBSD::AddDelete);
+
+use OpenBSD::Dependencies;
+use OpenBSD::PackingList;
+use OpenBSD::PackageInfo;
+use OpenBSD::PackageLocator;
+use OpenBSD::PackageName;
+use OpenBSD::PkgCfl;
+use OpenBSD::Add;
+use OpenBSD::SharedLibs;
+use OpenBSD::UpdateSet;
+use OpenBSD::Error;
sub failed_message
{
@@ -552,7 +551,7 @@ sub check_x509_signature
$state->set_name_from_handle($handle, '+');
my $plist = $handle->plist;
if ($plist->is_signed) {
- if ($state->{defines}->{nosig}) {
+ if ($state->defines('nosig')) {
$state->errsay("NOT CHECKING DIGITAL SIGNATURE FOR ",
$plist->pkgname);
$state->{check_digest} = 0;
@@ -742,7 +741,7 @@ sub newer_has_errors
$state->set_name_from_handle($handle);
$state->log("Can't install ", $handle->pkgname, ": ",
$handle->error_message, "\n");
- $bad++;
+ $state->{bad}++;
$set->cleanup($handle->has_error);
$state->tracker->cant($set);
return 1;
@@ -752,8 +751,8 @@ sub newer_has_errors
unless ($handle->plist->{arch}->check($state->{arch})) {
$state->set_name_from_handle($handle);
$state->log($handle->pkgname, " is not for the right architecture");
- if (!$defines{arch}) {
- $bad++;
+ if (!$state->defines('arch')) {
+ $state->{bad}++;
$set->cleanup(OpenBSD::Handle::CANT_INSTALL);
$state->tracker->cant($set);
return 1;
@@ -805,7 +804,7 @@ sub install_set
if ($set->older_to_do) {
my $r = $set->check_forward_dependencies($state);
if (!defined $r) {
- $bad++;
+ $state->{bad}++;
$set->cleanup(OpenBSD::Handle::CANT_INSTALL);
$state->tracker->cant($set);
return ();
@@ -821,26 +820,26 @@ sub install_set
if (@baddeps) {
$state->errsay("Can't install ", $set->print,
": can't resolve ", join(',', @baddeps));
- $bad++;
+ $state->{bad}++;
$set->cleanup(OpenBSD::Handle::CANT_INSTALL,"bad dependencies");
$state->tracker->cant($set);
return ();
}
if (!$set->solver->solve_wantlibs($state)) {
- $bad++;
+ $state->{bad}++;
$set->cleanup(OpenBSD::Handle::CANT_INSTALL, "libs not found");
$state->tracker->cant($set);
return ();
}
# if (!$set->solver->solve_tags($state)) {
-# if (!$defines{libdepends}) {
-# $bad++;
+# if (!$state->defines('libdepends')) {
+# $state->{bad}++;
# return ();
# }
# }
if (!$set->recheck_conflicts($state)) {
- $bad++;
+ $state->{bad}++;
$set->cleanup(OpenBSD::Handle::CANT_INSTALL, "fatal conflicts");
$state->tracker->cant($set);
return ();
@@ -848,7 +847,7 @@ sub install_set
if ($set->older_to_do) {
require OpenBSD::Replace;
if (!OpenBSD::Replace::is_set_safe($set, $state)) {
- $bad++;
+ $state->{bad}++;
$set->cleanup(OpenBSD::Handle::CANT_INSTALL, "exec detected");
$state->tracker->cant($set);
return ();
@@ -860,7 +859,7 @@ sub install_set
}
if (!$set->validate_plists($state)) {
- $bad++;
+ $state->{bad}++;
$set->cleanup(OpenBSD::Handle::CANT_INSTALL,
"file issues");
$state->tracker->cant($set);
@@ -874,66 +873,6 @@ sub install_set
return ();
}
-
-
-our ($opt_a, $opt_A, $opt_P, $opt_Q, $opt_r, $opt_u, $opt_U, $opt_l, $opt_z);
-
-handle_options('aqchruUzl:A:P:Q:', {},
- 'pkg_add [-acIinqrsUuvxz] [-A arch] [-B pkg-destdir] [-D name[=value]]',
- '[-L localbase] [-l file] [-P type] [-Q quick-destdir] pkg-name [...]');
-
-local $SIG{'INFO'} = sub { $state->status->print($state); };
-$state->{do_faked} = 0;
-$state->{arch} = $opt_A;
-
-if (defined $opt_Q and defined $opt_B) {
- Usage "-Q and -B are incompatible options";
-}
-if (defined $opt_Q and defined $opt_r) {
- Usage "-r and -Q are incompatible options";
-}
-if ($opt_P) {
- if ($opt_P eq 'cdrom') {
- $state->{cdrom_only} = 1;
- }
- elsif ($opt_P eq 'ftp') {
- $state->{ftp_only} = 1;
- }
- else {
- Usage "bad option: -P $opt_P";
- }
-}
-if (defined $opt_Q) {
- $state->{destdir} = $opt_Q;
- $state->{do_faked} = 1;
-} elsif (defined $opt_B) {
- $state->{destdir} = $opt_B;
-} elsif (defined $ENV{'PKG_PREFIX'}) {
- $state->{destdir} = $ENV{'PKG_PREFIX'};
-}
-if (defined $state->{destdir}) {
- $state->{destdir}.='/';
- $ENV{'PKG_DESTDIR'} = $state->{destdir};
-} else {
- $state->{destdir} = '';
- delete $ENV{'PKG_DESTDIR'};
-}
-
-
-$state->{automatic} = $opt_a;
-$state->{allow_replacing} = $opt_r || $opt_u || $opt_U;
-$state->{hard_replace} = $opt_r;
-$state->{newupdates} = $opt_u || $opt_U;
-
-if (@ARGV == 0 && !$opt_u && !$opt_l) {
- Usage "Missing pkgname";
-}
-
-# Here we create the list of packages to install
-# actually, an updateset list (@todo2), and we hope to do this lazily
-# later for the most part...
-my @todo2 = ();
-
sub inform_user_of_problems
{
my $state = shift;
@@ -976,13 +915,21 @@ sub do_quirks
};
}
+# Here we create the list of packages to install
+# actually, an updateset list (@todo2), and we hope to do this lazily
+# later for the most part...
+my @todo2 = ();
+
+
sub process_parameters
{
- my $add_hints = $opt_z ? "add_hints" : "add_hints2";
+ my ($self, $state) = @_;
+ my $add_hints = $state->opt('z') ? "add_hints" : "add_hints2";
# match fuzzily against a list
- if ($opt_l) {
- open my $f, '<', $opt_l or die "$!: bad list $opt_l";
+ if ($state->opt('l')) {
+ open my $f, '<', $state->opt('l') or
+ die "$!: bad list ".$state->opt('l');
my $_;
while (<$f>) {
chomp;
@@ -992,7 +939,7 @@ sub process_parameters
}
# update existing stuff
- if ($opt_u) {
+ if ($state->opt('u')) {
require OpenBSD::PackageRepository::Installed;
if (@ARGV == 0) {
@@ -1028,6 +975,7 @@ sub process_parameters
sub finish_display
{
+ my ($self, $state) = @_;
OpenBSD::Add::manpages_index($state);
@@ -1049,9 +997,65 @@ sub finish_display
inform_user_of_problems($state);
}
+sub handle_options
+{
+ my $self = shift;
+ my $state = $self->SUPER::handle_options('aruUzl:A:P:Q:', {},
+ 'pkg_add [-acIinqrsUuvxz] [-A arch] [-B pkg-destdir] [-D name[=value]]',
+ '[-L localbase] [-l file] [-P type] [-Q quick-destdir] pkg-name [...]');
+
+ $state->{do_faked} = 0;
+ $state->{arch} = $state->opt('A');
+
+ if (defined $state->opt('Q') and defined $state->opt('B')) {
+ Usage "-Q and -B are incompatible options";
+ }
+ if (defined $state->opt('Q') and defined $state->opt('r')) {
+ Usage "-r and -Q are incompatible options";
+ }
+ if ($state->opt('P')) {
+ if ($state->opt('P') eq 'cdrom') {
+ $state->{cdrom_only} = 1;
+ }
+ elsif ($state->opt('P') eq 'ftp') {
+ $state->{ftp_only} = 1;
+ }
+ else {
+ Usage "bad option: -P ".$state->opt('P');
+ }
+ }
+ if (defined $state->opt('Q')) {
+ $state->{destdir} = $state->opt('Q');
+ $state->{do_faked} = 1;
+ } elsif (defined $state->opt('B')) {
+ $state->{destdir} = $state->opt('B');
+ } elsif (defined $ENV{'PKG_PREFIX'}) {
+ $state->{destdir} = $ENV{'PKG_PREFIX'};
+ }
+ if (defined $state->{destdir}) {
+ $state->{destdir}.='/';
+ $ENV{'PKG_DESTDIR'} = $state->{destdir};
+ } else {
+ $state->{destdir} = '';
+ delete $ENV{'PKG_DESTDIR'};
+ }
+
+
+ $state->{automatic} = $state->opt('a');
+ $state->{hard_replace} = $state->opt('r');
+ $state->{newupdates} = $state->opt('u') || $state->opt('U');
+ $state->{allow_replacing} = $state->{hard_replace} ||
+ $state->{newupdates};
-framework(
-sub {
+ if (@ARGV == 0 && !$state->opt('u') && !$state->opt('l')) {
+ Usage "Missing pkgname";
+ }
+ return $state;
+}
+
+sub main
+{
+ my ($self, $state) = @_;
if ($state->{allow_replacing}) {
$state->progress->set_header("Checking packages");
do_quirks($state);
@@ -1068,5 +1072,12 @@ sub {
$state->quirks->tweak_list(\@todo2, $state);
};
}
-});
+}
+
+
+sub new_state
+{
+ return OpenBSD::PkgAdd::State->new;
+}
+1;
diff --git a/usr.sbin/pkg_add/pkg_create b/usr.sbin/pkg_add/OpenBSD/PkgCreate.pm
index c91a3bececa..6200916674d 100644
--- a/usr.sbin/pkg_add/pkg_create
+++ b/usr.sbin/pkg_add/OpenBSD/PkgCreate.pm
@@ -1,6 +1,6 @@
#! /usr/bin/perl
# ex:ts=8 sw=4:
-# $OpenBSD: pkg_create,v 1.139 2010/05/10 09:17:55 espie Exp $
+# $OpenBSD: PkgCreate.pm,v 1.1 2010/06/04 13:19:39 espie Exp $
#
# Copyright (c) 2003-2010 Marc Espie <espie@openbsd.org>
#
@@ -19,30 +19,17 @@
use strict;
use warnings;
-use OpenBSD::PackingList;
-use OpenBSD::PackageInfo;
-use OpenBSD::Getopt;
-use OpenBSD::Temp;
-use OpenBSD::Error;
-use OpenBSD::Ustar;
-use OpenBSD::ArcCheck;
-use OpenBSD::Paths;
-use OpenBSD::Subst;
-use OpenBSD::ProgressMeter;
-use File::Basename;
+use OpenBSD::AddCreateDelete;
-package OpenBSD::State;
-sub new
-{
- my $class = shift;
- bless {progress => OpenBSD::ProgressMeter->new,
- errors => 0, stash => {}}, $class;
-}
+package OpenBSD::PkgCreate::State;
+our @ISA = qw(OpenBSD::AddCreateDelete::State);
-sub progress
+sub init
{
my $self = shift;
- return $self->{progress};
+
+ $self->{stash} = {};
+ $self->SUPER::init(@_);
}
sub stash
@@ -54,10 +41,24 @@ sub stash
sub error
{
my $self = shift;
- $self->{errors}++;
- $self->progress->errprint(@_, "\n");
+ $self->{bad}++;
+ $self->errsay(@_);
}
+package OpenBSD::PkgCreate;
+
+use OpenBSD::PackingList;
+use OpenBSD::PackageInfo;
+use OpenBSD::Getopt;
+use OpenBSD::Temp;
+use OpenBSD::Error;
+use OpenBSD::Ustar;
+use OpenBSD::ArcCheck;
+use OpenBSD::Paths;
+use OpenBSD::Subst;
+use OpenBSD::ProgressMeter;
+use File::Basename;
+
# Extra stuff needed to archive files
package OpenBSD::PackingElement;
sub create_package
@@ -65,7 +66,7 @@ sub create_package
my ($self, $state) = @_;
$self->archive($state);
- if ($state->{verbose}) {
+ if ($state->verbose) {
$self->comment_create_package;
}
}
@@ -261,7 +262,7 @@ sub archive
my $o = $self->prepare_for_archival($state);
- $o->write unless $state->{errors};
+ $o->write unless $state->{bad};
}
sub pretend_to_archive
@@ -409,23 +410,12 @@ sub close
close($self->{fh});
}
-package main;
-
-my $state = OpenBSD::State->new;
-
-
-my $subst = OpenBSD::Subst->new;
-
-$state->{subst} = $subst;
-
-our ($opt_p, $opt_f, $opt_d, $opt_v,
- $opt_s, $opt_A, $opt_L,
- $opt_M, $opt_U, $opt_P, $opt_W, $opt_n,
- $opt_B, $opt_q, $opt_Q, $opt_x);
+package OpenBSD::PkgCreate;
+our @ISA = qw(OpenBSD::AddCreateDelete);
sub deduce_name
{
- my ($o, $frag, $not) = @_;
+ my ($state, $o, $frag, $not) = @_;
my $noto = $o;
my $nofrag = "no-$frag";
@@ -439,10 +429,10 @@ sub deduce_name
die "Missing fragments for $frag: $o and $noto don't exist";
}
if ($not) {
- print "Switching to $noto\n" if !defined $opt_q;
+ print "Switching to $noto\n" if !defined $state->opt('q');
return $noto if -e $noto;
} else {
- print "Switching to $o\n" if !defined $opt_q;
+ print "Switching to $o\n" if !defined $state->opt('q');
return $o if -e $o;
}
return;
@@ -450,13 +440,14 @@ sub deduce_name
sub read_fragments
{
- my ($plist, $filename) = @_;
+ my ($state, $plist, $filename) = @_;
- my $stack = [];
- push(@$stack, MyFile->new($filename));
+ my $stack = [];
+ my $subst = $state->{subst};
+ push(@$stack, MyFile->new($filename));
- return $plist->read($stack,
- sub {
+ return $plist->read($stack,
+ sub {
my ($stack, $cont) = @_;
local $_;
while(my $file = pop @$stack) {
@@ -473,7 +464,7 @@ sub read_fragments
} else {
next GETLINE unless defined $not;
}
- my $newname = deduce_name($file->name, $frag, $not);
+ my $newname = deduce_name($state, $file->name, $frag, $not);
if (defined $newname) {
push(@$stack, $file);
$file = MyFile->new($newname);
@@ -490,13 +481,13 @@ sub read_fragments
&$cont($subst->do($_));
}
}
- }
+ }
);
}
sub add_special_file
{
- my ($plist, $name, $opt) = @_;
+ my ($subst, $plist, $name, $opt) = @_;
if (defined $opt) {
my $o = OpenBSD::PackingElement::File->add($plist, $name);
$subst->copy($opt, $o->fullname) if defined $o->fullname;
@@ -505,7 +496,7 @@ sub add_special_file
sub add_description
{
- my ($plist, $name, $opt_d) = @_;
+ my ($subst, $plist, $name, $opt_d) = @_;
my $o = OpenBSD::PackingElement::FDESC->add($plist, $name);
my $comment = $subst->value('COMMENT');
if (defined $comment) {
@@ -551,293 +542,290 @@ my $regen_package = 0;
my $sign_only = 0;
my ($cert, $privkey);
+sub parse_and_run
+{
+ my $self = shift;
-set_usage(
-'pkg_create [-nQqvx] [-A arches] [-B pkg-destdir] [-D name[=value]]',
-'[-L localbase] [-M displayfile] [-P pkg-dependency]',
-'[-s x509 -s cert -s priv] [-U undisplayfile] [-W wantedlib]',
-'-d desc -D COMMENT=value -f packinglist -p prefix pkg-name');
-
-my $plist = new OpenBSD::PackingList;
-try {
- getopts('p:f:d:vM:U:hs:A:L:B:D:P:W:nqQx',
- {'D' =>
- sub {
- $subst->parse_option(shift);
- },
- 'f' =>
- sub {
- push(@contents, shift);
- },
- 'h' => sub { Usage(); },
- 'P' => sub {
- my $d = shift;
- $dependencies{$d} = 1;
- },
- 'W' => sub {
- my $w = shift;
- $wantlib{$w} = 1;
- },
- 's' => sub {
- push(@signature_params, shift);
+ my $state = OpenBSD::PkgCreate::State->new;
+ my $plist = new OpenBSD::PackingList;
+
+ $state->{opt} = {
+ 'f' =>
+ sub {
+ push(@contents, shift);
+ },
+ 'P' => sub {
+ my $d = shift;
+ $dependencies{$d} = 1;
+ },
+ 'W' => sub {
+ my $w = shift;
+ $wantlib{$w} = 1;
+ },
+ 's' => sub {
+ push(@signature_params, shift);
+ }
+ };
+ $self->handle_options('p:f:d:M:U:s:A:L:B:P:W:qQ', $state,
+ 'pkg_create [-nQqvx] [-A arches] [-B pkg-destdir] [-D name[=value]]',
+ '[-L localbase] [-M displayfile] [-P pkg-dependency]',
+ '[-s x509 -s cert -s priv] [-U undisplayfile] [-W wantedlib]',
+ '-d desc -D COMMENT=value -f packinglist -p prefix pkg-name');
+
+ my $subst = $state->{subst};
+
+ if (@ARGV == 0) {
+ $regen_package = 1;
+ } elsif (@ARGV != 1) {
+ if (@contents || @signature_params == 0) {
+ Usage "Exactly one single package name is required: ",
+ join(' ', @ARGV);
}
- });
-} catchall {
- Usage($_);
-};
-
-$state->progress->setup($opt_x);
-$state->{verbose} = $opt_v;
-
-if (@ARGV == 0) {
- $regen_package = 1;
-} elsif (@ARGV != 1) {
- if (@contents || @signature_params == 0) {
- Usage "Exactly one single package name is required: ",
- join(' ', @ARGV);
}
-}
-
-try {
-
-if (@signature_params > 0) {
- if (@signature_params != 3 || $signature_params[0] ne 'x509' ||
- !-f $signature_params[1] || !-f $signature_params[2]) {
- Usage "Signature only works as -s x509 -s cert -s privkey";
- }
- $cert = $signature_params[1];
- $privkey = $signature_params[2];
-}
-if (defined $opt_Q) {
- $opt_q = 1;
-}
+ try {
-if (!@contents) {
if (@signature_params > 0) {
- $sign_only = 1;
- } else {
- Usage "Packing list required";
+ if (@signature_params != 3 || $signature_params[0] ne 'x509' ||
+ !-f $signature_params[1] || !-f $signature_params[2]) {
+ Usage "Signature only works as -s x509 -s cert -s privkey";
+ }
+ $cert = $signature_params[1];
+ $privkey = $signature_params[2];
}
-}
-my $cont = 0;
-if ($regen_package) {
- if (@contents != 1) {
- Usage "Exactly one single packing list is required";
- }
- if (-d $contents[0] && -f $contents[0].'/'.CONTENTS) {
- $plist->set_infodir($contents[0]);
- $contents[0] .= '/'.CONTENTS;
- } else {
- $plist->set_infodir(dirname($contents[0]));
- }
- $plist->fromfile($contents[0]) or
- Fatal "Can't read packing list $contents[0]";
-} elsif ($sign_only) {
- if ($opt_n) {
- Fatal "Can't pretend to sign existing packages";
+ if (defined $state->opt('Q')) {
+ $state->{opt}{q} = 1;
}
- for my $pkgname (@ARGV) {
- require OpenBSD::PackageLocator;
- require OpenBSD::x509;
- my $true_package = OpenBSD::PackageLocator->find($pkgname);
- die "No such package $pkgname" unless $true_package;
- my $dir = $true_package->info;
- my $plist = OpenBSD::PackingList->fromfile($dir.CONTENTS);
- $plist->set_infodir($dir);
- my $sig = OpenBSD::PackingElement::DigitalSignature->new_x509;
- $sig->add_object($plist);
- $sig->{b64sig} = OpenBSD::x509::compute_signature($plist,
- $cert, $privkey);
- $plist->save;
- my $tmp = OpenBSD::Temp::permanent_file(".", "pkg");
- open( my $outfh, "|-", OpenBSD::Paths->gzip, "-o", $tmp);
-
- my $wrarc = OpenBSD::Ustar->new($outfh, ".");
- $plist->copy_over($wrarc, $true_package);
- $wrarc->close;
- $true_package->wipe_info;
- unlink($plist->pkgname.".tgz");
- rename($tmp, $plist->pkgname.".tgz") or
- die "Can't create final signed package $!";
- }
- exit(0);
-} else {
- print "Creating package $ARGV[0]\n" if !(defined $opt_q) && $opt_v;
- if (!$opt_q) {
- $plist->set_infodir(OpenBSD::Temp->dir);
- }
- add_description($plist, DESC, $opt_d);
- add_special_file($plist, DISPLAY, $opt_M);
- add_special_file($plist, UNDISPLAY, $opt_U);
- if (defined $opt_p) {
- OpenBSD::PackingElement::Cwd->add($plist, $opt_p);
- } else {
- Usage "Prefix required";
- }
- for my $d (sort keys %dependencies) {
- OpenBSD::PackingElement::Dependency->add($plist, $d);
+ if (!@contents) {
+ if (@signature_params > 0) {
+ $sign_only = 1;
+ } else {
+ Usage "Packing list required";
+ }
}
- for my $w (sort keys %wantlib) {
- OpenBSD::PackingElement::Wantlib->add($plist, $w);
- }
+ my $cont = 0;
+ if ($regen_package) {
+ if (@contents != 1) {
+ Usage "Exactly one single packing list is required";
+ }
+ if (-d $contents[0] && -f $contents[0].'/'.CONTENTS) {
+ $plist->set_infodir($contents[0]);
+ $contents[0] .= '/'.CONTENTS;
+ } else {
+ $plist->set_infodir(dirname($contents[0]));
+ }
+ $plist->fromfile($contents[0]) or
+ Fatal "Can't read packing list $contents[0]";
+ } elsif ($sign_only) {
+ if ($state->not) {
+ Fatal "Can't pretend to sign existing packages";
+ }
+ for my $pkgname (@ARGV) {
+ require OpenBSD::PackageLocator;
+ require OpenBSD::x509;
+
+ my $true_package = OpenBSD::PackageLocator->find($pkgname);
+ die "No such package $pkgname" unless $true_package;
+ my $dir = $true_package->info;
+ my $plist = OpenBSD::PackingList->fromfile($dir.CONTENTS);
+ $plist->set_infodir($dir);
+ my $sig = OpenBSD::PackingElement::DigitalSignature->new_x509;
+ $sig->add_object($plist);
+ $sig->{b64sig} = OpenBSD::x509::compute_signature($plist,
+ $cert, $privkey);
+ $plist->save;
+ my $tmp = OpenBSD::Temp::permanent_file(".", "pkg");
+ open( my $outfh, "|-", OpenBSD::Paths->gzip, "-o", $tmp);
+
+ my $wrarc = OpenBSD::Ustar->new($outfh, ".");
+ $plist->copy_over($wrarc, $true_package);
+ $wrarc->close;
+ $true_package->wipe_info;
+ unlink($plist->pkgname.".tgz");
+ rename($tmp, $plist->pkgname.".tgz") or
+ die "Can't create final signed package $!";
+ }
+ exit(0);
+ } else {
+ print "Creating package $ARGV[0]\n" if !(defined $state->opt('q')) && $state->opt('v');
+ if (!$state->opt('q')) {
+ $plist->set_infodir(OpenBSD::Temp->dir);
+ }
+ add_description($subst, $plist, DESC, $state->opt('d'));
+ add_special_file($subst, $plist, DISPLAY, $state->opt('M'));
+ add_special_file($subst, $plist, UNDISPLAY, $state->opt('U'));
+ if (defined $state->opt('p')) {
+ OpenBSD::PackingElement::Cwd->add($plist, $state->opt('p'));
+ } else {
+ Usage "Prefix required";
+ }
+ for my $d (sort keys %dependencies) {
+ OpenBSD::PackingElement::Dependency->add($plist, $d);
+ }
- if (defined $opt_A) {
- OpenBSD::PackingElement::Arch->add($plist, $opt_A);
- }
+ for my $w (sort keys %wantlib) {
+ OpenBSD::PackingElement::Wantlib->add($plist, $w);
+ }
- if (defined $opt_L) {
- OpenBSD::PackingElement::LocalBase->add($plist, $opt_L);
- }
- if ($ARGV[0] =~ m|([^/]+)$|o) {
- my $pkgname = $1;
- $pkgname =~ s/\.tgz$//o;
- $plist->set_pkgname($pkgname);
- }
- my $fullpkgpath = $subst->value('FULLPKGPATH');
- my $cdrom = $subst->value('PERMIT_PACKAGE_CDROM') ||
- $subst->value('CDROM');;
- my $ftp = $subst->value('PERMIT_PACKAGE_FTP') ||
- $subst->value('FTP');
- if (defined $fullpkgpath || defined $cdrom || defined $ftp) {
- $fullpkgpath //= '';
- $cdrom //= 'no';
- $ftp //= 'no';
- $cdrom = 'yes' if $cdrom =~ m/^yes$/io;
- $ftp = 'yes' if $ftp =~ m/^yes$/io;
+ if (defined $state->opt('A')) {
+ OpenBSD::PackingElement::Arch->add($plist, $state->opt('A'));
+ }
- OpenBSD::PackingElement::ExtraInfo->add($plist,
- $fullpkgpath, $cdrom, $ftp);
- } else {
- Warn "Package without FULLPKGPATH\n";
- }
- unless (defined $opt_q && defined $opt_n) {
- if ($state->progress->set_header("reading plist")) {
- $state->progress->message;
+ if (defined $state->opt('L')) {
+ OpenBSD::PackingElement::LocalBase->add($plist, $state->opt('L'));
+ }
+ if ($ARGV[0] =~ m|([^/]+)$|o) {
+ my $pkgname = $1;
+ $pkgname =~ s/\.tgz$//o;
+ $plist->set_pkgname($pkgname);
+ }
+ my $fullpkgpath = $subst->value('FULLPKGPATH');
+ my $cdrom = $subst->value('PERMIT_PACKAGE_CDROM') ||
+ $subst->value('CDROM');;
+ my $ftp = $subst->value('PERMIT_PACKAGE_FTP') ||
+ $subst->value('FTP');
+ if (defined $fullpkgpath || defined $cdrom || defined $ftp) {
+ $fullpkgpath //= '';
+ $cdrom //= 'no';
+ $ftp //= 'no';
+ $cdrom = 'yes' if $cdrom =~ m/^yes$/io;
+ $ftp = 'yes' if $ftp =~ m/^yes$/io;
+
+ OpenBSD::PackingElement::ExtraInfo->add($plist,
+ $fullpkgpath, $cdrom, $ftp);
} else {
- $| = 1;
- print "Reading plist...";
- $cont = 1;
+ Warn "Package without FULLPKGPATH\n";
+ }
+ unless (defined $state->opt('q') && defined $state->opt('n')) {
+ if ($state->progress->set_header("reading plist")) {
+ $state->progress->message;
+ } else {
+ $| = 1;
+ print "Reading plist...";
+ $cont = 1;
+ }
+ }
+ for my $contentsfile (@contents) {
+ read_fragments($state, $plist, $contentsfile) or
+ Fatal "Can't read packing list $contentsfile";
}
}
- for my $contentsfile (@contents) {
- read_fragments($plist, $contentsfile) or
- Fatal "Can't read packing list $contentsfile";
- }
-}
-
-
-my $base = '/';
-if (defined $opt_B) {
- $base = $opt_B;
-} elsif (defined $ENV{'PKG_PREFIX'}) {
- $base = $ENV{'PKG_PREFIX'};
-}
-$state->{base} = $base;
-unless (defined $opt_q && defined $opt_n) {
- if ($cont) {
- print "\nChecksumming...";
- } else {
- $state->progress->set_header("checksumming");
- }
- if ($regen_package) {
- $state->progress->visit_with_count($plist, 'verify_checksum', $state);
- } else {
- my $p2 = OpenBSD::PackingList->new;
- $state->progress->visit_with_count($plist, 'makesum_plist', $p2, $state);
- $p2->set_infodir($plist->infodir);
- $plist = $p2;
+ my $base = '/';
+ if (defined $state->opt('B')) {
+ $base = $state->opt('B');
+ } elsif (defined $ENV{'PKG_PREFIX'}) {
+ $base = $ENV{'PKG_PREFIX'};
}
- if ($cont) {
- print "\n";
- }
-}
-if (!defined $plist->{name}) {
- $state->error("Can't write unnamed packing list");
- exit 1;
-}
+ $state->{base} = $base;
-if (defined $opt_q) {
- if (defined $opt_Q) {
- $plist->print_file;
- } else {
- $plist->write(\*STDOUT);
+ unless (defined $state->opt('q') && defined $state->opt('n')) {
+ if ($cont) {
+ print "\nChecksumming...";
+ } else {
+ $state->progress->set_header("checksumming");
+ }
+ if ($regen_package) {
+ $state->progress->visit_with_count($plist, 'verify_checksum', $state);
+ } else {
+ my $p2 = OpenBSD::PackingList->new;
+ $state->progress->visit_with_count($plist, 'makesum_plist', $p2, $state);
+ $p2->set_infodir($plist->infodir);
+ $plist = $p2;
+ }
+ if ($cont) {
+ print "\n";
+ }
}
- exit 0 if defined $opt_n;
-}
-
-if ($plist->{deprecated}) {
- $state->error("Error: found obsolete constructs");
- exit 1;
-}
-$plist->avert_duplicates_and_other_checks($state);
-$state->{stash} = {};
+ if (!defined $plist->{name}) {
+ $state->error("Can't write unnamed packing list");
+ exit 1;
+ }
-if ($state->{errors} && $subst->empty('REGRESSION_TESTING')) {
- exit 1;
-}
-$state->{errors} = 0;
+ if (defined $state->opt('q')) {
+ if (defined $state->opt('Q')) {
+ $plist->print_file;
+ } else {
+ $plist->write(\*STDOUT);
+ }
+ exit 0 if defined $state->opt('n');
+ }
-if (defined $cert) {
- my $sig = OpenBSD::PackingElement::DigitalSignature->new_x509;
- $sig->add_object($plist);
- require OpenBSD::x509;
- $sig->{b64sig} = OpenBSD::x509::compute_signature($plist, $cert, $privkey);
- $plist->save if $regen_package;
-}
+ if ($plist->{deprecated}) {
+ $state->error("Error: found obsolete constructs");
+ exit 1;
+ }
-my $wname;
-if ($regen_package) {
- $wname = $plist->pkgname.".tgz";
-} else {
- $plist->save or Fatal "Can't write packing list";
- $wname = $ARGV[0];
-}
+ $plist->avert_duplicates_and_other_checks($state);
+ $state->{stash} = {};
-if ($opt_n) {
- $state->{archive} = OpenBSD::Ustar->new(undef, $plist->infodir);
- $plist->pretend_to_archive($state);
-} else {
- print "Creating gzip'd tar ball in '$wname'\n" if $opt_v;
- my $h = sub {
- unlink $wname;
- my $caught = shift;
- $SIG{$caught} = 'DEFAULT';
- kill $caught, $$;
- };
+ if ($state->{bad} && $subst->empty('REGRESSION_TESTING')) {
+ exit 1;
+ }
+ $state->{bad} = 0;
- local $SIG{'INT'} = $h;
- local $SIG{'QUIT'} = $h;
- local $SIG{'HUP'} = $h;
- local $SIG{'KILL'} = $h;
- local $SIG{'TERM'} = $h;
- open(my $fh, "|-", OpenBSD::Paths->gzip, "-f", "-o", $wname);
- $state->{archive} = OpenBSD::Ustar->new($fh, $plist->infodir);
+ if (defined $cert) {
+ my $sig = OpenBSD::PackingElement::DigitalSignature->new_x509;
+ $sig->add_object($plist);
+ require OpenBSD::x509;
+ $sig->{b64sig} = OpenBSD::x509::compute_signature($plist, $cert, $privkey);
+ $plist->save if $regen_package;
+ }
- if ($cont) {
- print "Archiving...";
+ my $wname;
+ if ($regen_package) {
+ $wname = $plist->pkgname.".tgz";
} else {
- $state->progress->set_header("archiving");
+ $plist->save or Fatal "Can't write packing list";
+ $wname = $ARGV[0];
}
- $state->progress->visit_with_size($plist, 'create_package', $state);
- if ($cont) {
- print "\n";
+
+ if ($state->opt('n')) {
+ $state->{archive} = OpenBSD::Ustar->new(undef, $plist->infodir);
+ $plist->pretend_to_archive($state);
+ } else {
+ print "Creating gzip'd tar ball in '$wname'\n" if $state->opt('v');
+ my $h = sub {
+ unlink $wname;
+ my $caught = shift;
+ $SIG{$caught} = 'DEFAULT';
+ kill $caught, $$;
+ };
+
+ local $SIG{'INT'} = $h;
+ local $SIG{'QUIT'} = $h;
+ local $SIG{'HUP'} = $h;
+ local $SIG{'KILL'} = $h;
+ local $SIG{'TERM'} = $h;
+ open(my $fh, "|-", OpenBSD::Paths->gzip, "-f", "-o", $wname);
+ $state->{archive} = OpenBSD::Ustar->new($fh, $plist->infodir);
+
+ if ($cont) {
+ print "Archiving...";
+ } else {
+ $state->progress->set_header("archiving");
+ }
+ $state->progress->visit_with_size($plist, 'create_package', $state);
+ if ($cont) {
+ print "\n";
+ }
+ $state->progress->clear;
+ $state->{archive}->close;
+ if ($state->{bad}) {
+ unlink($wname);
+ exit(1);
+ }
}
- $state->progress->clear;
- $state->{archive}->close;
- if ($state->{errors}) {
- unlink($wname);
+ } catch {
+ print STDERR "$0: $_\n";
exit(1);
- }
+ };
}
-} catch {
- print STDERR "$0: $_\n";
- exit(1);
-};
+
+1;
diff --git a/usr.sbin/pkg_add/pkg_delete b/usr.sbin/pkg_add/OpenBSD/PkgDelete.pm
index fefb945016c..cf90d48909a 100644
--- a/usr.sbin/pkg_add/pkg_delete
+++ b/usr.sbin/pkg_add/OpenBSD/PkgDelete.pm
@@ -1,6 +1,6 @@
#!/usr/bin/perl
# ex:ts=8 sw=4:
-# $OpenBSD: pkg_delete,v 1.134 2010/05/10 09:17:55 espie Exp $
+# $OpenBSD: PkgDelete.pm,v 1.1 2010/06/04 13:19:39 espie Exp $
#
# Copyright (c) 2003-2010 Marc Espie <espie@openbsd.org>
#
@@ -21,8 +21,8 @@ use warnings;
use OpenBSD::AddDelete;
-package OpenBSD::State;
-our @ISA=(qw(OpenBSD::UI));
+package OpenBSD::PkgDelete::State;
+our @ISA = qw(OpenBSD::AddDelete::State);
sub todo
{
@@ -30,8 +30,8 @@ sub todo
return $state->{todo};
}
-package OpenBSD::AddDelete;
-our ($state, %defines, $bad, $opt_B);
+package OpenBSD::PkgDelete;
+our @ISA = qw(OpenBSD::AddDelete);
use OpenBSD::PackingList;
use OpenBSD::RequiredBy;
@@ -39,26 +39,6 @@ use OpenBSD::Delete;
use OpenBSD::PackageInfo;
use OpenBSD::UpdateSet;
-handle_options('chxDnq', {},
- 'pkg_delete [-cIinqsvx] [-B pkg-destdir] [-D name[=value]] pkg-name [...]');
-
-local $SIG{'INFO'} = sub { $state->status->print($state); };
-$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/\/$/o;
-}
-$ENV{'PKG_DESTDIR'} = $opt_B;
-
-$state->{destdir} = $opt_B;
-if ($opt_B eq '') {
- $state->{destdirname} = '';
-} else {
- $state->{destdirname} = '${PKG_DESTDIR}';
-}
-
-$ENV{'PKG_DELETE_EXTRA'} = $state->{extra} ? "Yes" : "No";
-
my %done;
my $removed;
@@ -69,14 +49,16 @@ my @todo;
sub process_parameters
{
+ my ($self, $state) = @_;
OpenBSD::PackageInfo::solve_installed_names(\@ARGV, \@realnames,
"(removing them all)", $state);
@todo = OpenBSD::RequiredBy->compute_closure(@realnames);
if (@todo > @realnames) {
- my $details = $state->verbose >= 2 || $defines{verbosedeps};
- my $show = sub {
+ my $details = $state->verbose >= 2 ||
+ $state->defines('verbosedeps');
+ my $show = sub {
my ($p, $d) = @_;
$state->say("Can't remove ", join(' ', @$p),
" without also removing:\n",
@@ -102,11 +84,11 @@ sub process_parameters
}
}
my $them = @todo > 1 ? 'them' : 'it';
- if ($defines{dependencies} or
+ if ($state->defines('dependencies') or
$state->confirm("Do you want to remove $them as well", 0)) {
$state->say("(removing $them as well)");
} else {
- $bad = 1;
+ $state->{bad}++;
}
}
}
@@ -115,8 +97,31 @@ sub finish_display
{
}
-framework(
-sub {
+sub handle_options
+{
+ my $self = shift;
+ my $state = $self->SUPER::handle_options('', {},
+ 'pkg_delete [-cIinqsvx] [-B pkg-destdir] [-D name[=value]] pkg-name [...]');
+
+ my $base = $state->opt('B') // $ENV{'PKG_DESTDIR'} // '';
+ if ($base ne '') {
+ $base.='/' unless $base =~ m/\/$/o;
+ }
+ $ENV{'PKG_DESTDIR'} = $base;
+
+ $state->{destdir} = $base;
+ if ($base eq '') {
+ $state->{destdirname} = '';
+ } else {
+ $state->{destdirname} = '${PKG_DESTDIR}';
+ }
+ return $state;
+}
+
+sub main
+{
+ my ($self, $state) = @_;
+
# and finally, handle the removal
do {
$removed = 0;
@@ -136,7 +141,7 @@ sub {
}
my $r = OpenBSD::RequiredBy->new($pkgname);
if ($r->list > 0) {
- if ($defines{baddepend}) {
+ if ($state->defines('baddepend')) {
for my $p ($r->list) {
if ($done{$p}) {
$r->delete($p);
@@ -164,4 +169,11 @@ sub {
$removed++;
}
} while ($removed);
-});
+}
+
+sub new_state
+{
+ return OpenBSD::PkgDelete::State->new;
+}
+
+1;
diff --git a/usr.sbin/pkg_add/pkg_info b/usr.sbin/pkg_add/OpenBSD/PkgInfo.pm
index 52ca8b1b366..c3a660cbaaf 100644
--- a/usr.sbin/pkg_add/pkg_info
+++ b/usr.sbin/pkg_add/OpenBSD/PkgInfo.pm
@@ -1,6 +1,6 @@
#! /usr/bin/perl
# ex:ts=8 sw=4:
-# $OpenBSD: pkg_info,v 1.94 2010/05/10 09:17:55 espie Exp $
+# $OpenBSD: PkgInfo.pm,v 1.1 2010/06/04 13:19:39 espie Exp $
#
# Copyright (c) 2003-2010 Marc Espie <espie@openbsd.org>
#
@@ -19,11 +19,6 @@
use strict;
use warnings;
-use OpenBSD::PackageInfo;
-use OpenBSD::PackageName;
-use OpenBSD::Getopt;
-use OpenBSD::Error;
-
package OpenBSD::PackingElement;
sub dump_file
{
@@ -62,7 +57,12 @@ sub hunt_file
}
}
-package main;
+package OpenBSD::PkgInfo;
+use OpenBSD::PackageInfo;
+use OpenBSD::PackageName;
+use OpenBSD::Getopt;
+use OpenBSD::Error;
+
my $total_size = 0;
my $pkgs = 0;
@@ -407,137 +407,141 @@ sub print_info
}
}
-set_usage('pkg_info [-AaCcdfIKLMmPqRSstUv] [-E filename] [-e pkg-name] [-l str] [-Q query] [pkg-name] [...]');
+sub parse_and_run
+{
+ set_usage('pkg_info [-AaCcdfIKLMmPqRSstUv] [-E filename] [-e pkg-name] [-l str] [-Q query] [pkg-name] [...]');
+
+ my %defines;
+ my $locked;
+ try {
+ getopts('cCdfF:hIKLmPQ:qRsSUve:E:Ml:aAt',
+ {'e' =>
+ sub {
+ my $pat = shift;
+ my @list;
+ lock_db(1, $opt_q) unless $defines{nolock};
+ $locked = 1;
+ if ($pat =~ m/\//o) {
+ @list = find_by_path($pat);
+ } else {
+ @list = find_by_spec($pat);
+ }
+ if (@list == 0) {
+ $exit_code = 1;
+ $error_e = 1;
+ }
+ push(@ARGV, @list);
+ $terse = 1;
+ },
+ 'F' => sub {
+ for my $o (split /\,/o, shift) {
+ $defines{$o} = 1;
+ }
+ },
+ 'h' => sub { Usage(); },
+ 'E' =>
+ sub {
+ require File::Spec;
+
+ push(@sought_files, File::Spec->rel2abs(shift));
-my %defines;
-my $locked;
-try {
- getopts('cCdfF:hIKLmPQ:qRsSUve:E:Ml:aAt',
- {'e' =>
- sub {
- my $pat = shift;
- my @list;
- lock_db(1, $opt_q) unless $defines{nolock};
- $locked = 1;
- if ($pat =~ m/\//o) {
- @list = find_by_path($pat);
- } else {
- @list = find_by_spec($pat);
- }
- if (@list == 0) {
- $exit_code = 1;
- $error_e = 1;
- }
- push(@ARGV, @list);
- $terse = 1;
- },
- 'F' => sub {
- for my $o (split /\,/o, shift) {
- $defines{$o} = 1;
}
- },
- 'h' => sub { Usage(); },
- 'E' =>
- sub {
- require File::Spec;
-
- push(@sought_files, File::Spec->rel2abs(shift));
-
- }
- });
-} catchall {
- Usage($_);
-};
-
-lock_db(1, $opt_q) unless $locked or $defines{nolock};
-
-unless ($opt_c || $opt_M || $opt_U || $opt_d || $opt_f || $opt_I ||
- $opt_L || $opt_R || $opt_s ||
- $opt_S || $opt_P || $terse) {
- if (@ARGV == 0) {
- $opt_I = $opt_a = 1;
- } else {
- $opt_c = $opt_d = $opt_M = $opt_R = 1;
+ });
+ } catchall {
+ Usage($_);
+ };
+
+ lock_db(1, $opt_q) unless $locked or $defines{nolock};
+
+ unless ($opt_c || $opt_M || $opt_U || $opt_d || $opt_f || $opt_I ||
+ $opt_L || $opt_R || $opt_s ||
+ $opt_S || $opt_P || $terse) {
+ if (@ARGV == 0) {
+ $opt_I = $opt_a = 1;
+ } else {
+ $opt_c = $opt_d = $opt_M = $opt_R = 1;
+ }
}
-}
-if ($opt_Q) {
- require OpenBSD::PackageLocator;
- require OpenBSD::Search;
+ if ($opt_Q) {
+ require OpenBSD::PackageLocator;
+ require OpenBSD::Search;
- print "PKG_PATH=$ENV{PKG_PATH}\n" if $opt_v;
- my $partial = OpenBSD::Search::PartialStem->new($opt_Q);
+ print "PKG_PATH=$ENV{PKG_PATH}\n" if $opt_v;
+ my $partial = OpenBSD::Search::PartialStem->new($opt_Q);
- my $r = OpenBSD::PackageLocator->match_locations($partial);
+ my $r = OpenBSD::PackageLocator->match_locations($partial);
- for my $p (sort map {$_->name} @$r) {
- print $p, is_installed($p) ? " (installed)" : "" , "\n";
- }
+ for my $p (sort map {$_->name} @$r) {
+ print $p, is_installed($p) ? " (installed)" : "" , "\n";
+ }
- exit 0;
-}
+ exit 0;
+ }
-if ($opt_v) {
- $opt_c = $opt_d = $opt_f = $opt_M =
- $opt_U = $opt_R = $opt_s = $opt_S = 1;
-}
+ if ($opt_v) {
+ $opt_c = $opt_d = $opt_f = $opt_M =
+ $opt_U = $opt_R = $opt_s = $opt_S = 1;
+ }
-if (!defined $opt_l) {
- $opt_l = "";
-}
+ if (!defined $opt_l) {
+ $opt_l = "";
+ }
-if ($opt_K && !$opt_L) {
- Usage "-K only makes sense with -L";
-}
+ if ($opt_K && !$opt_L) {
+ Usage "-K only makes sense with -L";
+ }
-if (@ARGV == 0 && !$opt_a && !$opt_A) {
- Usage "Missing package name(s)" unless $terse || $opt_q;
-}
+ if (@ARGV == 0 && !$opt_a && !$opt_A) {
+ Usage "Missing package name(s)" unless $terse || $opt_q;
+ }
-if (@ARGV > 0 && ($opt_a || $opt_A)) {
- Usage "Can't specify package name(s) with -a";
-}
+ if (@ARGV > 0 && ($opt_a || $opt_A)) {
+ Usage "Can't specify package name(s) with -a";
+ }
-if (@ARGV > 0 && $opt_t) {
- Usage "Can't specify package name(s) with -t";
-}
+ if (@ARGV > 0 && $opt_t) {
+ Usage "Can't specify package name(s) with -t";
+ }
-if (@ARGV > 0 && $opt_m) {
- Usage "Can't specify package name(s) with -m";
-}
+ if (@ARGV > 0 && $opt_m) {
+ Usage "Can't specify package name(s) with -m";
+ }
-if (@ARGV == 0 && !$error_e) {
- @ARGV = sort(installed_packages(defined $opt_A ? 0 : 1));
- if ($opt_t) {
- require OpenBSD::RequiredBy;
- @ARGV = grep { OpenBSD::RequiredBy->new($_)->list == 0 } @ARGV;
+ if (@ARGV == 0 && !$error_e) {
+ @ARGV = sort(installed_packages(defined $opt_A ? 0 : 1));
+ if ($opt_t) {
+ require OpenBSD::RequiredBy;
+ @ARGV = grep { OpenBSD::RequiredBy->new($_)->list == 0 } @ARGV;
+ }
}
-}
-if (@sought_files) {
- my %hash = map { ($_, []) } @sought_files;
- @ARGV = filter_files(\%hash, @ARGV);
- for my $f (@sought_files) {
- my $l = $hash{$f};
- if (@$l) {
- print "$f: ", join(',', @$l), "\n" unless $opt_q;
- } else {
- $exit_code = 1;
+ if (@sought_files) {
+ my %hash = map { ($_, []) } @sought_files;
+ @ARGV = filter_files(\%hash, @ARGV);
+ for my $f (@sought_files) {
+ my $l = $hash{$f};
+ if (@$l) {
+ print "$f: ", join(',', @$l), "\n" unless $opt_q;
+ } else {
+ $exit_code = 1;
+ }
}
}
-}
-if ($opt_m) {
- @ARGV = manual_filter(@ARGV);
-}
+ if ($opt_m) {
+ @ARGV = manual_filter(@ARGV);
+ }
-for my $pkg (@ARGV) {
- if ($terse && !$opt_q) {
- print $opt_l, $pkg, "\n";
+ for my $pkg (@ARGV) {
+ if ($terse && !$opt_q) {
+ print $opt_l, $pkg, "\n";
+ }
+ find_pkg($pkg, \&print_info);
}
- find_pkg($pkg, \&print_info);
-}
-if ($pkgs > 1) {
- print "Total size: $total_size\n";
+ if ($pkgs > 1) {
+ print "Total size: $total_size\n";
+ }
+ exit($exit_code);
}
-exit($exit_code);
+1;
diff --git a/usr.sbin/pkg_add/OpenBSD/ProgressMeter.pm b/usr.sbin/pkg_add/OpenBSD/ProgressMeter.pm
index 9aa2e118d32..458aa06cd08 100644
--- a/usr.sbin/pkg_add/OpenBSD/ProgressMeter.pm
+++ b/usr.sbin/pkg_add/OpenBSD/ProgressMeter.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: ProgressMeter.pm,v 1.31 2010/05/10 09:17:55 espie Exp $
+# $OpenBSD: ProgressMeter.pm,v 1.32 2010/06/04 13:19:39 espie Exp $
#
# Copyright (c) 2010 Marc Espie <espie@openbsd.org>
#
@@ -26,8 +26,8 @@ sub new
sub setup
{
- my ($self, $opt_x) = @_;
- if (!$opt_x && -t STDOUT) {
+ my ($self, $opt_x, $opt_m) = @_;
+ if ($opt_m || (!$opt_x && -t STDOUT)) {
require OpenBSD::ProgressMeter::Term;
bless $self, "OpenBSD::ProgressMeter::Term";
$self->init;
diff --git a/usr.sbin/pkg_add/OpenBSD/ProgressMeter/Term.pm b/usr.sbin/pkg_add/OpenBSD/ProgressMeter/Term.pm
index 1791fca25a5..72f0490c6a3 100644
--- a/usr.sbin/pkg_add/OpenBSD/ProgressMeter/Term.pm
+++ b/usr.sbin/pkg_add/OpenBSD/ProgressMeter/Term.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Term.pm,v 1.3 2010/05/10 09:17:55 espie Exp $
+# $OpenBSD: Term.pm,v 1.4 2010/06/04 13:19:39 espie Exp $
#
# Copyright (c) 2004-2007 Marc Espie <espie@openbsd.org>
#
@@ -229,7 +229,8 @@ sub next
sub ntogo
{
- &OpenBSD::UI::ntogo_string;
+ my ($self, $state, $offset) = @_;
+ return $state->ntogo_string($offset);
}
sub compute_size
diff --git a/usr.sbin/pkg_add/OpenBSD/Replace.pm b/usr.sbin/pkg_add/OpenBSD/Replace.pm
index 079371757b2..6ab0516ea25 100644
--- a/usr.sbin/pkg_add/OpenBSD/Replace.pm
+++ b/usr.sbin/pkg_add/OpenBSD/Replace.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Replace.pm,v 1.71 2010/05/10 09:17:55 espie Exp $
+# $OpenBSD: Replace.pm,v 1.72 2010/06/04 13:19:39 espie Exp $
#
# Copyright (c) 2004-2010 Marc Espie <espie@openbsd.org>
#
@@ -203,7 +203,7 @@ sub is_set_safe
{
my ($set, $state) = @_;
- if ($state->{defines}->{update} && !$state->verbose) {
+ if ($state->defines('update') && !$state->verbose) {
return 1;
}
@@ -217,7 +217,7 @@ sub is_set_safe
}
return 1 if $ok;
- if ($state->{defines}->{update}) {
+ if ($state->defines('update')) {
$state->errsay("Forcing update");
return 1;
} elsif ($state->{interactive}) {
diff --git a/usr.sbin/pkg_add/OpenBSD/Update.pm b/usr.sbin/pkg_add/OpenBSD/Update.pm
index b36cca1ed88..2b2a082a88d 100644
--- a/usr.sbin/pkg_add/OpenBSD/Update.pm
+++ b/usr.sbin/pkg_add/OpenBSD/Update.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Update.pm,v 1.135 2010/05/10 09:17:55 espie Exp $
+# $OpenBSD: Update.pm,v 1.136 2010/06/04 13:19:39 espie Exp $
#
# Copyright (c) 2004-2010 Marc Espie <espie@openbsd.org>
#
@@ -135,7 +135,7 @@ sub process_handle
return 1;
}
}
- if (!$state->{defines}->{downgrade}) {
+ if (!$state->defines('downgrade')) {
push(@search, OpenBSD::Search::FilterLocation->more_recent_than($sname, \$oldfound));
}
push(@search, OpenBSD::Search::FilterLocation->new(
@@ -164,7 +164,7 @@ sub process_handle
next;
}
my $r = $plist->signature->compare($p2->signature);
- if (defined $r && $r > 0 && !$state->{defines}{downgrade}) {
+ if (defined $r && $r > 0 && !$state->defines('downgrade')) {
$oldfound = 1;
next;
}
@@ -176,7 +176,7 @@ sub process_handle
return \@l2;
}));
- if (!$state->{defines}->{allversions}) {
+ if (!$state->defines('allversions')) {
push(@search, OpenBSD::Search::FilterLocation->keep_most_recent);
}
@@ -314,7 +314,7 @@ sub stem2location
{
my ($self, $locator, $name, $state, $is_quirks) = @_;
my $l = $locator->match_locations(OpenBSD::Search::Stem->new($name));
- if (@$l > 1 && !$state->{defines}->{allversions}) {
+ if (@$l > 1 && !$state->defines('allversions')) {
$l = OpenBSD::Search::FilterLocation->keep_most_recent->filter_locations($l);
}
return $state->choose_location($name, $l, $is_quirks);
diff --git a/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm b/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm
index e17fd345cfd..4cc0f94c933 100644
--- a/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm
+++ b/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: UpdateSet.pm,v 1.55 2010/05/10 09:17:55 espie Exp $
+# $OpenBSD: UpdateSet.pm,v 1.56 2010/06/04 13:19:39 espie Exp $
#
# Copyright (c) 2007-2010 Marc Espie <espie@openbsd.org>
#
@@ -307,7 +307,7 @@ sub validate_plists
$state->vstat->tally;
# okay, let's retry the other way around if we haven't yet
if (!defined $state->{delete_first}) {
- if ($state->{defines}->{deletefirst} ||
+ if ($state->defines('deletefirst') ||
$state->confirm("Delete older packages first", 0)) {
$state->{delete_first} = 1;
$state->vstat->drop_changes;
diff --git a/usr.sbin/pkg_add/pkg b/usr.sbin/pkg_add/pkg
index ee4c327c40c..1d83e9cac87 100644
--- a/usr.sbin/pkg_add/pkg
+++ b/usr.sbin/pkg_add/pkg
@@ -1,8 +1,8 @@
#! /usr/bin/perl
# ex:ts=8 sw=4:
-# $OpenBSD: pkg,v 1.12 2010/05/10 09:17:54 espie Exp $
+# $OpenBSD: pkg,v 1.13 2010/06/04 13:19:39 espie Exp $
#
-# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
+# Copyright (c) 2010 Marc Espie <espie@openbsd.org>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
@@ -19,42 +19,27 @@
use strict;
use warnings;
-use Getopt::Std;
-
-sub check_dependencies($)
+sub run
{
- require OpenBSD::Search;
- require OpenBSD::PackageRepository::Installed;
- my $dependency = shift;
- my $m = OpenBSD::PackageRepository::Installed->new
- ->match_locations(OpenBSD::Search::PkgSpec->new($dependency));
- return (@$m != 0) ? 1 : 0;
+ my $cmd = shift;
+ my $module = "OpenBSD::Pkg\u$cmd";
+ eval "require $module;";
+ if ($@) {
+ die $@;
+ }
+ $module->parse_and_run;
}
+my @l = qw(add create delete info);
-# Pass this off to the old package commands
-my %opts;
-my %legacy = map +($_, 1), qw{add info delete create};
-if (@ARGV == 0) {
- die "needs arguments";
+for my $i (@l) {
+ if ($0 =~ m/\/?pkg_$i$/) {
+ run($i);
+ }
}
-getopts('v', \%opts);
-
-my $cmd = shift;
-
-if (defined $legacy{$cmd}) {
- if (defined $opts{'v'}) {
- unshift(@ARGV, '-v');
- }
- exec { "pkg_$cmd"} ("pkg_$cmd", @ARGV);
-} elsif ($cmd eq 'dependencies') {
- my $sub = shift;
- if ($sub eq 'check') {
- if (check_dependencies(shift)) {
- exit(0);
- } else {
- exit(1);
- }
+for my $i (@l) {
+ if ($ARGV[0] eq $i) {
+ shift;
+ run($i);
}
}
-die "Bad command $cmd";