For configuring the timezone, I first create '/etc/localtime' as a soft link to the appropriate zoneinfo file under the '/usr/share/zoneinfo' directory. Then, I run the dpkg-reconfigure command, and everything will be put in place.
So, for instance, to set up timezone 'Europe/Brussels':
AREA='Europe'
ZONE='Brussels'
ZONEINFO_FILE='/usr/share/zoneinfo/'"${AREA}"'/'"${ZONE}"
ln --force --symbolic "${ZONEINFO_FILE}" '/etc/localtime'
dpkg-reconfigure --frontend=noninteractive tzdata
(Note that the AREA is a subdirectory under '/usr/share/info', and the ZONE is a file under the AREA subdirectory).
For configuring the locales, I first run a sed script that will create a new copy of the '/etc/locale.gen' file, based on the contents of the '/usr/share/i18n/SUPPORTED' file. Every line from the input file will be copied, but it will be turned into a comment unless it is an entry of a UTF-8 locale for a language that I wish to make available on my system (e.g., English, Dutch, French, and German):
sed --regexp-extended --expression='
1 {
i\
# This file lists locales that you wish to have built. You can find a list\
# of valid supported locales at /usr/share/i18n/SUPPORTED, and you can add\
# user defined locales to /usr/local/share/i18n/SUPPORTED. If you change\
# this file, you need to rerun locale-gen.\
\
}
/^(en|nl|fr|de)(_[[:upper:]]+)?(\.UTF-8)?(@[^[:space:]]+)?[[:space:]]+UTF-8$/! s/^/# /
' /usr/share/i18n/SUPPORTED > /etc/locale.gen
Next, I set the default environment locale in the debconf database, e.g., to British English:
debconf-set-selections <<< 'locales locales/default_environment_locale select en_GB.UTF-8'
I subsequently remove the existing '/etc/default/locale' file (just to make sure that its old contents will not interfere with my new settings), and run the dpkg-reconfigure command to generate all of the locales that the sed script selected, and to create a new '/etc/default/locale' file with just an entry to set the 'LANG' variable to my selected default environment locale:
rm --force --verbose /etc/default/locale
dpkg-reconfigure --frontend=noninteractive locales
Then, depending on my requirements, I may want to run a few update-locale commands, to override, e.g., the variables that affect the formatting of values, and set them to a different locale (such as Irish English):
update-locale LC_NUMERIC='en_IE.UTF-8'
update-locale LC_TIME='en_IE.UTF-8'
update-locale LC_MONETARY='en_IE.UTF-8'
update-locale LC_PAPER='en_IE.UTF-8'
update-locale LC_NAME='en_IE.UTF-8'
update-locale LC_ADDRESS='en_IE.UTF-8'
update-locale LC_TELEPHONE='en_IE.UTF-8'
update-locale LC_MEASUREMENT='en_IE.UTF-8'
update-locale LC_IDENTIFICATION='en_IE.UTF-8'
(I could have specified all of these parameters on a single invocation of the update-locale command, but apparently, the order in which the entries get written to the '/etc/default/locale' file is unpredictable if I do so. I prefer them to always be in the same order, which is why I generate them one by one.)
And finally, I may want to run the update-locale command one last time, to set up the LANGUAGE variable (i.e., the list of languages in which I want translatable text messages to get displayed):
update-locale LANGUAGE='en_GB:en_US:en'