Linux RPM - 安装时间参数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8258647/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 02:33:23  来源:igfitidea点击:

RPM - Install time parameters

linuxunixbuildredhatrpm

提问by saravana_pc

I have packaged my application into an RPM package, say, myapp.rpm. While installing this application, I would like to receive some inputs from the user (an example for input could be - environment where the app is getting installed - "dev", "qa", "uat", "prod"). Based on the input, the application will install the appropriate files. Is there a way to pass parameters while installing the application?

我已经将我的应用程序打包到一个 RPM 包中,比如myapp.rpm。在安装此应用程序时,我希望收到用户的一些输入(输入示例可能是 - 安装应用程序的环境 - “dev”、“qa”、“uat”、“prod”)。根据输入,应用程序将安装适当的文件。有没有办法在安装应用程序时传递参数?

P.S.: A possible solution could be to create an RPM package for each environment. However, in our scenario, this is not a viable option since we have around 20 environments and we do not wish to have 20 different packages for the same application.

PS:一个可能的解决方案是为每个环境创建一个 RPM 包。然而,在我们的场景中,这不是一个可行的选择,因为我们有大约 20 个环境,我们不希望同一个应用程序有 20 个不同的包。

采纳答案by kbyrd

In general, RPM packages should not require user interaction. Time and time again, the RPM folks have stated that it is an explicit design goal of RPM to not have interactive installs. For packages that need some sort of input before first use, you typically ask for this information on first use, our you put it all in config files with macros or something and tell your users that they will have to configure the application before it is usable.

通常,RPM 包不需要用户交互。RPM 人员一次又一次地表示,RPM 的一个明确设计目标是不进行交互式安装。对于在第一次使用前需要某种输入的包,您通常会在第一次使用时询问这些信息,我们将它们全部放在带有宏或其他东西的配置文件中,并告诉您的用户他们必须在应用程序可用之前对其进行配置.

Even passing a parameter of some sort counts as end-user interaction. I think what you want is to have your pre or install scripts auto detect the environment somehow, maybe by having a file somewhere they can examine. I'll also point out that from an RPM user's perspective, having a package named *-qa.rpm is a lot more intuitive than passing some random parameter.

即使传递某种类型的参数也算作最终用户交互。我认为您想要的是让您的预安装或安装脚本以某种方式自动检测环境,也许通过在他们可以检查的地方放置一个文件。我还要指出,从 RPM 用户的角度来看,拥有一个名为 *-qa.rpm 的包比传递一些随机参数更直观。

For your exact problem, if you are installing different content, you shouldcreate different packages. If you try to do things differently, you're going to end up fighting the RPM system more and more.

对于您的确切问题,如果您要安装不同的内容,则应创建不同的包。如果您尝试以不同的方式做事,您最终会越来越多地与 RPM 系统作斗争。

It isn't hard to create a build system that can spit out 20+ packages that are all mostly similar. I've done it with a template-ish spec file and some scripts run by make that will create the various spec files and build the RPMs. Without knowing the specifics, it sounds like you might even have a core package that all 20+ environment packages depend on, then the environment specific packages install whatever is specific to their target environment.

创建一个可以生成 20 多个几乎都相似的包的构建系统并不难。我已经使用模板化的规范文件和由 make 运行的一些脚本完成了它,这些脚本将创建各种规范文件并构建 RPM。在不知道具体细节的情况下,听起来您甚至可能拥有一个所有 20 多个环境包都依赖的核心包,然后特定于环境的包安装特定于其目标环境的任何包。

回答by CormacM

You could use the relocate option, e.g.

您可以使用重定位选项,例如

rpm -i --relocate /env=/uat somepkg.rpm

and have your script look up the variable data from a file located in the "env" directory

并让您的脚本从位于“env”目录中的文件中查找变量数据

回答by chenrici

I think this is a very valid question, specially as soon as you are moving into the application development realm. There he configuration of the application for different target systems is your daily bread: you need to configure for Development, Integration Test, Acceptance Test, Production etc. I sure don't think building a seperate package for each enviroment is the solution. Basically it should be the same code running in different enviroments. I know that this requirement is not supported by rpm. But what you can do as a work around is to use a simple config file, that the %pre script knows to look for. The config file could be a simple shell script that for example sets environment variables, and then the different und pre and post scripts can use those.

我认为这是一个非常有效的问题,特别是一旦您进入应用程序开发领域。为不同的目标系统配置应用程序是您的日常工作:您需要针对开发、集成测试、验收测试、生产等进行配置。我肯定不认为为每个环境构建单独的包是解决方案。基本上它应该是在不同环境中运行的相同代码。我知道 rpm 不支持此要求。但是您可以做的解决方法是使用一个简单的配置文件,%pre 脚本知道要查找该文件。配置文件可以是一个简单的 shell 脚本,例如设置环境变量,然后不同的 und pre 和 post 脚本可以使用这些。