diff options
Diffstat (limited to 'perl-install/standalone/drakboot')
| -rwxr-xr-x | perl-install/standalone/drakboot | 444 |
1 files changed, 208 insertions, 236 deletions
diff --git a/perl-install/standalone/drakboot b/perl-install/standalone/drakboot index 58ad9f2bf..33b158b0a 100755 --- a/perl-install/standalone/drakboot +++ b/perl-install/standalone/drakboot @@ -1,8 +1,8 @@ #!/usr/bin/perl # DrakBoot -# $Id$ -# Copyright (C) 2001-2004 Mandriva +# $Id: drakboot 264949 2010-01-14 18:47:39Z tv $ +# Copyright (C) 2001-2008 Mandriva # Yves Duret, Thierry Vignaud # # This program is free software; you can redistribute it and/or modify @@ -29,7 +29,6 @@ use common; use interactive; use any; use bootloader; -use detect_devices; use fsedit; use fs; use Config; @@ -37,267 +36,234 @@ use POSIX; use Xconfig::various; use log; -my $splash_working = any { /^--splash$/ } @ARGV; - my $in = 'interactive'->vnew('su'); -my $all_hds = fsedit::get_hds(); -fs::get_raw_hds('', $all_hds); -fs::get_info_from_fstab($all_hds); -my $fstab = [ fs::get::fstab($all_hds) ]; -my $bootloader = bootloader::read($all_hds); +my $all_hds; +my $fstab; +my $bootloader; +my $cmdline = cat_('/proc/cmdline'); + +my $is_bootloader_mode = !$in->isa('interactive::gtk') || any { /^--boot$/ } @ARGV; + +if ($is_bootloader_mode || any { /^--splash$/ } @ARGV) { + $all_hds = fsedit::get_hds(); + fs::get_raw_hds('', $all_hds); + fs::get_info_from_fstab($all_hds); + $fstab = [ fs::get::fstab($all_hds) ]; + $bootloader = bootloader::read($all_hds); + if (!$bootloader) { + $in->ask_okcancel('', N("No bootloader found, creating a new configuration"), 0) or $in->exit; + any::setupBootloaderBeforeStandalone($in->do_pkgs, $bootloader ||= {}, $all_hds, $fstab); + } +} -if (!$in->isa('interactive::gtk') || any { /^--boot$/ } @ARGV) { +if ($is_bootloader_mode) { $::isWizard = 1; - lilo_choice(); + require security::level; + my $level = security::level::from_string(security::level::get()); + eval { any::setupBootloaderUntilInstalled($in, $bootloader, $all_hds, $fstab, $level) }; + die if $@ && $@ !~ /^wizcancel/; $in->exit(0); } -require ugtk2; -ugtk2->import(qw(:helpers :wrappers :create)); - -my $no_bootsplash; -my $x_mode = Xconfig::various::runlevel() == 5; -my $auto_mode = any::get_autologin(); -my $switch_theme = '/usr/share/bootsplash/scripts/switch-themes'; -my $remove_theme = '/usr/share/bootsplash/scripts/remove-theme'; - -my $w = ugtk2->new($splash_working ? N("Graphical boot theme selection") : N("System mode")); -my $window = $w->{window}; -$::main_window = $w->{real_window} if !$::isEmbedded; - -$window->signal_connect(delete_event => sub { ugtk2->exit(0) }); -unless ($::isEmbedded) { - $window->set_border_width(2); - - ### menus definition - # the menus are not shown but they provides shiny shortcut like C-q - my @menu_items = ([ N("/_File"), undef, undef, undef, '<Branch>' ], - [ N("/File/_Quit"), N("<control>Q"), sub { ugtk2->exit(0) }, undef, '<Item>' ], - ); - create_factory_menu($w->{rwindow}, @menu_items); - ######### menus end -} -my @users = sort(list_users()); -my @sessions = sort(split(' ', `/usr/sbin/chksession -l`)); - -my $user = member($auto_mode->{autologin}, @users) ? $auto_mode->{autologin} : $users[0]; -if (!$user) { - # no user, bad but add root anyway: - $user = "root"; - push @users, $user; -} -my $user_combo = Gtk2::ComboBox->new_with_strings(\@users, $user); -my $desktop_combo = Gtk2::ComboBox->new_with_strings(\@sessions, if_(member($auto_mode->{desktop}, @sessions), $auto_mode->{desktop})); - -my %themes = ('path' => '/usr/share/bootsplash/themes/', - 'sysconfig' => '/etc/sysconfig/bootsplash', - 'default' => 'Mandrakelinux', - 'def_thmb' => '/usr/share/libDrakX/pixmaps/nosplash_thumb.png', - 'lilo' => {'file' => '/lilo/message', - 'thumb' => '/lilo/thumb.png' }, - 'boot' => {'path' => '/images/', - #'thumb'=>'/images/thumb.png', - }, - ); -my $kernel_release = `uname -r`; -chomp $kernel_release; - -require Xconfig::resolution_and_depth; -my $cur_res; -if (my $x_res = Xconfig::resolution_and_depth::from_bios($bootloader->{default_vga})) { - $cur_res = $x_res->{X} . 'x' . $x_res->{Y}; -} else { - $no_bootsplash = 1; #- we can not select any theme we're not in Framebuffer mode :-/ - $cur_res = '800x600' +require ugtk3; +ugtk3->import(qw(:helpers :wrappers :create)); +require mygtk3; +mygtk3->import(qw(gtknew)); + +autologin_choice(); + +sub run_boot_window { + my ($title, $pack_list, $apply_sub) = @_; + + my $w = ugtk3->new($title); + my $window = $w->{window}; + mygtk3::register_main_window($w->{real_window}); + + $window->signal_connect(delete_event => sub { ugtk3->exit(0) }); + unless ($::isEmbedded) { + $window->set_border_width(2); + ### menus definition + # the menus are not shown but they provides shiny shortcut like C-q + my $ui = gtknew('UIManager', actions => [ + # [name, stock_id, value, label, accelerator, tooltip, callback] + [ 'FileMenu', undef, N("_File") ], + [ 'Quit', undef, N("_Quit"), N("<control>Q"), undef, sub { ugtk3->exit(0) } ], + ], + string => qq(<ui> + <menubar name='MenuBar'> + <menu action='FileMenu'> + <menuitem action='Quit'/> + </menu> + </menubar> +</ui>)); + $w->{rwindow}->add_accel_group($ui->get_accel_group); + + ######### menus end + } + gtkadd($window, gtknew('VBox', children => [ + @$pack_list, + 0, create_okcancel({ + cancel_clicked => sub { ugtk3->exit(0) }, + ok_clicked => sub { + $apply_sub->(); + ugtk3->exit(0); + } + }) ])); + $window->show_all; + gtkflush(); + $w->main; + $in->exit(0); } -$no_bootsplash = 0 if $::testing; +sub splash_choice() { + require bootsplash; + my ($cur_res, $bootsplash_available) = bootsplash::get_framebuffer_resolution(); + $bootsplash_available = 1 if $::testing; + + my $theme = bootsplash::themes_read_sysconfig($cur_res); + $bootsplash_available or $theme->{enabled} = 0; + + my $boot_pic = gtknew('Image', file => $bootsplash::default_thumbnail); + change_image($boot_pic, $theme->{name}, $cur_res); + + my $theme_combo = gtknew('ComboBox', text => $theme->{name}, list => [ bootsplash::themes_list_for_resolution($cur_res) ]); + $theme_combo->entry->signal_connect(changed => sub { + $theme->{name} = $theme_combo->entry->get_text; + change_image($boot_pic, $theme->{name}, $cur_res); + }); + + my $splash_box; + my $boot_warn = 1; + my %modes = ( + text => N("Text only"), + splash => N("Silent"), + ); + my $mode_combo = gtknew('ComboBox', text => $modes{$theme->{enabled} ? $cmdline =~ /\bsplash\b/ && $cmdline =~ /\bquiet\b/ ? 'splash' : 'text' : 'text'}, list => [ values %modes ]); + $mode_combo->entry->signal_connect(changed => sub { + $theme->{enabled} = $mode_combo->entry->get_text ne $modes{text}; + if ($boot_warn && !$bootsplash_available && $theme->{enabled}) { + if ($in->ask_yesorno(N("Warning"), + [ N("Your system bootloader is not in framebuffer mode. To activate graphical boot, select a graphic video mode from the bootloader configuration tool.") . "\n" . + N("Do you want to configure it now?") ])) { + enable_framebuffer(); + #- it would be nice to get available themes for new cur_res here + } + $boot_warn = 0; + } + $splash_box->set_sensitive($theme->{enabled}); + }); + + my $_thm_button = gtknew('Button', text => N("Install themes")); + + run_boot_window(N("Graphical boot theme selection"), + [ + 1, gtknew('VBox', spacing => 5, border_width => 5, children => [ + 0, gtknew('HBox', padding => 12, spacing => 5, children_tight => [ gtknew('Label', text => N("Graphical boot mode:")), $mode_combo ]), + 0, $splash_box = gtknew('HBox', sensitive => $theme->{enabled}, children_loose => [ + gtkadd(gtkcreate_frame(N("Theme")), + gtknew('VBox', border_width => 12, spacing => 12, children_tight => [ + $theme_combo, $boot_pic ])), ]), + ]), + ], + sub { + if ($theme->{enabled}) { + bootsplash::switch($theme->{name}); + } else { + bootsplash::remove(); + } + my $text = $mode_combo->entry->get_text; + my $mode = find { $modes{$_} eq $text } keys %modes; + set_splash_append($mode); + }); +} -my $splash_mode = !$no_bootsplash; -my $keep_logo = 1; +sub autologin_choice() { + my @users = sort(list_users()); + my @sessions = sort(split(' ', `/usr/sbin/chksession -l`)); -if (-r $themes{sysconfig}) { - local $_; - foreach (cat_($themes{sysconfig})) { - /^SPLASH=no/ and $splash_mode = 0; - /^THEME=(.*)/ and -f "$themes{path}$1$themes{boot}{path}bootsplash-$cur_res.jpg" and $themes{default} = $1; - /^LOGO_CONSOLE=(.*)/ and $keep_logo = $1 ne 'no'; - } -} + my $x_mode = Xconfig::various::runlevel() == 5; + my $auto_mode = any::get_autologin(); -my @boot_thms; -chdir($themes{path}); #- we must change directory for correct @boot_thms assignement -foreach (sort(all('.'))) { - if (-d "$themes{path}$_" && m/^[^.]/) { - -f "$themes{path}$_$themes{boot}{path}bootsplash-$cur_res.jpg" and push @boot_thms, $_; + my $user = member($auto_mode->{user}, @users) ? $auto_mode->{user} : $users[0]; + if (!$user) { + # no user, bad but add root anyway: + $user = "root"; + push @users, $user; } -} -push @boot_thms, $themes{default} unless member($themes{default}, @boot_thms); + my $user_combo = gtknew('ComboBox', text => $user, list => \@users); + my $desktop_combo = Gtk3::ComboBoxText->new_with_strings(\@sessions, if_(member($auto_mode->{desktop}, @sessions), $auto_mode->{desktop})); -my %combo = ('thms' => '', 'lilo' => ''); -foreach (keys(%combo)) { - $combo{$_} = gtkset_size_request(Gtk2::ComboBox->new_text, 10, -1); -} + my $auto_box = gtknew('Table', col_spacings => 5, row_spacings => 5, homogeneous => 1, children => [ + [ gtknew('Label_Left', text => N("Default user")), $user_combo ], + [ gtknew('Label_Left', text => N("Default desktop")), $desktop_combo ] ]); + $auto_box->set_sensitive($auto_mode->{user} ? 1 : 0); -$combo{boot} = gtkset_size_request(Gtk2::ComboBox->new_with_strings(\@boot_thms, $themes{default}), 10, -1);; - -my $boot_pic = gtkcreate_img($themes{def_thmb}); -change_image($boot_pic, $themes{default}); - -my $_thm_button = Gtk2::Button->new(N("Install themes")); -my $_B_create = gtksignal_connect(Gtk2::Button->new(N("Create new theme")), clicked => sub { system('/usr/sbin/draksplash ') }); - -#- ******** action to take on changing combos values - -$combo{boot}->entry->signal_connect(changed => sub { change_image($boot_pic, $combo{boot}->entry->get_text) }); - -my ($x_box, $splash_box); -my $boot_warn = 1; -gtkadd($window, - gtkpack_(Gtk2::VBox->new(0,0), - ($splash_working ? - (1, gtkpack_(gtkset_border_width(Gtk2::VBox->new(0, 5), 5), - 0, gtksignal_connect(gtkset_active(Gtk2::CheckButton->new(N("Use graphical boot")), $splash_mode), - clicked => sub { - $splash_mode = !$splash_mode; - if ($boot_warn && $no_bootsplash && $splash_mode) { - if ($in->ask_yesorno(N("Warning"), - [ N("Your system bootloader is not in framebuffer mode. To activate graphical boot, select a graphic video mode from the bootloader configuration tool.") . "\n" . - N("Do you want to configure it now?") ])) { - enable_framebuffer(); - #- it would be nice to get available themes for new cur_res here - }; - $boot_warn = 0 - } - $splash_box->set_sensitive($splash_mode); - }), - 1, gtkpack(gtkset_sensitive($splash_box = Gtk2::HBox->new(0, 0), $splash_mode), - gtkpack__(Gtk2::VBox->new(0, 5), - N("Theme"), - $combo{boot}, - #gtksignal_connect(Gtk2::CheckButton->new(N("Display theme\nunder console")), clicked => sub { invbool(\$keep_logo) }), - gtksignal_connect(gtkset_active(Gtk2::CheckButton->new(N("Display theme\nunder console")), $keep_logo), clicked => sub { invbool(\$keep_logo) }) - ), - Gtk2::VSeparator->new, - gtkpack__(Gtk2::VBox->new(0, 5), - $boot_pic)) - ), - ) - : - (1, gtkpack__(Gtk2::VBox->new(0, 5), - gtksignal_connect(gtkset_active(Gtk2::CheckButton->new(N("Launch the graphical environment when your system starts")), - $x_mode), - clicked => sub { - $x_box->set_sensitive(!$x_mode); - $x_mode = !$x_mode; - }), - gtkpack__(gtkset_sensitive($x_box = Gtk2::VBox->new(0, 0), $x_mode), - gtkpack__(Gtk2::VBox->new(0, 0), - my @auto_buttons = gtkradio((N("No, I do not want autologin")) x 2, - N("Yes, I want autologin with this (user, desktop)")), - ), - my $auto_box = create_packtable({ col_spacings => 5, row_spacings => 5, homogenous => 1 }, - [ Gtk2::Label->new(N("Default user")), $user_combo ], - [ Gtk2::Label->new(N("Default desktop")), $desktop_combo ], - ), - ) - ) - ), - 0, create_okcancel({ - cancel_clicked => sub { ugtk2->exit(0) }, - ok_clicked => sub { - Xconfig::various::runlevel($x_mode ? 5 : 3); - if ($splash_working) { - update_bootsplash($combo{boot}->entry->get_text, $splash_mode, $keep_logo); - } else { - updateAutologin(); - } - ugtk2->exit(0); - } - }, - ), - - ) - ) - ); - -if (!$splash_working) { + my @auto_buttons = gtkradio((N("No, I do not want autologin")) x 2, + N("Yes, I want autologin with this (user, desktop)")); $auto_buttons[1]->signal_connect('toggled' => sub { $auto_box->set_sensitive($auto_buttons[1]->get_active) }); $auto_buttons[0]->signal_connect('toggled' => sub { $auto_box->set_sensitive(!$auto_buttons[0]->get_active) }); - $auto_buttons[1]->set_active(1) if $auto_mode->{autologin}; - $auto_buttons[0]->set_active(1) if !$auto_mode->{autologin}; - $x_box->set_sensitive($x_mode); - $auto_box->set_sensitive($auto_mode->{autologin} ? 1 : 0); -} - -$window->show_all; -gtkflush(); -$w->main; -$in->exit(0); - - -sub lilo_choice() { - ask: - my $before = fs::fstab_to_string($all_hds); - any::setupBootloader($in, $bootloader, $all_hds, $fstab, $ENV{SECURE_LEVEL}) or $in->exit; - if ($before ne fs::fstab_to_string($all_hds)) { - #- for /tmp using tmpfs when "clean /tmp" is chosen - fs::write_fstab($all_hds); - } - any::installBootloader($in, $bootloader, $all_hds) or goto ask; + $auto_buttons[1]->set_active(1) if $auto_mode->{user}; + $auto_buttons[0]->set_active(1) if !$auto_mode->{user}; + + my $x_box; + run_boot_window(N("System mode"), + [ + 1, gtknew('VBox', spacing => 5, children_tight => [ + gtksignal_connect(gtkset_active(gtknew('CheckButton', text => N("Launch the graphical environment when your system starts")), + $x_mode), + clicked => sub { + $x_box->set_sensitive(!$x_mode); + $x_mode = !$x_mode; + }), + $x_box = gtknew('VBox', sensitive => $x_mode, children_tight => [ + gtknew('VBox', children_tight => [ @auto_buttons ]), + $auto_box + ]) ]) + ], + sub { + Xconfig::various::runlevel($x_mode ? 5 : 3); + $::testing and return; + if ($auto_buttons[1]->get_active) { + $auto_mode->{user} = $user_combo->entry->get_text; + $auto_mode->{desktop} = $desktop_combo->entry->get_text; + } else { + $auto_mode->{user} = undef; + $auto_mode->{desktop} = undef; + } + any::set_autologin($in->do_pkgs, $auto_mode); + }); } - #------------------------------------------------------------- # launch autologin functions #------------------------------------------------------------- -sub updateAutologin() { - my ($usern, $deskt) = ($user_combo->entry->get_text, $desktop_combo->entry->get_text); - $::testing and return; - if ($auto_buttons[1]->get_active) { - any::set_autologin($usern, $deskt); - } else { - any::set_autologin(); - } -} - -sub update_bootsplash { - my ($theme, $splash_mode, $keep_logo) = @_; - #- theme scripts will update SPLASH value in sysconfig file - if (-x $switch_theme) { - my $logo_console = $keep_logo ? 'theme' : 'no'; - if ($::testing) { - if ($splash_mode) { - print "substInFile { s/^LOGO_CONSOLE=.*/LOGO_CONSOLE=$logo_console/ } $themes{sysconfig}\n"; - print "system($switch_theme, $theme)\n"; - } else { - print "system($remove_theme)\n"; - } - } else { - if ($splash_mode) { - substInFile { s/^LOGO_CONSOLE=.*/LOGO_CONSOLE=$logo_console/ } $themes{sysconfig}; - system($switch_theme, $theme); - } else { - system($remove_theme); - } - } - } -} - sub change_image { - my ($boot_pic, $val) = @_; - my $img_file = $themes{path} . $val . $themes{boot}{path} . "bootsplash-$cur_res.jpg"; + my ($boot_pic, $theme, $res) = @_; + my $img_file = bootsplash::theme_get_image_for_resolution($theme, $res); -f $img_file or return; - my $boot_pixbuf = gtkcreate_pixbuf($img_file); + my $boot_pixbuf = gtknew('Pixbuf', file => $img_file); $boot_pixbuf = $boot_pixbuf->scale_simple(300, 200, 'nearest'); $boot_pic->set_from_pixbuf($boot_pixbuf); } + +sub set_splash_append { + my ($mode) = @_; + if ($mode ne 'splash') { + bootloader::remove_append_simple($bootloader, 'splash'); + bootloader::remove_append_simple($bootloader, 'quiet'); + } else { + bootloader::set_append_simple($bootloader, 'splash'); + bootloader::set_append_simple($bootloader, 'quiet'); + } + modify_bootloader($bootloader, $all_hds); +} + sub enable_framebuffer() { - my $vga = Xconfig::resolution_and_depth::from_bios($bootloader->{default_vga}); - my ($current_entry) = cat_('/proc/cmdline') =~ /^BOOT_IMAGE=(\S+)/; + my $vga = bootsplash::get_framebuffer_resolution(); + my ($current_entry) = $cmdline =~ /^BOOT_IMAGE=(\S+)/; my %entries = ( $current_entry => 1 ); @@ -315,7 +281,7 @@ Be sure your video card supports the mode you choose."), format => \&Xconfig::resolution_and_depth::to_string }, map { - { text => $_->{label}, val => \$entries{$_->{label}}, type => 'bool' } + { text => $_->{label}, val => \$entries{$_->{label}}, type => 'bool' }; } grep { $_->{label} !~ /failsafe|floppy|memtest/ } @{$bootloader->{entries}} ]); if ($vga) { @@ -325,10 +291,16 @@ Be sure your video card supports the mode you choose."), my $entry = find { $_->{label} eq $label } @{$bootloader->{entries}}; $entry->{vga} = $vga; } - bootloader::install($bootloader, $all_hds); + modify_bootloader($bootloader, $all_hds); } }; die if $@ && $@ !~ /^wizcancel/; $::WizardWindow->destroy unless $::isEmbedded; $vga; } + +sub modify_bootloader { + my ($bootloader, $all_hds) = @_; + bootloader::action($bootloader, 'write', $all_hds); + bootloader::action($bootloader, 'when_config_changed'); +} |
