如何检测 .deb 包的架构?

Byt*_*der 3 package-management packaging dpkg architecture

存储库中有一个 .deb 包,它被声明为 32 位,但安装了 64 位二进制文​​件。apt-get从存储库安装以及下载 .deb 文件并运行都是这种情况dpkg -i

如果我安装该文件进行尝试,它会升级/覆盖我现有的 32 位应用程序,并且我无法再运行它(在 15.04 32 位 Ubuntu 上)。当这种情况第一次发生时,我用 搜索了安装的可执行文件并which用 检查了它的类型file,证明它是一个 64 位 ELF 二进制文件:

$ file qtox
qtox: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, stripped
Run Code Online (Sandbox Code Playgroud)

因此,当我等待维护人员解决问题时,如何确定包(来自存储库或 .deb 文件)包含哪种架构?

我尝试了存储库版本和apt-cache show.deb文件,但它们都报告 32 位,这是错误的。apt-cache policydpkg -I

除了访问包的元信息(我认为这就是我尝试过的命令所做的?)之外,是否有机会找到包含的可执行文件的真实体系结构,这显然不适合。

A.B*_*.B. 5

在我的示例中创建一个脚本foo

#!/bin/bash

# Create a temporary folder in /tmp
dir=$(mktemp -d)

# Extract the deb file
dpkg -x "$1" "$dir"

printf "\n%s\n\n" "$1"

# Show the package architecture information
dpkg --info $1 | \
    awk '/Architecture/ {printf "defined dpkg architecture is:\t%s\n", $2}'

# Show the executable format via find and awk for ELF
find $dir -type f -exec file -b {} \; | \
        sort -u | \
        awk '/ELF/ {printf "executable format is: \t\t%s\n", $0}'

rm -rf "$dir"

exit 0
Run Code Online (Sandbox Code Playgroud)

用法

./foo <deb_file>
Run Code Online (Sandbox Code Playgroud)

例子

% ./foo qtox_1.1\~git20150707.cfeeb03-97_i386.deb

qtox_1.1~git20150707.cfeeb03-97_i386.deb

defined dpkg architecture is:   i386
executable format is :          ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, stripped
Run Code Online (Sandbox Code Playgroud)