/[soft]/rpm/urpmi/branches/1/urpmi.addmedia
ViewVC logotype

Contents of /rpm/urpmi/branches/1/urpmi.addmedia

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3132 - (show annotations) (download)
Wed Feb 29 23:59:36 2012 UTC (8 years, 4 months ago) by tv
File size: 7311 byte(s)
branch

1 #!/usr/bin/perl
2
3 # $Id: urpmi.addmedia 271299 2010-11-21 15:54:30Z peroyvind $
4
5 #- Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005 MandrakeSoft SA
6 #- Copyright (C) 2005-2010 Mandriva SA
7 #-
8 #- This program is free software; you can redistribute it and/or modify
9 #- it under the terms of the GNU General Public License as published by
10 #- the Free Software Foundation; either version 2, or (at your option)
11 #- any later version.
12 #-
13 #- This program is distributed in the hope that it will be useful,
14 #- but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 #- GNU General Public License for more details.
17 #-
18 #- You should have received a copy of the GNU General Public License
19 #- along with this program; if not, write to the Free Software
20 #- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
22 use strict;
23 use urpm;
24 use urpm::args;
25 use urpm::msg;
26 use urpm::download ();
27 use urpm::cfg;
28 use urpm::media;
29 use urpm::util 'member';
30
31 sub usage {
32 my $m = shift;
33 my $usage =
34 #-PO: The URI types strings 'file:', 'ftp:', 'http:', and 'cdrom:' must not be translated!
35 #-PO: neither the ``with''. Only what is between <brackets> can be translated.
36 N("usage: urpmi.addmedia [options] <name> <url>
37 where <url> is one of
38 [file:/]/<path>
39 ftp://<login>:<password>\@<host>/<path>
40 ftp://<host>/<path>
41 http://<host>/<path>
42 cdrom://<path>
43
44 usage: urpmi.addmedia [options] --distrib --mirrorlist <url>
45 usage: urpmi.addmedia [options] --mirrorlist <url> <name> <relative path>
46
47 examples:
48
49 urpmi.addmedia --distrib --mirrorlist '\$MIRRORLIST'
50 urpmi.addmedia --mirrorlist '\$MIRRORLIST' backports media/main/backports
51 urpmi.addmedia --distrib --zeroconf
52
53
54 and [options] are from
55 ") . N(" --help - print this help message.
56 ") . N(" --wget - use wget to retrieve distant files.
57 ") . N(" --curl - use curl to retrieve distant files.
58 ") . N(" --prozilla - use prozilla to retrieve distant files.
59 ") . N(" --aria2 - use aria2 to retrieve distant files.
60 ") . N(" --metalink - generate and use a local metalink.
61 ") . N(" --limit-rate - limit the download speed.
62 ") . N(" --proxy - use specified HTTP proxy, the port number is assumed
63 to be 1080 by default (format is <proxyhost[:port]>).
64 ") . N(" --proxy-user - specify user and password to use for proxy
65 authentication (format is <user:password>).
66 ") . N(" --update - create an update medium,
67 or discard non-update media (when used with --distrib)
68 ") . N(" --xml-info - use the specific policy for downloading xml info files
69 one of: never, on-demand, update-only, always. cf urpmi.cfg(5)
70 ") . N(" --probe-synthesis - use synthesis file.
71 ") . N(" --probe-rpms - use rpm files (instead of synthesis).
72 ") . N(" --no-probe - do not try to find any synthesis file.
73 ") . N(" --urpmi-root - use another root for urpmi db & rpm installation.
74 ") . N(" --distrib - automatically create all media from an installation
75 medium.
76 ") . N(" --interactive - with --distrib, ask confirmation for each media
77 ") . N(" --all-media - with --distrib, add every listed media
78 ") . N(" --virtual - create virtual media wich are always up-to-date.
79 ") . N(" --no-md5sum - disable MD5SUM file checking.
80 ") . N(" --nopubkey - don't import pubkey of added media
81 ") . N(" --raw - add the media in config, but don't update it.
82 ") . N(" -q - quiet mode.
83 ") . N(" -v - verbose mode.
84 ");
85 print($m ? "$usage\n$m" : $usage);
86 exit 1;
87 }
88
89 $ENV{PATH} = "/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin";
90 delete @ENV{qw(ENV BASH_ENV IFS CDPATH)};
91
92 $options{force} = 0;
93 my $urpm = urpm->new_parse_cmdline or usage();
94
95 if ($options{'xml-info'}) {
96 member($options{'xml-info'}, urpm::xml_info_policies()) or die N("known xml-info policies are %s", join(', ', urpm::xml_info_policies())) . "\n";
97 }
98
99 our ($name, $url, $with, $relative_synthesis) = our @cmdline;
100 my $with_dir;
101
102 $options{quiet} = 1 if $options{verbose} < 0;
103
104 $url or ($url, $name) = ($name, '');
105 if ($options{mirrorlist} || $options{zeroconf}) {
106 if ($options{distrib}) {
107 $url and die N("no argument needed for --distrib --mirrorlist <url>") . "\n";
108 } else {
109 ($with_dir, $url) = ($url, undef);
110 }
111 } else {
112 $url =~ m,^(([^:]*):/)?/, or die N("bad <url> (for local directory, the path must be absolute)") . "\n";
113 }
114
115 if ($< != 0) {
116 $urpm->{fatal}(1, N("Only superuser is allowed to add media"));
117 }
118 if (!-e $urpm->{config}) {
119 $urpm->{log}(N("creating config file [%s]", $urpm->{config}));
120 open my $_f, '>', $urpm->{config} or $urpm->{fatal}(6, N("Can't create config file [%s]", $urpm->{config}));
121 }
122 my $_urpmi_lock = urpm::lock::urpmi_db($urpm, 'exclusive', wait => $options{wait_lock});
123 urpm::media::read_config($urpm, 'nocheck');
124
125 my $ok = 1;
126 if ($options{distrib}) {
127 $with || $relative_synthesis
128 and usage N("no need to give <relative path of synthesis> with --distrib");
129
130 my $add_media_callback = $options{interactive} ?
131 sub {
132 my ($medianame, $add_by_default) = @_;
133 my $yesexpr = N("Yy");
134 $add_by_default = 1 if $options{allmedia};
135 my $answer = message_input_(
136 N("\nDo you want to add media '%s'?", $medianame) . ($add_by_default ? N(" (Y/n) ") : N(" (y/N) ")),
137 boolean => 1,
138 );
139 return $answer ? $answer =~ /[$yesexpr]/ : $add_by_default;
140 } : $options{allmedia} ? sub {
141 1;
142 } : undef;
143
144 urpm::media::add_distrib_media($urpm,
145 $name,
146 $url,
147 mirrorlist => $options{mirrorlist},
148 zeroconf => $options{zeroconf},
149 virtual => $options{virtual},
150 only_updates => $options{update},
151 probe_with => $options{probe_with},
152 nolock => $options{nolock},
153 ask_media => $add_media_callback,
154 'xml-info' => $options{'xml-info'},
155 ) or $urpm->{fatal}(10, N("unable to add medium"));
156 $ok = urpm::media::update_media($urpm, %options,
157 quiet => $options{verbose} < 0,
158 callback => \&urpm::download::sync_logger);
159 } else {
160 $name && $name !~ m!/! or usage();
161
162 if ($with eq "with") {
163 $relative_synthesis or usage N("<relative path of synthesis> missing\n");
164 }
165 if ($options{probe_with} && $options{probe_with} eq 'rpms' && !urpm::is_local_url($url)) {
166 die N("Can't use %s with remote medium", "--probe-rpms");
167 }
168
169 urpm::media::add_medium($urpm,
170 $name, $url, $relative_synthesis,
171 mirrorlist => $options{mirrorlist},
172 zeroconf => $options{zeroconf},
173 'with-dir' => $with_dir,
174 virtual => $options{virtual},
175 update => $options{update},
176 ignore => $options{raw},
177 nolock => $options{nolock},
178 'xml-info' => $options{'xml-info'},
179 ) or $urpm->{fatal}(10, N("unable to add medium"));
180
181 urpm::download::copy_cmd_line_proxy($name);
182 if ($options{raw}) {
183 urpm::media::write_config($urpm);
184 } else {
185 $ok = urpm::media::update_media($urpm, %options,
186 quiet => $options{verbose} < 0,
187 callback => \&urpm::download::sync_logger);
188 }
189 }
190
191 #- try to umount removable devices which may have been mounted.
192 urpm::removable::try_umounting_removables($urpm);
193
194 exit($ok ? 0 : 1);
195
196 # vim:ts=8:sts=4:sw=4

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.28