我正在用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);发布于 2011-01-08 02:12:49
你可以试试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任何具有非空白版本表的内容都应该是可安装的。
https://stackoverflow.com/questions/4628585
复制相似问题