Nar*_*wal 5 bash environment-variables dpkg deb post-install
我制作了一个 debian 包,用于自动安装 oozie。postinst 脚本基本上是一个 shell 脚本,在安装包后运行。我想访问这个脚本中的环境变量。我应该在哪里设置环境变量?
根据您实际想要完成的任务,将信息传递到包脚本的正确方法是使用Debconf变量。
简而言之,您添加一个debian/templates如下文件:
Template: oozie/secret
Type: string
Default: xyzzy
Description: Secret word for teleportation?
Configure the secret word which allows the player to teleport.
Run Code Online (Sandbox Code Playgroud)
并将您的 postinst 脚本更改为类似的内容
#!/bin/sh -e
# Source debconf library.
. /usr/share/debconf/confmodule
db_input medium oozie/secret || true
db_go
# Check their answer.
db_get oozie/secret
instead_of_env=$RET
: do something with the variable
Run Code Online (Sandbox Code Playgroud)
在运行打包脚本之前,您可以在 Debconf 数据库中预置一个值;oozie/secret那么它不会提示输入该值。只需做类似的事情
debconf-set-selections <<<'oozie oozie/secret string plugh'
Run Code Online (Sandbox Code Playgroud)
预先配置它的值plugh。
另请参阅http://www.fifi.org/doc/debconf-doc/tutorial.html
无法保证安装程序在特定环境中运行,或者dpkg由特定用户调用,或者来自用户可以操纵的环境。在这些情况下,正确的包装需要稳健性和可预测性;还要考虑可用性。