rendered paste body#!/usr/bin/perl
use lib qw(/usr/lib/libDrakX);
use standalone;
use interactive;
use fs::any;
use fs::type;
use fs::partitioning;
use fs::partitioning_wizard;
use MDK::Common;
use common;
push @::textdomains, 'draklive-install';
{
#mklivecd specific stuff
system("mkdir -p /tmp/etc");
system("cp /etc/fstab /tmp/etc/fstab.hwdetect");
# this will a new initrd when setup bootloader
system("cat /proc/cmdline |grep livecd && rm -rf /boot/*.img");
system("cat /proc/cmdline |grep livecd && rm -rf /boot/boot*");
use diskdrake::interactive;
package diskdrake::interactive;
my $old = \&hd_possible_actions;
undef *hd_possible_actions;
*hd_possible_actions = sub {
#- for the partition wizard to show the auto-allocate option
local $::isInstall = 1;
&$old;
};
undef *Done;
#- skip the fstab/reboot checks
*Done = \&diskdrake_interactive_Done;
#- don't ask whether to Move/Hide old files
undef *need_migration;
*need_migration = sub { 'hide' };
}
sub umount_all {
my ($fstab) = @_;
#- make sure nothing is mounted in the new root
foreach (sort { $b cmp $a } grep { /^$::prefix/ } map { (split)[1] } cat_('/proc/mounts')) {
system('umount', $_);
}
#- make sure selected devices aren't mounted, and swap isn't used
foreach (grep { isSwap($_) } @$fstab) {
eval { fs::mount::swapoff($_->{device}) };
}
foreach (map { $_->{mntpoint} && !isSwap($_) ? "/dev/$_->{device}" : () } @$fstab) {
system('umount', $_);
}
}
sub on_reboot_needed {
my ($in) = @_;
fs::partitioning_wizard::warn_reboot_needed($in);
$in->exit(0);
}
my $in = 'interactive'->vnew('su');
$::prefix = '/mnt/install';
my $all_hds = {};
my $fstab = [];
fs::any::get_hds($all_hds, $fstab, [], {}, 'skip_mtab', $in);
umount_all($fstab);
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 - MCNLive");
{
local $::isStandalone = $has_running_wm; # center me if run in xsetup.d script
my $w = ugtk2->new($title);
ugtk2::gtkadd($w->{window},
ugtk2::gtkcreate_img("MandrivaOne-install"),
ugtk2::gtknew('Label', height => 5),
N("This wizard will help you to install the live distribution."),
ugtk2::create_okcancel($w));
$w->{ok}->grab_focus;
$w->main;
}
fs::partitioning_wizard::main($in, $all_hds, $fstab, [], undef, {}, 'skip_mtab');
mkdir_p($::prefix) or die "unable to create $::prefix";
#- install_steps::doPartitionDisksAfter - mklivecd specific, replaces the commented code.
sub doPartitionDisksAfter {
my ($all_hds, $fstab, $opts) = @_;
if (!$::testing) {
my $hds = $all_hds->{hds};
partition_table::write($_) foreach @$hds;
}
fs::set_removable_mntpoints($all_hds);
fs::mount_options::set_all_default($all_hds, %$opts, lang::fs_options($opts->{locale}));
@$fstab = fs::get::fstab($all_hds);
}
doPartitionDisksAfter($all_hds, $fstab, $in);
# volgende regel knallt eruit met mcnlive, perl error, vervangen door de sub bovenaan
#fs::any::write_hds($all_hds, $fstab, undef, \&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
my $wait = do {
local $::isInstall = 1; # quick hack to embed the wait message
$in->wait_message('', N("Computing total size"));
};
my $total = first(split(/\s+/, `du -sbx /union 2>/dev/null`));
undef $wait;
sub build_copy_command {
my ($source, $dest) = @_;
join(' ',
'tar', 'c', '--one-file-system', '-C', $source, '.',
'|',
'tar', 'xvv', '-C', $dest,
);
}
($wait, my $update_progress) = do {
local $::isInstall = 1; # quick hack to embed the wait message;
copying_message_with_progress_bar($in, N("Copying in progress"));
};
open(my $OUTPUT, '-|', build_copy_command('/union', $::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;
}
}
}
undef $update_progress;
undef $wait;
#- FIXME: maybe factorize with draklive, using draklive --clean-chroot ?
#- remove unwanted files and packages
#unlink(map { $::prefix . $_ } '/.autofsck',
# '/home/guest/Desktop/draklive-copy-wizard.desktop',
# '/home/guest/Desktop/draklive-install.desktop');
#system('chroot', $::prefix, 'rpm', '-e', 'draklive-install');
#- enable first boot wizard at system boot
#output($::prefix . '/etc/sysconfig/firstboot', 'FIRSTBOOT=yes');
#- enable drakx-finish-install at system boot
#output($::prefix . '/etc/sysconfig/finish-install', qq(
#FINISH_INSTALL=yes
#LICENSE=no
#LANGUAGE=no
#KEYBOARD=no
#TIMEZONE=no
#NETWORK=yes
#AUTHENTICATION=yes
#USERS=yes
#USER_RENAME_FROM=guest
#GLX=no
#));
#- unselect guest 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;
#- allow to install doc in disk install
substInFile { undef $_ if /^\%_excludedocs/ } $::prefix . '/etc/rpm/macros';
#- create required directories and devices
mkdir_p($::prefix . $_) foreach qw(/dev /etc /proc /sys /initrd /tmp /media /mnt);
run_program::run('makedev', $::prefix . '/dev');
#- write fstab
fs::write_fstab($all_hds, $::prefix);
#mklivecd specific, add missing entries, no cdrom entry yet, pts ???
open FSTAB, '>>', "$::prefix/etc/fstab";
print FSTAB "\nnone"."\t"."/proc"."\t"."proc"."\t"."defaults"."\t"."0 0";
print FSTAB "\n";
close FSTAB;
# enable back some disabled services
#require services;
#services::start_service_on_boot($_) foreach qw(dkms crond);
# re-establish original inittab otherwise system wont boot in read/write mode, mklivecd specific
system("cat /initrd/etc/inittab |sed -e /'^# si'/'s/# si/si/' >/inittab;mv -f /inittab $::prefix/etc/inittab");
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);
###
### duplicate code
###
#- from disdrake::interactive
{
package diskdrake::interactive;
sub diskdrake_interactive_Done {
my ($in, $all_hds) = @_;
eval { raid::verify($all_hds->{raids}) };
if (my $err = $@) {
$::expert or die;
$in->ask_okcancel('', [ formatError($err), N("Continue anyway?") ]) or return;
}
foreach (@{$all_hds->{hds}}) {
if (!write_partitions($in, $_, 'skip_check_rebootNeeded')) {
return if !$::isStandalone;
$in->ask_yesorno(N("Quit without saving"), N("Quit without writing the partition table?"), 1) or return;
}
}
#- skip that fstab/reboot steps
if (!$::isInstall && 0) {
my $new = fs::fstab_to_string($all_hds);
if ($new ne $all_hds->{current_fstab} && $in->ask_yesorno('', N("Do you want to save /etc/fstab modifications"), 1)) {
$all_hds->{current_fstab} = $new;
fs::write_fstab($all_hds);
}
update_bootloader_for_renumbered_partitions($in, $all_hds);
if (any { $_->{rebootNeeded} } @{$all_hds->{hds}}) {
$in->ask_warn('', N("You need to reboot for the partition table modifications to take place"));
tell_wm_and_reboot();
}
}
if (my $part = find { $_->{mntpoint} && !maybeFormatted($_) } fs::get::fstab($all_hds)) {
$in->ask_okcancel('', N("You should format partition %s.
Otherwise no entry for mount point %s will be written in fstab.
Quit anyway?", $part->{device}, $part->{mntpoint})) or return if $::isStandalone && 0; #- no, please
}
1;
}
}
# forked from interactive::wait_message
sub copying_message {
my ($o, $title, $message, $b_temp) = @_;
my $w = $o->wait_messageW($title, N("Copying in progress"), ugtk2::gtknew('VBox', children_tight => [
ugtk2::gtkcreate_img("MandrivaOne-advert"),
$message,
]));
push @tempory::objects, $w if $b_temp;
my $b = before_leaving { $o->wait_message_endW($w) };
#- enable access through set
MDK::Common::Func::add_f4before_leaving(sub { $o->wait_message_nextW($_[1], $w) }, $b, 'set');
$b;
}
# forked from interactive::gtk::wait_message_with_progress_bar
sub copying_message_with_progress_bar {
my ($in, $o_title) = @_;
my $progress = Gtk2::ProgressBar->new;
my $w = copying_message($in, $o_title, $progress);
my $displayed;
$progress->signal_connect(expose_event => sub { $displayed = 1; 0 });
$w, sub {
my ($msg, $current, $total) = @_;
if ($msg) {
$w->set($msg);
}
if ($total) {
$progress or internal_error('You must first give some text to display');
$progress->set_fraction($current / $total);
$progress->show;
$displayed = 0;
mygtk2::flush() while !$displayed;
} else {
$progress->hide if !$total;
}
};
}