summaryrefslogtreecommitdiffstats
path: root/urpmi.removemedia
diff options
context:
space:
mode:
Diffstat (limited to 'urpmi.removemedia')
-rwxr-xr-xurpmi.removemedia51
1 files changed, 22 insertions, 29 deletions
diff --git a/urpmi.removemedia b/urpmi.removemedia
index 0bf7d7db..00af3991 100755
--- a/urpmi.removemedia
+++ b/urpmi.removemedia
@@ -26,31 +26,16 @@ use urpm;
use urpm::msg;
use urpm::download;
use urpm::media;
+use urpm::args;
$ENV{PATH} = "/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin";
delete @ENV{qw(ENV BASH_ENV IFS CDPATH)};
my @toremove;
-#- default option values
-my %options = (
- noclean => 1,
- strict_match => 1,
- verbose => 1,
-);
-
-{
- my $options_end = 0;
- foreach (@ARGV) {
- $_ eq '--' and $options_end = 1, next;
- unless ($options_end) {
- /^--?a$/ and $options{all} = 1, next;
- /^--?c$/ and $options{noclean} = 0, next;
- /^--?y$/ and $options{strict_match} = 0, next;
- /^--?v$/ and $options{verbose} = 1, next;
- /^--?q$/ and $options{verbose} = 0, next;
- /^-/ and do {
- print N("usage: urpmi.removemedia [-a] <name> ...
+sub usage {
+ my ($msg) = @_;
+ print N("usage: urpmi.removemedia (-a | <name> ...)
where <name> is a medium name to remove.
") . N(" --help - print this help message.
") . N(" -a - select all media.
@@ -58,33 +43,41 @@ where <name> is a medium name to remove.
") . N(" -y - fuzzy match on media names.
") . N(" -q - quiet mode.
") . N(" -v - verbose mode.
-") . (/^--?h(?:elp)$/ ? '' : N("\nunknown options '%s'\n", $_));
- exit 0;
- };
- }
- push @toremove, $_;
- }
+") . $msg;
+ exit 0;
}
+
+#- default option values
+$options{noclean} = 1;
+$options{strict_match} = 1;
+
my $urpm = new urpm;
+
+our @cmdline; #- set by urpm::args
+urpm::args::parse_cmdline(urpm => $urpm) or exit(1);
+
+
+$options{verbose} > 0 or $urpm->{log} = sub {};
+
if ($< != 0) {
$urpm->{fatal}(1, N("Only superuser is allowed to remove media"));
}
-$options{verbose} > 0 or $urpm->{log} = sub {};
-
my $_urpmi_lock = urpm::lock::urpmi_db($urpm, 'exclusive');
urpm::media::read_config($urpm);
urpm::download::set_cmdline_proxy();
my @entries = map { $_->{name} } @{$urpm->{media}};
+my @toremove;
if ($options{all}) {
+ !@cmdline or usage('');
@toremove = @entries or die N("nothing to remove (use urpmi.addmedia to add a media)\n");
} else {
- @toremove or die N("the entry to remove is missing\n(one of %s)\n", join(", ", @entries));
+ @toremove = @cmdline or usage(N("the entry to remove is missing\n(one of %s)\n", join(", ", @entries)));
}
-my @selected = urpm::media::select_media_by_name($urpm, \@toremove, $options{strict_match})
+my @selected = urpm::media::select_media_by_name($urpm, \@toremove, !$urpm->{options}{fuzzy})
or exit 1;
urpm::media::remove_media($urpm, \@selected);