summaryrefslogtreecommitdiffstats
path: root/urpmi
blob: d67a49007665ec8645ba506ee74602187ccb5fee (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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
#!/usr/bin/perl

#- Copyright (C) 1999,2001 MandrakeSoft (pixel@linux-mandrake.com)
#-
#- This program is free software; you can redistribute it and/or modify
#- it under the terms of the GNU General Public License as published by
#- the Free Software Foundation; either version 2, or (at your option)
#- any later version.
#-
#- 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.

#use strict qw(subs vars refs);
use urpm;

#- get I18N translation method.
import urpm _;

#- default options.
my $update = 0;
my $media = '';
my $synthesis = '';
my $auto = 0;
my $allow_medium_change = 0;
my $auto_select = 0;
my $force = 0;
my $allow_nodeps = 0;
my $allow_force = 0;
my $parallel = '';
my $sync = undef;
my $X = 0;
my $WID = 0;
my $all = 0;
my $rpm_opt = "vh";
my $use_provides = 1;
my $fuzzy = 0;
my $src = 0;
my $clean = 0;
my $noclean = 0;
my $pre_clean_cache = 0;
my $post_clean_cache = 1;
my $verbose = 0;
my $root = '';
my $bug = '';
my $env = '';
my $log = '';
my $verify_rpm = 1;
my $test = 0;

my $uid;
my @files;
my @src_files;
my @names;
my @src_names;

$ENV{PATH} = "/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin";
delete @ENV{qw(ENV BASH_ENV IFS CDPATH)};
($<, $uid) = ($>, $<);
$ENV{HOME} ||= "/root";
$ENV{USER} ||= "root";
    
sub usage {
    print STDERR _("urpmi version %s
Copyright (C) 1999, 2000, 2001, 2002 MandrakeSoft.
This is free software and may be redistributed under the terms of the GNU GPL.

usage:
", $urpm::VERSION) . _("  --help         - print this help message.
") . _("  --update       - use only update media.
") . _("  --media        - use only the media listed by comma.
") . _("  --synthesis    - use the synthesis given instead of urpmi db.
") . _("  --auto         - automatically select a package in choices.
") . _("  --auto-select  - automatically select packages to upgrade the system.
") . _("  --fuzzy        - impose fuzzy search (same as -y).
") . _("  --src          - next package is a source package (same as -s).
") . _("  --clean        - remove rpm from cache before anything else.
") . _("  --noclean      - keep rpm not used in cache.
") . _("  --force        - force invocation even if some packages do not exist.
") . _("  --allow-nodeps - allow asking user to install packages without
                   dependencies checking.
") . _("  --allow-force  - allow asking user to install packages without
                   dependencies checking and integrity.
") . _("  --parallel     - distributed urpmi accross machines of alias.
") . _("  --wget         - use wget to retrieve distant files.
") . _("  --curl         - use curl to retrieve distant files.
") . _("  --proxy        - use specified HTTP proxy, the port number is assumed
                   to be 1080 by default (format is <proxyhost[:port]>).
") . _("  --proxy-user   - specify user and password to use for proxy
                   authentication (format is <user:password>).
") . _("  --bug          - output a bug report in directory indicated by
                   next arg.
") . _("  --env          - use specific environment (typically a bug
                   report).
") . _("  --X            - use X interface.
") . _("  --best-output  - choose best interface according to the environment:
                   X or text mode.
") . _("  --verify-rpm   - verify rpm signature before installation
                   (--no-verify-rpm disable it, default is enabled).
") . _("  --test         - verify if the installation can be achieved correctly.
") . _("  -a             - select all matches on command line.
") . _("  -p             - allow search in provides to find package.
") . _("  -P             - do not search in provides to find package.
") . _("  -y             - impose fuzzy search (same as --fuzzy).
") . _("  -s             - next package is a source package (same as --src).
") . _("  -q             - quiet mode.
") . _("  -v             - verbose mode.
") . "\n" . _("  names or rpm files given on command line are installed.
");
    exit(0);
}

#- parse arguments list.
my @nextargv;
my $command_line = join " ", @ARGV;
while (defined($_ = shift @ARGV)) {
    /^--help$/ and do { usage; next };
    /^--no-locales$/ and do { undef *_; undef *urpm::_; *_ = *urpm::_ = sub { sprintf(shift @_, @_) }; next };
    /^--update$/ and do { $update = 1; next };
    /^--media$/ and do { push @nextargv, \$media; next };
    /^--mediums$/ and do { push @nextargv, \$media; next };
    /^--synthesis$/ and do { push @nextargv, \$synthesis; next };
    /^--auto$/ and do { $auto = 1; next };
    /^--allow-medium-change$/ and do { $allow_medium_change = 1; next };
    /^--auto-select$/ and do { $auto_select = 1; next };
    /^--fuzzy$/ and do { $fuzzy = 1; next };
    /^--src$/ and do { $src = 1; next };
    /^--clean$/ and do { $clean = 1; $noclean = 0; next };
    /^--noclean$/ and do { $clean = 0; $noclean = 1; next };
    /^--(no-)?pre-clean$/ and do { $pre_clean_cache = !$1; next };
    /^--(no-)?post-clean$/ and do { $post_clean_cache = !$1; next };
    /^--force$/ and do { $force = 1; next };
    /^--allow-nodeps$/ and do { $allow_nodeps = 1; next };
    /^--allow-force$/ and do { $allow_force = 1; next };
    /^--parallel$/ and do { push @nextargv, \$parallel; next };
    /^--wget$/ and do { $sync = sub { my $options = shift @_;
				      if (ref $options) { $options->{prefer} = 'wget' }
				      else { $options = { dir => $options, prefer => 'wget' } }
				      urpm::sync_webfetch($options, @_) }; next };
    /^--curl$/ and do { $sync = \&urpm::sync_webfetch; next };
    /^--proxy$/ and do {
	my ($proxy, $port) = ($_ = shift @ARGV) =~ m,^(?:http://)?([^:]+(:\d+)?)/*$, or
	    die _("bad proxy declaration on command line\n");
	$proxy .= ":1080" unless $port;
	$urpm->{proxy}{http_proxy} = "http://$proxy";
	next;
    };
    /^--proxy-user$/ and do {
	($_ = shift @ARGV) =~ /(.+):(.+)/, or
	    die _("bad proxy declaration on command line\n");
	$urpm->{proxy}->{user} = $1;
	$urpm->{proxy}->{pwd} = $2;
	next;
    };
    /^--bug$/ and do { push @nextargv, \$bug; next };
    /^--env$/ and do { push @nextargv, \$env; next };
    /^--X$/ and do { $X = 1; next };
    /^--WID=(.*)$/ and do { $WID = $1; next };
    /^--WID$/ and do { push @nextargv, \$WID; next };
    /^--best-output$/ and do { $X ||= $ENV{DISPLAY} && -x "/usr/sbin/grpmi" && system('/usr/X11R6/bin/xtest', '') == 0;
			       next };
    /^--(no-)?verify-rpm$/ and do { $verify_rpm = !$1; next };
    /^--(no-)?test$/ and do { $test = !$1; next };
    /^--comment$/ and do { push @nextargv, undef; next };
    /^--root$/ and do { push @nextargv, \$root; next };
    /^-(.*)$/ and do { foreach (split //, $1) {
	/[\?h]/ and do { usage; next };
	/a/ and do { $all = 1; next };
	/c/ and do { next };
	/m/ and do { next };
	/M/ and do { next }; #- nop
	/q/ and do { $rpm_opt = ""; next };
	/p/ and do { $use_provides = 1; next };
	/P/ and do { $use_provides = 0; next };
	/y/ and do { $fuzzy = 1; next };
	/s/ and do { $src = 1; next };
	/v/ and do { $verbose = 1; next };
	die _("urpmi: unknown option \"-%s\", check usage with --help\n", $1); } next };
    @nextargv and do { my $r = shift @nextargv; $r and $$r = $_; next };
    if (/\.rpm$/) {
	if (/\.src\.rpm$/) {
	    push @src_files, $_;
	} else {
	    push @files, untaint($_);
	}
	next;
    }
    if ($src) {
	push @src_names, $_;
    } else {
	push @names, $_;
    }
    $src = 0; #- reset switch for next package.
}

#- params contains informations to parse installed system.
my $urpm = new urpm;
my ($pid_out, $pid_err);

#- prepare bug report.
if ($bug) {
    system("rm", "-rf", $bug);
    mkdir $bug or $urpm->{fatal}(8, _("Unable to create directory [%s] for bug report", $bug));
    #- copy all synthesis file used, along with configuration of urpmi
    system("cp", "-af", $urpm->{config}, $urpm->{skiplist}, $urpm->{instlist}, $bug);
    local *DIR;
    opendir DIR, $urpm->{statedir};
    while (defined ($_ = readdir DIR)) {
	/synthesis\./ and system "cp", "-af", "$urpm->{statedir}/$_", $bug;
    }
    closedir DIR;
    #- allow log file.
    $log = "$bug/urpmi.log";
}

if ($env) {
    print STDERR "using specific environment on $env\n";
    $log = "$env/urpmi_env.log";
    unlink $log;
    #- setting new environment.
    $urpm->{config} = "$env/urpmi.cfg";
    $urpm->{skiplist} = "$env/skip.list";
    $urpm->{instlist} = "$env/inst.list";
    $urpm->{statedir} = $env;
} else {
    if ($uid > 0) {
	#- only src files are installable using urpmi.
	@names || @files and $urpm->{fatal}(1, _("Only superuser is allowed to install packages"));

	#- allow installation.
	if (@src_files) {
	    system("rpm", "-i$rpm_opt", @src_files, ($root ? ("--root", $root) : ()));
	    $? and message(_("Installation failed")), exit 1;
	}
	exit 0;
    } else {
	#- allow log if not defined.
	$log ||= "/var/log/urpmi.log";
    }
}

if ($log) {
    #- log only at this point in case of query usage.
    log_it(scalar localtime, " urpmi called with $command_line\n");

    open SAVEOUT, ">&STDOUT"; select SAVEOUT; $| = 1;
    open SAVEERR, ">&STDERR"; select SAVEERR; $| = 1;
    unless ($pid_out = open STDOUT, "|-") {
	while (<STDIN>) {
	    open F, ">>$log"; select F; $| = 1;
	    select SAVEOUT; $| = 1;
	    $/ = \1;
	    print SAVEOUT $_;
	    print F $_;
	    close F;
	}
	exit 0;
    }
    unless ($pid_err = open STDERR, "|-") {
	while (<STDIN>) {
	    open F, ">>$log"; select F; $| = 1;
	    select SAVEERR; $| = 1;
	    $/ = \1;
	    print SAVEERR $_;
	    print F $_;
	    close F;
	}
	exit 0;
    }
    select STDERR; $| = 1;     # make unbuffered
    select STDOUT; $| = 1;     # make unbuffered
}

#- use specific sync routine.
$sync and $urpm->{sync} = $sync;

#- remove verbose if not asked.
unless ($bug) {
    $urpm->{fatal} = sub { printf SAVEERR "%s\n", $_[1]; exit($_[0]) };
    $urpm->{error} = sub { printf SAVEERR "%s\n", $_[0] };
    $urpm->{log} = sub { printf SAVEERR "%s\n", $_[0] };
}
$verbose or $urpm->{log} = sub {};

$urpm->configure(nocheck_access => $env || $uid > 0,
		 media => $media,
		 synthesis => $synthesis,
		 update => $update,
		 root => $root,
		 bug => $bug,
		 parallel => $parallel,
		);

my $state = {};
my %requested = $urpm->register_rpms(@files, @src_files);

#- search the packages according the selection given by the user,
#- basesystem is added to the list so if it need to be upgraded,
#- all its dependency will be updated too.
#- make sure basesystem exists before.
if (@names) {
    $urpm->search_packages(\%requested, [ @names ],
			   all => $all,
			   use_provides => $use_provides,
			   fuzzy => $fuzzy)
      or $force or exit 1;
}
if (@src_names) {
    $urpm->search_packages(\%requested, [ @src_names ],
			   all => $all,
			   use_provides => $use_provides,
			   fuzzy => $fuzzy,
			   src => 1)
      or $force or exit 1;
}

#- filter to add in packages selected required packages.
sub ask_choice {
    my ($urpm, $db, $state, $choices) = @_;
    my $n = 1; #- default value.
    my (@l) = map { scalar $_->fullname } @$choices;
    my $from = undef; #TODO

    if (@l > 1 && !$auto) {
	my $msg = (defined $from ?
		   _("One of the following packages is needed to install %s:", $from) :
		   _("One of the following packages is needed:"));
	if ($X) {
	    `gchooser "$msg" @l`;
	    $n = $? >> 8 || die;
	} else {
	    message("$msg");
	    my $i = 0; foreach (@l) { message(" " . ++$i . "- $_") }
	    while (1) {
		$n = message_input(_("What is your choice? (1-%d) ", $i));
		defined $n or exit 1;
		1 <= $n && $n <= $i and last;
		message(_("Sorry, bad choice, try again\n"));
	    }
	}
    }

    $choices->[$n - 1];
};

#- do the resolution of dependencies between requested package (and auto selection if any).
#- handle parallel option if any.
$urpm->resolve_dependencies($state, \%requested,
			    rpmdb => $env && "$env/rpmdb.cz",
			    auto_select => $auto_select,
			    callback_choices => \&ask_choice,
			   );

if (%{$state->{ask_unselect} || {}}) {
    unless ($auto) {
	my $list = join "\n", map { scalar $urpm->{depslist}[$_]->fullname } keys %{$state->{ask_unselect}};
	my $msg = _("Some package requested cannot be installed:\n%s\ndo you agree ?", $list);
	if ($X) {
	    my $ok = _("Ok");
	    my $cancel = _("Cancel");
	    `gmessage -default $ok -buttons "$ok:0,$cancel:2" "$msg"`;
	    $? and exit 0;
	} else {
	    $noexpr = _("Nn");
	    $yesexpr = _("Yy");
	    message_input($msg . _(" (Y/n) ")) =~ /[$noexpr]/ and exit 0;
	}
    }
    delete @{$state->{selected}}{keys %{$state->{ask_unselect}}};
}
if (%{$state->{ask_remove} || {}}) {
    unless ($auto) {
	my $list = join "\n", sort { $a cmp $b } keys %{$state->{ask_remove}};
	my $msg = _("The following packages have to be removed for others to be upgraded:\n%s\ndo you agree ?", $list);
	if ($X) {
	    my $ok = _("Ok");
	    my $cancel = _("Cancel");
	    `gmessage -default $ok -buttons "$ok:0,$cancel:2" "$msg"`;
	    $? and exit 0;
	} else {
	    $noexpr = _("Nn");
	    $yesexpr = _("Yy");
	    message_input($msg . _(" (Y/n) ")) =~ /[$noexpr]/ and exit 0;
	}
    }
}

#- get out of package that should not be upgraded.
$urpm->deselect_unwanted_packages($state->{selected});

#- package to install as a array of strings.
my @to_install;

#- check if there is at least one package to install that
#- has not been given by the user.
my $ask_user = $env;
my $sum = 0;
my @root_only;

foreach my $pkg (sort { $a->name cmp $b->name } @{$urpm->{depslist}}[keys %{$state->{selected}}]) {
    $ask_user ||= $pkg->flag_required || $auto_select || $parallel;

    my $fullname = $pkg->fullname;
    if (!$env && $uid > 0 && $pkg->arch ne 'src') {
	push @root_only, $fullname;
    } elsif ($uid > 0 || $pkg->arch ne 'src') {
	$sum += $pkg->size;
	push @to_install, $fullname;
    }
}
if ($env) {
    my $msg = _("To satisfy dependencies, the following packages are going to be installed (%d MB)", toMb($sum));
    my $p = join "\n", @to_install;
    print STDERR "$msg:\n$p\n";
    exit 0; #- exit now for specific environment.
}
if (@root_only) {
    print STDERR _("You need to be root to install the following dependencies:\n%s\n", join ' ', @root_only);
    exit 1;
} elsif (!$auto && ($ask_user || $X) && @to_install) {
    my $msg = _("To satisfy dependencies, the following packages are going to be installed (%d MB)", toMb($sum));
    my $msg2 = _("Is this OK?");
    my $p = join "\n", @to_install;
    if ($X) {
	my $ok = _("Ok");
	my $cancel = _("Cancel");
	`gmessage -default $ok -buttons "$ok:0,$cancel:2" "$msg:\n$p\n\n$msg2"`;
	$? and exit 0;
    } else {
	$noexpr = _("Nn");
	$yesexpr = _("Yy");
	message_input("$msg:\n$p\n$msg2" . _(" (Y/n) ")) =~ /[$noexpr]/ and exit 0;
    }
}

#- if not root, the list become invisible and no download will be possible.
my ($local_sources, $list, $local_to_removes) = $urpm->get_source_packages($state->{selected}, clean => $clean);
unless ($local_sources || $list) {
    $urpm->{fatal}(3, _("unable to get source packages, aborting"));
}
#- clean cache with file that are not necessary with this transaction.
if (!$noclean && $pre_clean_cache) {
    foreach (@$local_to_removes) {
	unlink $_;
    }
}

my %sources = $urpm->download_source_packages($local_sources, $list, ($X ? '' : 'force_local'),
					      (!$auto || $allow_medium_change) && sub {
						  my $msg = _("Please insert the medium named \"%s\" on device [%s]", @_);
						  my $msg2 = _("Press Enter when ready...");
						  if ($X) {
						      my $ok = _("Ok");
						      my $cancel = _("Cancel");
						      $msg =~ s/"/\\"/g;
						      `gmessage -default $ok -buttons "$ok:0,$cancel:2" "$msg"`;
						      !$?;
						  } else {
						      defined message_input("$msg\n$msg2 ");
						  }
					      });
my %sources_install = %{$urpm->extract_packages_to_install(\%sources) || {}};

if (%sources_install || %sources) {
    if ($verify_rpm) {
	my @invalid_sources;

	foreach (values %sources_install, values %sources) {
	    URPM::verify_rpm($_) =~ /NOT OK/ and push @invalid_sources, $_;
	}

	if (@invalid_sources) {
	    my $msg = _("The following packages have bad signatures");
	    my $msg2 = _("Do you want to continue installation ?");
	    my $p = join "\n", @invalid_sources;
	    if ($auto) {
		message("$msg:\n$p\n", 'noX');
		exit 1;
	    } else {
		if ($X) {
		    my $ok = _("Ok");
		    my $cancel = _("Cancel");
		    `gmessage -default $cancel -buttons "$ok:0,$cancel:2" "$msg:\n$p\n\n$msg2"`;
		    $? and exit 1;
		} else {
		    $noexpr = _("Nn");
		    $yesexpr = _("Yy");
		    message_input("$msg:\n$p\n$msg2" . _(" (y/N) ")) =~ /[$yesexpr]/ or exit 1;
		}
	    }
	}
    }

    #- check for local files.
    foreach (values %sources_install, values %sources) {
	m|^/| && ! -e $_ or next;
	message(_("Installation failed, some files are missing.\nYou may want to update your urpmi database"));
	exit 2;
    }

    if ($parallel) {
	message(_("distributing %s\n", join(' ', values %sources_install, values %sources)), 'noX');
	#- no remove are handle here, automatically done by each distant node.
	$urpm->{log}("starting distributed install");
	$urpm->parallel_install([ keys %{$state->{ask_remove} || {}} ], \%sources_install, \%sources,
				test => $test);
    } else {
	message(_("installing %s\n", join(' ', values %sources_install, values %sources)), 'noX');
	log_it(scalar localtime, " ", join(' ', values %sources_install, values %sources), "\n");
	$urpm->{log}("starting installing packages");
	if ($uid > 0) {
	    system("rpm", "-i$rpm_opt", values %sources_install, values %sources,
		   ($root ? ("--root", $root) : ()), ($test ? ("--test", $test) : ()));
	    $? and message(_("Installation failed")), exit 1;
	    exit 0;
	} else {
	    if ($X && !$root && !$test) {
		system("rpm", "-e", "--nodeps", keys %{$state->{ask_remove} || {}});
		system("grpmi", $WID ? ("--WID=$WID") : (),
		       (map { ("-noupgrade", $_) } values %sources_install), values %sources);
		if ($?) {
		    #- grpmi handles --nodeps and --force by itself,
		    #- and $WID is defined when integrated in rpminst.
		    $WID or message(_("Installation failed"));
		    exit(($? >> 8) + 32); #- forward grpmi error + 32
		}
	    } else {
		my @l = $urpm->install([ keys %{$state->{ask_remove} || {}} ], \%sources_install, \%sources,
				       translate_message => 1,
				       test => $test, oldpackage => $state->{oldpackage}, post_clean_cache => $post_clean_cache);
		if (@l) {
		    message(_("Installation failed") . ":\n" . join("\n",  map { "\t$_" } @l));

		    m|^/| && !-e $_ and exit 2 foreach values %sources_install, values %sources; #- missing local file
		    $auto || !$allow_nodeps && !$allow_force and exit 1; #- if auto has been set, avoid asking user.

		    $noexpr = _("Nn");
		    $yesexpr = _("Yy");
		    message_input(_("Try installation without checking dependencies? (y/N) "), $force && $yesexpr) =~ /[$yesexpr]/
		      or exit 1;
		    $urpm->{log}("starting installing packages without deps");
		    @l = $urpm->install([ keys %{$state->{ask_remove} || {}} ], \%sources_install, \%sources,
					translate_message => 1, nodeps => 1,
					test => $test, oldpackage => $state->{oldpackage}, post_clean_cache => $post_clean_cache);
		    if (@l) {
			message(_("Installation failed") . ":\n" . join("\n", map { "\t$_" } @l));
			!$allow_force and exit 1;
			message_input(_("Try installation even more strongly (--force)? (y/N) "), $force && $yesexpr) =~ /[$yesexpr]/
			  or exit 1;
			$urpm->{log}("starting force installing packages without deps");
			@l = $urpm->install([ keys %{$state->{ask_remove} || {}} ], \%sources_install, \%sources,
					    translate_message => 1, nodeps => 1, force => 1,
					    test => $test, oldpackage => $state->{oldpackage}, post_clean_cache => $post_clean_cache);
			@l and $urpm->fatal(2, _("Installation failed") . ":\n" . join("\n", map { "\t$_" } @l));
		    }
		} else {
		    $test and message(_("Installation is possible"));
		}
	    }
	}
    }
} else {
    message(_("everything already installed"), $auto);
}
#- try to umount removable device which may have been mounted.
$urpm->try_umounting_removables;

#- this help flushing correctly by closing this file before (piped on tee).
#- but killing them is generally better.
if ($pid_err && $pid_out) {
    kill 15, $pid_err, $pid_out;
    close STDERR;
    close STDOUT;
}

sub toMb {
    my $nb = $_[0] / 1024 / 1024;
    int $nb + 0.5;
}

sub log_it {
    #- if invoked as a simple user, nothing should be logged.
    if ($log) {
	local *LOG;
	open LOG, ">>$log" or die "can't output to log file\n";
	print LOG @_;
    }
}

#- message functions.
sub message {
    my ($msg, $noX) = @_;
    if ($X && !$noX && !$auto) {
	`gmessage -default Ok -buttons Ok "$msg"`;
	$bug and log_it($msg);
    } else {
	if ($bug) {
	    print STDOUT "$msg\n";
	} else {
	    print SAVEOUT "$msg\n";
	}
    }
}
sub message_input {
    my ($msg, $default_input) = @_;

    if ($X && !default_input) { #- if a default input is given, the user doesn't have to choose (and being asked).
	`gmessage -default Ok -buttons Ok "$msg"`;
	$bug and log_it($msg);
    } else {
	if ($bug) {
	    print STDOUT "$msg";
	} else {
	    print SAVEOUT "$msg";
	}
    }

    my $input = $default_input || <STDIN>;
    $bug and log_it($input);
    return $input;
}

sub untaint {
    my @r = ();
    foreach (@_) {
        /(.*)/;
	push @r, $1;
    }
    @r == 1 ? $r[0] : @r
}