#! /usr/bin/perl
# ex:ts=8 sw=4:
-# $OpenBSD: FwUpdate.pm,v 1.21 2017/03/25 22:26:44 sthen Exp $
+# $OpenBSD: FwUpdate.pm,v 1.22 2017/05/29 12:28:54 espie Exp $
#
# Copyright (c) 2014 Marc Espie <espie@openbsd.org>
#
use warnings;
use OpenBSD::PkgAdd;
use OpenBSD::PackageRepository;
+use OpenBSD::PackageLocator;
+
+package OpenBSD::FwUpdate::Locator;
+our @ISA = qw(OpenBSD::PackageLocator);
+
+sub add_default
+{
+ my ($self, $state, $p) = @_;
+ my $path = $state->opt('p');
+ if (!$path) {
+ my $dir = OpenBSD::Paths->os_directory;
+ if (!defined $dir) {
+ $state->fatal("Couldn't find/parse OS version");
+ }
+ $path = "http://firmware.openbsd.org/firmware/$dir/";
+ }
+ $p->add(OpenBSD::PackageRepository->new($path, $state));
+}
package OpenBSD::FwUpdate::State;
our @ISA = qw(OpenBSD::PkgAdd::State);
-sub find_path
+sub locator
{
- my $state = shift;
- my $dir = OpenBSD::Paths->os_directory;
- if (defined $dir) {
- $state->{path} = "http://firmware.openbsd.org/firmware/$dir/";
- } else {
- $state->fatal("Couldn't find/parse OS version");
- }
+ return "OpenBSD::FwUpdate::Locator";
}
sub handle_options
$state->OpenBSD::State::handle_options('adinp:',
'[-adinv] [-D keyword] [-p path] [driver...]');
$state->{not} = $state->opt('n');
- if ($state->opt('p')) {
- $state->{path} = $state->opt('p');
- } else {
- $state->find_path;
- }
if ($state->opt('i')) {
$state->{not} = 1;
}
if ($state->opt('a') && @ARGV != 0) {
$state->usage;
}
- $state->{fw_repository} =
- OpenBSD::PackageRepository->new($state->{path}, $state);
$state->{fw_verbose} = $state->{v};
if ($state->{v}) {
$state->{v}--;
}
if ($state->{fw_verbose}) {
- $state->say("Path to firmware: #1", $state->{path});
+ $state->say("Path to firmware: #1",
+ $state->locator->printable_default_path($state));
}
$state->{subst}->add('NO_SCP', 1);
}
} else {
$set = $state->updateset->add_hints($pkgname);
}
- $set->add_repositories($state->{fw_repository});
return $set;
}
# ex:ts=8 sw=4:
-# $OpenBSD: PackageLocator.pm,v 1.109 2017/05/18 12:24:15 espie Exp $
+# $OpenBSD: PackageLocator.pm,v 1.110 2017/05/29 12:28:54 espie Exp $
#
# Copyright (c) 2003-2010 Marc Espie <espie@openbsd.org>
#
my $default_path;
-sub build_default_path
+sub add_default
{
- my ($self, $state) = @_;
- $default_path = OpenBSD::PackageRepositoryList->new($state);
-
+ my ($self, $state, $p) = @_;
my $w;
if (defined $ENV{TRUSTED_PKG_PATH}) {
$v =~ s/\:+$//o;
while (my $o = OpenBSD::PackageRepository->parse(\$v, $state)) {
$o->{trusted} = 1;
- $default_path->add($o);
+ $p->add($o);
}
} else {
$w = "./:installpath";
$w =~ s/^\:+//o;
$w =~ s/\:+$//o;
while (my $o = OpenBSD::PackageRepository->parse(\$w, $state)) {
- $default_path->add($o);
+ $p->add($o);
}
}
}
+sub build_default_path
+{
+ my ($self, $state) = @_;
+ $default_path = OpenBSD::PackageRepositoryList->new($state);
+
+ $self->add_default($state, $default_path);
+}
+
sub default_path
{
+ my ($self, $state) = @_;
if (!defined $default_path) {
- &build_default_path;
+ $self->build_default_path($state);
}
return $default_path;
}
+sub printable_default_path
+{
+ my ($self, $state) = @_;
+
+ return join(':', $self->default_path($state)->do_something('url'));
+}
+
sub path_parse
{
my ($self, $pkgname, $state, $path) = (@_, './');
# ex:ts=8 sw=4:
-# $OpenBSD: PackageRepositoryList.pm,v 1.30 2015/07/09 12:57:55 espie Exp $
+# $OpenBSD: PackageRepositoryList.pm,v 1.31 2017/05/29 12:28:54 espie Exp $
#
# Copyright (c) 2003-2006 Marc Espie <espie@openbsd.org>
#
sub do_something
{
my ($self, $do, $pkgname, @args) = @_;
- if ($pkgname eq '-') {
+ if (defined $pkgname && $pkgname eq '-') {
return OpenBSD::PackageRepository->pipe->new($self->{state})->$do($pkgname, @args);
}
for my $repo (@{$self->{l}}) {
# ex:ts=8 sw=4:
-# $OpenBSD: State.pm,v 1.45 2017/03/09 14:33:32 espie Exp $
+# $OpenBSD: State.pm,v 1.46 2017/05/29 12:28:54 espie Exp $
#
# Copyright (c) 2007-2014 Marc Espie <espie@openbsd.org>
#
bless {state => $state}, $class;
}
+sub locator
+{
+ my $self = shift;
+ return $self->{state}->locator;
+}
+
sub installed
{
my ($self, $all) = @_;
sub path_parse
{
my ($self, $pkgname) = @_;
- require OpenBSD::PackageLocator;
- return OpenBSD::PackageLocator->path_parse($pkgname, $self->{state});
+ return $self->locator->path_parse($pkgname, $self->{state});
}
sub find
{
my ($self, $pkg) = @_;
- require OpenBSD::PackageLocator;
- return OpenBSD::PackageLocator->find($pkg, $self->{state});
+ return $self->locator->find($pkg, $self->{state});
}
sub reinitialize
sub match_locations
{
my $self = shift;
- require OpenBSD::PackageLocator;
- return OpenBSD::PackageLocator->match_locations(@_, $self->{state});
+ return $self->locator->match_locations(@_, $self->{state});
}
sub grabPlist
{
my ($self, $url, $code) = @_;
- require OpenBSD::PackageLocator;
- return OpenBSD::PackageLocator->grabPlist($url, $code, $self->{state});
+ return $self->locator->grabPlist($url, $code, $self->{state});
}
sub path
our @ISA = qw(Exporter);
our @EXPORT = ();
+sub locator
+{
+ require OpenBSD::PackageLocator;
+ return "OpenBSD::PackageLocator";
+}
+
sub new
{
my $class = shift;