apt-get 下载有版本限制

apt-get 下载有版本限制

我需要使用apt-get download来获取文件的特定版本.deb,但不一定是确切的版本。.deb依赖项可以使用诸如>=0.3.0和之类的表达式,我想apt-get download获取与使用此类依赖项下载的版本相同的版本。

总结一下,我想要做的事情是这样的:

$ apt-get download package='>=0.3.0'

知道如何获得该功能吗?

答案1

你可以通过先找出哪个版本是最新版本,并且大于或等于你想要的最低版本来实现这一点。然后,你使用 下载该版本apt-get download。这里有一个脚本可以做到这一点(它有点丑陋,但你明白我的意思):

#!/bin/bash

if [ $# -lt 2 ]; then
    echo "Usage: $0 <packagename> <minimum version>"
    exit 1
fi

pkgname="$1"
minversion="$2"

V="0"

for version in `apt-cache madison $pkgname | awk -F'|' '{print $2}'`; do
    echo "Considering $version"
    if dpkg --compare-versions $version ge $minversion; then
        echo "- Version is at least $minversion"
        if dpkg --compare-versions $version gt $V; then
            echo "- This is the newest version so far"
            V=$version
        else
            echo "- We already have a newer version"
        fi
    else
        echo "- This is older than $minversion"
    fi
done

if [ "$V" = "0" ]; then
    echo "There is no version greater than or equal to $minversion"
    exit 1
fi

echo "Selected version: $V"

echo "Downloading"
apt-get download $pkgname=$V
echo "Done"

您必须添加错误检查,以防软件包不存在等,但这包含核心解决方案。另外,我在这里假设您想要至少是特定版本的最新可用软件包。如果您想要至少是特定版本的最旧可用软件包,则必须调整脚本以在找到至少是您想要的版本的东西后停止搜索。

答案2

因为您想要的正是您能得到的东西,所以使用自定义档案目录以“仅下载模式”apt-get install运行可能是值得的:apt-get install

-d, --download-only
  Download only; package files are only retrieved, not unpacked or installed.
  Configuration Item: APT::Get::Download-Only.

如何更改档案目录?这是一个配置选项:

FILES
  [...]

  /var/cache/apt/archives/
  Storage area for retrieved package files. Configuration Item: Dir::Cache::Archives.

可以使用以下参数暂时更改它们--option

-o, --option
  Set a Configuration Option; This will set an arbitrary configuration option. 
  The syntax is -o Foo::Bar=bar.  -o and --option can be used multiple times 
  to set different options.

总结一下:

apt-get install -d -o dir::cache::archives="/some/cache/dir" <package>

此命令将下载(仅下载,不安装)与 相关的文件.deb。目录将包含包的文件、其依赖项、锁定文件和“部分”目录(应为空)。筛选出您需要的确切文件应该很简单。<package>/some/cache/dir.deb.deb

答案3

apt-get download还允许您设置目标发布。这有帮助吗?

apt-get download package/testing

评论#1(不能使用注释)——添加参数--print-uris不需要apt-get installroot 权限(但您必须自行下载——最好使用 wget -i FILE_LIST)。

答案4

即使没有 SU 权限,您仍然可以运行 apt-cache 并结合过滤来获取该信息。使用类似以下命令:

在 Debian 5 上:

apt-cache show <pkg> | head | grep -i version 

在 6 上您可以使用:

apt-cache show <pkg> | tail | grep -i version

Apt-cache 似乎已经改变了 5 到 6 之间的列表排序行为,因此在 6 中最新的列表排在最后。

需要注意的是,如果您使用此输出,正如您所说的“获取与使用此类依赖项下载的版本相同的版本”,则可用软件包的版本可能会在运行 apt-get update(当然使用 su privs)时发生变化,或者如果已将其设置为自动运行,并且发生在您收集版本和运行安装期望该版本的脚本之间。

相关内容