From 5295430b1fc68246a39c96efd8e593de9322f222 Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Sat, 3 Mar 2018 22:37:04 +0000 Subject: Complete support for using a remote repository. --- lib/MGA/DrakISO/BuildRoot.pm | 28 +++++++++++++++++++++++----- lib/MGA/DrakISO/Utils.pm | 10 +++++++--- 2 files changed, 30 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/MGA/DrakISO/BuildRoot.pm b/lib/MGA/DrakISO/BuildRoot.pm index 4a7cfe0..d9bd2c4 100644 --- a/lib/MGA/DrakISO/BuildRoot.pm +++ b/lib/MGA/DrakISO/BuildRoot.pm @@ -92,6 +92,7 @@ sub install_live_system { # Mount the stage2 installer filesystem. if ($remote_method) { + mkdir_p($chroot . '/tmp'); my $local_mdkinst = $chroot . '/tmp/mdkinst.sqfs'; run_('curl', '--silent', '-o', $local_mdkinst, $arch_repository . '/install/stage2/mdkinst.sqfs') or die "ERROR: failed to download mdkinst.sqfs from remote repository\n"; @@ -172,7 +173,7 @@ sub install_live_system { "HOME=/", ); my $cmd = "/usr/bin/runinstall2 --local_install --auto_install $rooted_auto_inst"; - $cmd .= "--method $remote_method" if $remote_method; + $cmd .= " --method $remote_method" if $remote_method; run_in_root($chroot, $arch, 'sh', '-c', "$env $cmd") or die "ERROR: failed to install base system\n"; @@ -332,6 +333,7 @@ sub write_auto_inst_cfg { " X => { disabled => 1 },", " keep_unrequested_dependencies => 0,", " match_all_hardware => 1,", + " curl_options => '--silent',", " autoExitInstall => 1,", "};", ); @@ -438,7 +440,7 @@ sub build_local_repo { my $class = $path_parts[-3]; my $dst_dir = $local_repo_dir . $class; mkdir_in_root($root, $dst_dir) if ! -d "$root$dst_dir"; - copy_to_root($root, $dst_dir, undef, $src_path); + copy_file_to_root($root, $dst_dir, undef, $src_path); $classes{$class} = 1; } @@ -448,7 +450,7 @@ sub build_local_repo { my $media_info_dir = $local_repo_dir . $class . '/media_info'; mkdir_in_root($root, $media_info_dir); my $pubkey = $arch_repository . '/media/' . $class . '/release/media_info/pubkey'; - copy_to_root($root, $media_info_dir, undef, $pubkey); + copy_file_to_root($root, $media_info_dir, undef, $pubkey); run_in_root($root, $arch, 'genhdlist2', if_($::verbose < 2, '-q'), $local_repo_dir . $class) or die "ERROR: failed to generate hdlists for '$class' local repository\n"; } @@ -692,11 +694,27 @@ sub mkdir_in_root { or die "ERROR: failed to make directory $dir in Live system root\n"; } +sub copy_file_to_root { + my ($root, $dst_dir, $mode, $src_file) = @_; + + my $dst_file = $dst_dir . '/' . basename($src_file); + if ($src_file =~ m!^(ftp|http)://!) { + run_as_root('curl', '--silent', '-o', $root . $dst_file, $src_file) + or die "ERROR: couldn't copy $src_file to $dst_file\n"; + } else { + run_as_root('cp', $src_file, $root . $dst_file) + or die "ERROR: couldn't copy $src_file to $dst_file\n"; + } + + return if !defined $mode; + + run_as_root('chmod', sprintf("%o", $mode), $root . $dst_file) + or die "ERROR: failed to change mode of $dst_file in Live system root\n"; +} + sub copy_to_root { my ($root, $dest, $mode, @files) = @_; - # TODO: support source files in remote repositories - run_as_root('cp', '-af', '--no-preserve=ownership', @files, $root . $dest) or die "ERROR: failed to copy file to $dest in Live system root\n"; diff --git a/lib/MGA/DrakISO/Utils.pm b/lib/MGA/DrakISO/Utils.pm index 0f97080..b0a942d 100644 --- a/lib/MGA/DrakISO/Utils.pm +++ b/lib/MGA/DrakISO/Utils.pm @@ -111,10 +111,14 @@ sub device_mkfs { sub copy_or_link { my ($src_file, $dst_file) = @_; - # TODO: support remote sources. mkdir_p(dirname($dst_file)); - symlinkf($src_file, $dst_file) - or die "ERROR: couldn't link $src_file to $dst_file\n"; + if ($src_file =~ m!^(ftp|http)://!) { + run_as_root('curl', '--silent', '-o', $dst_file, $src_file) + or die "ERROR: couldn't copy $src_file to $dst_file\n"; + } else { + symlinkf($src_file, $dst_file) + or die "ERROR: couldn't link $src_file to $dst_file\n"; + } } sub mk_dev_null { -- cgit v1.2.1