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

标签 perl ubuntu debian apt

我正在用 Perl 为 Ubuntu 编写一个安装后脚本(与 here 相同的脚本)。其中一个步骤是安装软件包列表。问题是如果 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);

最佳答案

你可以试试apt-cache policy .例子:

$ 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

任何带有非空白版本表的东西都应该是可安装的。

关于perl - 使用 apt-get 检查要安装的软件包列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4628585/

相关文章:

go - 在debian armv7l上安装Go的最新版本[保留]

perl - XML::LibXSLT 无法在 Heroku 上安装

perl - 如何重新定义内置 Perl 函数?

windows - 当我在同一系统中使用 Ubuntu/Windows 时,如何配置 Skype 以保持相同的历史记录位置?

ubuntu - Ansible开发环境

debian - 如何限制 xdebug-profiler 创建的 cachegrind 文件

perl - -$ |在Perl工作?

perl - 如何从 Perl 程序返回一个值给 Korn-shell 脚本?

c++ - 新构建的 Ubuntu 可执行文件失败,出现 "Invalid argument"(退出代码 126)

mysql - Redmine 和 SVN - 安装 pam_mysql 时出现问题