Example #1
0
 def MakeDirectories(self, doLaunchdPlists):
   """Make directories for our package if needed.  Note conditional on
   doLaunchdPlists."""
   dirs = [ self.KeystoneDir() ]
   if doLaunchdPlists:
     dirs.append(self.LaunchAgentConfigDir())
     if self.IsSystemKeystone():
       dirs.append(self.LaunchDaemonConfigDir())
   umask(022)
   for d in dirs:
     p = popen_returns_proc(['/bin/mkdir', '-p', d])
     result = p.wait()
     if os.WEXITSTATUS(result) != 0:
       raise Failure(self.keystone.package, self.root, 'mkdir -p')
Example #2
0
    def run_fatformat(self, target):
        """Partition and format a device (presumably USB stick) into a single-partition FAT format."""
        try:
            # Set umask to be the same as normal ubuntu user umask (0022) that ubuquity install assumes
            # instead of default root umask (0066) that we are otherwise using.
            posix.umask(022)

            self.prepare()  # does stuff we don't need, but it doesn't hurt

            self.install_stage_set('Partitioning and formatting device')
            self.debconf_progress_start(0, 100, 'Partitioning and formatting device')
            self.debconf_progress_set(0)
            self.create_and_format_fatdevice(target)
            self.debconf_progress_set(100)
            self.write_status('success\nFormat completed')
            self.info('formatting success')
        except:
            self.cleanup()
            self.write_status('failure\nFormatting failed')
            self.error('formatting failed')
            raise
Example #3
0
def Umask(argv):
    if len(argv) == 0:
        # umask() has a dumb API: you can't get it without modifying it first!
        # NOTE: dash disables interrupts around the two umask() calls, but that
        # shouldn't be a concern for us.  Signal handlers won't call umask().
        mask = posix.umask(0)
        posix.umask(mask)  #
        print('0%03o' % mask)  # octal format
        return 0

    if len(argv) == 1:
        a = argv[0]
        try:
            new_mask = int(a, 8)
        except ValueError:
            # NOTE: This happens if we have '8' or '9' in the input too.

            util.warn('*** umask with symbolic input not implemented ***')
            return 1
        else:
            posix.umask(new_mask)
            return 0

    raise args.UsageError('umask: unexpected arguments')
 def test_umask(self):
     if hasattr(posix, 'umask'):
         old_mask = posix.umask(0)
         self.assert_(isinstance(old_mask, int))
         posix.umask(old_mask)
Example #5
0
 def tearDown(self):
     shutil.rmtree(self.temp_dir)
     posix.umask(self.prev_umask)
Example #6
0
 def setUp(self):
     self.temp_dir = tempfile.mkdtemp()
     self.file_path = self.temp_dir + 'sample.txt'
     self.sample_contents = 'Random text: aldmkfhjwoem103u74.'
     # To avoid confusion in the mode tests.
     self.prev_umask = posix.umask(0)
 def tearDown(self):
   shutil.rmtree(self.temp_dir)
   posix.umask(self.prev_umask)
 def setUp(self):
   self.temp_dir = tempfile.mkdtemp()
   self.file_path = self.temp_dir + 'sample.txt'
   self.sample_contents = 'Random text: aldmkfhjwoem103u74.'
   # To avoid confusion in the mode tests.
   self.prev_umask = posix.umask(0)
Example #9
0
    def run_install(self, target, hostname, adminuser, adminpassword, recovery_data=None, large_install=False):
        """Perform normal product install."""
        try:
            # Set umask to be the same as normal ubuntu user umask (0022) that ubuquity install assumes
            # instead of default root umask (0066) that we are otherwise using.
            posix.umask(022)

            self.prepare()
            self.hostname = hostname
            self.large_install = large_install
            
            self.install_stage_set('Preparing target disk')
            self.debconf_progress_start(0, 100, '')
            self.debconf_progress_set(0)

            self.debconf_progress_region(0, 4)
            self.create_filesystems(target)
            self.setup_fat_partition('/target-fat')
            self.debconf_progress_set(4)

            # Copy recovery data for the first time, to ensure that the data is available
            # in case this recovery fails
            self.copy_recovery_data(recovery_data)
            
            self.install_stage_set('Copying files')

            # Note: resume partition setup is not a problem
            # because we do not use swap in live-cd => ubiquity
            # cannot find a swap partition to use for resume..

            # Set configuration values to the debconf database so that
            # Ubiquity can find them.

            # Grub boot device
            self.set_debconf_variable('grub-installer/bootdev', target)

            # Disable os-prober so that grub installer will not find other
            # devices to boot from. This is not configurable from debconf
            # and requires this hack (or menu.lst cleanup afterwards).
            os_prober = '/usr/bin/os-prober'
            os_prober_orig = '/usr/bin/os-prober.orig'

            # Note: first move command in unionfs system changes the directory permissions,
            # avoiding this by doing a copy/delete instead of move.
            run_command([constants.CMD_CP, '-f', os_prober, os_prober_orig], retval=runcommand.FAIL)
            run_command([constants.CMD_RM, '-f', os_prober], retval=runcommand.FAIL)

            helpers.write_file(os_prober, '#!/bin/sh\nexit 0\n', append=False, perms=0755)

            # Admin user and passwd
            self.set_debconf_variable('passwd/username', adminuser)
            self.set_debconf_variable('passwd/user-fullname', 'Administrator')
            self.set_debconf_variable('passwd/user-uid', '999')

            # Note: here we could use real password received from UI (currently cleartext)
            # eg.: self.set_debconf_variable('passwd/user-password', adminpassword)
            # For now the admin password is disabled.
            self.set_debconf_variable('passwd/user-password-crypted', '*')

            # Set root password disabled.
            self.set_debconf_variable('passwd/root-password-crypted', '*')

            # Disable unwanted parts of Ubiquity
            # 1. language_apply (first two)
            # 2. apt_setup
            # 3. timezone_apply (zone and clock)
            # 4. keyboard_chooser
            for i in ['/usr/lib/ubiquity/localechooser/post-base-installer',
                      '/usr/lib/ubiquity/localechooser/prebaseconfig',
                      '/usr/share/ubiquity/apt-setup',
                      '/usr/lib/ubiquity/tzsetup/prebaseconfig',
                      '/usr/share/ubiquity/clock-setup',
                      '/usr/lib/ubiquity/kbd-chooser/prebaseconfig']:
                helpers.write_file(i, textwrap.dedent("""\
                #!/bin/sh
                exit 0
                """))

            # Run Ubiquity to do the main part of installation
            self.debconf_progress_region(4, 97)
            if install.Install(self).run_command():
                raise Exception('Ubiquity installer failed')

            # Set back os-prober
            # Note: first move command in unionfs system changes the directory permissions,
            # avoiding this by doing a delete/copy/delete instead of move.
            run_command([constants.CMD_RM, '-f', os_prober], retval=runcommand.FAIL)
            run_command([constants.CMD_CP, '-f', os_prober_orig, os_prober], retval=runcommand.FAIL)
            run_command([constants.CMD_RM, '-f', os_prober_orig], retval=runcommand.FAIL)

            # Clear debconf database
            for i in ['grub-installer/bootdev',
                      'passwd/user-password',
                      'passwd/user-password-crypted',
                      'passwd/root-password-crypted',
                      'passwd/username',
                      'passwd/user-fullname',
                      'passwd/user-uid']:
                self.set_debconf_variable(i, None)

            # Ensure that the default user has sudo rights because
            # user-setup-apply fails when username is "admin".
            helpers.write_file('/target/etc/sudoers', textwrap.dedent("""\
            # Ensure that the default user has admin rights always.
            %s ALL=(ALL) NOPASSWD: ALL
            """ % adminuser), append=True, perms=None)

            # Add GRUB options to /boot/grub/menu.lst:
            #   * recover from kernel panic (panic=60)
            #   * force a 16-bit VESA mode for Virtual PC 2007 compatibility
            #     (affects only startup)
            
            f = open('/target/boot/grub/menu.lst')
            grub_menu = f.read()
            f.close()

            def_re = re.compile(r'^# defoptions=')
            alt_re = re.compile(r'^# altoptions=')

            updated_grub_menu = ''
            for l in grub_menu.split('\n'):
                if (def_re.match(l) is not None) or (alt_re.match(l) is not None):
                    updated_grub_menu += '%s panic=60 vga=785' % l
                else:
                    updated_grub_menu += l

                updated_grub_menu += '\n'

            f = open('/target/boot/grub/menu.lst', 'wb')
            f.write(updated_grub_menu)
            f.close()

            run_command(['/usr/sbin/chroot', '/target', '/sbin/update-grub'], retval=runcommand.FAIL)

            # Fix permissions of all ubiquity-created files on target system.
            # These permissions are broken because of root umask (0066) is used
            # when running installer instead of ubuntu-user umask (0022))
            #
            # Files affected include at least: /etc/hosts, /etc/iftab, /etc/kernel-img.conf, /boot/grub, /boot/grub/*
            #
            # The following files already have proper permissions (files do exist before write),
            # but setting anyways: /etc/hostname, /etc/network/interfaces
            #
            # Note: this is still in place as a safeguard even when the umask is now set
            # in script start.

            for f, p in [['etc/hosts', 0644],
                         ['etc/iftab', 0644],
                         ['etc/hostname', 0644],
                         ['etc/network/interfaces', 0644],
                         ['etc/kernel-img.conf', 0644]]:
                os.chmod(os.path.join('/target', f), p)

            for r, d, files in os.walk('/target/boot/grub'):
                os.chmod(r, 0755)
                for f in files:
                    os.chmod(os.path.join(r, f), 0644)

            # Note: Use this if the login stuff gets broken again and
            # debugging is required.
            # helpers.write_file('/target/etc/sudoers', textwrap.dedent("""\
            # debug ALL=(ALL) NOPASSWD: ALL
            # """), append=True, perms=None)
            # run_command(['/usr/sbin/chroot', '/target', 'adduser', '--disabled-password', '--gecos', 'Debug', '--uid', '1020', 'debug'])
            # run_command(['/usr/sbin/chroot', '/target', 'chpasswd'], stdin='debug:debug\n')

            self.install_stage_set('Finishing installation')

            if not os.path.exists(constants.LOWMEM_MARKER_FILE):
                # XXX: database stuff: (when testusage is implemented)
                # - stop database
                # - stop cron scripts from accessing database
                # - copy database to installed system
                # - copy marker files to installed system?
                #   - configured marker, other marker files
                #   - whole /var/lib/l2tpgw/ ?
                # - copy uuid file to installed system?
                # - copy logfiles to installed system
                # - remove/nocopy: fastboot marker
                pass

            self.debconf_progress_region(97, 99)

            # Recreate ssh keys
            for f, t in [['/etc/ssh/ssh_host_rsa_key', 'rsa'], ['/etc/ssh/ssh_host_dsa_key', 'dsa']]:
                run_command(['/usr/sbin/chroot', '/target', '/bin/rm', '-f', f], retval=runcommand.FAIL)
                run_command(['/usr/sbin/chroot', '/target', '/usr/bin/ssh-keygen', '-q', '-N', '', '-f',f, '-t', t, '-C', 'root@%s' % self.hostname], retval=runcommand.FAIL)

            # Copy recovery data (again)
            self.copy_recovery_data(recovery_data)

            self.copy_debconf()
            self.cleanup()
            self.debconf_progress_set(100)

            self.write_status('success\nInstall completed')
            self.info('installation success')
        except:
            self.cleanup()
            self.write_status('failure\nInstall failed')
            self.error('installation failed')
            raise