3
# Copyright (C) 2009-2010 Canonical Ltd.
4
# Copyright (C) 2012 Hewlett-Packard Development Company, L.P.
6
# Author: Scott Moser <scott.moser@canonical.com>
7
# Author: Juerg Haefliger <juerg.haefliger@hp.com>
9
# This program is free software: you can redistribute it and/or modify
10
# it under the terms of the GNU General Public License version 3, as
11
# published by the Free Software Foundation.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
# Ensure this is aliased to a name not 'distros'
22
# since the module attribute 'distros'
23
# is a list of distros that are supported, not a sub-module
24
from cloudinit import distros as ds
26
from cloudinit import util
28
distros = ['ubuntu', 'debian']
31
def handle(name, cfg, cloud, log, args):
35
value = util.get_cfg_option_str(cfg, "byobu_by_default", "")
38
log.debug("Skipping module named %s, no 'byobu' values found", name)
41
if value == "user" or value == "system":
42
value = "enable-%s" % value
44
valid = ("enable-user", "enable-system", "enable",
45
"disable-user", "disable-system", "disable")
46
if value not in valid:
47
log.warn("Unknown value %s for byobu_by_default", value)
49
mod_user = value.endswith("-user")
50
mod_sys = value.endswith("-system")
51
if value.startswith("enable"):
53
dc_val = "byobu byobu/launch-by-default boolean true"
56
if value == "disable":
60
dc_val = "byobu byobu/launch-by-default boolean false"
64
(users, _groups) = ds.normalize_users_groups(cfg, cloud.distro)
65
(user, _user_config) = ds.extract_default(users)
67
log.warn(("No default byobu user provided, "
68
"can not launch %s for the default user"), bl_inst)
70
shcmd += " sudo -Hu \"%s\" byobu-launcher-%s" % (user, bl_inst)
71
shcmd += " || X=$(($X+1)); "
73
shcmd += "echo \"%s\" | debconf-set-selections" % dc_val
74
shcmd += " && dpkg-reconfigure byobu --frontend=noninteractive"
75
shcmd += " || X=$(($X+1)); "
78
cmd = ["/bin/sh", "-c", "%s %s %s" % ("X=0;", shcmd, "exit $X")]
79
log.debug("Setting byobu to %s", value)
80
util.subp(cmd, capture=False)