home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / bin / ubiquity < prev    next >
Encoding:
Text File  |  2006-08-30  |  4.2 KB  |  137 lines

  1. #!/usr/bin/python
  2.  
  3. '''
  4. Installer
  5.  
  6. This is a installer program for a Ubuntu or Metadistros Live system.
  7. This is the main program, but there are also a couple of libraries to
  8. help it to work, such as the frontend.
  9. The way it works is simple. It detects the frontend to use, then
  10. load the module for that frontend. After that, it makes some calls
  11. through the frontend in order to get the info necessary to install.
  12.  
  13. Once it has the info, partitioning, format, copy the distro to the disk
  14. and configure everything.
  15. '''
  16.  
  17. import sys
  18. import os
  19. import errno
  20. import shutil
  21. import subprocess
  22.  
  23. sys.path.insert(0, '/usr/lib/ubiquity')
  24.  
  25. from ubiquity import misc
  26.  
  27. cdebconf = False
  28.  
  29. VERSION = '1.1.11'
  30. TARGET = '/target'
  31.  
  32. log_file = '/var/log/installer/syslog'
  33.  
  34. def install(frontend=None):
  35.     '''install(frontend=None) -> none
  36.     
  37.     Get the type of frontend to use and load the module for that.
  38.     If frontend is None, defaults to the first of gtkui and kde-ui that
  39.     exists.
  40.     '''
  41.     if frontend is None:
  42.         frontends = ['gtkui', 'kde-ui']
  43.     else:
  44.         frontends = [frontend]
  45.     mod = __import__('ubiquity.frontend', globals(), locals(), frontends)
  46.     for f in frontends:
  47.         if hasattr(mod, f):
  48.             ui = getattr(mod, f)
  49.             break
  50.     else:
  51.         raise AttributeError, ('No frontend available; tried %s' %
  52.                                ', '.join(frontends))
  53.  
  54.     unmount_target()
  55.     distro = misc.distribution().lower()
  56.     wizard = ui.Wizard(distro)
  57.     ret = wizard.run()
  58.     copy_debconf()
  59.     unmount_target()
  60.     if ret == 10:
  61.         wizard.do_reboot()
  62.  
  63. def copy_debconf():
  64.     """Copy a few important questions into the installed system."""
  65.     targetdb = '/target/var/cache/debconf/config.dat'
  66.     for q in ('^debian-installer/keymap$',):
  67.         subprocess.call(['debconf-copydb', 'configdb', 'targetdb', '-p', q,
  68.                          '--config=Name:targetdb', '--config=Driver:File',
  69.                          '--config=Filename:%s' % targetdb])
  70.  
  71. def unmount_target():
  72.     paths = []
  73.     mounts = open('/proc/mounts')
  74.     for line in mounts:
  75.         path = line.split(' ')[1]
  76.         if path == '/target' or path.startswith('/target/'):
  77.             paths.append(path)
  78.     mounts.close()
  79.     paths.sort()
  80.     paths.reverse()
  81.     for path in paths:
  82.         misc.ex('umount', path)
  83.  
  84. def prepend_path(directory):
  85.     if 'PATH' in os.environ and os.environ['PATH'] != '':
  86.         os.environ['PATH'] = '%s:%s' % (directory, os.environ['PATH'])
  87.     else:
  88.         os.environ['PATH'] = directory
  89.  
  90. if __name__ == '__main__':
  91.     if not os.path.exists(os.path.dirname(log_file)):
  92.         os.makedirs(os.path.dirname(log_file))
  93.     # The frontend should take care of displaying a helpful message if we
  94.     # are being run without root privileges.
  95.     try:
  96.         sys.stderr = open(log_file, 'a', 1)
  97.         os.dup2(sys.stderr.fileno(), 2)
  98.     except IOError, err:
  99.         if err.errno != errno.EACCES:
  100.             raise
  101.  
  102.     print >>sys.stderr, "Ubiquity %s" % VERSION
  103.     version_file = open('/var/log/installer/version', 'w')
  104.     print >>version_file, 'ubiquity %s' % VERSION
  105.     version_file.close()
  106.  
  107.     if cdebconf:
  108.         # Note that this needs to be set before DebconfCommunicate is
  109.         # imported by anything.
  110.         os.environ['DEBCONF_USE_CDEBCONF'] = '1'
  111.         prepend_path('/usr/lib/cdebconf')
  112.     prepend_path('/usr/lib/ubiquity/compat')
  113.  
  114.     if 'UBIQUITY_DEBUG' in os.environ or 'ESPRESSO_DEBUG' in os.environ:
  115.         if 'UBIQUITY_DEBUG_CORE' not in os.environ:
  116.             os.environ['UBIQUITY_DEBUG_CORE'] = '1'
  117.         if 'DEBCONF_DEBUG' not in os.environ:
  118.             os.environ['DEBCONF_DEBUG'] = 'developer|filter'
  119.  
  120.     # Default to enabling internal (non-debconf) debugging.
  121.     if 'UBIQUITY_DEBUG_CORE' not in os.environ:
  122.         os.environ['UBIQUITY_DEBUG_CORE'] = '1'
  123.  
  124.     # Clean up old state.
  125.     if os.path.exists("/var/lib/ubiquity/apt-installed"):
  126.         os.unlink("/var/lib/ubiquity/apt-installed")
  127.     if os.path.exists("/var/lib/ubiquity/remove-kernels"):
  128.         os.unlink("/var/lib/ubiquity/remove-kernels")
  129.     shutil.rmtree("/var/lib/partman", ignore_errors=True)
  130.  
  131.     if len(sys.argv) == 2:
  132.         install(sys.argv[1])
  133.     else:
  134.         install()
  135.  
  136. # vim:ai:et:sts=4:tw=80:sw=4:
  137.