From 309c3eb1b7000f5b0d33c38f0eb56b30688cdbff Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Tue, 14 Jun 2011 16:23:46 -0400 Subject: Support disabling of byobu. LP: #797336 --- cloudinit/CloudConfig/cc_byobu.py | 43 +++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 11 deletions(-) (limited to 'cloudinit/CloudConfig/cc_byobu.py') diff --git a/cloudinit/CloudConfig/cc_byobu.py b/cloudinit/CloudConfig/cc_byobu.py index 1a4545af..406a1f67 100644 --- a/cloudinit/CloudConfig/cc_byobu.py +++ b/cloudinit/CloudConfig/cc_byobu.py @@ -27,19 +27,40 @@ def handle(name,cfg,cloud,log,args): if not value: return - if value == "user": - user = util.get_cfg_option_str(cfg,"user","ubuntu") - cmd = [ 'sudo', '-Hu', user, 'byobu-launcher-install' ] - elif value == "system": - shcmd="echo '%s' | debconf-set-selections && %s" % \ - ( "byobu byobu/launch-by-default boolean true", - "dpkg-reconfigure byobu --frontend=noninteractive" ) - cmd = [ "/bin/sh", "-c", shcmd ] - else: + if value == "user" or value == "system": + value = "enable-%s" % value + + valid = ( "enable-user", "enable-system", "enable", + "disable-user", "disable-system", "disable" ) + if not value in valid: log.warn("Unknown value %s for byobu_by_default" % value) - return - log.debug("enabling byobu for %s" % value) + mod_user = value.endswith("-user") + mod_sys = value.endswith("-system") + if value.startswith("enable"): + bl_inst = "install" + dc_val = "byobu byobu/launch-by-default boolean true" + mod_sys = True + else: + if value == "disable": + mod_user = True + mod_sys = True + bl_inst = "uninstall" + dc_val = "byobu byobu/launch-by-default boolean false" + + shcmd = "" + if mod_user: + user = util.get_cfg_option_str(cfg,"user","ubuntu") + shcmd += " sudo -Hu \"%s\" byobu-launcher-%s" % (user, bl_inst) + shcmd += " || X=$(($X+1)); " + if mod_sys: + shcmd += "echo \"%s\" | debconf-set-selections" % dc_val + shcmd += " && dpkg-reconfigure byobu --frontend=noninteractive" + shcmd += " || X=$(($X+1)); " + + cmd = [ "/bin/sh", "-c", "%s %s %s" % ("X=0;", shcmd, "exit $X" ) ] + + log.debug("setting byobu to %s" % value) try: subprocess.check_call(cmd) -- cgit v1.2.3