Processing
 

Non-interactive method for dpkg-reconfigure tzdata

29/12/2011 17:46#1

kenny

Member

Joined at: 12 months ago

Post: 44

Thank: 0

Thanked: 0

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.

Is there a way to use dpkg-reconfigure without it being interactive?

29/12/2011 18:02Top#2

swill

Member

Joined at: 12 months ago

Post: 2

Thank: 0

Thanked: 0

I found the following details for you.

http://serverfault.com/a/84528

Edit: (copy and paste from the above link...)
You need to specify the frontend as `noninteractive' and it will save your current settings.

dpkg-reconfigure will take the current system settings as gospel, so simply change your timezone the way you would normally and run it with the non-interactive flag

e.g. for me to change to "Europe/Dublin" where I am:

# echo "Europe/Dublin" > /etc/timezone     # dpkg-reconfigure -f noninteractive tzdata 

Obviously this allows you to use puppet/cfengine as you like to distribute /etc/timezone also.

19/12/2013 23:24Top#3

josch

Member

Joined at: 12 months ago

Post: 2

Thank: 0

Thanked: 0

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:

  • set the following environment variables to avoid that debconf tries to ask the user any questions:

    export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true 
  • 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 
  • 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.

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 

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.

01/09/2016 15:17Top#4

jah

Member

Joined at: 12 months ago

Post: 7

Thank: 0

Thanked: 0

Advancing josch's answer; set the debconf db values and remove /etc/{localtime,timezone} before running dpkg-reconfigure:-

$ echo "tzdata tzdata/Areas select Europe" > some/file.txt $ echo "tzdata tzdata/Zones/Europe select Berlin" >> some/file.txt $ sudo debconf-set-selections some/file.txt $ sudo rm /etc/timezone $ sudo rm /etc/localtime $ sudo dpkg-reconfigure -f noninteractive tzdata Current default time zone: 'Europe/Berlin' Local time is now:      Thu Sep  1 17:13:16 CEST 2016. Universal Time is now:  Thu Sep  1 15:13:16 UTC 2016. 

This method is known to work on:-

  • Ubunty Trusty (14.04.5 LTS)
Similar articles

Non-interactive method for dpkg-reconfigure tzdata

5 years ago - Reply: 3 - Views: 143

monit is not able to read mongod.lock

2 years ago - Reply: 3 - Views: 141

Ubuntu: hadoop command not found

2 years ago - Reply: 4 - Views: 244

C# Mono Console.ReadLine quitting

4 years ago - Reply: 1 - Views: 87

linking jsoncpp on Ubuntu

2 years ago - Reply: 1 - Views: 6

Build artifacts over ssh jenkins - PHP

3 years ago - Reply: 1 - Views: 38

Can't load Metasploit after installation

3 years ago - Reply: 5 - Views: 222

Selenium FirefoxDriver in Headless get error

2 years ago - Reply: 1 - Views: 97

Unable to start MongoDB. ERROR: addr already in use

2 years ago - Reply: 2 - Views: 120

ZSH Agnoster Theme showing machine name

2 years ago - Reply: 4 - Views: 250

Unable to start firefox browser with jenkins user

2 years ago - Reply: 2 - Views: 113

vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re