summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorespie <espie@openbsd.org>2009-10-11 22:08:27 +0000
committerespie <espie@openbsd.org>2009-10-11 22:08:27 +0000
commit21c4a32062c5c523987a43a8ed6463e88a7fb5c7 (patch)
tree260e0f50da0ec61caba82bb08607aea26d2b5bc6
parentXr port-modules(5) (diff)
downloadwireguard-openbsd-21c4a32062c5c523987a43a8ed6463e88a7fb5c7.tar.xz
wireguard-openbsd-21c4a32062c5c523987a43a8ed6463e88a7fb5c7.zip
new mode of operation: fuzzy addition. Allows adding packages even if
you don't know version numbers. Useful for quickly trying to duplicate an installation on a new machine from the package list as obtained through pkg_info. Generally won't give a perfect result, but hey, if you have 300 packages installed, will get you 95% of the way there. prompted by problems reported by theo and msf.
-rw-r--r--usr.sbin/pkg_add/pkg_add63
-rw-r--r--usr.sbin/pkg_add/pkg_add.123
2 files changed, 76 insertions, 10 deletions
diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add
index 061d90ad8de..ef6d0940876 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.341 2009/10/11 13:54:41 espie Exp $
+# $OpenBSD: pkg_add,v 1.342 2009/10/11 22:08:27 espie Exp $
#
# Copyright (c) 2003-2009 Marc Espie <espie@openbsd.org>
#
@@ -680,13 +680,13 @@ sub reorder
}
}
-set_usage('pkg_add [-acIinqruvx] [-A arch] [-B pkg-destdir] [-F keywords]',
-'[-L localbase] [-P type] [-Q quick-destdir] pkg-name [...]');
+set_usage('pkg_add [-acIinqruvxz] [-A arch] [-B pkg-destdir] [-F keywords]',
+'[-L localbase] [-l list] [-P type] [-Q quick-destdir] pkg-name [...]');
-our ($opt_a, $opt_v, $opt_n, $opt_I, $opt_L, $opt_B, $opt_A, $opt_P, $opt_Q, $opt_x, $opt_r, $opt_q, $opt_c, $opt_i, $opt_u);
+our ($opt_a, $opt_v, $opt_n, $opt_I, $opt_L, $opt_B, $opt_A, $opt_P, $opt_Q, $opt_x, $opt_r, $opt_q, $opt_c, $opt_i, $opt_u, $opt_l, $opt_z);
$opt_v = 0;
try {
- getopts('aqchivnruxIL:f:F:B:A:P:Q:',
+ getopts('aqchivnruxzIl:L:f:F:B:A:P:Q:',
{
'h' => sub { Usage(); },
'F' => sub {
@@ -761,19 +761,66 @@ $state->{interactive} = $opt_i;
$state->{beverbose} = $opt_n || ($opt_v >= 2);
$state->{allow_replacing} = $opt_r || $opt_u;
-if (@ARGV == 0 && !$opt_u) {
+if (@ARGV == 0 && !$opt_u && !$opt_l) {
Usage "Missing pkgname";
}
+if ($opt_l && @ARGV != 0) {
+ Usage "No pkgnames after -l";
+}
+
+
lock_db($state->{not}) unless $state->{defines}->{nolock};
$state->setup_progressmeter($opt_x);
$state->check_root;
-
my @todo = ();
my @todo2 = ();
-if ($opt_u) {
+if ($opt_l) {
+ open my $f, '<', $opt_l or die "$!: bad list $opt_l";
+ my $_;
+ while (<$f>) {
+ chomp;
+ s/\s.*//;
+ push(@ARGV, $_);
+ }
+}
+
+if ($opt_l || $opt_z) {
+ my $k = OpenBSD::Search::FilterLocation->keep_most_recent;
+ $state->progress->set_header("Looking for packages");
+ for my $_ (@ARGV) {
+ my $l;
+ # first try to find us exactly
+ $state->progress->message("Looking for $_");
+ $l = OpenBSD::PackageLocator->match_locations(OpenBSD::Search::Exact->new($_));
+ if (@$l == 0) {
+ my @search =();
+ my $t = $_;
+ $t =~ s/\-\d([^-]*)\-?/--/;
+ push(@search, OpenBSD::Search::Stem->new($t));
+ $l = OpenBSD::PackageLocator->match_locations(OpenBSD::Search::Stem->new($t), $k);
+ }
+ if (@$l == 0) {
+ $state->progress->clear;
+ print "Can't find $_\n";
+ } elsif (@$l > 1) {
+ if ($state->{interactive}) {
+ my %cnd = map {($_->name, $_)} @$l;
+ my $result = OpenBSD::Interactive::choose1($_,
+ 1, sort keys %cnd);
+ push @todo, $cnd{$result} if defined $result;
+ } else {
+ $state->progress->clear;
+ print "Ambiguous: $_\n";
+ }
+ } else {
+ push(@todo, $l->[0]);
+ }
+ @todo2 = map { OpenBSD::UpdateSet->from_location($_) } @todo;
+ }
+} elsif ($opt_u) {
require OpenBSD::Update;
if (@ARGV == 0) {
diff --git a/usr.sbin/pkg_add/pkg_add.1 b/usr.sbin/pkg_add/pkg_add.1
index 1ec3b321e32..9a4a8b3ec86 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.79 2009/10/11 18:45:42 espie Exp $
+.\" $OpenBSD: pkg_add.1,v 1.80 2009/10/11 22:08:27 espie Exp $
.\"
.\" Documentation and design originally from FreeBSD. All the code has
.\" been rewritten since. We keep the documentation's notice:
@@ -24,10 +24,11 @@
.Sh SYNOPSIS
.Nm pkg_add
.Bk -words
-.Op Fl acIinqruvx
+.Op Fl acIinqruvxz
.Op Fl A Ar arch
.Op Fl B Ar pkg-destdir
.Op Fl F Ar keywords
+.Op Fl l Ar file
.Op Fl L Ar localbase
.Op Fl P Ar type
.Op Fl Q Ar quick-destdir
@@ -277,6 +278,18 @@ If scripts exist for a given package, do not execute them.
Switch on interactive mode.
.Nm
may ask questions to the user if faced with difficult decisions.
+.It Fl l Ar file
+installs packages from the raw output of
+.Xr pkg_info 1 ,
+as saved in
+.Ar file .
+Generally, use with
+.Li pkg_info >file ,
+to reproduce an installation from machine to machine.
+.Fl l
+will try its best to reproduce the installation, even if the
+version numbers don't quite match and even if some packages cannot
+be found.
.It Fl L Ar localbase
Install a package under
.Ar localbase .
@@ -364,6 +377,12 @@ turn on more verbose output.
.It Fl x
Disable progress-meter.
.El
+.It Fl z
+Fuzzy package addition:
+.Nm
+should do its best to match package names passed on the command line,
+even if the versions don't match and it will proceed even if
+some packages can't be found.
.Pp
By default, when adding packages via FTP, the
.Xr ftp 1