# Copyright (C) 2005 Mandriva # Olivier Blin # Copyright (C) 2017-2018 Mageia # Martin Whitaker # # 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 # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA. # SYNOPSIS # -------- # This package provides a function to build the compressed image that will # be mounted as a loopback filesystem when booting a Live system. package MGA::DrakISO::BuildLoop; use strict; use MDK::Common; use File::Temp qw(tmpnam); use MGA::DrakISO::LiveBuild; use MGA::DrakISO::Utils; use Exporter; our @ISA = qw(Exporter); our @EXPORT = qw(build_live_loopback_file); # This is the top-level function called to build the loopback image. The Live # root filesystem must have been prepared before calling this function. # sub build_live_loopback_file { my ($build) = @_; my $root = $build->get_live_root; # make sure no external filesystems are mounted before creating the loopback umount_all_in_root($root); my $total = directory_usage($root); print "Have to process " . int($total/1000000) . " MB\n" if $::verbose; my $dest = $build->get_build_dir('loopbacks') . '/distrib.sqfs'; mkdir_p(dirname($dest)); my $exclude_list = tmpnam(); my @excluded_files = expand_file_list($build, @{$build->{loopbacks}{exclude} || []}); output_p($exclude_list, map { $root . "$_\n" } grep { run_as_root('test', '-e', $root . $_) } @excluded_files); my $sort = $build->{settings}{config_root} . '/config/distrib.sort'; run_as_root(join(' ', 'mksquashfs', $root, $dest, '-noappend', '-comp', 'xz', '-b', '1048576', '-ef', $exclude_list, if_(-f $sort, '-sort', $sort), if_($::verbose > 2, '-info', '-progress'), if_($::verbose < 2, '-no-progress'), # due to lack of a -quiet option if_($::verbose < 2, '> /dev/null'), )) or die "ERROR: unable to run mksquashfs\n"; unlink $exclude_list; } sub expand_file_list { my ($build, @files) = @_; map { $_->{path} ? $_->{path} : chomp_(cat_(glob(($_->{rooted} && $build->get_live_root) . $_->{source}))); } @files; } 1;