How to download packages from a command-line given repository?

pet*_*erh 4 debian dpkg

It is not about the common download & install thing, what apt (aptitude, etc) does, it is a scripted download a package file.

I found the dget tool for this task, which works quite well. But, unfortunately, it doesn't have any option to specify a different repository URL as it is given in the /etc/apt/sources.list.

它以某种方式可能吗?实际上,类似dget功能是最好的,我也可以在其中指定 repo URL。


Ps 非常感谢你的脚本,但我更喜欢一个 debian 工具来完成这个非常 简单的任务。它将成为构建脚本的一部分,供外部使用,任何不必要的复杂性都会带来无法忍受的附带成本。它必须由 debian 工具完成。

ps2。最后我通过更新系统范围的存储库解决了这个问题,并使用dget. 非常感谢脚本!

Ste*_*itt 10

我能找到的所有工具都使用本地apt信息(以及/etc/apt/sources.list上次apt-get update运行时定义的等中的存储库)。不过,解释存储库格式并不太难。

节省

#!/bin/sh
# Downloads a package from a repository
# dlpkg repo distro suite arch package

for arch in all "${4}"; do
    curl "${1}/dists/${2}/${3}/binary-${arch}/Packages.xz" | xz -d | "$(dirname $0)/pkgfilename" -v "PACKAGE=${5}" | while read filename; do
        curl -O "${1}/${filename}"
    done
done
Run Code Online (Sandbox Code Playgroud)

作为dlpkg,和

#!/usr/bin/awk -f

/Package:/ {
    package = $2
}

package == PACKAGE && /Filename:/ {
    print $2
}
Run Code Online (Sandbox Code Playgroud)

as pkgfilename,使它们可执行,然后您可以通过运行下载包

./dlpkg <repository URL> <distribution> <suite> <architecture> <package>
Run Code Online (Sandbox Code Playgroud)

例如

./dlpkg http://ftp.fr.debian.org/debian unstable main amd64 libc6
Run Code Online (Sandbox Code Playgroud)

如果您需要处理Packages文件不符合规范顺序(Packagebefore Filename)的存储库,您可以改用以下 AWK 脚本:

#!/usr/bin/awk -f

BEGIN {
    filename = ""
}

/^$/ {
    filename = ""
    stanza = 0
}

/Package:/ {
    if ($2 == PACKAGE) {
        stanza = 1
        if (filename != "") {
            print filename
            stanza = 0
        }
    }
}

/Filename:/ {
    filename = $2
    if (stanza == 1) {
        print filename
        filename = ""
    }
}
Run Code Online (Sandbox Code Playgroud)

没有错误处理,这留给读者作为练习。也没有签名验证...