我想通过 dpkg-reconfigure 使用通过非交互模式(在脚本中)提供的所有值来配置 ubuntu 包。
事实上,我的情况是 firebird 配置(http://www.firebirdsql.org/manual/ubusetup.html),当使用命令时:
sudo dpkg-reconfigure firebird2.5-superclassic -freadline
Run Code Online (Sandbox Code Playgroud)
向我询问 2 个值,其中答案是 'Y' 和 'newpwd' 。
示例输出如下所示:
sudo dpkg-reconfigure firebird2.5-superclassic -freadline
* Firebird 2.5 superclassic server not running
Configuring firebird2.5-superclassic
------------------------------------
Accept if you want Firebird server to start automatically.
If you only need the Firebird client and there are no databases that will be served by this host, decline.
Enable Firebird server? Y
Password for firebird 2.5
-------------------------
Firebird has a special user named SYSDBA, which is the user that has access to all databases. SYSDBA can also create new databases and users. Because of this, it
is necessary to secure SYSDBA with a password.
The password is stored in /etc/firebird/2.5/SYSDBA.password (readable only by root). You may modify it there (don't forget to update the security database too,
using the gsec utility), or you may use dpkg-reconfigure to update both.
To keep your existing password, leave this blank.
Password for SYSDBA:
* Starting Firebird 2.5 superclassic server...
...done.
* Firebird 2.5 superclassic server already running
Run Code Online (Sandbox Code Playgroud)
我已经here strings
通过这样的 bash 脚本尝试过:
sudo dpkg-reconfigure firebird2.5-superclassic -f readline << EOF
Y
newpwd
EOF
Run Code Online (Sandbox Code Playgroud)
但是,由于某种原因这不起作用,它要求提供值。
任何想法如何将所需的值提供给脚本?
Gil*_*il' 21
Debian 软件包使用debconf来收集安装时设置。Debconf 支持多个前端来提示用户输入值。选择要使用的 debconf 前端的-f
选项dpkg-reconfigure
。
该readline
前端被设计用于交互使用。不要在自动脚本中使用它。
如果默认值没问题,那么只需使用noninteractive
前端即可。
如果您想提供不同的值,您有两种选择。您可以坚持使用noninteractive
前端,并预置 debconf 数据库。最简单的方法是在一台机器上安装软件包并进行交互配置,然后从中提取相关部分/var/cache/debconf/config.dat
并将此文件提供给 debconf:
DEBCONF_DB_OVERRIDE='File {/path/to/config.dat}' dpkg-reconfigure -fnoninteractive firebird2.5-superclassic
Run Code Online (Sandbox Code Playgroud)
另一种方法是使用editor
前端,并将环境变量VISUAL
(或EDITOR
,但如果设置VISUAL
了EDITOR
则优先)设置为一个程序,该程序将包含当前设置的文件作为参数,并用您想要的设置覆盖该文件。
ken*_*orb 17
使用debconf-set-selections
命令将新值插入 debconf 数据库 ( /var/cache/debconf/config.dat
)。
Eli的回答对我来说不清楚,所以我会一步一步地解释。
要做的第一件事是以交互方式安装软件包并通过(更改firebird
为您的软件包名称)获取选择的选项:
sudo debconf-get-selections | grep ^firebird
Run Code Online (Sandbox Code Playgroud)
或者:
grep -C2 firebird /var/cache/debconf/config.dat
Run Code Online (Sandbox Code Playgroud)
然后用答案预置 debconf 数据库debconf-set-selections
,例如:
echo firebird2.5-superclassic shared/firebird/enabled boolean true | sudo debconf-set-selections -v
echo firebird2.5-superclassic shared/firebird/sysdba_password/new_password password foo | sudo debconf-set-selections -v
Run Code Online (Sandbox Code Playgroud)
其中语法是:
echo foo-owner-package-name foo-template-name value-type value | debconf-set-selections
Run Code Online (Sandbox Code Playgroud)
这是另一个ttf-mscorefonts-installer
包装示例:
echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | sudo debconf-set-selections
Run Code Online (Sandbox Code Playgroud)
注意:输入选择可以来自标准输入或文件。
检查:man debconf-set-selections
了解更多信息。
注意:如果debconf-get-selections
没有找到,请使用
apt-get install debconf-utils
Run Code Online (Sandbox Code Playgroud)
安装。
另一种方法是使用Kickstart。
Jos*_* R. 11
您始终可以使用expect 语言来自动与期望其输入的流程进行交互tty
。我之前没有真正使用过它,所以我无法真正在此处添加代码,但您的是一个典型的用例。
更新:
[Peter Butkovic] 我认为我指出了expect
一个正确的方向,我以这个剧本结尾:
#!/usr/bin/expect
spawn dpkg-reconfigure firebird2.5-superclassic -freadline
expect "Enable Firebird server?"
send "Y\r"
expect "Password for SYSDBA:"
send "newpwd\r"
# done
expect eof
Run Code Online (Sandbox Code Playgroud)
小智 5
我已经摸索了大约一个小时,只是试图将解决方案浓缩为一个单行代码,我终于找到了它:debconf-set-selections
echo "debconf debconf/frontend select noninteractive" | sudo debconf-set-selections
Run Code Online (Sandbox Code Playgroud)
这将强制 debconf 使用默认值而不是打扰您。您还可以为任何 Debian 软件包设置默认配置,请参阅联机帮助页了解更多信息。
归档时间: |
|
查看次数: |
27264 次 |
最近记录: |