summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xdraklive51
-rw-r--r--lib/MDV/Draklive/Utils.pm49
2 files changed, 54 insertions, 46 deletions
diff --git a/draklive b/draklive
index a52c476..e70115d 100755
--- a/draklive
+++ b/draklive
@@ -36,6 +36,7 @@ use File::Temp;
use IPC::Open3;
use IO::Select;
use IO::Handle;
+use MDV::Draklive::Utils;
my $dir_distrib_sqfs = {
mountpoint => '/distrib',
@@ -366,48 +367,6 @@ my %overlay = (
},
);
-sub directory_usage { first(split /\s/, `du -sb $_[0]`) }
-
-#- expand only if the pattern contains '*'
-#- and matches dot characters (like shell dotglob)
-sub glob__ {
- my ($pattern) = @_;
- $pattern =~ /\*/ ? glob_($pattern) : $pattern;
-}
-
-sub run_ {
- my $options = ref $_[0] eq 'HASH' ? shift @_ : {};
- my @cmd = @_;
- $options->{timeout} ||= 'never';
- my $setarch = delete $options->{setarch};
- unshift @cmd, 'setarch', $setarch if $setarch;
- print STDERR "running " . (exists $options->{root} && "(in chroot) ") . join(' ', @cmd) . "\n";
- run_program::raw($options, @cmd);
-}
-
-sub run_foreach {
- my ($foreach, @command) = @_;
- print STDERR "running " . join(' ', @command) . "\n";
- my $pid = open3(my $cmd_in, my $cmd_out, undef, @command);
- my $selector = IO::Select->new($cmd_out);
- while (my @ready = $selector->can_read) {
- foreach my $fh (@ready) {
- local $_ = scalar<$fh>;
- return if /^open3:/;
- $foreach->();
- $selector->remove($fh) if eof($fh);
- }
- }
- close($cmd_out);
- close($cmd_in);
- return waitpid($pid, 0) > 0 && !($? >> 8);
-}
-
-sub mtools_run_ {
- local $ENV{MTOOLS_SKIP_CHECK} = 1;
- &run_;
-}
-
sub get_live_name {
my ($live) = @_;
join('-', grep { $_ } @{$live->{settings}}{qw(name product version desktop region media arch)});
@@ -851,7 +810,7 @@ sub copy_files_to {
my ($source, $dest, $o_opts) = @$_;
$dest = $root . '/' . $dest;
mkdir_p($dest =~ m|/$| ? $dest : dirname($dest));
- my @sources = glob__($live->{settings}{config_root} . '/' . $source);
+ my @sources = MDV::Draklive::Utils::glob__($live->{settings}{config_root} . '/' . $source);
print STDERR "copying @sources to $dest\n";
cp_f(@sources, $dest);
my $o_perm = $o_opts && $o_opts->{mode};
@@ -1242,7 +1201,7 @@ sub device_mkfs {
sub set_device_label {
my ($device, $type, $label) = @_;
if ($type eq 'vfat') {
- mtools_run_('mlabel', '-i', $device, '::' . $label);
+ MDV::Draklive::Utils::mtools_run_('mlabel', '-i', $device, '::' . $label);
} elsif (member($type, 'ext2', 'ext3')) {
run_('e2label', $device, $label);
} else {
@@ -1558,8 +1517,8 @@ sub record_usb_master {
maybe_umount_device($device);
if (get_media_setting($media, 'fs') eq 'vfat') {
- mtools_run_('mattrib', '+h', '-i', $device, '::' . $_) foreach @hidden_files;
- mtools_run_('mattrib', '+r', '+s', '-/', '-i', $device, '::' . $_)
+ MDV::Draklive::Utils::mtools_run_('mattrib', '+h', '-i', $device, '::' . $_) foreach @hidden_files;
+ MDV::Draklive::Utils::mtools_run_('mattrib', '+r', '+s', '-/', '-i', $device, '::' . $_)
foreach $media_boot, $media_loopbacks;
}
}
diff --git a/lib/MDV/Draklive/Utils.pm b/lib/MDV/Draklive/Utils.pm
new file mode 100644
index 0000000..e3e2e2b
--- /dev/null
+++ b/lib/MDV/Draklive/Utils.pm
@@ -0,0 +1,49 @@
+package MDV::Draklive::Utils;
+
+use Exporter;
+our @ISA = qw(Exporter);
+our @EXPORT = qw(directory_usage run_ run_foreach);
+
+sub directory_usage { first(split /\s/, `du -sb $_[0]`) }
+
+#- expand only if the pattern contains '*'
+#- and matches dot characters (like shell dotglob)
+sub glob__ {
+ my ($pattern) = @_;
+ $pattern =~ /\*/ ? glob_($pattern) : $pattern;
+}
+
+sub run_ {
+ my $options = ref $_[0] eq 'HASH' ? shift @_ : {};
+ my @cmd = @_;
+ $options->{timeout} ||= 'never';
+ my $setarch = delete $options->{setarch};
+ unshift @cmd, 'setarch', $setarch if $setarch;
+ print STDERR "running " . (exists $options->{root} && "(in chroot) ") . join(' ', @cmd) . "\n";
+ run_program::raw($options, @cmd);
+}
+
+sub run_foreach {
+ my ($foreach, @command) = @_;
+ print STDERR "running " . join(' ', @command) . "\n";
+ my $pid = open3(my $cmd_in, my $cmd_out, undef, @command);
+ my $selector = IO::Select->new($cmd_out);
+ while (my @ready = $selector->can_read) {
+ foreach my $fh (@ready) {
+ local $_ = scalar<$fh>;
+ return if /^open3:/;
+ $foreach->();
+ $selector->remove($fh) if eof($fh);
+ }
+ }
+ close($cmd_out);
+ close($cmd_in);
+ return waitpid($pid, 0) > 0 && !($? >> 8);
+}
+
+sub mtools_run_ {
+ local $ENV{MTOOLS_SKIP_CHECK} = 1;
+ &run_;
+}
+
+1;