使用 apt-get 检查要安装的软件包列表

发布于 2024-10-10 21:26:24 字数 1638 浏览 5 评论 0原文

我正在 Perl 中为 Ubuntu 编写一个安装后脚本(与 此处)。步骤之一是安装软件包列表。问题是,如果任何一个包的 apt-get install 以多种不同方式失败,脚本就会严重终止。我想阻止这种情况发生。

发生这种情况的原因是 apt-get install 对于它不喜欢的软件包失败。例如,当我尝试安装一个无意义的单词(即输入了错误的包名称)

$ sudo apt-get install oblihbyvl
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package oblihbyvl

,但如果包名称已被废弃(从 ppa 安装手刹)

$ sudo apt-get install handbrake
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package handbrake is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'handbrake' has no installation candidate
$ apt-cache search handbrake
handbrake-cli - versatile DVD ripper and video transcoder - command line
handbrake-gtk - versatile DVD ripper and video transcoder - GTK GUI

等等......

我尝试解析 的结果apt-cache 和 apt-get -s install 在安装之前尝试捕获所有可能性,但我似乎一直在寻找新的方法来允许失败继续到实际的安装系统命令。

我的问题是,Perl 中是否有一些工具(例如模块,尽管我想尽可能避免安装模块,因为这应该是新安装 Ubuntu 后运行的第一件事)或 apt-* 或 dpkg让我在安装之前确保所有软件包都可以安装,如果不能以某种方式优雅地失败,让用户决定要做什么?

注意我正在做一些事情:

my @list_of_install_candidates = (...);
my @to_install = grep { my $output = qx{ apt-get -s install $_ }; parse_output($output); } @list_of_install_candidates;
system('apt-get', 'install', @to_install);

I am writing a post-install script for Ubuntu in Perl (same script as seen here). One of the steps is to install a list of packages. The problem is that if apt-get install fails in some of many different ways for any one of the packages the script dies badly. I would like to prevent that from happening.

This happens because of the ways that apt-get install fails for packages that it doesn't like. For example when I try to install a nonsense word (i.e. typed in the wrong package name)

$ sudo apt-get install oblihbyvl
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package oblihbyvl

but if instead the package name has been obsoleted (installing handbrake from ppa)

$ sudo apt-get install handbrake
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package handbrake is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'handbrake' has no installation candidate
$ apt-cache search handbrake
handbrake-cli - versatile DVD ripper and video transcoder - command line
handbrake-gtk - versatile DVD ripper and video transcoder - GTK GUI

etc, etc ...

I have tried parsing the results of apt-cache and apt-get -s install to try to catch all possibilities before doing the install, but I seem to keep finding new ways to allow failures to continue to the actual install system command.

My question is, is there some facility either in Perl (e.g. a module, though I would like to avoid installing modules if possible as this is supposed to be the first thing run after a new install of Ubuntu) or apt-* or dpkg that would let me be sure that the packages are all available to be installed before installing and if not fail gracefully in some way that lets the user decide what to do?

N.B. I am doing something along the lines of:

my @list_of_install_candidates = (...);
my @to_install = grep { my $output = qx{ apt-get -s install $_ }; parse_output($output); } @list_of_install_candidates;
system('apt-get', 'install', @to_install);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

毁我热情 2024-10-17 21:26:24

您可以尝试apt-cache策略。示例:

$ apt-cache policy handbrake
handbrake:
  Installed: (none)
  Candidate: (none)
  Version table:

$ apt-cache policy foo
N: Unable to locate package foo

$ apt-cache policy openbox
openbox:
  Installed: 3.4.11.1-1
  Candidate: 3.4.11.1-1
  Version table:
 *** 3.4.11.1-1 0
        500 http://mirrors.xmission.com/ubuntu/ maverick/universe i386 Packages
        100 /var/lib/dpkg/status

任何具有非空白版本表的内容都应该是可安装的。

You might try apt-cache policy. examples:

$ apt-cache policy handbrake
handbrake:
  Installed: (none)
  Candidate: (none)
  Version table:

$ apt-cache policy foo
N: Unable to locate package foo

$ apt-cache policy openbox
openbox:
  Installed: 3.4.11.1-1
  Candidate: 3.4.11.1-1
  Version table:
 *** 3.4.11.1-1 0
        500 http://mirrors.xmission.com/ubuntu/ maverick/universe i386 Packages
        100 /var/lib/dpkg/status

Anything with a non-blank version table should be installable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文