summaryrefslogtreecommitdiffstats
path: root/lib/MGA/DrakISO/Utils.pm
diff options
context:
space:
mode:
authorMartin Whitaker <mageia@martin-whitaker.me.uk>2017-12-18 10:54:01 +0000
committerMartin Whitaker <mageia@martin-whitaker.me.uk>2017-12-18 10:54:01 +0000
commit296dc5bb53c430c8842ab7327d8a76b5750c64b4 (patch)
tree5670e983d5d459466dac2b7a49b7ce14827c7e9d /lib/MGA/DrakISO/Utils.pm
parent7e53518a7d8709998482eef1e9da21ee1a1886a9 (diff)
downloaddrakiso-296dc5bb53c430c8842ab7327d8a76b5750c64b4.tar
drakiso-296dc5bb53c430c8842ab7327d8a76b5750c64b4.tar.gz
drakiso-296dc5bb53c430c8842ab7327d8a76b5750c64b4.tar.bz2
drakiso-296dc5bb53c430c8842ab7327d8a76b5750c64b4.tar.xz
drakiso-296dc5bb53c430c8842ab7327d8a76b5750c64b4.zip
Start creating a new set of tools for generating Mageia ISO images.
The aim is to share as much code as possible between the tool used to generate the Live ISOs and the tool used to generate the classic installer ISOs. This is derived from the user/martinw/use-grub2 branch of draklive.
Diffstat (limited to 'lib/MGA/DrakISO/Utils.pm')
-rw-r--r--lib/MGA/DrakISO/Utils.pm85
1 files changed, 85 insertions, 0 deletions
diff --git a/lib/MGA/DrakISO/Utils.pm b/lib/MGA/DrakISO/Utils.pm
new file mode 100644
index 0000000..1f14241
--- /dev/null
+++ b/lib/MGA/DrakISO/Utils.pm
@@ -0,0 +1,85 @@
+package MGA::DrakISO::Utils;
+
+use MDK::Common;
+use common;
+use run_program;
+use IPC::Open3;
+use IO::Select;
+
+use Exporter;
+our @ISA = qw(Exporter);
+our @EXPORT = qw(directory_usage run_ run_foreach);
+
+sub directory_usage {
+ my ($dir, $o_apparent) = @_;
+ my $apparent = $o_apparent && "--apparent-size";
+ first(split /\s/, `du -s -B 1 $apparent $dir`);
+ }
+
+#- 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';
+ if (arch() !~ /^arm/) {
+ my $targetarch = delete $options->{targetarch};
+ unshift @cmd, 'setarch', $targetarch if $targetarch;
+ }
+ 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 device_allocate_file {
+ my ($device, $size) = @_;
+ run_('dd', "of=$device", 'count=0', 'bs=1', "seek=" . removeXiBSuffix($size));
+}
+
+#- format $device as type $type
+# FIXME: use fs::format
+sub device_mkfs {
+ my ($device, $type, $o_label, $o_inode_size) = @_;
+ if ($type eq 'vfat') {
+ run_('mkfs.vfat', if_(defined $o_label, '-n', $o_label), $device);
+ } elsif (member($type, 'ext2', 'ext3', 'ext4')) {
+ run_("mkfs.$type", "-m", 0,
+ if_(defined $o_label, '-L', $o_label),
+ if_($o_inode_size, '-I', $o_inode_size),
+ if_(!-b $device, '-F'),
+ $device);
+ } elsif ($type eq 'swap') {
+ run_('mkswap', if_(defined $o_label, '-L', $o_label), $device);
+ } else {
+ die "unable to mkfs for unsupported media type $type\n";
+ }
+}
+
+1;