aboutsummaryrefslogtreecommitdiffstats
path: root/gurpmi.addmedia
blob: a530e6917cbe69c833c6ec82adea6ac3d81f48b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/perl
#*****************************************************************************
# 
#  Copyright (c) 2004 Guillaume Cottenceau (gc at mandrakesoft dot com)
#  Copyright (c) 2006 Thierry Vignaud <tvignaud@mandriva.com>
#  Copyright (c) 2004-2006 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;

BEGIN {
    @ARGV == 0 || "@ARGV" =~ /-h/ and do {
        print "usage: gurpmi.addmedia [options] <name> <url> [with <relative_path>]
where <url> is one of
  file://<path>
  ftp://<login>:<password>@<host>/<path> with <relative filename of hdlist>
  ftp://<host>/<path> with <relative filename of hdlist>
  http://<host>/<path> with <relative filename of hdlist>
  removable://<path>
and [options] are from
  --update         create an update medium.
  --silent-success don't show popup window on success
";
        exit(0);
    };
}

use lib qw(/usr/lib/libDrakX);
use urpm;
use common;

require_root_capability();

use rpmdrake;
use Getopt::Long;

eval { require ugtk2; ugtk2->import(qw(:all)) };
if ($@) {
    print "This program cannot be run in console mode.\n";
    use POSIX qw(_exit);
    _exit(0);  #- skip ugtk2::END
}
$::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, $silent_success) = (0, 0);

GetOptions(
    'update'	     => \$update,
    '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,^(file://|ftp://|http://|removable://), || $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 for 1 .. ($with ? 4 : 2);
}

$fromfile and do {
    interactive_msg('gurpmi.addmedia',
N("%s

Is it ok to continue?",
@names > 1
? 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 = urpm->new;
urpm::media::read_config($urpm);
my $success = 1;
for (@addmedia_args) {
    #- NB: that short circuits
    $success = $success && add_medium_and_check(
	$urpm,
	{ probe_with => !$_->[2] },
	$_->[0],
	$_->[1],
	$_->[3],
	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);
}