首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用apt-get检查要安装的软件包列表

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

Stack Overflow用户
提问于 2011-01-08 01:49:46
回答 1查看 3.3K关注 0票数 2

我正在用Perl为Ubuntu编写一个安装后脚本(与here中的脚本相同)。其中一个步骤是安装软件包列表。问题是,对于任何一个包,如果apt-get install在许多不同的方式中有一些失败了,脚本就会死得很厉害。我想防止这种情况发生。

这是因为apt-get install对它不喜欢的包失败的方式。例如,当我试图安装一个无意义的单词时(例如,输入了错误的软件包名称)

代码语言:javascript
复制
$ sudo apt-get install oblihbyvl
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package oblihbyvl

但是如果相反,软件包名称已经过时(从ppa安装手刹车)

代码语言:javascript
复制
$ 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-cacheapt-get -s install的结果,试图在安装之前捕获所有可能性,但我似乎一直在寻找新的方法,允许失败继续执行实际的安装系统命令。

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

注意:我正在做一些事情,大致如下:

代码语言:javascript
复制
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);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-01-08 02:12:49

你可以试试apt-cache policy。示例:

代码语言:javascript
复制
$ 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

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4628585

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档