def __init__(self): """Frontend initialisation.""" self.locale = None self.dbfilter = None self.dbfilter_status = None self.current_layout = None if 'DEBIAN_HAS_FRONTEND' in os.environ: # We may only instantiate Debconf once, as it fiddles with # sys.stdout. See LP #24727. self.db = debconf.Debconf() else: self.db = None page_list = self.debconf_operation('get', 'oem-config/steps') pages = page_list.replace(',', ' ').split() self.pages = [] for valid_page in VALID_PAGES: if valid_page in pages: self.pages.append("step_%s" % valid_page) for page in pages: if page not in VALID_PAGES: syslog.syslog(syslog.LOG_WARNING, "Unknown step name in oem-config/steps: %s" % page) if not self.pages: raise ValueError, "No valid steps in oem-config/steps"
def copy_debconf(): """Copy a few important questions into the installed system.""" if not TARGET: return targetdb = TARGET + '/var/cache/debconf/config.dat' patterns = ['^oem-config/'] oem = False import debconf dccomm = subprocess.Popen( ['debconf-communicate', '-fnoninteractive', 'ubiquity'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True, universal_newlines=True) try: dc = debconf.Debconf(read=dccomm.stdout, write=dccomm.stdin) try: if dc.get('oem-config/enable') == 'true': oem = True except debconf.DebconfError: pass finally: dccomm.stdin.close() dccomm.wait() if not oem: patterns.append('^keyboard-configuration/') patterns.append('^console-setup/') for q in patterns: misc.execute_root('debconf-copydb', 'configdb', 'targetdb', '-p', q, '--config=Name:targetdb', '--config=Driver:File', '--config=Mode:0644', '--config=Filename:%s' % targetdb)
def get_debconf(): debconf.runFrontEnd() db = debconf.Debconf() try: yield db finally: db.stop()
def set_debconf(self, owner, question, value): dccomm = subprocess.Popen(['chroot', self.target, 'debconf-communicate', '-fnoninteractive', owner], stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True) dc = debconf.Debconf(read=dccomm.stdout, write=dccomm.stdin) dc.set(question, value) dc.fset(question, 'seen', 'true') dccomm.stdin.close() dccomm.wait()
def __init__(self, template, title=None, priority='high', subst='CHOICES'): debconf.runFrontEnd() self.template = template self.db = debconf.Debconf(title) self.db.capb('backup') self.priority = priority self.subst = subst
def target_mounted(target='/target'): if not os.path.exists(target) or not is_mounted(target): db = debconf.Debconf(run_frontend=True) db.capb('backup') db.input(debconf.CRITICAL, 'base-installer/no_target_mounted') db.go() return False return True
def __init__(self): """Initial attributes.""" install_misc.InstallBase.__init__(self) if not os.path.exists('/var/lib/ubiquity'): os.makedirs('/var/lib/ubiquity') with open('/var/lib/ubiquity/started-installing', 'a'): pass if not os.path.exists('/var/lib/ubiquity'): os.makedirs('/var/lib/ubiquity') with open('/var/lib/ubiquity/started-installing', 'a'): pass self.update_proc = None if os.path.isdir('/rofs'): self.source = '/rofs' elif os.path.isdir('/UNIONFS'): # Klaus Knopper says this may not actually work very well # because it'll copy the WHOLE WORLD (~12GB). self.source = '/UNIONFS' else: self.source = '/var/lib/ubiquity/source' self.db = debconf.Debconf() self.blacklist = {} if 'UBIQUITY_OEM_USER_CONFIG' in os.environ: self.source = None self.target = '/' return assert os.path.ismount(self.target), \ 'Failed to mount the target: %s' % str(self.target) self.select_language_packs(save=True) self.select_ecryptfs() if self.db.get('ubiquity/install/generate-blacklist') == 'true': self.db.progress('START', 0, 100, 'ubiquity/install/title') self.db.progress('INFO', 'ubiquity/install/blacklist') self.generate_blacklist() apt_pkg.init_config() apt_pkg.config.set("Dir", self.target) apt_pkg.config.set("Dir::State::status", self.target_file('var/lib/dpkg/status')) apt_pkg.config.set("APT::GPGV::TrustedKeyring", self.target_file('etc/apt/trusted.gpg')) apt_pkg.config.set("Acquire::gpgv::Options::", "--ignore-time-conflict") apt_pkg.config.set("DPkg::Options::", "--root=%s" % self.target) # We don't want apt-listchanges or dpkg-preconfigure, so just clear # out the list of pre-installation hooks. apt_pkg.config.clear("DPkg::Pre-Install-Pkgs") apt_pkg.init_system()
def apply_keyboard(): """Set the keyboard layout to the default layout for the language selected. If a user wants a different layout, they can be reasonably expected to change it in System -> Preferences -> Keyboard. """ # Mostly taken from ubi-console-setup. # We need to get rid of /etc/default/keyboard, or keyboard-configuration # will think it's already configured and behave differently. Try to save # the old file for interest's sake, but it's not a big deal if we can't. osextras.unlink_force('/etc/default/keyboard.pre-ubiquity') try: os.rename('/etc/default/keyboard', '/etc/default/keyboard.pre-ubiquity') except OSError: osextras.unlink_force('/etc/default/keyboard') import debconf dccomm = subprocess.Popen( ['debconf-communicate', '-fnoninteractive', 'ubiquity'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True, universal_newlines=True) try: dc = debconf.Debconf(read=dccomm.stdout, write=dccomm.stdin) try: # Make sure debconf doesn't do anything with crazy "preseeded" # answers to these questions. If you want to preseed these, use the # *code variants. dc.fset('keyboard-configuration/layout', 'seen', 'false') dc.fset('keyboard-configuration/variant', 'seen', 'false') dc.fset('keyboard-configuration/model', 'seen', 'false') dc.fset('console-setup/codeset47', 'seen', 'false') except debconf.DebconfError: return finally: dccomm.stdin.close() dccomm.wait() # Accept all the defaults, given the preseeded language. child_env = dict(os.environ) child_env['OVERRIDE_ALLOW_PRESEEDING'] = '1' subprocess.call( ['dpkg-reconfigure', '-fnoninteractive', 'keyboard-configuration'], env=child_env) misc.execute('setupcon', '--save-only') # Reprocess /lib/udev/rules.d/64-xorg-xkb.rules misc.execute('udevadm', 'trigger', '--subsystem-match=input', '--action=change') misc.execute('udevadm', 'settle')
def preset_debconf(resets=None, preseeds=None, seen=None): db = debconf.Debconf(run_frontend=True) if resets: for template in resets: db.reset(template) if preseeds: for template, value in preseeds: db.set(template, value) if seen: for template, value in seen: db.fset(template, 'seen', value)
def get_locales(self): """set timezone and keymap attributes from debconf. It uses the same values the user have selected on live system. get_locales() -> timezone, keymap, locales""" debconf.runFrontEnd() db = debconf.Debconf() try: self.timezone = db.get('express/timezone') if self.timezone == '': self.timezone = db.get('tzconfig/choose_country_zone_multiple') except: self.timezone = open('/etc/timezone').readline().strip() self.keymap = db.get('debian-installer/keymap') self.locales = db.get('locales/default_environment_locale') return True
def get_locales(self): '''get_locales() -> timezone, keymap, locales Get the timezone, keymap and locales from the Debconf database and return them. ''' debconf.runFrontEnd() db = debconf.Debconf() try: self.timezone = db.get('express/timezone') if self.timezone == '': self.timezone = db.get('tzconfig/choose_country_zone_multiple') except: self.timezone = open('/etc/timezone').readline().strip() self.keymap = db.get('debian-installer/keymap') self.locales = db.get('locales/default_environment_locale') return True
def set_debconf(target, question, value, db=None): try: if 'UBIQUITY_OEM_USER_CONFIG' in os.environ and db: dccomm = None dc = db else: dccomm = subprocess.Popen([ 'log-output', '-t', 'ubiquity', '--pass-stdout', 'chroot', target, 'debconf-communicate', '-fnoninteractive', 'ubiquity' ], stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True) dc = debconf.Debconf(read=dccomm.stdout, write=dccomm.stdin) dc.set(question, value) dc.fset(question, 'seen', 'true') finally: if dccomm: dccomm.stdin.close() dccomm.wait()
def display_output(self, text): import socket import debconf as dc if 'DEBIAN_FRONTEND' not in os.environ or os.environ[ 'DEBIAN_FRONTEND'] != 'passthrough': return sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM, 0) sock.connect(os.environ['DEBCONF_PIPE']) dcfd = sock.makefile() sock.close() db = dc.Debconf(read=dcfd, write=dcfd) tmp = tempfile.NamedTemporaryFile(prefix="apt-listchanges-tmp") os.fchmod(tmp.fileno(), 0o644) tmp.write(b'''Template: apt-listchanges/info Type: title Description: NEWS Template: apt-listchanges/title Type: title Description: ${title} Template: apt-listchanges/news Type: note Description: ${packages_count} packages\n''') for line in text.split('\n'): if line.strip(): tmp.write(' ' + line + '\n') else: tmp.write(' .\n') tmp.flush() db.command('x_loadtemplatefile', tmp.name) tmp.close() db.info('apt-listchanges/info') db.subst('apt-listchanges/title', 'title', self.title) db.subst('apt-listchanges/news', 'packages_count', self.packages_count) db.settitle('apt-listchanges/title') db.fset('apt-listchanges/news', 'seen', 'false') db.input('high', 'apt-listchanges/news') db.go() dcfd.close()
def open_terminal(): """Set up the terminal to run ubiquity's debconf frontend.""" # Set up a framebuffer and start bterm if debian-installer/framebuffer # says to do so. See, in rootskel: # src/lib/debian-installer-startup.d/S40framebuffer-module-linux-x86 # TODO: more careful architecture handling import debconf # Start a new session and start a controlling terminal. Approach loosely # borrowed from util-linux. if 'UBIQUITY_CTTY' not in os.environ: os.environ['UBIQUITY_CTTY'] = '1' import termios try: os.setsid() except OSError: pass ttyn = os.ttyname(0) tty = os.open(ttyn, os.O_RDWR | os.O_NONBLOCK) flags = fcntl.fcntl(tty, fcntl.F_GETFL) fcntl.fcntl(tty, fcntl.F_SETFL, flags) # Leave stderr alone in the following; it's already redirected to # our log file. for i in range(tty): if i != 2: os.close(i) for i in range(2): if tty != i: os.dup2(tty, i) if tty >= 3: os.close(tty) fcntl.ioctl(0, termios.TIOCSCTTY, 1) if 'UBIQUITY_BTERM' not in os.environ: os.environ['UBIQUITY_BTERM'] = '1' framebuffer = False dccomm = subprocess.Popen( ['debconf-communicate', '-fnoninteractive', 'ubiquity'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True, universal_newlines=True) try: dc = debconf.Debconf(read=dccomm.stdout, write=dccomm.stdin) try: if dc.get('debian-installer/framebuffer') == 'true': framebuffer = True except debconf.DebconfError: pass finally: dccomm.stdin.close() dccomm.wait() if framebuffer: def fb_has(substring): try: with open('/proc/fb') as fb: for line in fb: if substring in line: return True except IOError: pass return False got_fb = False if fb_has('VESA'): got_fb = True devnull = open('/dev/null', 'w') if not got_fb: subprocess.call(['modprobe', '-q', 'vesafb'], stdout=devnull, stderr=devnull) if fb_has(''): got_fb = True if not got_fb: subprocess.call(['modprobe', '-q', 'vga16fb'], stdout=devnull, stderr=devnull) if fb_has(''): got_fb = True if got_fb: if not os.path.isdir('/sys/class/graphics/fbcon'): subprocess.call(['modprobe', '-q', 'fbcon'], stdout=devnull, stderr=devnull) # TODO: import debian-installer-utils and use update-dev? subprocess.call(['udevadm', 'settle']) devnull.close() if os.path.exists('/dev/fb0'): bterm_args = [ 'bterm', '-f', '/usr/share/ubiquity/unifont.bgf', '--' ] bterm_args.extend(sys.argv) os.execvp('bterm', bterm_args)
def __init__(self): debconf.runFrontEnd() self.db = debconf.Debconf()
def __init__(self, title=None): if title: self.db = debconf.Debconf(run_frontend=True, title=title) else: self.db = debconf.Debconf(run_frontend=True) self.db.capb('backup')