使用 apt-get 检查要安装的软件包列表
我正在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试
apt-cache策略
。示例:任何具有非空白版本表的内容都应该是可安装的。
You might try
apt-cache policy
. examples:Anything with a non-blank version table should be installable.