diff options
author | Harm Weites <harm@weites.com> | 2013-12-18 23:36:16 +0000 |
---|---|---|
committer | Harm Weites <harm@weites.com> | 2013-12-18 23:36:16 +0000 |
commit | 1781668dd65737a800c2c8fdbb79c6f1288d3ef2 (patch) | |
tree | d6497df3ec579eb6952782c97b1f9166c87a7dcb /cloudinit/distros/freebsd.py | |
parent | d5613a54c27f3b494c7012dbdd68635a112e1e57 (diff) | |
download | vyos-cloud-init-1781668dd65737a800c2c8fdbb79c6f1288d3ef2.tar.gz vyos-cloud-init-1781668dd65737a800c2c8fdbb79c6f1288d3ef2.zip |
new: Apply the locale to the default login class.
Diffstat (limited to 'cloudinit/distros/freebsd.py')
-rw-r--r-- | cloudinit/distros/freebsd.py | 30 |
1 files changed, 26 insertions, 4 deletions
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 |