From 1781668dd65737a800c2c8fdbb79c6f1288d3ef2 Mon Sep 17 00:00:00 2001 From: Harm Weites Date: Wed, 18 Dec 2013 23:36:16 +0000 Subject: new: Apply the locale to the default login class. --- cloudinit/distros/freebsd.py | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'cloudinit/distros') diff --git a/cloudinit/distros/freebsd.py b/cloudinit/distros/freebsd.py index 55efbb7b..fd66b901 100644 --- a/cloudinit/distros/freebsd.py +++ b/cloudinit/distros/freebsd.py @@ -210,10 +210,32 @@ class Distro(distros.Distro): def _write_network(self, settings): return - - def apply_locale(): - return - + + def apply_locale(self, locale, out_fn=None): + loginconf = '/etc/login.conf' + newloginconf = '/tmp/login.conf.new' + backupconf = '/etc/login.conf.orig' + + newconf = open(newloginconf, 'w') + origconf = open(loginconf, 'r') + + for line in origconf: + newconf.write(re.sub('^default:', r'default:lang=%s:' % locale, line)) + newconf.close() + origconf.close() + # Make a backup of login.conf. + copyfile(loginconf, backupconf) + # And copy the new login.conf. + copyfile(newloginconf, loginconf) + + try: + util.logexc("Running cap_mkdb for %s", locale) + util.subp(['cap_mkdb', '/etc/login.conf']) + except: + # cap_mkdb failed, so restore the backup. + util.logexc("Failed to apply locale %s", locale) + copyfile(backupconf, loginconf) + def install_packages(): return -- cgit v1.2.3