From 9d2df7d6738db9dc59cb2edb5aaa94a6ee5991b5 Mon Sep 17 00:00:00 2001 From: Olivier Blin Date: Wed, 19 Mar 2008 23:35:58 +0000 Subject: split in subroutines and localize variables --- draklive-install | 265 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 149 insertions(+), 116 deletions(-) diff --git a/draklive-install b/draklive-install index 996b8e6..a97e4bf 100755 --- a/draklive-install +++ b/draklive-install @@ -30,6 +30,33 @@ push @::textdomains, 'draklive-install'; *need_migration = sub { 'hide' }; } +install_live(); + +sub install_live() { + my $in = 'interactive'->vnew('su'); + $in->{pop_wait_messages} = 0; + + $::isWizard = 1; + $::Wizard_no_previous = 1; + $::Wizard_pix_up = "MandrivaOne-install-icon"; + + my $all_hds = {}; + my $fstab = []; + $::prefix = '/mnt/install'; + my $copy_source = '/'; + + display_start_message(); + init_hds($in, $all_hds, $fstab); + ask_partitions($in, $all_hds, $fstab); + prepare_root($in, $all_hds); + copy_root($in, $copy_source); + complete_install($in, $all_hds); + setup_bootloader($in, $all_hds, $fstab); + finish_installation($fstab); + display_end_message($in); + $in->exit(0); +} + sub umount_all { my ($fstab) = @_; #- make sure nothing is mounted in the new root @@ -51,19 +78,11 @@ sub on_reboot_needed { $in->exit(0); } -my $in = 'interactive'->vnew('su'); -$in->{pop_wait_messages} = 0; -my $wait; - -require any; -my $has_running_wm = to_bool(any::running_window_manager()); -$::isWizard = 1; -$::Wizard_no_previous = 1; -$::Wizard_pix_up = "MandrivaOne-install-icon"; -my $title = N("Mandriva Live"); -{ +sub display_start_message() { + require any; + my $has_running_wm = to_bool(any::running_window_manager()); local $::isStandalone = $has_running_wm; # center me if run in xsetup.d script - my $w = ugtk2->new($title); + my $w = ugtk2->new(N("Mandriva Live")); ugtk2::gtkadd($w->{window}, ugtk2::gtkcreate_img("MandrivaOne-install"), ugtk2::gtknew('Label', height => 5), @@ -73,44 +92,43 @@ my $title = N("Mandriva Live"); $w->main; } -$wait = $in->wait_message('', N("Please wait")); -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) ]; -fs::merge_info_from_mtab($fstab); -eval { fs::mount::umount_all($fstab) }; - -$::prefix = '/mnt/install'; -$all_hds = {}; -$fstab = []; -fs::any::get_hds($all_hds, $fstab, [], {}, 'skip_mtab', $in); - -umount_all($fstab); - -undef $wait; -fs::partitioning_wizard::main($in, $all_hds, $fstab, [], undef, {}, 'skip_mtab'); +sub umount_first_pass() { + 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) ]; + fs::merge_info_from_mtab($fstab); + eval { fs::mount::umount_all($fstab) }; +} -mkdir_p($::prefix) or die "unable to create $::prefix"; +sub init_hds { + my ($in, $all_hds, $fstab) = @_; + my $_wait = $in->wait_message('', N("Please wait")); + umount_first_pass(); + fs::any::get_hds($all_hds, $fstab, [], {}, 'skip_mtab', $in); + umount_all($fstab); +} -fs::any::write_hds($all_hds, $fstab, undef, sub { on_reboot_needed($in) }, {}); -fs::any::check_hds_boot_and_root($all_hds, $fstab); -fs::partitioning::choose_partitions_to_format($in, $fstab); -umount_all($fstab); -fs::partitioning::format_mount_partitions($in, $all_hds, $fstab); +sub ask_partitions { + my ($in, $all_hds, $fstab) = @_; + fs::partitioning_wizard::main($in, $all_hds, $fstab, [], undef, {}, 'skip_mtab'); -#- create required directories and devices (early to have a consistent root before calling other programs) -$wait = $in->wait_message('', N("Please wait")); -fs::any::prepare_minimal_root($all_hds); -run_program::run('makedev', $::prefix . '/dev'); -undef $wait; + mkdir_p($::prefix) or die "unable to create $::prefix"; -my $copy_source = '/'; + fs::any::write_hds($all_hds, $fstab, undef, sub { on_reboot_needed($in) }, {}); + fs::any::check_hds_boot_and_root($all_hds, $fstab); + fs::partitioning::choose_partitions_to_format($in, $fstab); + umount_all($fstab); + fs::partitioning::format_mount_partitions($in, $all_hds, $fstab); +} -#- copy to disk -$wait = $in->wait_message('', N("Computing total size")); -my $total = first(split(/\s+/, `du -sbx $copy_source 2>/dev/null`)); -undef $wait; +sub prepare_root { + my ($in, $all_hds) = @_; + #- create required directories and devices (early to have a consistent root before calling other programs) + my $_wait = $in->wait_message('', N("Please wait")); + fs::any::prepare_minimal_root($all_hds); + run_program::run('makedev', $::prefix . '/dev'); +} sub build_copy_command { my ($source, $dest) = @_; @@ -121,86 +139,101 @@ sub build_copy_command { ); } -($wait, my $update_progress) = copying_message_with_progress_bar($in, N("Copying in progress")); -open(my $OUTPUT, '-|', build_copy_command($copy_source, $::prefix)); -{ - local $_; - my $current = my $previous = 0; - while (<$OUTPUT>) { - (undef, undef, my $size) = split; - $current += $size; - if ($current <= $total && $current/$total > $previous/$total + 0.001) { - $update_progress->('', $current, $total); - $previous = $current; - } - } +sub get_total_size { + my ($in, $source) = @_; + #- copy to disk + my $_wait = $in->wait_message('', N("Computing total size")); + first(split(/\s+/, `du -sbx $source 2>/dev/null`)); } -undef $update_progress; -undef $wait; - -$wait = $in->wait_message('', N("Please wait")); - -my $real_rpm_dir = "/tmp/rpm/real"; -cp_f(glob($real_rpm_dir . "/*"), $::prefix . "/var/lib/rpm") if -d $real_rpm_dir; - -#- FIXME: maybe factorize with draklive, using draklive --clean-chroot ? -#- remove unwanted files and packages -my $live_user_desktop = chomp_(run_program::rooted_get_stdout($::prefix, "su - $live_user -c 'xdg-user-dir DESKTOP'")); -unlink(map { $::prefix . $_ } '/.autofsck', - '/etc/modprobe.d/mandriva-live', - $live_user_desktop . '/draklive-copy-wizard.desktop', - $live_user_desktop . '/draklive-install.desktop'); -system('chroot', $::prefix, 'rpm', '-e', 'draklive-install'); - -#- copy sysconfig files for first boot -cp_f(glob('/etc/draklive-install.d/sysconfig/*'), $::prefix . '/etc/sysconfig'); - -#- allow mdkonline to be started again -eval { rm_rf($::prefix . '/etc/skel/.MdkOnline', glob($::prefix . '/home/*/.MdkOnline')) }; - -#- unselect live user in kdm -my $kdm_cfg = '/etc/kde/kdm/kdmrc'; -update_gnomekderc($::prefix . $kdm_cfg, - 'X-:0-Greeter' => (PreselectUser => 'None', DefaultUser => '')) if -f $kdm_cfg; -any::set_autologin($in->do_pkgs, undef); - -#- allow to install doc in disk install -substInFile { undef $_ if /^\%_excludedocs/ } $::prefix . '/etc/rpm/macros'; - -#- write fstab -fs::write_fstab($all_hds, $::prefix); - -#- remove harddisks from harddrake's config file, so that hardddisks -#- are automatically rediscovered at first boot -require Storable; -my $harddrake_file = $::prefix . "/etc/sysconfig/harddrake2/previous_hw"; -my $harddrake_conf = eval { Storable::retrieve($harddrake_file) }; -if ($harddrake_conf) { - delete $harddrake_conf->{HARDDISK}; - Storable::store($harddrake_conf, $harddrake_file); + +sub copy_root { + my ($in, $copy_source) = @_; + my $total = get_total_size($in, $copy_source); + + my ($_wait, $update_progress) = copying_message_with_progress_bar($in, N("Copying in progress")); + open(my $OUTPUT, '-|', build_copy_command($copy_source, $::prefix)); + { + local $_; + my $current = my $previous = 0; + while (<$OUTPUT>) { + (undef, undef, my $size) = split; + $current += $size; + if ($current <= $total && $current/$total > $previous/$total + 0.001) { + $update_progress->('', $current, $total); + $previous = $current; + } + } + } } -# enable back some disabled services -require services; -services::start_service_on_boot($_) foreach qw(dkms crond); +sub complete_install { + my ($in, $all_hds) = @_; + my $_wait = $in->wait_message('', N("Please wait")); + + my $real_rpm_dir = "/tmp/rpm/real"; + cp_f(glob($real_rpm_dir . "/*"), $::prefix . "/var/lib/rpm") if -d $real_rpm_dir; + + #- FIXME: maybe factorize with draklive, using draklive --clean-chroot ? + #- remove unwanted files and packages + my $live_user_desktop = chomp_(run_program::rooted_get_stdout($::prefix, "su - $live_user -c 'xdg-user-dir DESKTOP'")); + unlink(map { $::prefix . $_ } '/.autofsck', + '/etc/modprobe.d/mandriva-live', + $live_user_desktop . '/draklive-copy-wizard.desktop', + $live_user_desktop . '/draklive-install.desktop'); + system('chroot', $::prefix, 'rpm', '-e', 'draklive-install'); + + #- copy sysconfig files for first boot + cp_f(glob('/etc/draklive-install.d/sysconfig/*'), $::prefix . '/etc/sysconfig'); + + #- allow mdkonline to be started again + eval { rm_rf($::prefix . '/etc/skel/.MdkOnline', glob($::prefix . '/home/*/.MdkOnline')) }; + + #- unselect live user in kdm + my $kdm_cfg = '/etc/kde/kdm/kdmrc'; + update_gnomekderc($::prefix . $kdm_cfg, + 'X-:0-Greeter' => (PreselectUser => 'None', DefaultUser => '')) if -f $kdm_cfg; + any::set_autologin($in->do_pkgs, undef); + + #- allow to install doc in disk install + substInFile { undef $_ if /^\%_excludedocs/ } $::prefix . '/etc/rpm/macros'; + + fs::write_fstab($all_hds, $::prefix); + + #- remove harddisks from harddrake's config file, so that hardddisks + #- are automatically rediscovered at first boot + require Storable; + my $harddrake_file = $::prefix . "/etc/sysconfig/harddrake2/previous_hw"; + my $harddrake_conf = eval { Storable::retrieve($harddrake_file) }; + if ($harddrake_conf) { + delete $harddrake_conf->{HARDDISK}; + Storable::store($harddrake_conf, $harddrake_file); + } -undef $wait; -use bootloader; -my $bootloader = {}; -any::setupBootloaderBeforeStandalone($in->do_pkgs, $bootloader, $all_hds, $fstab); -{ + # enable back some disabled services + require services; + services::start_service_on_boot($_) foreach qw(dkms crond); +} + +sub setup_bootloader { + my ($in, $all_hds, $fstab) = @_; + use bootloader; + my $bootloader = {}; + any::setupBootloaderBeforeStandalone($in->do_pkgs, $bootloader, $all_hds, $fstab); local $::Wizard_no_previous = 0; any::setupBootloaderUntilInstalled($in, $bootloader, $all_hds, $fstab, $ENV{SECURE_LEVEL}); } -#- cleanly umount here, it will avoid fs journals to be corrupted after a hackish reboot -umount_all($fstab); - -$::Wizard_finished = 1; -$in->ask_okcancel(N("Congratulations"), N("Please halt your computer, remove your live system, and restart your computer.")); - -$in->exit(0); +sub finish_installation { + my ($fstab) = @_; + #- cleanly umount here, it will avoid fs journals to be corrupted after a hackish reboot + umount_all($fstab); +} +sub display_end_message { + my ($in) = @_; + $::Wizard_finished = 1; + $in->ask_okcancel(N("Congratulations"), N("Please halt your computer, remove your live system, and restart your computer.")); +} ### ### duplicate code -- cgit v1.2.1