Beispiel #1
0
    def progress_loop(self):
        """prepare, copy and config the system in the core install process."""

        self.start_debconf()
        dbfilter = partman_commit.PartmanCommit(self)
        if dbfilter.run_command(auto_process=True) != 0:
            print >> self.console, '\nUnable to commit the partition table, exiting.'
            return

        self.start_debconf()
        dbfilter = install.Install(self)
        ret = dbfilter.run_command(auto_process=True)
        if ret == 0:
            dbfilter = plugininstall.Install(self)
            ret = dbfilter.run_command(auto_process=True)
        if ret == 0:
            self.run_success_cmd()
            print >> self.console, 'Installation complete.'
            if self.get_reboot():
                misc.execute("reboot")
        if ret != 0:
            if ret == 3:
                # error already handled by Install
                sys.exit(ret)
            elif (os.WIFSIGNALED(ret) and os.WTERMSIG(ret)
                  in (signal.SIGINT, signal.SIGKILL, signal.SIGTERM)):
                sys.exit(ret)
            elif os.path.exists('/var/lib/ubiquity/install.trace'):
                tbfile = open('/var/lib/ubiquity/install.trace')
                realtb = tbfile.read()
                tbfile.close()
                raise RuntimeError("Install failed with exit code %s\n%s" %
                                   (ret, realtb))
Beispiel #2
0
def chroot_cleanup(target, x11=False):
    """Undo the work done by chroot_setup."""
    if target == '/':
        return

    if x11 and 'DISPLAY' in os.environ:
        misc.execute('umount', os.path.join(target, 'tmp/.X11-unix'))
        try:
            os.rmdir(os.path.join(target, 'tmp/.X11-unix'))
        except OSError:
            pass
        osextras.unlink_force(os.path.join(target, 'root/.Xauthority'))

    chrex(target, 'umount', '/sys')
    chrex(target, 'umount', '/proc')
    misc.execute('umount', os.path.join(target, 'dev'))

    initctl = os.path.join(target, 'sbin/initctl')
    if os.path.exists('%s.REAL' % initctl):
        os.rename('%s.REAL' % initctl, initctl)

    start_stop_daemon = os.path.join(target, 'sbin/start-stop-daemon')
    if os.path.exists('%s.REAL' % start_stop_daemon):
        os.rename('%s.REAL' % start_stop_daemon, start_stop_daemon)
    else:
        osextras.unlink_force(start_stop_daemon)

    policy_rc_d = os.path.join(target, 'usr/sbin/policy-rc.d')
    osextras.unlink_force(policy_rc_d)
    def progress_loop(self):
        """prepare, copy and config the system in the core install process."""

        self.start_debconf()
        dbfilter = partman_commit.PartmanCommit(self)
        if dbfilter.run_command(auto_process=True) != 0:
            print >>self.console, '\nUnable to commit the partition table, exiting.'
            return

        self.start_debconf()
        dbfilter = install.Install(self)
        ret = dbfilter.run_command(auto_process=True)
        if ret == 0:
            dbfilter = plugininstall.Install(self)
            ret = dbfilter.run_command(auto_process=True)
        if ret == 0:
            self.run_success_cmd()
            print >>self.console, 'Installation complete.'
            if self.get_reboot():
                misc.execute("reboot")
        if ret != 0:
            if ret == 3:
                # error already handled by Install
                sys.exit(ret)
            elif (os.WIFSIGNALED(ret) and
                  os.WTERMSIG(ret) in (signal.SIGINT, signal.SIGKILL,
                                       signal.SIGTERM)):
                sys.exit(ret)
            elif os.path.exists('/var/lib/ubiquity/install.trace'):
                tbfile = open('/var/lib/ubiquity/install.trace')
                realtb = tbfile.read()
                tbfile.close()
                raise RuntimeError("Install failed with exit code %s\n%s" %
                                  (ret, realtb))
Beispiel #4
0
def chroot_cleanup(target, x11=False):
    """Undo the work done by chroot_setup."""
    if target == '/':
        return

    if x11 and 'DISPLAY' in os.environ:
        misc.execute('umount', os.path.join(target, 'tmp/.X11-unix'))
        try:
            os.rmdir(os.path.join(target, 'tmp/.X11-unix'))
        except OSError:
            pass
        osextras.unlink_force(os.path.join(target,
                                           'root/.Xauthority'))

    chrex(target, 'umount', '/sys')
    chrex(target, 'umount', '/proc')
    misc.execute('umount', os.path.join(target, 'dev'))

    initctl = os.path.join(target, 'sbin/initctl')
    if os.path.exists('%s.REAL' % initctl):
        os.rename('%s.REAL' % initctl, initctl)

    start_stop_daemon = os.path.join(target, 'sbin/start-stop-daemon')
    if os.path.exists('%s.REAL' % start_stop_daemon):
        os.rename('%s.REAL' % start_stop_daemon, start_stop_daemon)
    else:
        osextras.unlink_force(start_stop_daemon)

    policy_rc_d = os.path.join(target, 'usr/sbin/policy-rc.d')
    osextras.unlink_force(policy_rc_d)
Beispiel #5
0
 def install(self, target, progress, *args, **kwargs):
     progress.info('ubiquity/install/locales')
     rv = InstallPlugin.install(self, target, progress, *args, **kwargs)
     if not rv:
         # fontconfig configuration needs to be adjusted based on the
         # selected locale (from language-selector-common.postinst). Ignore
         # errors.
         misc.execute('chroot', target, 'fontconfig-voodoo', '--auto', '--force', '--quiet')
     return rv
 def install(self, target, progress, *args, **kwargs):
     progress.info('ubiquity/install/locales')
     rv = InstallPlugin.install(self, target, progress, *args, **kwargs)
     if not rv:
         # fontconfig configuration needs to be adjusted based on the
         # selected locale (from language-selector-common.postinst). Ignore
         # errors.
         misc.execute('chroot', target, 'fontconfig-voodoo', '--auto', '--force', '--quiet')
     return rv
Beispiel #7
0
def chroot_setup(target, x11=False):
    """Set up /target for safe package management operations."""
    if target == '/':
        return

    policy_rc_d = os.path.join(target, 'usr/sbin/policy-rc.d')
    f = open(policy_rc_d, 'w')
    print >>f, """\
#!/bin/sh
exit 101"""
    f.close()
    os.chmod(policy_rc_d, 0755)

    start_stop_daemon = os.path.join(target, 'sbin/start-stop-daemon')
    if os.path.exists(start_stop_daemon):
        os.rename(start_stop_daemon, '%s.REAL' % start_stop_daemon)
    f = open(start_stop_daemon, 'w')
    print >>f, """\
#!/bin/sh
echo 1>&2
echo 'Warning: Fake start-stop-daemon called, doing nothing.' 1>&2
exit 0"""
    f.close()
    os.chmod(start_stop_daemon, 0755)

    initctl = os.path.join(target, 'sbin/initctl')
    if os.path.exists(initctl):
        os.rename(initctl, '%s.REAL' % initctl)
        f = open(initctl, 'w')
        print >>f, """\
#!/bin/sh
echo 1>&2
echo 'Warning: Fake initctl called, doing nothing.' 1>&2
exit 0"""
        f.close()
        os.chmod(initctl, 0755)

    if not os.path.exists(os.path.join(target, 'proc/cmdline')):
        chrex(target, 'mount', '-t', 'proc', 'proc', '/proc')
    if not os.path.exists(os.path.join(target, 'sys/devices')):
        chrex(target, 'mount', '-t', 'sysfs', 'sysfs', '/sys')
    misc.execute('mount', '--bind', '/dev', os.path.join(target, 'dev'))

    if x11 and 'DISPLAY' in os.environ:
        if 'SUDO_USER' in os.environ:
            xauthority = os.path.expanduser('~%s/.Xauthority' %
                                            os.environ['SUDO_USER'])
        else:
            xauthority = os.path.expanduser('~/.Xauthority')
        if os.path.exists(xauthority):
            shutil.copy(xauthority,
                        os.path.join(target, 'root/.Xauthority'))

        if not os.path.isdir(os.path.join(target, 'tmp/.X11-unix')):
            os.mkdir(os.path.join(target, 'tmp/.X11-unix'))
        misc.execute('mount', '--bind', '/tmp/.X11-unix',
                     os.path.join(target, 'tmp/.X11-unix'))
Beispiel #8
0
def chroot_setup(target, x11=False):
    """Set up /target for safe package management operations."""
    if target == '/':
        return

    policy_rc_d = os.path.join(target, 'usr/sbin/policy-rc.d')
    f = open(policy_rc_d, 'w')
    print >> f, """\
#!/bin/sh
exit 101"""
    f.close()
    os.chmod(policy_rc_d, 0755)

    start_stop_daemon = os.path.join(target, 'sbin/start-stop-daemon')
    if os.path.exists(start_stop_daemon):
        os.rename(start_stop_daemon, '%s.REAL' % start_stop_daemon)
    f = open(start_stop_daemon, 'w')
    print >> f, """\
#!/bin/sh
echo 1>&2
echo 'Warning: Fake start-stop-daemon called, doing nothing.' 1>&2
exit 0"""
    f.close()
    os.chmod(start_stop_daemon, 0755)

    initctl = os.path.join(target, 'sbin/initctl')
    if os.path.exists(initctl):
        os.rename(initctl, '%s.REAL' % initctl)
        f = open(initctl, 'w')
        print >> f, """\
#!/bin/sh
echo 1>&2
echo 'Warning: Fake initctl called, doing nothing.' 1>&2
exit 0"""
        f.close()
        os.chmod(initctl, 0755)

    if not os.path.exists(os.path.join(target, 'proc/cmdline')):
        chrex(target, 'mount', '-t', 'proc', 'proc', '/proc')
    if not os.path.exists(os.path.join(target, 'sys/devices')):
        chrex(target, 'mount', '-t', 'sysfs', 'sysfs', '/sys')
    misc.execute('mount', '--bind', '/dev', os.path.join(target, 'dev'))

    if x11 and 'DISPLAY' in os.environ:
        if 'SUDO_USER' in os.environ:
            xauthority = os.path.expanduser('~%s/.Xauthority' %
                                            os.environ['SUDO_USER'])
        else:
            xauthority = os.path.expanduser('~/.Xauthority')
        if os.path.exists(xauthority):
            shutil.copy(xauthority, os.path.join(target, 'root/.Xauthority'))

        if not os.path.isdir(os.path.join(target, 'tmp/.X11-unix')):
            os.mkdir(os.path.join(target, 'tmp/.X11-unix'))
        misc.execute('mount', '--bind', '/tmp/.X11-unix',
                     os.path.join(target, 'tmp/.X11-unix'))
 def apply_real_keyboard(self, model, layout, variant, options):
     args = []
     if model is not None and model != "":
         args.extend(("-model", model))
     args.extend(("-layout", layout))
     if variant != "":
         args.extend(("-variant", variant))
     for option in options:
         args.extend(("-option", option))
     misc.execute("setxkbmap", *args)
 def apply_real_keyboard(self, model, layout, variant, options):
     args = []
     if model is not None and model != '':
         args.extend(("-model", model))
     args.extend(("-layout", layout))
     if variant != '':
         args.extend(("-variant", variant))
     args.extend(("-option", ""))
     for option in options:
         args.extend(("-option", option))
     misc.execute("setxkbmap", *args)
 def apply_real_keyboard(self, model, layout, variant, options):
     args = []
     if model is not None and model != '':
         args.extend(("-model", model))
     args.extend(("-layout", layout))
     if variant != '':
         args.extend(("-variant", variant))
     args.extend(("-option", ""))
     for option in options:
         args.extend(("-option", option))
     print >>sys.stderr,' ----->DENTRO APPLY REAL KEYBOARD'
     misc.execute("setxkbmap", *args)
Beispiel #12
0
    def umount_source(self):
        """umounting loop system from cloop or squashfs system."""

        devs = self.devs
        devs.reverse()
        mountpoints = self.mountpoints
        mountpoints.reverse()

        for mountpoint in mountpoints:
            if not misc.execute("umount", mountpoint):
                raise install_misc.InstallStepError("Failed to unmount %s" % mountpoint)
        for dev in devs:
            if dev != "" and dev != "unused" and not misc.execute("losetup", "-d", dev):
                raise install_misc.InstallStepError("Failed to detach loopback device %s" % dev)
Beispiel #13
0
    def umount_source(self):
        """umounting loop system from cloop or squashfs system."""

        devs = self.devs
        devs.reverse()
        mountpoints = self.mountpoints
        mountpoints.reverse()

        for mountpoint in mountpoints:
            if not misc.execute('umount', mountpoint):
                raise install_misc.InstallStepError("Failed to unmount %s" % mountpoint)
        for dev in devs:
            if (dev != '' and dev != 'unused' and
                not misc.execute('losetup', '-d', dev)):
                raise install_misc.InstallStepError(
                    "Failed to detach loopback device %s" % dev)
Beispiel #14
0
    def umount_source(self):
        """umounting loop system from cloop or squashfs system."""

        devs = self.devs
        devs.reverse()
        mountpoints = self.mountpoints
        mountpoints.reverse()

        for mountpoint in mountpoints:
            if not misc.execute('umount', mountpoint):
                raise install_misc.InstallStepError("Failed to unmount %s" % mountpoint)
        for dev in devs:
            if (dev != '' and dev != 'unused' and
                not misc.execute('losetup', '-d', dev)):
                raise install_misc.InstallStepError(
                    "Failed to detach loopback device %s" % dev)
Beispiel #15
0
 def on_testdomain_click(self, widget):
     if misc.execute('realm', 'discover', self.domain_name.get_text()):
         self.domain_name_ok.show()
         self.domain_name_error_label.hide()
     else:
         self.domain_name_ok.hide()
         self.domain_name_error(self.domain_connection_error_text)
         self.domain_name_error_label.show()
Beispiel #16
0
 def install(self, target, progress, *args, **kwargs):
     progress.info('ubiquity/install/locales')
     rv = plugin.InstallPlugin.install(
         self, target, progress, *args, **kwargs)
     if not rv:
         if 'UBIQUITY_OEM_USER_CONFIG' not in os.environ:
             # Start using the newly-generated locale, if possible.
             try:
                 locale.setlocale(locale.LC_ALL, '')
             except locale.Error:
                 pass
         # fontconfig configuration needs to be adjusted based on the
         # selected locale (from language-selector-common.postinst). Ignore
         # errors.
         misc.execute(
             'chroot', target, 'fontconfig-voodoo',
             '--auto', '--force', '--quiet')
     return rv
 def __init__(self):
     self.suffix = misc.dmimodel()
     if self.suffix:
         self.suffix = '-%s' % self.suffix
     else:
         if misc.execute("laptop-detect"):
             self.suffix = '-laptop'
         else:
             self.suffix = '-desktop'
     self.allow_password_empty = False
Beispiel #18
0
    def mount_one_image(self, fsfile, mountpoint=None):
        if os.path.splitext(fsfile)[1] == '.cloop':
            blockdev_prefix = 'cloop'
        elif os.path.splitext(fsfile)[1] == '.squashfs':
            blockdev_prefix = 'loop'

        if blockdev_prefix == '':
            raise install_misc.InstallStepError(
                "No source device found for %s" % fsfile)

        dev = ''
        sysloops = sorted([
            x for x in os.listdir('/sys/block')
            if x.startswith(blockdev_prefix)
        ])
        for sysloop in sysloops:
            try:
                with open(os.path.join('/sys/block', sysloop,
                                       'size')) as sysloopf:
                    sysloopsize = sysloopf.readline().strip()
                if sysloopsize == '0':
                    if osextras.find_on_path('udevadm'):
                        udevinfo_cmd = ['udevadm', 'info']
                    else:
                        udevinfo_cmd = ['udevinfo']
                    udevinfo_cmd.extend(
                        ['-q', 'name', '-p',
                         os.path.join('/block', sysloop)])
                    with open('/dev/null') as devnull:
                        udevinfo = subprocess.Popen(udevinfo_cmd,
                                                    stdout=subprocess.PIPE,
                                                    stderr=devnull,
                                                    universal_newlines=True)
                    devbase = udevinfo.communicate()[0]
                    if udevinfo.returncode != 0:
                        devbase = sysloop
                    dev = '/dev/%s' % devbase
                    break
            except Exception:
                continue

        if dev == '':
            raise install_misc.InstallStepError(
                "No loop device available for %s" % fsfile)

        misc.execute('losetup', dev, fsfile)
        if mountpoint is None:
            mountpoint = '/var/lib/ubiquity/%s' % sysloop
        if not os.path.isdir(mountpoint):
            os.mkdir(mountpoint)
        if not misc.execute('mount', dev, mountpoint):
            misc.execute('losetup', '-d', dev)
            misc.execute('mount', '-o', 'loop', fsfile, mountpoint)
            dev = 'unused'

        return (dev, mountpoint)
Beispiel #19
0
 def __init__(self):
     self.suffix = misc.dmimodel()
     if self.suffix:
         self.suffix = '-%s' % self.suffix
     else:
         if misc.execute("laptop-detect"):
             self.suffix = '-laptop'
         else:
             self.suffix = '-desktop'
     self.allow_password_empty = False
     self.hostname_error_text = ""
     self.domain_connection_error_text = ""
Beispiel #20
0
    def mount_one_image(self, fsfile, mountpoint=None):
        if os.path.splitext(fsfile)[1] == '.cloop':
            blockdev_prefix = 'cloop'
        elif os.path.splitext(fsfile)[1] == '.squashfs':
            blockdev_prefix = 'loop'

        if blockdev_prefix == '':
            raise install_misc.InstallStepError(
                "No source device found for %s" % fsfile)

        dev = ''
        sysloops = sorted([x for x in os.listdir('/sys/block')
                           if x.startswith(blockdev_prefix)])
        for sysloop in sysloops:
            try:
                with open(os.path.join('/sys/block', sysloop,
                                       'size')) as sysloopf:
                    sysloopsize = sysloopf.readline().strip()
                if sysloopsize == '0':
                    if osextras.find_on_path('udevadm'):
                        udevinfo_cmd = ['udevadm', 'info']
                    else:
                        udevinfo_cmd = ['udevinfo']
                    udevinfo_cmd.extend(
                        ['-q', 'name', '-p', os.path.join('/block', sysloop)])
                    with open('/dev/null') as devnull:
                        udevinfo = subprocess.Popen(
                            udevinfo_cmd, stdout=subprocess.PIPE,
                            stderr=devnull, universal_newlines=True)
                    devbase = udevinfo.communicate()[0]
                    if udevinfo.returncode != 0:
                        devbase = sysloop
                    dev = '/dev/%s' % devbase
                    break
            except:
                continue

        if dev == '':
            raise install_misc.InstallStepError(
                "No loop device available for %s" % fsfile)

        misc.execute('losetup', dev, fsfile)
        if mountpoint is None:
            mountpoint = '/var/lib/ubiquity/%s' % sysloop
        if not os.path.isdir(mountpoint):
            os.mkdir(mountpoint)
        if not misc.execute('mount', dev, mountpoint):
            misc.execute('losetup', '-d', dev)
            misc.execute('mount', '-o', 'loop', fsfile, mountpoint)
            dev = 'unused'

        return (dev, mountpoint)
Beispiel #21
0
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')
Beispiel #22
0
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')
Beispiel #23
0
    def mount_one_image(self, fsfile, mountpoint=None):
        if os.path.splitext(fsfile)[1] == ".cloop":
            blockdev_prefix = "cloop"
        elif os.path.splitext(fsfile)[1] == ".squashfs":
            blockdev_prefix = "loop"

        if blockdev_prefix == "":
            raise install_misc.InstallStepError("No source device found for %s" % fsfile)

        dev = ""
        sysloops = sorted([x for x in os.listdir("/sys/block") if x.startswith(blockdev_prefix)])
        for sysloop in sysloops:
            try:
                with open(os.path.join("/sys/block", sysloop, "size")) as sysloopf:
                    sysloopsize = sysloopf.readline().strip()
                if sysloopsize == "0":
                    if osextras.find_on_path("udevadm"):
                        udevinfo_cmd = ["udevadm", "info"]
                    else:
                        udevinfo_cmd = ["udevinfo"]
                    udevinfo_cmd.extend(["-q", "name", "-p", os.path.join("/block", sysloop)])
                    with open("/dev/null") as devnull:
                        udevinfo = subprocess.Popen(
                            udevinfo_cmd, stdout=subprocess.PIPE, stderr=devnull, universal_newlines=True
                        )
                    devbase = udevinfo.communicate()[0]
                    if udevinfo.returncode != 0:
                        devbase = sysloop
                    dev = "/dev/%s" % devbase
                    break
            except:
                continue

        if dev == "":
            raise install_misc.InstallStepError("No loop device available for %s" % fsfile)

        misc.execute("losetup", dev, fsfile)
        if mountpoint is None:
            mountpoint = "/var/lib/ubiquity/%s" % sysloop
        if not os.path.isdir(mountpoint):
            os.mkdir(mountpoint)
        if not misc.execute("mount", dev, mountpoint):
            misc.execute("losetup", "-d", dev)
            misc.execute("mount", "-o", "loop", fsfile, mountpoint)
            dev = "unused"

        return (dev, mountpoint)
Beispiel #24
0
def chroot_cleanup(target, x11=False):
    """Undo the work done by chroot_setup."""
    chrex(target, 'cp', '/usr/eXtern/systemX/Shared/CoreMsc/grub','/etc/default/grub')
    chrex(target, 'update-grub')
    if target == '/':
        return

    if x11 and 'DISPLAY' in os.environ:
        misc.execute('umount', os.path.join(target, 'tmp/.X11-unix'))
        try:
            os.rmdir(os.path.join(target, 'tmp/.X11-unix'))
        except OSError:
            pass
        osextras.unlink_force(os.path.join(target,
                                           'root/.Xauthority'))

    chrex(target, 'rm', '/usr/eXtern/live')
    #chrex(target, 'cp', '/usr/eXtern/systemX/Shared/CoreMsc/grub','/etc/default/grub')
    #chrex(target, 'cp', '/usr/eXtern/systemX/Shared/CoreMsc/lsb-release','/etc/lsb-release')
    #chrex(target, 'cp', '/usr/eXtern/systemX/Shared/CoreMsc/hostname','/etc/hostname')
    #chrex(target, 'update-grub')
    chrex(target, 'umount', '/sys')
    chrex(target, 'umount', '/proc')
    misc.execute('umount', os.path.join(target, 'run'))
    misc.execute('umount', os.path.join(target, 'dev'))

    initctl = os.path.join(target, 'sbin/initctl')
    if os.path.exists('%s.REAL' % initctl):
        os.rename('%s.REAL' % initctl, initctl)

    start_stop_daemon = os.path.join(target, 'sbin/start-stop-daemon')
    if os.path.exists('%s.REAL' % start_stop_daemon):
        os.rename('%s.REAL' % start_stop_daemon, start_stop_daemon)
    else:
        osextras.unlink_force(start_stop_daemon)

    policy_rc_d = os.path.join(target, 'usr/sbin/policy-rc.d')
    osextras.unlink_force(policy_rc_d)
Beispiel #25
0
def chrex(target, *args):
    """executes commands on chroot system (provided by *args)."""
    return misc.execute('chroot', target, *args)
Beispiel #26
0
    def mount_source(self):
        """mounting loop system from cloop or squashfs system."""

        self.devs = []
        self.mountpoints = []

        if not os.path.isdir(self.source):
            syslog.syslog('mkdir %s' % self.source)
            os.mkdir(self.source)

        fs_preseed = self.db.get('ubiquity/install/filesystem-images')

        if fs_preseed == '':
            # Simple autodetection on unionfs systems
            with open('/proc/mounts') as mounts:
                for line in mounts:
                    (device, fstype) = line.split()[1:3]
                    if fstype == 'squashfs' and os.path.exists(device):
                        misc.execute('mount', '--bind', device, self.source)
                        self.mountpoints.append(self.source)
                        return

            # Manual detection on non-unionfs systems
            fsfiles = [os.path.join(self.casper_path, 'filesystem.cloop'),
                       os.path.join(self.casper_path, 'filesystem.squashfs'),
                       '/cdrom/META/META.squashfs',
                       '/live/image/live/filesystem.squashfs']

            for fsfile in fsfiles:
                if fsfile != '' and os.path.isfile(fsfile):
                    dev, mountpoint = self.mount_one_image(fsfile, self.source)
                    self.devs.append(dev)
                    self.mountpoints.append(mountpoint)

        elif len(fs_preseed.split()) == 1:
            # Just one preseeded image.
            if not os.path.isfile(fs_preseed):
                raise install_misc.InstallStepError(
                    "Preseeded filesystem image %s not found" % fs_preseed)

                dev, mountpoint = self.mount_one_image(fsfile, self.source)
                self.devs.append(dev)
                self.mountpoints.append(mountpoint)
        else:
            # OK, so we need to mount multiple images and unionfs them
            # together.
            for fsfile in fs_preseed.split():
                if not os.path.isfile(fsfile):
                    raise install_misc.InstallStepError(
                        "Preseeded filesystem image %s not found" % fsfile)

                dev, mountpoint = self.mount_one_image(fsfile)
                self.devs.append(dev)
                self.mountpoints.append(mountpoint)

            assert self.devs
            assert self.mountpoints

            misc.execute('mount', '-t', 'unionfs', '-o',
                         'dirs=' + ':'.join(['%s=ro' % x
                                             for x in self.mountpoints]),
                         'unionfs', self.source)
            self.mountpoints.append(self.source)
 def __init__(self):
     self.laptop = execute("laptop-detect")
     self.allow_password_empty = False
Beispiel #28
0
    def mount_source(self):
        """mounting loop system from cloop or squashfs system."""

        self.devs = []
        self.mountpoints = []

        if not os.path.isdir(self.source):
            syslog.syslog('mkdir %s' % self.source)
            os.mkdir(self.source)

        fs_preseed = self.db.get('ubiquity/install/filesystem-images')

        if fs_preseed == '':
            # Simple autodetection on unionfs systems
            with open('/proc/mounts') as mounts:
                for line in mounts:
                    (device, fstype) = line.split()[1:3]
                    if fstype == 'squashfs' and os.path.exists(device):
                        misc.execute('mount', '--bind', device, self.source)
                        self.mountpoints.append(self.source)
                        return

            # Manual detection on non-unionfs systems
            fsfiles = [
                os.path.join(self.casper_path, 'filesystem.cloop'),
                os.path.join(self.casper_path, 'filesystem.squashfs'),
                '/cdrom/META/META.squashfs',
                '/live/image/live/filesystem.squashfs'
            ]

            for fsfile in fsfiles:
                if fsfile != '' and os.path.isfile(fsfile):
                    dev, mountpoint = self.mount_one_image(fsfile, self.source)
                    self.devs.append(dev)
                    self.mountpoints.append(mountpoint)

        elif len(fs_preseed.split()) == 1:
            # Just one preseeded image.
            if not os.path.isfile(fs_preseed):
                raise install_misc.InstallStepError(
                    "Preseeded filesystem image %s not found" % fs_preseed)

                dev, mountpoint = self.mount_one_image(fsfile, self.source)
                self.devs.append(dev)
                self.mountpoints.append(mountpoint)
        else:
            # OK, so we need to mount multiple images and unionfs them
            # together.
            for fsfile in fs_preseed.split():
                if not os.path.isfile(fsfile):
                    raise install_misc.InstallStepError(
                        "Preseeded filesystem image %s not found" % fsfile)

                dev, mountpoint = self.mount_one_image(fsfile)
                self.devs.append(dev)
                self.mountpoints.append(mountpoint)

            assert self.devs
            assert self.mountpoints

            misc.execute(
                'mount', '-t', 'unionfs', '-o',
                'dirs=' + ':'.join(['%s=ro' % x for x in self.mountpoints]),
                'unionfs', self.source)
            self.mountpoints.append(self.source)
Beispiel #29
0
def chrex(target, *args):
    """executes commands on chroot system (provided by *args)."""
    return misc.execute('chroot', target, *args)
Beispiel #30
0
    def mount_source(self):
        """mounting loop system from cloop or squashfs system."""

        self.devs = []
        self.mountpoints = []

        if not os.path.isdir(self.source):
            syslog.syslog("mkdir %s" % self.source)
            os.mkdir(self.source)

        fs_preseed = self.db.get("ubiquity/install/filesystem-images")

        if fs_preseed == "":
            # Simple autodetection on unionfs systems
            with open("/proc/mounts") as mounts:
                for line in mounts:
                    (device, fstype) = line.split()[1:3]
                    if fstype == "squashfs" and os.path.exists(device):
                        misc.execute("mount", "--bind", device, self.source)
                        self.mountpoints.append(self.source)
                        return

            # Manual detection on non-unionfs systems
            fsfiles = [
                os.path.join(self.casper_path, "filesystem.cloop"),
                os.path.join(self.casper_path, "filesystem.squashfs"),
                "/cdrom/META/META.squashfs",
                "/live/image/live/filesystem.squashfs",
            ]

            for fsfile in fsfiles:
                if fsfile != "" and os.path.isfile(fsfile):
                    dev, mountpoint = self.mount_one_image(fsfile, self.source)
                    self.devs.append(dev)
                    self.mountpoints.append(mountpoint)

        elif len(fs_preseed.split()) == 1:
            # Just one preseeded image.
            if not os.path.isfile(fs_preseed):
                raise install_misc.InstallStepError("Preseeded filesystem image %s not found" % fs_preseed)

                dev, mountpoint = self.mount_one_image(fsfile, self.source)
                self.devs.append(dev)
                self.mountpoints.append(mountpoint)
        else:
            # OK, so we need to mount multiple images and unionfs them
            # together.
            for fsfile in fs_preseed.split():
                if not os.path.isfile(fsfile):
                    raise install_misc.InstallStepError("Preseeded filesystem image %s not found" % fsfile)

                dev, mountpoint = self.mount_one_image(fsfile)
                self.devs.append(dev)
                self.mountpoints.append(mountpoint)

            assert self.devs
            assert self.mountpoints

            misc.execute(
                "mount",
                "-t",
                "unionfs",
                "-o",
                "dirs=" + ":".join(["%s=ro" % x for x in self.mountpoints]),
                "unionfs",
                self.source,
            )
            self.mountpoints.append(self.source)
Beispiel #31
0
 def __init__(self):
     self.laptop = execute("laptop-detect")
     self.allow_password_empty = False