summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Whitaker <mageia@martin-whitaker.me.uk>2017-11-25 20:22:46 +0000
committerMartin Whitaker <mageia@martin-whitaker.me.uk>2017-11-25 20:22:46 +0000
commitb42500157ca26d602072c0515d0810aadd8bfb12 (patch)
tree56d060d5672d68e04ceffc981d6debe9c44fef7e
parent3f312ebc4b3f0e8bb55f85eef1784c64ebd707f7 (diff)
downloaddrakiso-b42500157ca26d602072c0515d0810aadd8bfb12.tar
drakiso-b42500157ca26d602072c0515d0810aadd8bfb12.tar.gz
drakiso-b42500157ca26d602072c0515d0810aadd8bfb12.tar.bz2
drakiso-b42500157ca26d602072c0515d0810aadd8bfb12.tar.xz
drakiso-b42500157ca26d602072c0515d0810aadd8bfb12.zip
draklive2: removed functions not needed for building ISOs.
-rwxr-xr-xdraklive2883
1 files changed, 2 insertions, 881 deletions
diff --git a/draklive2 b/draklive2
index ad0ce5c..ecc4ac1 100755
--- a/draklive2
+++ b/draklive2
@@ -1,9 +1,8 @@
#!/usr/bin/perl
-# draklive $Id: draklive 150793 2007-04-05 12:08:47Z blino $
-
# Copyright (C) 2005 Mandriva
# Olivier Blin <oblin@mandriva.com>
+# Copyright (C) 2017 Mageia
#
# 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
@@ -685,32 +684,11 @@ sub create_classical_bootloader {
output_p($live->get_system_root . '/boot/grub/menu.lst', build_grub_cfg_raw($live, $live->{media}, -e $initrd && $initrd_prefix, { oem_rescue_idx => $oem_rescue_idx }, $part_idx));
}
-sub create_tarball {
- my ($live) = @_;
- run_("tar", "cjf", get_disk_master_prefix($live) . ".tar.bz2", $live->get_system_root);
-}
-
-sub set_device_label {
- my ($device, $type, $label) = @_;
- if ($type eq 'vfat') {
- MDV::Draklive::Utils::mtools_run_('mlabel', '-i', $device, '::' . $label);
- } elsif (member($type, 'ext2', 'ext3')) {
- run_('e2label', $device, $label);
- } else {
- die "unable to set label for unsupported media type $type\n";
- }
-}
-
sub get_cdrom_master_path {
my ($live, $opts) = @_;
$live->get_builddir . $live->{prefix}{build}{dist} . '/' . $live->get_name . ($opts->{boot} && "-boot-$opts->{boot}") . '.iso';
}
-sub get_cdrom_replicator_path {
- my ($live) = @_;
- get_disk_replicator_prefix($live) . ".iso";
-}
-
sub create_cdrom_master {
my ($live, $opts) = @_;
my $label = $live->{media}->get_media_label or die "the source device must be described by a label\n";
@@ -800,142 +778,6 @@ sub build_iso_image {
}
}
-sub get_disk_master_prefix {
- my ($live) = @_;
- $live->get_builddir . $live->{prefix}{build}{dist} . '/' . $live->get_name;
-}
-
-sub get_disk_master_path {
- my ($live) = @_;
- get_disk_master_prefix($live) . '.img';
-}
-
-sub get_partition_loop {
- my ($hd, $part) = @_;
- require devices;
- my $loop = devices::find_free_loop();
- run_('losetup', '-o', $part->{start} * $common::SECTORSIZE, '-s', $part->{size} * $common::SECTORSIZE, $loop, $hd->{file})
- or die "unable to setup loop device";
- return $loop;
-}
-
-sub get_harddisk_geometry {
- my ($media) = @_;
- $media->{geom} || {
- heads => 16,
- sectors => 63, # sectors per track
- };
-}
-
-sub get_hd_from_layout {
- my ($media, $dest) = @_;
- my $geom = get_harddisk_geometry($media);
- my $required_sectors = fold_left { $::a + $::b } map { $_->{size} } @{$media->{partitions}};
- $required_sectors += $geom->{sectors}; # keep one more track
- $geom->{cylinders} = POSIX::ceil($required_sectors / ($geom->{sectors} * $geom->{heads}));
- my $total_sectors = $geom->{cylinders} * $geom->{heads} * $geom->{sectors};
- bless {
- totalsectors => $total_sectors,
- geom => $geom,
- file => $dest,
- }, 'partition_table::dos';
-}
-
-sub get_hd_from_file {
- my ($media, $file) = @_;
- my $hd = bless {
- geom => get_harddisk_geometry($media),
- file => $file,
- }, 'partition_table::dos';
- partition_table::read($hd);
- return $hd;
-}
-
-sub supplement_media_partitions {
- my ($media, $hd) = @_;
- #- try to find additional partition details (start, device)
- #- by matching actual partition table and partitions list
- my @all_parts = partition_table::get_normal_parts($hd);
- foreach my $idx (0 .. $#all_parts) {
- $media->{partitions}[$idx]{$_} = $all_parts[$idx]{$_} foreach qw(start device);
- }
-}
-
-sub set_part_real_device {
- my ($hd, $part) = @_;
- #- FIXME: find a better way to compute mmcblk device path
- my $ext = $hd->{file} =~ m!^/dev/mmcblk! ? 'p' : '';
- $part->{real_device} = -f $hd->{file} ? get_partition_loop($hd, $part) : ($hd->{file} . $ext . $part->{device});
-}
-
-sub allocate_master {
- my ($media, $opts) = @_;
-
- $media->supplement_slash_size($opts->{slash_size}) if $opts->{slash_size};
- my $hd = get_hd_from_layout($media, $opts->{device});
-
- mkdir_p(dirname($opts->{device}));
- MDV::Draklive::Utils::device_allocate_file($opts->{device}, $hd->{totalsectors} * $common::SECTORSIZE);
-}
-
-sub format_master {
- my ($media, $opts) = @_;
-
- $media->supplement_slash_size($opts->{slash_size}) if $opts->{slash_size};
-
- my $hd = get_hd_from_layout($media, $opts->{device});
- partition_table::raw::zero_MBR($hd);
-
- #- FIXME: maybe use fsedit::allocatePartitions to factorize even more?
- foreach my $part (@{$media->{partitions}}) {
- my $hole = find { fs::type::isEmpty($_) && $_->{size} >= $part->{size} } partition_table::get_normal_parts_and_holes($hd)
- or die "not enough room for $part->{mntpoint}";
- $part->{start} = $hole->{start};
- fs::type::set_fs_type($part, $part->{fs_type});
- partition_table::add($hd, $part, 'Primary');
- }
-
- print "writing partition table\n";
- partition_table::write($hd);
- #- FIXME: move out from diskdrake::interactive::write_partitions to partition_table::write ?
- run_program::run('udevadm', 'settle');
-
- my $inode_size = $media->get_media_setting('inode_size');
- foreach my $part (@{$media->{partitions}}) {
- set_part_real_device($hd, $part);
- MDV::Draklive::Utils::device_mkfs($part->{real_device}, $part->{fs_type}, $part->{device_LABEL}, $inode_size)
- or die "unable to format $part->{real_device} in $hd->{file}\n";
- devices::del_loop($part->{real_device}) if -f $hd->{file};
- }
-}
-
-sub format_disk {
- my ($live, $opts) = @_;
- local $opts->{slash_size} = guess_disk_master_size($live);
- format_master($live->{media}, $opts);
-}
-
-sub guess_disk_master_size {
- my ($live) = @_;
-
- # slash_size:
- @{$live->{mount}{dirs} || []} ?
- (directory_usage($live->get_builddir . $live->{prefix}{build}{loopbacks}, 'apparent') +
- directory_usage($live->get_builddir . $live->{prefix}{build}{boot}) +
- directory_usage($live->get_builddir . $live->{prefix}{build}{files})
- ) :
- directory_usage($live->get_system_root);
-}
-
-sub create_disk_master {
- my ($live, $opts) = @_;
- local $opts->{slash_size} = guess_disk_master_size($live);
- local $opts->{device} = get_disk_master_path($live);
- allocate_master($live->{media}, $opts);
- format_master($live->{media}, $opts);
- record_master($live, $opts);
-}
-
#- $opts:
#- media: alternate media
#- onthefly : if true, the create function must output to stdout
@@ -954,690 +796,6 @@ sub maybe_umount_device {
run_('umount', $device) if cat_('/proc/mounts') =~ m!^$device\s+!m;
}
-sub format_cdrom_device {
- my ($live, $opts) = @_;
- run_('wodim', '-v', 'dev=' . get_media_device($live, $opts), "blank=fast");
-}
-
-#- $opts:
-#- media: alternate media
-sub format_device {
- my ($live, $opts) = @_;
-
- get_media_device($live, $opts) or die "no device defined in media configuration\n";
- if (my $format = $live->{media}->get_boot_setting('format', $opts)) {
- $format->($live, $opts);
- } else {
- warn "not implemented yet\n";
- }
-}
-
-sub record_cdrom_path {
- my ($live, $path, $opts) = @_;
- my $device = get_media_device($live, $opts)
- or die "no device defined in media configuration\n";
-
- #- CD-Rom images can be hybrid, thus handle recording on both CD-Rom and disks
- $device = basename(expand_symlinks($device));
- my $sysfs_device = "/sys/block/$device/capability";
- #- GENHD_FL_CD is 8 (include/linux/genhd.h)
- my $is_cdrom = !-e $sysfs_device || hex(cat_($sysfs_device)) & 8;
-
- if ($is_cdrom) {
- my $src = $opts->{onthefly} ? '-' : $path;
- run_('wodim', '-v', 'dev=' . $device, $src);
- } else {
- run_('dd', if_(!$opts->{onthefly}, "if=$path"), "of=$device", "bs=2M");
- }
-}
-
-sub record_cdrom_master {
- my ($live, $opts) = @_;
- record_cdrom_path($live, get_cdrom_master_path($live, $opts), $opts);
-}
-
-sub record_cdrom_replicator {
- my ($live, $opts) = @_;
- record_cdrom_path($live, get_cdrom_replicator_path($live), $opts);
-}
-
-sub rsync_delete_options {
- my ($opts) = @_;
- $opts->{keep_files} ? () : '--delete';
-}
-
-sub install_grub_to_image {
- my ($live, $media, $img, $opts) = @_;
- my $media_boot = $live->get_media_prefix('boot', $opts->{boot});
- my $grub_dir = "$media_boot/grub";
- my $grub_script = $grub_dir . "/install.sh";
- my $grub_src = first(glob_($live->get_system_root . "/lib/grub/*-mageia"));
- mkdir_p($live->{mnt} . $grub_dir);
- cp_af(glob_("$grub_src/*"), $live->{mnt} . $grub_dir);
-
- my $part_idx = $media->find_boot_partition_index;
- my $grub_prefix = $media->find_partition_index('/boot') ? "/grub" : $grub_dir;
-
- open(my $grub, "| /sbin/grub --batch --no-floppy");
- # using disk loopback fails, have to use image path
- print $grub <<EOF;
-device (hd0) $img
-root (hd0,$part_idx)
-setup --prefix=$grub_prefix (hd0)
-quit
-EOF
- close($grub) or die "unable to run grub\n";
-
- output($live->{mnt} . $grub_script, <<EOG);
-grub --device-map=$media_boot/grub/device.map --batch <<EOF
-root (hd0,$part_idx)
-setup --stage2=$media_boot/grub/stage2 (hd0)
-quit
-EOF
-EOG
-
- chmod 0755, $live->{mnt} . $grub_script;
-}
-
-sub install_disk_bootloader {
- my ($live, $media, $boot_device, $opts) = @_;
-
- return if $live->{system}{skip_bootloader_install};
-
- my $media_boot = $live->get_media_prefix('boot', $opts->{boot});
- my $device = get_media_device($live, $opts);
- my $bootloader = $media->get_boot_setting('bootloader', $opts);
-
- member($bootloader, 'grub', 'syslinux') or die "no bootloader defined in media configuration\n";
- if ($bootloader eq 'syslinux') {
- cp_f($live->get_builddir . $_, $live->{mnt}) foreach map {
- $live->{prefix}{boot} . $_;
- } get_syslinux_path($media, $opts), $media->get_initrd_path, @syslinux_boot_files;
- } elsif ($bootloader eq 'grub') {
- if (need_media_specific_boot($live) || $opts->{force_bootloader_config}) {
- #- FIXME: add get_grub_path (when building boot configuration files)
- # and get_bootloader_path (when copying)
- mkdir_p($live->{mnt} . $media_boot . '/grub');
- cp_f($live->get_builddir . $live->{prefix}{build}{boot} . '/gfxmenu', $live->{mnt} . $media_boot) if $live->{system}{gfxboot};
- output_p($live->{mnt} . $media_boot . '/grub/menu.lst', build_grub_cfg($live, $media, $opts, $boot_device));
- }
- }
-
- if (-b $boot_device) {
- if ($bootloader eq 'syslinux') {
- #- use syslinux -s, "safe, slow and stupid" version of SYSLINUX, unless specified otherwise
- run_('syslinux', if_(!$media->{fast_syslinux}, '-s'), $boot_device)
- or die "unable to run syslinux on $device\n";
- } elsif ($bootloader eq 'grub') {
- install_grub_to_image($live, $media, $device, $opts);
- }
- } else {
- warn "not running $bootloader on non block device $device\n";
- }
-}
-
-sub record_usb_master {
- my ($live, $opts) = @_;
- my $media = $live->{media};
- my $media_boot = $live->get_media_prefix('boot', $opts->{boot});
- my $media_loopbacks = $live->get_media_prefix('loopbacks', $opts->{boot});
-
- my $main_device = get_media_device($live, $opts)
- or die "unable to find recording device (missing label? try with --device <device>)\n";
-
- my $hd = get_hd_from_file($media, $main_device);
- supplement_media_partitions($media, $hd);
-
- my $slash_idx = $media->find_partition_index('/');
- my $slash = $media->{partitions}[$slash_idx];
- set_part_real_device($hd, $slash);
-
- if (my $label = !$opts->{boot_only} && $media->get_media_label) {
- set_device_label($slash->{real_device}, $media->get_media_setting('fs'), $label);
- }
-
- mkdir_p($live->{mnt});
- run_('mount', $slash->{real_device}, $live->{mnt})
- or die "unable to mount $slash->{real_device}\n";
-
- rm_rf($live->{mnt} . $media_boot) if -e $live->{mnt} . $media_boot;
- cp_af($live->get_builddir . $live->{prefix}{build}{boot}, $live->{mnt} . $media_boot);
-
- install_disk_bootloader($live, $media, $slash->{real_device}, $opts);
-
- do {
- my $loopbacks_source = $live->get_builddir . $live->{prefix}{build}{loopbacks} . '/';
- my $total = directory_usage($loopbacks_source);
- my $list_file = tmpnam();
- output_p($list_file, map { ".$_\n" } list_selected_loopbacks($live));
- local $/ = "\r";
- my $r = run_foreach(update_progress_rsync($live, $total),
- 'rsync', '-vdP', '--inplace', '--files-from=' . $list_file, rsync_delete_options($opts),
- $loopbacks_source, $live->{mnt} . $media_loopbacks,
- );
- unlink $list_file;
- if (!$r) {
- run_('umount', $slash->{real_device});
- maybe_umount_device($slash->{real_device});
- devices::del_loop($slash->{real_device}) if -f $hd->{file};
- die "unable to copy loopback files\n";
- }
-
- cp_af(glob_($live->get_builddir . $live->{prefix}{build}{files} . '/*'), $live->{mnt});
- } unless $opts->{boot_only};
-
- my @hidden_files = map { basename($_) } glob_($live->{mnt} . "/.*"), glob_($live->{mnt} . "/autorun.*");
-
- run_('umount', $slash->{real_device});
- maybe_umount_device($slash->{real_device});
-
- if ($media->get_media_setting('fs') eq 'vfat') {
- MDV::Draklive::Utils::mtools_run_('mattrib', '+h', '-i', $slash->{real_device}, '::' . $_) foreach @hidden_files;
- MDV::Draklive::Utils::mtools_run_('mattrib', '+r', '+s', '-/', '-i', $slash->{real_device}, '::' . $_)
- foreach $media_boot, $media_loopbacks;
- }
-
- devices::del_loop($slash->{real_device}) if -f $hd->{file};
-}
-
-sub record_harddisk_master {
- my ($live, $opts) = @_;
-
- my $media = $live->{media};
-
- my $main_device = get_media_device($live, $opts)
- or die "unable to find recording device (missing label? try with --device <device>)\n";
-
- my $hd = get_hd_from_file($media, $main_device);
- supplement_media_partitions($media, $hd);
- my @partitions = grep { $_->{mntpoint} =~ m!^/! } @{$media->{partitions}};
-
- mkdir_p($live->{mnt});
- foreach my $part (sort { $a->{mntpoint} cmp $b->{mntpoint} } @partitions) {
- set_part_real_device($hd, $part);
- my $mnt = $live->{mnt} . $part->{mntpoint};
- mkdir_p($mnt);
- run_('mount', $part->{real_device}, $mnt)
- or die "unable to mount $part->{real_device}\n";
- }
-
- my $r = 1;
- do {
- my $source = $live->get_system_root;
- my $total = directory_usage($source);
- local $/ = "\r";
- $r = run_foreach(update_progress_rsync($live, $total), 'rsync', rsync_delete_options($opts), '-a', $source . '/', $live->{mnt})
- or last;
- } unless $opts->{boot_only};
-
- my $boot_idx = $media->find_boot_partition_index;
- my $boot_part = $media->{partitions}[$boot_idx];
- install_disk_bootloader($live, $media, $boot_part->{real_device}, $opts);
-
- foreach my $part (sort { $b->{mntpoint} cmp $a->{mntpoint} } @partitions) {
- run_('umount', $part->{real_device});
- maybe_umount_device($part->{real_device});
- devices::del_loop($part->{real_device}) if -f $hd->{file};
- }
-
- $r or die "unable to copy system files\n";
-
- record_oem_rescue($live, $opts) if $live->{oem_rescue};
-}
-
-#- $opts:
-#- onthefly : if true, the record function must read from stdin
-sub record_master {
- my ($live, $opts) = @_;
-
- if (my $record = $live->{media}->get_boot_setting('record', $opts)) {
- $record->($live, $opts);
- } else {
- warn "not implemented yet\n";
- }
-}
-
-#- $opts:
-#- onthefly : if true, the record function must read from stdin
-sub record_replicator {
- my ($live, $opts) = @_;
-
- my $replicator_media = $live->{replicator}{media} or die "no replicator media";
- if (my $record_replicator = $replicator_media->get_boot_setting('record_replicator', $opts)) {
- $record_replicator->($live, $opts);
- } else {
- warn "not implemented yet\n";
- }
-}
-
-sub pipe_subs {
- my ($writer, $reader) = @_;
- my ($r, $w) = POSIX::pipe;
- if (my $pid = fork()) {
- POSIX::close($w) or die "couldn't close: $!\n";
- my $stdin = POSIX::dup(0) or die "couldn't dup: $!\n";
- POSIX::dup2($r, 0) or die "couldn't dup2: $!\n";
- POSIX::close($r);
- $reader->();
- POSIX::close(0) or warn "writer exited $?\n";
- POSIX::dup2($stdin, 0) or die "couldn't dup2: $!\n";
- waitpid($pid, 0);
- } else {
- POSIX::close($r) or die "couldn't close: $!\n";
- #- don't screw up reader
- POSIX::dup2(POSIX::open('/dev/null', &POSIX::O_WRONLY), 2) or die "couldn't dup2: $!\n";
- POSIX::dup2($w, 1) or die "couldn't dup2: $!\n";
- POSIX::close($w);
- $| = 1; #- autoflush write
- exit !$writer->();
- }
-}
-
-sub record_onthefly {
- my ($live, $opts) = @_;
-
- my $record = $live->{media}->get_storage_setting('record');
- unless ($record) {
- warn "not implemented yet\n";
- return;
- }
- if (my $create = $live->{media}->get_storage_setting('record_needs_master') && $live->{media}->get_storage_setting('create')) {
- local $opts->{onthefly} = 1;
- #- pipe creation step to recording step
- pipe_subs(sub { $create->($live, $opts) },
- sub { $record->($live, $opts) });
- } else {
- #- no creation step, record directly
- $record->($live, $opts);
- }
-}
-
-sub need_compressed_image {
- my ($live) = @_;
- #- compress image if not having loopbacks already
- !to_bool(list_selected_loopbacks($live));
-}
-
-sub get_disk_image_path {
- my ($live) = @_;
- if ($live->{settings}{compression_method} eq 'gzip') {
- get_disk_master_path($live) . if_(need_compressed_image($live), '.gz');
- }
- else {
- get_disk_master_path($live) . if_(need_compressed_image($live), '.bz2');
- }
-}
-
-sub create_disk_image {
- my ($live) = @_;
- if (!need_compressed_image($live)) {
- warn "already using loopback: skipping image creation\n";
- return;
- }
- my $master = get_disk_master_path($live);
- my $dest = get_disk_image_path($live);
- mkdir_p(dirname($dest));
-
- if ($live->{settings}{compression_method} eq 'gzip') {
- run_('gzip', '>', $dest, '-f', '-c', '--fast', $master);
- }
- else {
- run_('bzip2', '>', $dest, '-f', '-k', '-c', $master);
- }
-}
-
-sub create_image {
- my ($live) = @_;
-
- if (my $create = $live->{media}->get_media_setting('image')) {
- $create->($live);
- } else {
- warn "not implemented yet\n";
- }
-}
-
-sub create_vm_image {
- my ($live) = @_;
-
- my $vm_type = $live->{settings}{vm_type};
- if (!$vm_type) {
- warn "no vm_type has been set in settings, skipping";
- return;
- }
-
- if (!$live->{media}->get_media_setting('image')) {
- warn "not implemented yet\n";
- return;
- }
-
- my $master = get_disk_master_path($live);
- if (!-f $master) {
- warn "no master image, skipping\n";
- }
-
- my $vm_image = get_disk_master_prefix($live) . ".$vm_type";
- run_("qemu-img", "convert", "-O", $vm_type, $master, $vm_image);
-}
-
-sub get_rescue_files {
- my ($live, $rescue_opts, $o_extra_files) = @_;
- my $media_boot = $live->get_media_prefix('boot');
- my $initrd = $media_boot . $rescue_opts->{media}->get_initrd_path;
- my @stage2_files = $live->{settings}{replicator_type} eq 'drakx' ? (
- '/usr/lib/drakx-installer-stage2/install/stage2/mdkinst.sqfs',
- $live->get_system_root . '/bin/dd',
- ) : '/usr/lib/drakx-installer-rescue/rescue.sqfs';
- (
- '/usr/lib/drakx-installer-images/isolinux/alt0/vmlinuz' => $media_boot . '/vmlinuz',
- '/usr/lib/drakx-installer-images/isolinux/alt0/all.rdz' => $initrd,
- (map { $_ => '/install/stage2/' } @stage2_files),
- @{$o_extra_files || []},
- #- FIXME: factorize with copy_files_to to handle glob
- (map { $live->{settings}{config_root} . '/' . $_->[0] => '/' . $_->[1] } @{$rescue_opts->{files} || []}),
- );
-}
-
-sub record_rescue_files {
- my ($mnt, $device, $rescue_files) = @_;
- my $failed;
- foreach (group_by2(@$rescue_files)) {
- my ($src, $dest) = @$_;
- $dest = $mnt . $dest;
- mkdir_p($dest =~ m!/$! ? $dest : dirname($dest));
- if (!run_('rsync', '-vdP', '--inplace', $src, $dest)) {
- $failed = 1;
- last;
- }
- }
-
- #- FIXME
- chmod 0755, $mnt . '/' . 'oem-rescue.sh';
-
- if ($failed) {
- run_('umount', $mnt);
- maybe_umount_device($device);
- die "unable to copy rescue files\n";
- }
-}
-
-sub record_oem_rescue {
- my ($live, $opts) = @_;
-
- my $media = $live->{media};
- my $oem_rescue_idx = $media->find_partition_index('OEM_RESCUE');
- defined $oem_rescue_idx or die "no OEM_RESCUE partition";
-
- my $main_device = get_media_device($live, $opts)
- or die "unable to find recording device (missing label? try with --device <device>)\n";
-
- my $hd = get_hd_from_file($media, $main_device);
- supplement_media_partitions($media, $hd);
-
- my $oem_rescue = $media->{partitions}[$oem_rescue_idx];
- set_part_real_device($hd, $oem_rescue);
-
- mkdir_p($live->{mnt});
- run_('mount', $oem_rescue->{real_device}, $live->{mnt})
- or die "unable to mount $oem_rescue->{real_device}\n";
-
- record_rescue_files($live->{mnt}, $oem_rescue->{real_device}, [ get_rescue_files($live, $live->{oem_rescue}) ]);
-
- run_('umount', $oem_rescue->{real_device});
- maybe_umount_device($oem_rescue->{real_device});
- devices::del_loop($oem_rescue->{real_device}) if -f $hd->{file};
-}
-
-sub get_disk_replicator_prefix {
- my ($live) = @_;
- $live->get_builddir . $live->{prefix}{build}{dist} . '/' . $live->get_name . '.rest';
-}
-
-sub get_disk_replicator_path {
- my ($live) = @_;
- get_disk_replicator_prefix($live) . ".img";
-}
-
-sub get_disk_replicator_files {
- my ($live) = @_;
- get_rescue_files($live, $live->{replicator}, [ get_disk_image_path($live) => '/images/' ]);
-}
-
-sub get_disk_replicator_images_list {
- my ($live) = @_;
- my $master_path = get_disk_master_path($live);
- my $master_size = (stat($master_path))[7];
- "EN,English," . basename(get_disk_image_path($live)) . ",on,$master_size\n";
-}
-
-sub create_usb_replicator {
- my ($live, $opts) = @_;
- my %files = get_disk_replicator_files($live);
- local $opts->{slash_size} = fold_left { $::a + $::b } map { directory_usage($_, 'apparent') } keys(%files);
- local $opts->{device} = get_disk_replicator_path($live);
- allocate_master($live->{replicator}{media}, $opts);
- format_master($live->{replicator}{media}, $opts);
- record_usb_replicator($live, $opts);
-}
-
-sub record_usb_replicator {
- my ($live, $opts) = @_;
-
- my $media = $live->{replicator}{media};
- my $media_boot = $live->get_media_prefix('boot');
-
- $opts->{append} ||= $live->{replicator}{append};
- my $main_device = get_media_device($live, $opts)
- or die "unable to find recording device (missing label? try with --device <device>)\n";
-
- my $hd = get_hd_from_file($media, $main_device);
- supplement_media_partitions($media, $hd);
-
- my $slash_idx = $media->find_partition_index('/');
- my $slash = $media->{partitions}[$slash_idx];
- set_part_real_device($hd, $slash);
-
- mkdir_p($live->{mnt});
- run_('mount', $slash->{real_device}, $live->{mnt})
- or die "unable to mount $slash->{real_device}\n";
- rm_rf($live->{mnt} . $media_boot) if -e $live->{mnt} . $media_boot;
- {
- local $opts->{force_bootloader_config} = 1;
- install_disk_bootloader($live, $media, $slash->{real_device}, $opts);
- }
-
- record_rescue_files($live->{mnt}, $slash->{real_device}, [ get_disk_replicator_files($live) ]);
- output_p($live->{mnt} . "/images/list", get_disk_replicator_images_list($live));
-
- run_('umount', $slash->{real_device});
- maybe_umount_device($slash->{real_device});
- devices::del_loop($slash->{real_device}) if -f $hd->{file};
-}
-
-sub create_cdrom_replicator {
- my ($live, $opts) = @_;
-
- # FIXME: factorize with usb replicator, write in builddir/replicator/images-list
- my $images_list = "/tmp/images-replicator.list";
- output_p($images_list, get_disk_replicator_images_list($live));
-
- # FIXME: write in builddir/replicator/syslinux.cfg
- my $syslinux_cfg = "/tmp/syslinux-replicator.cfg";
- local $opts->{append} = $live->{replicator}{append};
- output_p($syslinux_cfg, build_syslinux_cfg($live, $live->{replicator}{media}, $opts));
-
- my $label = $live->{replicator}{media}->get_media_label or die "the source device must be described by a label\n";
- my $dest = get_cdrom_replicator_path($live);
- build_iso_image(
- $live,
- $dest,
- $syslinux_cfg,
- $label,
- $live->get_media_prefix('boot', $opts->{boot}) . '/syslinux=' . $live->get_builddir . $live->{prefix}{build}{boot} . '/syslinux',
- "/images/list=$images_list",
- (map {
- my ($src, $dest) = @$_;
- my $dest_file = $dest =~ m!/$! ? $dest . basename($src) : $dest;
- $dest_file . "=" . $src;
- } group_by2(get_disk_replicator_files($live))),
- );
-}
-
-sub create_replicator {
- my ($live, $opts) = @_;
-
- if (my $create = $live->{replicator}{media} && $live->{replicator}{media}->get_media_setting('replicator')) {
- $create->($live, $opts);
- } else {
- warn "not implemented yet\n";
- }
-}
-
-sub update_progress_rsync {
- my ($live, $total) = @_;
- my $all_files = 0;
- my $current_file = 0;
- $live->{update_progress} ? sub {
- if (/^\s*(\d+)\s+\d+%\s+/) {
- $current_file = $1;
- $live->{update_progress}->(undef, $all_files + $current_file, $total);
- }
- if (/(?:^|\n)\S+/) {
- $all_files += $current_file;
- $current_file = 0;
- }
- } : sub { print };
-}
-
-sub copy_wizard {
- my ($live) = @_;
-
- MDV::Draklive::Config::complete_config($live);
- $live->{system}{vga_mode} = 788 if !defined $live->{system}{vga_mode};
- my $live_media = $live->{prefix}{live}{mnt} . $live->{prefix}{media}{mnt};
-
- require interactive;
- require wizards;
- my $in = 'interactive'->vnew('su');
- my (@available_storage, @available_devices);
- my ($storage, $device, $format);
- my %source_types = (
- live => N("Use current live system"),
- file => N("Select a file"),
- );
- my ($source_type, $source_path);
- my $media_boot = $live->get_media_prefix('boot');
- my $media_loopbacks = $live->get_media_prefix('loopbacks');
- my $source_is_mounted = sub { -d ($live->{settings}{builddir} . $media_boot) };
- my $umount_source = sub {
- if ($source_type ne 'live' && $source_is_mounted->()) {
- run_('umount', $live->{settings}{builddir});
- rmdir($live->{settings}{builddir});
- }
- };
- my $w;
- $w = wizards->new({
- name => N("Live system copy wizard"),
- pages => {
- welcome => {
- name => N("Welcome to the live system copy wizard"),
- no_back => 1,
- next => 'source',
- },
- source => {
- name => N("Which live system do you want to copy?"),
- data => [ if_(-d ($live_media . $media_loopbacks),
- { type => 'list', val => \$source_type,
- list => sort(keys(%source_types)),
- format => sub { $source_types{$_[0]} } }),
- { type => 'file', val => \$source_path,
- disabled => sub { $source_type eq 'live' } } ],
- pre => $umount_source,
- complete => sub {
- if ($source_type eq 'live') {
- $live->{settings}{builddir} = $live_media;
- } else {
- $live->{settings}{builddir} = File::Temp::tempdir();
- if (!run_('mount', '-o', 'loop', $source_path, $live->{settings}{builddir})) {
- $in->ask_warn(N("Error"), N("Unable to use selected file"));
- return 1;
- }
- }
- 0;
- },
- post => sub {
- my $boot = $live->{settings}{builddir} . $media_boot;
- @available_storage = sort(grep { -d "$boot/$_" && exists $MDV::Draklive::Storage::storage_types{$_}{detect} } all($boot));
- if (@available_storage == 1) {
- $storage = $available_storage[0];
- return 'device';
- }
- return 'storage';
- }
- },
- storage => {
- name => N("Please select the medium type"),
- data => [ { type => 'list', allow_empty_list => 1,
- val => \$storage, list => \@available_storage } ],
- next => 'device',
- },
- device => {
- name => N("Please select the device that will contain the new live system"),
- pre => sub {
- my %devices = map { $_->{device} => $_ } $MDV::Draklive::Storage::storage_types{$storage}{detect}->();
- $_->{formatted_name} = $_->{usb_description} || $_->{info} || $_->{device} foreach values %devices;
- @available_devices = ();
- require fs::proc_partitions;
- foreach (fs::proc_partitions::read([ values %devices ])) {
- if ($_->{rootDevice} && exists $devices{$_->{rootDevice}}) {
- my $description = $devices{$_->{rootDevice}}{usb_description} || $devices{$_->{rootDevice}}{info};
- $_->{formatted_name} = $description ? "$description ($_->{device})" : $_->{device};
- push @available_devices, $_;
- }
- }
- delete $devices{$_->{rootDevice}} foreach @available_devices;
- unshift @available_devices, map { $devices{$_} } sort keys %devices;
- undef $device;
- },
- data => [ { type => 'list', allow_empty_list => 1,
- val => \$device, , list => \@available_devices,
- format => sub { $_[0]{formatted_name} } },
- { text => N("Format selected device"), val => \$format, type => 'bool' } ],
- complete => sub {
- return 0 if defined $device;
- $in->ask_warn(N("Error"), N("You must select a device!"));
- 1;
- },
- post => sub {
- (my $_wait, $live->{update_progress}) = $in->wait_message_with_progress_bar;
- do {
- local $::isInstall = 1; # quick hack to embed the wait message
- $live->{update_progress}->(N("Copying in progress"));
- };
- eval {
- my $opts = { media => { storage => $storage, device => '/dev/' . $device->{device} } };
- format_device($live, $opts) if $format;
- record_onthefly($live, $opts);
- };
- delete $live->{update_progress};
- if (my $error = $@) {
- $in->ask_warn(N("Error"), $error);
- $w->{pages}{device}{end} = 1;
- }
- return "end";
- },
- },
- end => {
- name => N("Congratulations") . "\n\n" . N("Your live system is now copied."),
- no_back => 1,
- end => 1,
- },
- }
- });
- $w->process($in);
- $umount_source->();
- $in->exit;
-}
-
sub clean {
my ($live) = @_;
# umount filesystem in the live before cleaning
@@ -1653,18 +811,10 @@ my @actions = (
{ name => 'post-install', do => \&post_install_system },
{ name => 'initrd', do => \&create_initrd },
{ name => 'boot', do => \&prepare_bootloader },
- { name => 'tarball', do => \&create_tarball },
{ name => 'loop', do => \&create_loopback_files },
{ name => 'master', do => \&create_master },
- { name => 'image', do => \&create_image },
- { name => 'vm-image', do => \&create_vm_image },
- { name => 'replicator', do => \&create_replicator },
- { name => 'format', do => \&format_device },
- { name => 'record', do => \&record_master },
- { name => 'record-onthefly', do => \&record_onthefly },
- { name => 'record-replicator', do => \&record_replicator },
);
-my @all = qw(install boot loop master image vm-image replicator);
+my @all = qw(install boot loop master);
die "you must be root to run this program\n" if $>;
@@ -1675,13 +825,9 @@ my $config_path = $MDV::Draklive::Config::default_config_path;
my $settings_path = $MDV::Draklive::Config::default_settings_path;
GetOptions(
"help" => sub { Pod::Usage::pod2usage('-verbose' => 1) },
- "copy-wizard" => \$live_object->{copy_wizard},
- "keep-files" => \$opts{keep_files},
"boot-only" => \$opts{boot_only},
- "boot-image=s" => sub { $opts{boot} = $_[1]; $opts{boot_only} = 1 },
"all" => sub { $_->{to_run} = 1 foreach grep { member($_->{name}, @all) } @actions },
(map { $_->{name} => \$_->{to_run} } @actions),
- "device=s" => sub { $opts{device} = $_[1] },
"all-regions" => sub { $live_object->{all_regions} = 1 },
"config-root=s" => \$config_root,
"config=s" => \$config_path,
@@ -1690,9 +836,6 @@ GetOptions(
) or Pod::Usage::pod2usage();
require standalone;
-if ($live_object->{copy_wizard}) {
- copy_wizard($live_object);
-} else {
every { !$_->{to_run} } @actions and Pod::Usage::pod2usage();
MDV::Draklive::Config::read_config($live_object, $config_root, $config_path, $settings_path);
MDV::Draklive::Config::check_config($live_object);
@@ -1706,7 +849,6 @@ if ($live_object->{copy_wizard}) {
print qq(* step "$_->{name}" done\n);
}
}
-}
__END__
@@ -1723,26 +865,13 @@ draklive [options]
--install install selected distribution in chroot
--boot prepare initrd and bootloader files
- --tarball build chroot tarball
--loop build compressed loopback files
--master build master image
- --image build compressed master image
- --replicator build replicator image (to dump master on systems)
--all run all steps, from installation to mastering
--clean clean installation chroot and work directory
- --device <dev> use this device for live recording (not needed
- if the device already has the required label)
- --format format selected device
- --record record live on selected media
- --record-onthefly record live by creating master from loopback files
- on the fly
- --keep-files keep existing files on media when recording
- --record-replicator
- record replicator on selected media
-
--initrd build initrd only
--post-install run post install only (rpms and patches installation)
@@ -1762,23 +891,15 @@ draklive [options]
--all-regions proceed with all configured regions
- --copy-wizard run the copy wizard
-
--boot-only copy only boot files
(affects master/record steps)
- --boot-image <method>
- create a boot image for the selected method
- (affects master/record steps, implies --boot-only)
-
Examples:
draklive --clean
draklive --all
- draklive --record --device /dev/sdb1
-
draklive --config config/live.cfg --install
=head1 OPTIONS