dpkg-reconfigure tzdata的非交互式方法 [英] Non-interactive method for dpkg-reconfigure tzdata
问题描述
当我第一次设置Ubuntu服务器时,请确保先aptitude install tzdata
,然后再dpkg-reconfigure tzdata
,以便正确设置时区.
When I first setup an Ubuntu server, I make sure I aptitude install tzdata
, then dpkg-reconfigure tzdata
so that I set my timezone properly.
我正在尝试使用脚本来自动化服务器设置,并注意到这种自动操作的方式,因为它需要在用户干预下进行交互式会话.
I am trying to automate my server setup with a script, and noticed this piece sort of throws a wrench into it being automatic, as it requires an interactive session with user intervention.
是否可以使用dpkg-reconfigure而不进行交互?
Is there a way to use dpkg-reconfigure without it being interactive?
推荐答案
swill的回答并不正确.如果您想要无人值守/脚本化的dpkg软件包配置,那么您想使用debconf预播机制.
The answer by swill is not how it is done properly. If you want unattended/scripted dpkg configuration of packages, then you want to use the debconf preseeding mechanism.
在您的情况下,这意味着您必须执行以下操作:
In your case this means that you have to do the following:
-
设置以下环境变量以避免debconf尝试向用户提出任何问题:
set the following environment variables to avoid that debconf tries to ask the user any questions:
export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true
然后使用以下preseed.txt文件(或所需的任何其他设置)填充debconf:
then preseed debconf with the following preseed.txt file (or whatever other settings you desire):
tzdata tzdata/Areas select Europe
tzdata tzdata/Zones/Europe select Berlin
您可以通过运行以下命令来设置上面的文件:
you set the above preseed file by running:
debconf-set-selections /your/preseed.txt
您现在可以通过apt
安装tzdata(如果尚未安装)或运行dpkg-reconfigure
.最后,将根据您在debconf预置文件中指定的内容来设置tzdata.
you can now either install tzdata (if it is not installed yet) via apt
or run dpkg-reconfigure
. In the end, tzdata will be set up according to what you specified in your debconf preseed file.
请记住,您可以使用debconf preseeding自动执行更多操作.例如,在我的前提下,我总是设置:
Remember that you can automate lots more using debconf preseeding. For example in my preseeds I always set:
locales locales/locales_to_be_generated multiselect en_US.UTF-8 UTF-8
locales locales/default_environment_locale select en_US.UTF-8
您始终可以通过运行debconf-get-selections
来检查当前系统的debconf设置.输出应该使您对使用debconf preseeding能够自动化多少系统配置有所了解.
You can always inspect the debconf settings of your current system by running debconf-get-selections
. The output should give you some idea of how much of the system configuration you are able to automate using debconf preseeding.
这篇关于dpkg-reconfigure tzdata的非交互式方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!