summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackageLocator.pm28
-rw-r--r--usr.sbin/pkg_add/pkg_add69
-rw-r--r--usr.sbin/pkg_add/pkg_add.115
3 files changed, 97 insertions, 15 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PackageLocator.pm b/usr.sbin/pkg_add/OpenBSD/PackageLocator.pm
index 1df041e61fc..79680c203f9 100644
--- a/usr.sbin/pkg_add/OpenBSD/PackageLocator.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PackageLocator.pm
@@ -1,4 +1,4 @@
-# $OpenBSD: PackageLocator.pm,v 1.7 2004/01/28 22:30:50 espie Exp $
+# $OpenBSD: PackageLocator.pm,v 1.8 2004/03/07 19:29:08 espie Exp $
#
# Copyright (c) 2003 Marc Espie.
#
@@ -111,6 +111,11 @@ sub open
return $fh;
}
+# by default, we don't know how to list packages there.
+sub simplelist
+{
+}
+
package OpenBSD::PackageLocation::SCP;
our @ISA=qw(OpenBSD::PackageLocation OpenBSD::PackageLocation::FTPorSCP);
@@ -158,16 +163,22 @@ sub list
{
my $self = shift;
my @l = ();
- opendir(my $dir, $self->{location}) or return undef;
+ my $dname = $self->{location};
+ opendir(my $dir, $dname) or return undef;
while (my $e = readdir $dir) {
- next unless -f "$dir/$e";
- next unless $e = ~ m/\.tgz$/;
+ next unless -f "$dname/$e";
+ next unless $e =~ m/\.tgz$/;
push(@l, $`);
}
close($dir);
return @l;
}
+sub simplelist
+{
+ return $_[0]->list();
+}
+
package OpenBSD::PackageLocation::FTPorSCP;
sub _list
@@ -313,6 +324,15 @@ sub find
return $package;
}
+sub available
+{
+ my @l = ();
+ foreach my $loc (@pkgpath) {
+ push(@l, $loc->simplelist());
+ }
+ return @l;
+}
+
sub info
{
my $self = shift;
diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add
index e6f22ebd56e..4bd73da5214 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.27 2004/02/20 19:13:51 espie Exp $
+# $OpenBSD: pkg_add,v 1.28 2004/03/07 19:29:08 espie Exp $
#
# Copyright (c) 2003 Marc Espie.
#
@@ -39,6 +39,7 @@ use Getopt::Std;
use File::Copy;
our %forced = ();
+our ($ftp_only, $cdrom_only);
# XXX we don't want to load this package all the time
package OpenBSD::RequiredBy;
@@ -100,11 +101,18 @@ package OpenBSD::PackingElement::Arch;
sub check
{
- my $self = $_[0];
+ my ($self, $forced_arch) = @_;
my ($machine_arch, $arch);
for my $ok (@{$self->{arches}}) {
return 1 if $ok eq '*';
+ if (defined $forced_arch) {
+ if ($ok eq $forced_arch) {
+ return 1;
+ } else {
+ next;
+ }
+ }
if (!defined $machine_arch) {
chomp($machine_arch = `/usr/bin/arch -s`);
}
@@ -121,11 +129,23 @@ package main;
my $errors = 0;
-our ($opt_v, $opt_n, $opt_I, $opt_f, $opt_L, $opt_B);
-getopts('vnIL:f:B:');
+our ($opt_v, $opt_n, $opt_I, $opt_f, $opt_L, $opt_B, $opt_A, $opt_P);
+getopts('vnIL:f:B:A:P:');
if ($opt_f) {
%forced = map {($_, 1)} split(/,/, $opt_f);
}
+if ($opt_P) {
+ if ($opt_P eq 'cdrom') {
+ $cdrom_only = 1;
+ }
+ elsif ($opt_P eq 'ftp') {
+ $ftp_only = 1;
+ }
+ else {
+ die "bad option: -P $opt_P";
+ }
+}
+
$opt_L = '/usr/local' unless defined $opt_L;
my $destdir;
@@ -264,9 +284,28 @@ sub solve_dependencies
push(@deps, $to_install->{$candidates[0]});
push(@$to_register, $candidates[0]);
} else {
- # okay, give up, use the default
- push(@deps, $dep->{def});
- push(@$to_register, $dep->{def});
+ # try with list of packages
+ my @candidates = OpenBSD::PackageName::pkgspec_match($dep->{pattern}, OpenBSD::PackageLocator::available());
+ # one single choice
+ if (@candidates == 1) {
+ push(@deps, $candidates[0]);
+ push(@$to_register, $candidates[0]);
+ } elsif (@candidates > 1) {
+ # grab default if available
+ if (grep {$_ eq $dep->{def}} @candidates) {
+ push(@deps, $dep->{def});
+ push(@$to_register, $dep->{def});
+ # grab first one otherwise
+ } else {
+ push(@deps, $candidates[0]);
+ push(@$to_register, $candidates[0]);
+ }
+ } else {
+ # can't get a list of packages, assume default
+ # will be there.
+ push(@deps, $dep->{def});
+ push(@$to_register, $dep->{def});
+ }
}
}
}
@@ -370,9 +409,19 @@ sub really_add($$)
my $plist = $handle->{plist};
my $dir = $handle->info();
my $pkgname = $plist->pkgname();
+ my $problems = 0;
+
+ my $extra = $plist->{extrainfo};
+ if ($cdrom_only && ((!defined $extra) || $extra->{cdrom} ne 'yes')) {
+ print "Package $pkgname is not for cdrom.\n";
+ $problems++;
+ }
+ if ($ftp_only && ((!defined $extra) || $extra->{ftp} ne 'yes')) {
+ print "Package $pkgname is not for ftp.\n";
+ $problems++;
+ }
$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();
@@ -396,7 +445,7 @@ sub really_add($$)
print "Collision: the following files already exists\n\t",
join("\n\t", @$colliding), "\n";
}
- die if $problems;
+ exit(1) if $problems;
my $interrupted;
local $SIG{'INT'} = sub {
@@ -486,7 +535,7 @@ while (my $pkg = shift @todo) {
next;
}
if ($plist->has('arch')) {
- unless ($plist->{arch}->check()) {
+ unless ($plist->{arch}->check($opt_A)) {
print "$pkg is not for the right architecture\n";
next MAINLOOP unless $forced{arch};
}
diff --git a/usr.sbin/pkg_add/pkg_add.1 b/usr.sbin/pkg_add/pkg_add.1
index d0aca48181a..d710d09fc28 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.12 2004/02/20 19:13:51 espie Exp $
+.\" $OpenBSD: pkg_add.1,v 1.13 2004/03/07 19:29:08 espie Exp $
.\"
.\" FreeBSD install - a package for the installation and maintenance
.\" of non-core utilities.
@@ -26,9 +26,11 @@
.Sh SYNOPSIS
.Nm pkg_add
.Op Fl Inv
+.Op Fl A Ar arch
.Op Fl B Ar pkg-destdir
.Op Fl f Ar keys
.Op Fl L Ar localbase
+.Op Fl P Ar type
.Ar pkg-name Op Ar ...
.Sh DESCRIPTION
The
@@ -121,6 +123,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 A Ar arch
+Assume
+.Ar arch
+as current machine architecture for any package tests.
.It Fl B Ar pkg-destdir
Set
.Ar pkg-destdir
@@ -165,6 +171,13 @@ See
.Xr bsd.port.mk 5
for a description of
.Ev LOCALBASE .
+.It Fl P Ar type
+Check permissions for distribution, where
+.Ar type
+can be
+.Sq cdrom
+or
+.Sq ftp .
.El
.Pp
By default, when adding packages via FTP, the