summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Whitaker <mageia@martin-whitaker.me.uk>2017-11-29 14:49:43 +0000
committerMartin Whitaker <mageia@martin-whitaker.me.uk>2017-11-29 14:52:36 +0000
commit3b3edc1a1c59f0e675c10d8f6f33a8800f9be783 (patch)
tree77755cbb7aba58226ef6dcecce14a7f865ef9899
parentbb3602d4081e5d6d56ea3629f808cc2ed5f56f94 (diff)
downloaddrakiso-3b3edc1a1c59f0e675c10d8f6f33a8800f9be783.tar
drakiso-3b3edc1a1c59f0e675c10d8f6f33a8800f9be783.tar.gz
drakiso-3b3edc1a1c59f0e675c10d8f6f33a8800f9be783.tar.bz2
drakiso-3b3edc1a1c59f0e675c10d8f6f33a8800f9be783.tar.xz
drakiso-3b3edc1a1c59f0e675c10d8f6f33a8800f9be783.zip
draklive2: split into sections and order functions consistently.
No code changes - just consistently order functions from highest level to lowest level. This is all to improve code readability.
-rwxr-xr-xdraklive2232
1 files changed, 130 insertions, 102 deletions
diff --git a/draklive2 b/draklive2
index fe6a471..3c05d57 100755
--- a/draklive2
+++ b/draklive2
@@ -37,6 +37,10 @@ use MDV::Draklive::Loopback;
use MDV::Draklive::Config;
use MDV::Draklive::Storage;
+###############################################################################
+# Common Helper Functions
+###############################################################################
+
sub get_langs {
my ($live) = @_;
uniq(
@@ -45,6 +49,28 @@ sub get_langs {
);
}
+sub mount_system_fs {
+ my ($live) = @_;
+ run_('mount', '-t', 'devtmpfs', '/dev', $live->get_system_root . '/dev');
+ run_('mount', '-t', 'proc', '/proc', $live->get_system_root . '/proc');
+ run_('mount', '-t', 'sysfs', '/sys', $live->get_system_root . '/sys');
+ run_('mount', '-t', 'debugfs', '/sys/kernel/debug/usb', $live->get_system_root . '/sys/kernel/debug/usb');
+}
+
+sub umount_system_fs {
+ my ($live) = @_;
+ eval { fs::mount::umount($live->get_system_root . $_) } foreach qw(/dev /proc /run /sys/kernel/debug/usb /sys);
+}
+
+sub umount_external_fs {
+ my ($live) = @_;
+ eval { fs::mount::umount($live->get_system_root . $_) } foreach map { "/mnt/$_" } all($live->get_system_root . "/mnt");
+}
+
+###############################################################################
+# Install Phase
+###############################################################################
+
sub install_system {
my ($live) = @_;
@@ -78,55 +104,6 @@ sub install_system {
post_install_system($live);
}
-sub configure_draklive_resize {
- my ($live) = @_;
-
- my $resizable_loopback = find { $_->{min_size} } @{$live->{mount}{dirs} || []};
- if ($resizable_loopback) {
- my $media_loopbacks = $live->get_media_prefix('loopbacks');
- my $ext = $loop_types{$resizable_loopback->{type}}{extension};
- output($live->get_system_root . '/etc/sysconfig/draklive-resize', <<EOF);
-DRAKLIVE_RESIZE=yes
-LOOPBACK=$live->{prefix}{live}{mnt}$live->{prefix}{media}{mnt}${media_loopbacks}$resizable_loopback->{path}$ext
-TYPE=$resizable_loopback->{fs}
-MIN_SIZE=$resizable_loopback->{min_size}
-MOUNT=$live->{prefix}{live}{mnt}$resizable_loopback->{mountpoint}_resized
-OLD_MOUNT=$live->{prefix}{live}{mnt}$resizable_loopback->{mountpoint}
-UNION=/
-EOF
- }
-}
-
-sub copy_files_to {
- my ($live, $files, $root) = @_;
- foreach (@$files) {
- my ($source, $dest, $o_opts) = @$_;
- $dest = $root . '/' . $dest;
- mkdir_p($dest =~ m|/$| ? $dest : dirname($dest));
- my @sources = MDV::Draklive::Utils::glob__($live->{settings}{config_root} . '/' . $source);
- print STDERR "copying @sources to $dest\n";
- cp_af(@sources, $dest);
- my $o_perm = $o_opts && $o_opts->{mode};
- chmod $o_perm, $dest if $o_perm;
- }
-}
-
-sub join_lists {
- my ($separator, $head, @lists) = @_;
- @{$head || []}, map { $separator, @$_ } @lists;
-}
-
-sub remove_files_from {
- my ($files, $root) = @_;
- run_('find', $root, '(', join_lists('-o', map { [ '-name', $_ ] } @$files), ')', '-exec', 'rm', '-r', '{}', ';')
- if $files && @$files;
-}
-
-sub clean_system_conf_file {
- my ($live, $file) = @_;
- substInFile { undef $_ if /^[^#]/ } $live->get_system_root . $file;
-}
-
sub post_install_system {
my ($live) = @_;
@@ -243,6 +220,55 @@ sub post_install_system {
umask $previous_umask;
}
+sub configure_draklive_resize {
+ my ($live) = @_;
+
+ my $resizable_loopback = find { $_->{min_size} } @{$live->{mount}{dirs} || []};
+ if ($resizable_loopback) {
+ my $media_loopbacks = $live->get_media_prefix('loopbacks');
+ my $ext = $loop_types{$resizable_loopback->{type}}{extension};
+ output($live->get_system_root . '/etc/sysconfig/draklive-resize', <<EOF);
+DRAKLIVE_RESIZE=yes
+LOOPBACK=$live->{prefix}{live}{mnt}$live->{prefix}{media}{mnt}${media_loopbacks}$resizable_loopback->{path}$ext
+TYPE=$resizable_loopback->{fs}
+MIN_SIZE=$resizable_loopback->{min_size}
+MOUNT=$live->{prefix}{live}{mnt}$resizable_loopback->{mountpoint}_resized
+OLD_MOUNT=$live->{prefix}{live}{mnt}$resizable_loopback->{mountpoint}
+UNION=/
+EOF
+ }
+}
+
+sub copy_files_to {
+ my ($live, $files, $root) = @_;
+ foreach (@$files) {
+ my ($source, $dest, $o_opts) = @$_;
+ $dest = $root . '/' . $dest;
+ mkdir_p($dest =~ m|/$| ? $dest : dirname($dest));
+ my @sources = MDV::Draklive::Utils::glob__($live->{settings}{config_root} . '/' . $source);
+ print STDERR "copying @sources to $dest\n";
+ cp_af(@sources, $dest);
+ my $o_perm = $o_opts && $o_opts->{mode};
+ chmod $o_perm, $dest if $o_perm;
+ }
+}
+
+sub remove_files_from {
+ my ($files, $root) = @_;
+ run_('find', $root, '(', join_lists('-o', map { [ '-name', $_ ] } @$files), ')', '-exec', 'rm', '-r', '{}', ';')
+ if $files && @$files;
+}
+
+sub join_lists {
+ my ($separator, $head, @lists) = @_;
+ @{$head || []}, map { $separator, @$_ } @lists;
+}
+
+sub clean_system_conf_file {
+ my ($live, $file) = @_;
+ substInFile { undef $_ if /^[^#]/ } $live->get_system_root . $file;
+}
+
sub write_dist_lists {
my ($live) = @_;
@@ -270,59 +296,9 @@ sub write_dist_lists {
output_p($langs_file, map { lang::l2name($_) . " (" . $_ . ")\n" } sort(@langs));
}
-sub mount_system_fs {
- my ($live) = @_;
- run_('mount', '-t', 'devtmpfs', '/dev', $live->get_system_root . '/dev');
- run_('mount', '-t', 'proc', '/proc', $live->get_system_root . '/proc');
- run_('mount', '-t', 'sysfs', '/sys', $live->get_system_root . '/sys');
- run_('mount', '-t', 'debugfs', '/sys/kernel/debug/usb', $live->get_system_root . '/sys/kernel/debug/usb');
-}
-
-sub umount_system_fs {
- my ($live) = @_;
- eval { fs::mount::umount($live->get_system_root . $_) } foreach qw(/dev /proc /run /sys/kernel/debug/usb /sys);
-}
-
-sub umount_external_fs {
- my ($live) = @_;
- eval { fs::mount::umount($live->get_system_root . $_) } foreach map { "/mnt/$_" } all($live->get_system_root . "/mnt");
-}
-
-sub expand_file_list {
- my ($live, @files) = @_;
- map {
- $_->{path} ?
- $_->{path} :
- chomp_(cat_(glob(($_->{rooted} && $live->get_system_root) . $_->{source})));
- } @files;
-}
-
-#- hardlink recursively file list to a directory
-sub hardlink_filtered {
- my ($src, $dest, $files) = @_;
- mkdir_p($dest);
- my $pwd = $ENV{PWD};
- chdir($src);
- my $list_file = tmpnam();
- output_p($list_file, map { "$_\n" } grep { -e $src . $_ } @$files);
- #- cpio -pldm won't copy recursively, use rsync -r instead
- system('rsync', '-ar', '--files-from=' . $list_file, '--link-dest=' . $src, $src, $dest);
- unlink $list_file;
- chdir($pwd);
-}
-
-sub list_loopback_modules {
- my ($live) = @_;
- map {
- my $l = $_;
- map {
- my $list = $_;
- my $name = basename($list);
- $name =~ s/\.[^.]+$//;
- { type => $l->{type}, name => $name, files => [ expand_file_list($live, { source => $list }) ] };
- } glob(($_->{rooted} && $live->get_system_root) . $_->{source});
- } @{$live->{loopbacks}{modules}};
-}
+###############################################################################
+# Loop Phase
+###############################################################################
sub create_loopback_files {
my ($live) = @_;
@@ -368,6 +344,42 @@ sub create_loopback_files {
}
}
+sub expand_file_list {
+ my ($live, @files) = @_;
+ map {
+ $_->{path} ?
+ $_->{path} :
+ chomp_(cat_(glob(($_->{rooted} && $live->get_system_root) . $_->{source})));
+ } @files;
+}
+
+#- hardlink recursively file list to a directory
+sub hardlink_filtered {
+ my ($src, $dest, $files) = @_;
+ mkdir_p($dest);
+ my $pwd = $ENV{PWD};
+ chdir($src);
+ my $list_file = tmpnam();
+ output_p($list_file, map { "$_\n" } grep { -e $src . $_ } @$files);
+ #- cpio -pldm won't copy recursively, use rsync -r instead
+ system('rsync', '-ar', '--files-from=' . $list_file, '--link-dest=' . $src, $src, $dest);
+ unlink $list_file;
+ chdir($pwd);
+}
+
+sub list_loopback_modules {
+ my ($live) = @_;
+ map {
+ my $l = $_;
+ map {
+ my $list = $_;
+ my $name = basename($list);
+ $name =~ s/\.[^.]+$//;
+ { type => $l->{type}, name => $name, files => [ expand_file_list($live, { source => $list }) ] };
+ } glob(($_->{rooted} && $live->get_system_root) . $_->{source});
+ } @{$live->{loopbacks}{modules}};
+}
+
sub list_selected_loopbacks {
my ($live) = @_;
my @pack = $live->{settings}{pack} ? @{$live->{packs}{$live->{settings}{pack}} || []} : ();
@@ -376,6 +388,10 @@ sub list_selected_loopbacks {
(map { $live->{prefix}{build}{modules} . '/' . $_->{name} . $loop_types{$_->{type}}{extension} } @pack_modules);
}
+###############################################################################
+# Boot Phase
+###############################################################################
+
sub prepare_bootloader {
my ($live) = @_;
create_initrd($live);
@@ -570,6 +586,10 @@ sub build_uefi_grub2_cfg {
);
}
+###############################################################################
+# Master Phase
+###############################################################################
+
sub create_master {
my ($live) = @_;
@@ -668,6 +688,10 @@ sub build_iso_image {
}
}
+###############################################################################
+# Clean Phase
+###############################################################################
+
sub clean {
my ($live) = @_;
# umount filesystem in the live before cleaning
@@ -676,6 +700,10 @@ sub clean {
rm_rf($_) foreach grep { -e $_ } $live->get_builddir, $live->get_system_root;
}
+###############################################################################
+# Main Program
+###############################################################################
+
my @actions = (
{ name => 'dump-config', do => \&MDV::Draklive::Config::dump_config },
{ name => 'clean', do => \&clean },