forked from josch/mmdebstrap
Anticipate arch-test not being installed and only check if chroot architecture is unequal host's architecture
This commit is contained in:
parent
c96a1526b2
commit
0166f95545
1 changed files with 48 additions and 30 deletions
78
mmdebstrap
78
mmdebstrap
|
@ -954,37 +954,55 @@ sub main() {
|
|||
$options->{nativearch} = $nativearch;
|
||||
$options->{foreignarchs} = \@foreignarchs;
|
||||
|
||||
my $deb2qemu = {
|
||||
alpha => 'alpha',
|
||||
amd64 => 'x86_64',
|
||||
arm => 'arm',
|
||||
arm64 => 'aarch64',
|
||||
armel => 'arm',
|
||||
armhf => 'arm',
|
||||
hppa => 'hppa',
|
||||
i386 => 'i386',
|
||||
m68k => 'm68k',
|
||||
mips => 'mips',
|
||||
mips64 => 'mips64',
|
||||
mips64el => 'mips64el',
|
||||
mipsel => 'mipsel',
|
||||
powerpc => 'ppc',
|
||||
ppc64 => 'ppc64',
|
||||
ppc64el => 'ppc64le',
|
||||
riscv64 => 'riscv64',
|
||||
s390x => 's390x',
|
||||
sh4 => 'sh4',
|
||||
sparc => 'sparc',
|
||||
sparc64 => 'sparc64',
|
||||
};
|
||||
open my $fh, '-|', 'arch-test', '-n', $nativearch // die "failed to fork(): $!";
|
||||
chomp (my $content = do { local $/; <$fh> });
|
||||
close $fh;
|
||||
if ($? != 0 or $content ne "$nativearch: ok") {
|
||||
if (!exists $deb2qemu->{$nativearch}) {
|
||||
die "no mapping from $nativearch to qemu-user binary";
|
||||
{
|
||||
my $deb2qemu = {
|
||||
alpha => 'alpha',
|
||||
amd64 => 'x86_64',
|
||||
arm => 'arm',
|
||||
arm64 => 'aarch64',
|
||||
armel => 'arm',
|
||||
armhf => 'arm',
|
||||
hppa => 'hppa',
|
||||
i386 => 'i386',
|
||||
m68k => 'm68k',
|
||||
mips => 'mips',
|
||||
mips64 => 'mips64',
|
||||
mips64el => 'mips64el',
|
||||
mipsel => 'mipsel',
|
||||
powerpc => 'ppc',
|
||||
ppc64 => 'ppc64',
|
||||
ppc64el => 'ppc64le',
|
||||
riscv64 => 'riscv64',
|
||||
s390x => 's390x',
|
||||
sh4 => 'sh4',
|
||||
sparc => 'sparc',
|
||||
sparc64 => 'sparc64',
|
||||
};
|
||||
chomp (my $hostarch = `dpkg --print-architecture`);
|
||||
if ($hostarch ne $nativearch) {
|
||||
my $pid = open my $fh, '-|' // die "failed to fork(): $!";
|
||||
if ($pid == 0) {
|
||||
{ exec 'arch-test', '-n', $nativearch; }
|
||||
# if exec didn't work (for example because the arch-test program is
|
||||
# missing) prepare for the worst and assume that the architecture
|
||||
# cannot be executed
|
||||
print "$nativearch: not supported on this machine/kernel\n";
|
||||
exit 1;
|
||||
}
|
||||
chomp (my $content = do { local $/; <$fh> });
|
||||
close $fh;
|
||||
if ($? != 0 or $content ne "$nativearch: ok") {
|
||||
print STDERR "I: $nativearch cannot be executed, falling back to qemu-user\n";
|
||||
if (!exists $deb2qemu->{$nativearch}) {
|
||||
die "no mapping from $nativearch to qemu-user binary";
|
||||
}
|
||||
$options->{qemu} = $deb2qemu->{$nativearch};
|
||||
} else {
|
||||
print STDERR "I: $nativearch can be executed on this $hostarch machine\n";
|
||||
}
|
||||
} else {
|
||||
print STDERR "I: chroot architecture $nativearch is equal to the host's architecture\n";
|
||||
}
|
||||
$options->{qemu} = $deb2qemu->{$nativearch};
|
||||
}
|
||||
|
||||
if (scalar @ARGV > 0) {
|
||||
|
|
Loading…
Reference in a new issue