BaseUtilsGentoo/install_system.pl

39 lines
1.0 KiB
Perl
Raw Normal View History

#!/usr/bin/env perl
use v5.36.0;
use strict;
use warnings;
use utf8;
use Path::Tiny;
use lib path(__FILE__)->parent->child('lib') . '';
use BaseUtils;
my $utils = BaseUtils->new;
main();
sub main() {
die 'Must be superuser.' if $< != 0;
my $target_dir = shift @ARGV or die 'No target dir passed.';
my $destination_dir = shift @ARGV or die 'No destination dir passed.';
$target_dir = path($target_dir);
$destination_dir = path($destination_dir);
$utils->createBasicMountsChroot($target_dir);
populateDirectory($destination_dir);
my $mnt_gentoo = $target_dir->child('mnt/gentoo');
populateDirectory($mnt_gentoo);
$utils->mountRbind($destination_dir, $mnt_gentoo);
my $packages = $utils->readPackagesToInstall();
$utils->execChroot($target_dir, 'emerge', '--root', '/mnt/gentoo', '--noreplace', '-K', @$packages);
}
sub populateDirectory($dir) {
my $return_code = system 'mkdir', '-pv', $dir;
if ($return_code != 0) {
die "Unable to create $dir.";
}
}