#!/usr/bin/perl #***************************************************************************** # # Copyright (c) 2004 Guillaume Cottenceau (gc at mandrakesoft dot com) # Copyright (c) 2006-2007 Thierry Vignaud # Copyright (c) 2004-2007 Mandriva SA # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2, as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # #***************************************************************************** # # $Id$ use strict; use Rpmdrake::init; use Rpmdrake::open_db; BEGIN { @ARGV == 0 || "@ARGV" =~ /-h/ and do { print "usage: gurpmi.addmedia [options] [with ] where is one of [file:/]/ ftp://:\@/ ftp:/// http:/// removable:// and [options] are from --distrib install a set of media from a distribution --silent-success don't show popup window on success --update create an update medium. "; exit(0); }; } use lib qw(/usr/lib/libDrakX); use urpm::media; use common; require_root_capability(); use rpmdrake; use Getopt::Long; use ugtk2 qw(:all); $::isStandalone = 1; my $fromfile; if (@ARGV == 1 && $ARGV[0] =~ /\.urpmi-media$/) { @ARGV = map { s/^\s*//; s/\s*$//; $_ } split /\n/, cat_($ARGV[0]); $fromfile = 1; } my ($update, $distrib, $silent_success) = (0, 0, 0); GetOptions( 'update' => \$update, 'distrib' => \$distrib, 'silent-success' => \$silent_success, ); # compatibility with -update: if ($ARGV[0] =~ /^-?-update/) { $update = 1; shift @ARGV; } my @addmedia_args; my @names; while (@ARGV) { my ($name, $url, $with, $with_hdlist) = @ARGV; $with eq 'with' or ($with, $with_hdlist) = (undef, undef); if ($url !~ m,^(([^:]*):/)?/,) { interactive_msg('gurpmi.addmedia', N("bad (for local directory, the path must be absolute)") . "\n\n$url"); myexit(-1); } if ($with && !$with_hdlist) { interactive_msg('gurpmi.addmedia', N("Unable to add medium, wrong or missing arguments")); myexit(-1); } push @addmedia_args, [ $name, $url, $with, $with_hdlist ]; push @names, $name; shift @ARGV foreach 1 .. ($with ? 4 : 2); } $fromfile and do { interactive_msg('gurpmi.addmedia', N("%s Is it ok to continue?", $distrib || 1 < @names ? N("You are about to add new packages media, %s. That means you will be able to add new software packages to your system from these new media.", join ", ", @names) : N("You are about to add a new packages medium, `%s'. That means you will be able to add new software packages to your system from that new medium.", $names[0]) ), yesno => 1) or myexit(-1); }; my $urpm = fast_open_urpmi_db(); my $success = 1; foreach (@addmedia_args) { #- NB: that short circuits $success = $success && add_medium_and_check( $urpm, { probe_with => !$_->[2], distrib => $distrib }, $_->[0], $_->[1], if_(!$distrib, $_->[3]), if_($update, update => $update), ); } if ($success) { interactive_msg( 'gurpmi.addmedia', @names > 1 ? N("Successfully added media %s.", join ", ", @names) : N("Successfully added medium `%s'.", $names[0]) ) if !$silent_success; myexit(0); } else { myexit(-1); }