From ee3c362650de294390fc40a583c0dee3b678b4aa Mon Sep 17 00:00:00 2001 From: Olivier Blin Date: Thu, 25 Sep 2008 10:59:05 +0000 Subject: add --replicator to build replicator image (to dump master on systems) --- draklive | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/draklive b/draklive index 4060db8..24a65e6 100755 --- a/draklive +++ b/draklive @@ -159,6 +159,7 @@ my %storage = ( create => \&create_disk_master, record => \&record_harddisk_master, image => \&create_disk_image, + replicator => \&create_disk_replicator_usb, }, ); @@ -1666,6 +1667,80 @@ sub create_image { } } +sub get_disk_replicator_path { + my ($live) = @_; + get_builddir($live) . $live->{prefix}{build}{dist} . '/' . get_live_name($live) . '.rest.img'; +} + +sub get_disk_replicator_media() { + { storage => 'usb', bootloader => 'grub' }; +} + +sub get_disk_replicator_files { + my ($live) = @_; + my $media = get_disk_replicator_media(); + my $media_boot = get_media_prefix($live, 'boot'); + my $initrd = $media_boot . get_initrd_path($media); + ( + '/usr/lib/drakx-installer-images/isolinux/alt0/vmlinuz' => $media_boot . '/vmlinuz', + '/usr/lib/drakx-installer-images/isolinux/alt0/all.rdz' => $initrd, + '/usr/lib/drakx-installer-rescue/rescue.sqfs' => '/install/stage2/', + get_disk_image_path($live) => '/images/', + ); +} + +sub create_disk_replicator_usb { + my ($live) = @_; + my $dest = get_disk_replicator_path($live); + my %files = get_disk_replicator_files($live); + my $size = fold_left { $::a + $::b } map { directory_usage($_) } keys(%files); + my $loop = allocate_master($dest, 3000000 + $size, 'vfat'); + my $opts = { device => $loop, disk_device => $dest }; + record_disk_replicator_usb($live, $opts); + run_('losetup', '-d', $loop); +} + +sub record_disk_replicator_usb { + my ($live, $opts) = @_; + my $media = get_disk_replicator_media(); + my $media_boot = get_media_prefix($live, 'boot'); + my $device = get_media_device($live, $opts) + or die "unable to find recording device (missing label? try with --device )\n"; + mkdir_p($live->{mnt}); + run_('mount', if_(-f $device, '-o', 'loop'), $device, $live->{mnt}) + or die "unable to mount $device\n"; + rm_rf($live->{mnt} . $media_boot) if -e $live->{mnt} . $media_boot; + install_usb_bootloader($live, $media, $opts); + + my $failed; + foreach (group_by2(get_disk_replicator_files($live))) { + my ($src, $dest) = @$_; + $dest = $live->{mnt} . $dest; + mkdir_p($dest =~ m!/$! ? $dest : dirname($dest)); + if (!run_('rsync', '-vdP', '--inplace', $src, $dest)) { + $failed = 1; + last; + } + } + if ($failed) { + run_('umount', $live->{mnt}); + maybe_umount_device($device); + die "unable to copy replicator files\n"; + } + run_('umount', $live->{mnt}); + maybe_umount_device($device); +} + +sub create_replicator { + my ($live) = @_; + + if (my $create = get_boot_setting($live->{media}, 'replicator')) { + $create->($live); + } else { + warn "not implemented yet\n"; + } +} + sub copy_wizard { my ($live) = @_; @@ -1887,11 +1962,12 @@ my @actions = ( { name => 'loop', do => \&create_loopback_files }, { name => 'master', do => \&create_master }, { name => 'image', do => \&create_image }, + { name => 'replicator', do => \&create_replicator }, { name => 'format', do => \&format_device }, { name => 'record', do => \&record_master }, { name => 'record-onthefly', do => \&record_onthefly }, ); -my @all = qw(install boot loop master image); +my @all = qw(install boot loop master image replicator); die "you must be root to run this program\n" if $>; @@ -1951,6 +2027,7 @@ draklive [options] --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 -- cgit v1.2.1