如何自动设置“键盘配置”包?

我正在编写一个脚本,使用debootstrap(在Ubuntu 16.04服务器机器上)将Ubuntu 16.04服务器安装到chroot jail中。

在设置keyboard-configuration包期间,它会询问键盘类型:

 Setting up keyboard-configuration (1.108ubuntu15) ... debconf: unable to initialize frontend: Dialog debconf: (TERM is not set, so the dialog frontend is not usable.) debconf: falling back to frontend: Readline Configuring keyboard-configuration ---------------------------------- The layout of keyboards varies per country, with some countries having multiple common layouts. Please select the country of origin for the keyboard of this computer. 1. Afghani 48. Irish 2. Albanian 49. Italian ... 28. English (UK) 75. Slovak 29. English (US) 76. Slovenian ... 45. Icelandic 92. Vietnamese 46. Indian 93. Wolof 47. Iraqi Country of origin for the keyboard: 

我想自动化这个,所以它不会问,只是继续安装。

我怎样才能做到这一点?

我在类似的StackOverflow问题上找到了答案 :

 DEBIAN_FRONTEND=noninteractive apt-get install keyboard-configuration 

你可以使用xdotool 。 当启动脚本put & sleep && xdotool type && xdotool key Return

我没有测试过这个,但它应该可以工作。

答案2:

运行该命令,但输出重定向到文件( > testfile )。

打开另一个终端并运行

 while true do if [ "$(tac testfile | grep -m 1 .)" = "Country of origin for the keyboard" ] then xdotool type  && xdotool key Return && break fi done 

然后,单击第一个终端上的。

答案3:

我想你需要做的就是把你想要的数字放在一个文件, testfile ,并运行附加< testfile的命令。

“debootstrap实际上只是一个shell脚本” – 来自https://wiki.debian.org/Debootstrap

这意味着您可以阅读脚本以查看是否有方法通过环境变量传递信息,在调用deboostrap时提供参数,或者为特定应用程序创建自己的修改版本。

这很容易自动化,您只需要为此软件包设置正确的debconf配置。

首先安装debconf-utils

 sudo apt install debconf-utils 

如果您已经配置了软件包,则可以使用以下命令读取debconf配置:

 debconf-get-selections | grep keyboard-configuration 

如果您尚未配置软件包或想要更改选择,则可以执行以下操作:

 dpkg-reconfigure keyboard-configuration 

将您的选择导出到文件

 debconf-get-selections | grep keyboard-configuration > selections.conf 

selections.conf复制到目标计算机并设置选择:

 debconf-set-selections < selections.conf 

安装或重新配置软件包时,现在将自动选择您的选择。

 dpkg-reconfigure keyboard-configuration -f noninteractive