summaryrefslogtreecommitdiffstats
path: root/perl-install/bootlook.pm
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2001-07-24 10:23:21 +0000
committerPascal Rigaux <pixel@mandriva.com>2001-07-24 10:23:21 +0000
commit7e5672eb837597a08dc886dc022f704be9b97665 (patch)
tree51aba798e9eb6501aa32cc1cfdbf4d759a031b3b /perl-install/bootlook.pm
parent5d8a5663900537c6695f08692920d666f5ec9213 (diff)
downloaddrakx-7e5672eb837597a08dc886dc022f704be9b97665.tar
drakx-7e5672eb837597a08dc886dc022f704be9b97665.tar.gz
drakx-7e5672eb837597a08dc886dc022f704be9b97665.tar.bz2
drakx-7e5672eb837597a08dc886dc022f704be9b97665.tar.xz
drakx-7e5672eb837597a08dc886dc022f704be9b97665.zip
generalize the use of chomp_ as the functional alternative to chomp (and works on lists)
Diffstat (limited to 'perl-install/bootlook.pm')
-rw-r--r--perl-install/bootlook.pm3
1 files changed, 1 insertions, 2 deletions
diff --git a/perl-install/bootlook.pm b/perl-install/bootlook.pm
index a8c5f693c..4a75f24db 100644
--- a/perl-install/bootlook.pm
+++ b/perl-install/bootlook.pm
@@ -54,8 +54,7 @@ my $a_mode = (-e "/etc/aurora/Monitor") ? 1 : 0;
my $l_mode = isAutologin();
my %auto_mode = get_autologin("");
my $inmain = 0;
-my $lilogrub = `detectloader -q`;
-chomp $lilogrub;
+my $lilogrub = chomp_(`detectloader -q`);
my $window = $::isEmbedded ? new Gtk::Plug ($::XID) : new Gtk::Window ("toplevel");
$window->signal_connect(delete_event => sub { $::isEmbedded ? kill(USR1, $::CCPID) : Gtk->exit(0) });
href='#n244'>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 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685
#!/usr/bin/perl
#*****************************************************************************
# 
#  Copyright (c) 2002 Guillaume Cottenceau (gc at mandrakesoft dot com)
# 
#  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 lib qw(/usr/lib/libDrakX);
use common;

require_root_capability();

use rpmdrake;
use URPM::Signature;

eval { require ugtk2; ugtk2->import(qw(:all)) };
if ($@) {
    print "This program cannot be run in console mode.\n";
    c::_exit(0);  #- skip ugtk2::END
}
$::isStandalone = 1;

my $urpm;
my ($mainw, $remove, $edit, $list_tv);

sub selrow {
    my ($o_list_tv) = @_;
    defined $o_list_tv or $o_list_tv = $list_tv;
    my ($model, $iter) = $o_list_tv->get_selection->get_selected;
    $model && $iter or return -1;
    my $path = $model->get_path($iter);
    my $row = $path->to_string;
    return $row;
}

sub remove_row {
    my ($model, $path_str) = @_;
    my $iter = $model->get_iter_from_string($path_str);
    $iter or return;
    $model->remove($iter);
}

sub add_callback {
    my $w = ugtk2->new(N("Add a medium"), grab => 1, center => 1, transient => $mainw->{rwindow});
    my %radios_infos = (local => { name => N("Local files"), url => N("Path:"), dirsel => 1 },
			ftp => { name => N("FTP server"), url => N("URL:"), loginpass => 1 },
			http => { name => N("HTTP server"), url => N("URL:") },
			removable => { name => N("Removable device"), url => N("Path or mount point:"), dirsel => 1 },
			security => { name => N("Security updates"), url => N("URL:"), securitysel => 1 },
		       );
    my @radios_names_ordered = qw(local ftp http removable security);
    my @modes_buttons = gtkradio($radios_infos{local}{name}, map { $radios_infos{$_}{name} } @radios_names_ordered);
    my $notebook = Gtk2::Notebook->new;
    $notebook->set_show_tabs(0); $notebook->set_show_border(0);
    my $count_nbs;
    mapn {
	my $info = $radios_infos{$_[0]};
	my $url_entry = sub {
	    gtkpack_(Gtk2::HBox->new(0, 0),
		     1, $info->{url_entry} = gtkentry(),
		     if_($info->{dirsel}, 0, gtksignal_connect(Gtk2::Button->new(but(N("Browse..."))),
							       clicked => sub { $info->{url_entry}->set_text(ask_dir()) })),
		     if_($info->{securitysel}, 0, gtksignal_connect(Gtk2::Button->new(but(N("Choose a mirror..."))),
								    clicked => sub { my $m = choose_mirror();
										     if ($m) {
											 $info->{url_entry}->set_text(make_url_mirror($m));
											 $info->{hdlist_entry}->set_text('../base/hdlist.cz');
                                                                                         $info->{hdlist_entry}->set_sensitive(1);
                                                                                         $info->{hdlist_check}->set_active(1);
										     }
										 })));
	};
        my $tips = Gtk2::Tooltips->new;
        my $checkbut_entry = sub {
            my ($name, $label, $visibility, $callback, $tip) = @_;
            [ gtkpack_(Gtk2::HBox->new(0, 0),
                       1, Gtk2::Label->new,
                       0, gtksignal_connect($info->{$name.'_check'} = gtkset_tip($tips, Gtk2::CheckButton->new($label), $tip),
                                            clicked => sub { $info->{$name.'_entry'}->set_sensitive($_[0]->get_active);
                                                             $callback and $callback->(@_);
                                                         })),
              gtkset_visibility(gtkset_sensitive($info->{$name.'_entry'} = gtkentry(), 0), $visibility) ];
        };
	my $loginpass_entries = sub {
	    map { 
                  $checkbut_entry->(@$_, sub {
                                        $info->{pass_check}->set_active($_[0]->get_active);
                                        $info->{login_check}->set_active($_[0]->get_active);
                                    })
              } ([ 'login', N("Login:"), 1 ], [ 'pass', N("Password:"), 0 ])
	};
	my $nb = $count_nbs++;
	gtksignal_connect($_[1], 'clicked' => sub { $_[0]->get_active and $notebook->set_current_page($nb) });
	$notebook->append_page(my $book = create_packtable({},
		      [ gtkset_alignment(Gtk2::Label->new(N("Name:")), 1, 0.5),
                        $info->{name_entry} = gtkentry($_[0] eq 'security' and 'update_source') ],
		      [ gtkset_alignment(Gtk2::Label->new($info->{url}), 1, 0.5),
                        $url_entry->() ],
		      $checkbut_entry->('hdlist', N("Relative path to synthesis/hdlist:"), 1, undef,
                                        N("If left blank, synthesis/hdlist will be automatically probed")),
		      if_($info->{loginpass}, $loginpass_entries->())));
	$book->show;
    } \@radios_names_ordered, \@modes_buttons;

    my $checkok = sub {
	my $info = $radios_infos{$radios_names_ordered[$notebook->get_current_page]};
	my ($name, $url) = map { $info->{$_.'_entry'}->get_text } qw(name url);
	$name eq '' || $url eq '' and interactive_msg('rpmdrake', N("You need to fill up at least the two first entries.")), return 0;
	if (member($name, map { $_->{name} } @{$urpm->{media}})) {
	    $info->{name_entry}->select_region(0, -1);
	    interactive_msg('rpmdrake', 
N("There is already a medium by that name, do you
really want to replace it?"), yesno => 1) or return 0;
	}
	1;
    };

    my ($type, $probe, %i, %make_url);
    gtkadd($w->{window},
	   gtkpack(Gtk2::VBox->new(0,5),
		   Gtk2::Label->new(N("Adding a medium:")),
		   gtkpack__(Gtk2::HBox->new(0, 0), Gtk2::Label->new(but(N("Type of medium:"))), @modes_buttons),
		   $notebook,
		   Gtk2::HSeparator->new,
		   gtkpack(create_hbox(),
			   gtksignal_connect(Gtk2::Button->new(N("Ok")), clicked => sub {
						 if ($checkok->()) {
	$w->{retval} = { nb => $notebook->get_current_page };
	$type = $radios_names_ordered[$w->{retval}{nb}];
	my $info = $radios_infos{$type};
	%i = (name => $info->{name_entry}->get_text, url => $info->{url_entry}->get_text, hdlist => $info->{hdlist_entry}->get_text);
	%make_url = (local => "file:/$i{url}", http => $i{url}, security => $i{url}, removable => "removable:/$i{url}");
	$i{url} =~ s|^ftp://||;
	$make_url{ftp} = sprintf "ftp://%s%s", $info->{login_check}->get_active
	                                           ? ($info->{login_entry}->get_text.':'.$info->{pass_entry}->get_text.'@')
						   : '',
					       $i{url};
        $probe = $info->{hdlist_check}->get_active == 0 || $i{hdlist} eq '';
	Gtk2->main_quit;
    }
					     }),
			   gtksignal_connect(Gtk2::Button->new(N("Cancel")), clicked => sub { $w->{retval} = 0; Gtk2->main_quit }))));
    if ($w->main) {
	if (member($i{name}, map { $_->{name} } @{$urpm->{media}})) {
	    standalone::explanations("Removing medium $i{name}");
	    $urpm->select_media($i{name});
	    $urpm->remove_selected_media;
	}
	add_medium_and_check($urpm,
			     { probe_with => $probe },
			     $i{name}, $make_url{$type}, $i{hdlist}, update => $type eq 'security');
	return 1;
    }
    return 0;
}

sub remove_callback {
    my $row = selrow();
    $row == -1 and return;
    my $wait = wait_msg(N("Please wait, removing medium..."));
    my $name = $urpm->{media}[$row]{name};
    standalone::explanations("Removing medium $name");
    $urpm->select_media($name);
    $urpm->remove_selected_media;
    $urpm->update_media(noclean => 1);
    remove_wait_msg($wait);
}

sub edit_callback {
    my $row = selrow();
    $row == -1 and return;
    my $medium = $urpm->{media}[$row];
    my $w = ugtk2->new(N("Edit a medium"), grab => 1, center => 1, transient => $mainw->{rwindow});
    my ($url_entry, $hdlist_entry, $url, $with_hdlist);
    gtkadd($w->{window},
	   gtkpack_(Gtk2::VBox->new(0,5),
		    0, Gtk2::Label->new(N("Editing medium \"%s\":", $medium->{name})),
		    0, create_packtable({},
					[ N("URL:"), $url_entry = gtkentry($medium->{url}) ],
					[ N("Relative path to synthesis/hdlist:"), $hdlist_entry = gtkentry($medium->{with_hdlist}) ]),
		    0, Gtk2::HSeparator->new,
		    0, gtkpack(create_hbox(),
			       gtksignal_connect(Gtk2::Button->new(N("Save changes")), clicked => sub {
						     $w->{retval} = 1;
						     ($url, $with_hdlist) = ($url_entry->get_text, $hdlist_entry->get_text);
						     Gtk2->main_quit;
						 }),
			       gtksignal_connect(Gtk2::Button->new(N("Cancel")), clicked => sub { $w->{retval} = 0; Gtk2->main_quit }))));
    $w->{rwindow}->set_size_request(600, -1);
    if ($w->main) {
	my ($name, $update) = map { $medium->{$_} } qw(name update);
	$url =~ m|^removable://| and (interactive_msg(N("You need to insert the medium to continue"),
						      N("In order to save the changes, you need to insert the medium in the drive."),
						      yesno => 1, text => { yes => N("Ok"), no => N("Cancel") }) or return 0);
	standalone::explanations("Removing medium $name");
	$urpm->select_media($name);
	$urpm->remove_selected_media;
	add_medium_and_check($urpm, {}, $name, $url, $with_hdlist, update => $update);
	return 1;
    }
    return 0;
}

sub update_callback {
    update_sources_interactive($urpm, transient => $mainw->{rwindow});
}

sub proxy_callback {
    my $w = ugtk2->new(N("Configure proxies"), grab => 1, center => 1, transient => $mainw->{rwindow});
    my ($proxy, $proxy_user) = curl_download::readproxy();
    my ($user, $pass) = $proxy_user =~ /^(.+):(.+)$/;
    my ($proxybutton, $proxyentry, $proxyuserbutton, $proxyuserentry, $proxypasswordentry);
    gtkadd($w->{window},
	   gtkpack__(Gtk2::VBox->new(0, 5),
		     gtkset_justify(Gtk2::Label->new(N("If you need a proxy, enter the hostname and an optional port (syntax: <proxyhost[:port]>):")), 'center'),
		     gtkpack_(Gtk2::HBox->new(0, 10),
			      0, gtkset_active($proxybutton = Gtk2::CheckButton->new(N("Proxy hostname:")), to_bool($proxy)),
			      1, gtkset_sensitive($proxyentry = gtkentry($proxy), to_bool($proxy))),
		     gtkset_justify(Gtk2::Label->new(N("You may specify a user/password for the proxy authentication:")), 'center'),
		     gtkpack_(Gtk2::HBox->new(0, 10),
			      0, gtkset_active($proxyuserbutton = Gtk2::CheckButton->new(N("User:")), to_bool($proxy_user)),
			      1, gtkset_sensitive($proxyuserentry = gtkentry($user), to_bool($proxy_user)),
			      0, Gtk2::Label->new(N("Password:")),
			      1, gtkset_visibility(gtkset_sensitive($proxypasswordentry = gtkentry($pass), to_bool($proxy_user)), 0)),
		     Gtk2::HSeparator->new,
		     gtkpack(create_hbox(),
			     gtksignal_connect(Gtk2::Button->new(N("Ok")), clicked => sub {
						   $w->{retval} = 1;
						   $proxy = $proxybutton->get_active ? $proxyentry->get_text : '';
						   $proxy_user = $proxyuserbutton->get_active
						     ? ($proxyuserentry->get_text.':'.$proxypasswordentry->get_text) : '';
						   Gtk2->main_quit;
					       }),
			     gtksignal_connect(Gtk2::Button->new(N("Cancel")), clicked => sub { $w->{retval} = 0; Gtk2->main_quit }))));
    $proxybutton->signal_connect(clicked => sub { $proxyentry->set_sensitive($_[0]->get_active);
						  $_[0]->get_active and return;
						  $proxyuserbutton->set_active(0);
						  $proxyuserentry->set_sensitive(0);
						  $proxypasswordentry->set_sensitive(0); });
    $proxyuserbutton->signal_connect(clicked => sub { $proxyuserentry->set_sensitive($_[0]->get_active);
						      $proxypasswordentry->set_sensitive($_[0]->get_active) });

    $w->main and curl_download::writeproxy($proxy, $proxy_user);
}

sub parallel_read_sysconf {
    my @conf;
    foreach (cat_('/etc/urpmi/parallel.cfg')) {
        my ($name, $protocol, $command) = /([^:]+):([^:]+):(.*)/ or print STDERR "Warning, unrecognized line in /etc/urpmi/parallel.cfg:\n$_";
        my $medias = $protocol =~ s/\(([^\)]+)\)$// ? [ split /,/, $1 ] : [];
        push @conf, { name => $name, protocol => $protocol, medias => $medias, command => $command };
    }
    \@conf;
}

sub parallel_write_sysconf {
    my ($conf) = @_;
    output '/etc/urpmi/parallel.cfg',
           map { my $m = @{$_->{medias}} ? '('.join(',', @{$_->{medias}}).')' : '';
                 "$_->{name}:$_->{protocol}$m:$_->{command}\n" } @$conf;
}

sub remove_parallel {
    my ($num, $conf) = @_;
    if ($num != -1) {
        splice @$conf, $num, 1;
        parallel_write_sysconf($conf);
    }
}

sub edit_parallel {
    my ($num, $conf) = @_;
    my $edited = $num == -1 ? {} : $conf->[$num];

    my $w = ugtk2->new($num == -1 ? N("Add a parallel group") : N("Edit a parallel group"), grab => 1);
    my $name_entry;

    my $medias_ls = Gtk2::ListStore->new("Glib::String");
    my $medias = Gtk2::TreeView->new_with_model($medias_ls);
    $medias->append_column(Gtk2::TreeViewColumn->new_with_attributes(undef, Gtk2::CellRendererText->new, 'text' => 0));
    $medias->set_headers_visible(0);
    $medias->get_selection->set_mode('browse');
    $medias_ls->append_set([ 0 => $_ ]) foreach @{$edited->{medias}};

    my $add_media = sub {
        my $w = ugtk2->new(N("Add a medium limit"), grab => 1);
        my $medias_list_ls = Gtk2::ListStore->new("Glib::String");
        my $medias_list = Gtk2::TreeView->new_with_model($medias_list_ls);
        $medias_list->append_column(Gtk2::TreeViewColumn->new_with_attributes(undef, Gtk2::CellRendererText->new, 'text' => 0));