Exemple #1
0
    def update_menu(self, action_result):
        if (action_result.result and 'goNext' in action_result.result
                and action_result.result['goNext']):
            return ActionResult(True, None)
        if self.position == 0:
            self.contentwin.addstr(self.height - 3, 5, '<Go Back>')
            self.contentwin.refresh()
            self.hide_window()
            self.action_panel.hide()
            return ActionResult(False, None)
        else:
            if (action_result.result != None
                    and 'diskIndex' in action_result.result):
                params = action_result.result['diskIndex']
                if self.menu_helper:
                    self.menu_helper(params)

            result = self.items[self.position - 1][1]()
            if result.success:
                self.hide_window()
                self.action_panel.hide()
                return result
            else:
                if 'goBack' in result.result and result.result['goBack']:
                    self.contentwin.refresh()
                    self.hide_window()
                    self.action_panel.hide()
                    return ActionResult(False, None)
Exemple #2
0
    def exit_function(self, selected_item_params):
        selection = self.NET_CONFIG_OPTION_STRINGS.index(
            selected_item_params[0])

        if selection == self.NET_CONFIG_OPTION_DHCP:
            self.install_config['network']['type'] = 'dhcp'

        elif selection == self.NET_CONFIG_OPTION_DHCP_HOSTNAME:
            network_config = {}
            random_id = '%12x' % random.randrange(16**12)
            random_hostname = 'photon-' + random_id.strip()
            accepted_chars = list(range(ord('A'), ord('Z') + 1))
            accepted_chars = list(range(ord('a'), ord('z') + 1))
            accepted_chars.extend(range(ord('0'), ord('9') + 1))
            accepted_chars.extend([ord('.'), ord('-')])
            result = WindowStringReader(
                self.maxy, self.maxx, 13, 80, 'hostname', None, None,
                accepted_chars, NetworkConfigure.validate_hostname, None,
                'Choose the DHCP hostname for your system', 'DHCP Hostname:',
                2, network_config, random_hostname, True).get_user_string(None)
            if not result.success:
                return ActionResult(False, {'custom': False})

            self.install_config['network'] = network_config
            self.install_config['network']['type'] = 'dhcp'

        elif selection == self.NET_CONFIG_OPTION_MANUAL:
            network_config = {}
            items = ['IP Address', 'Netmask', 'Gateway', 'Nameserver']
            keys = ['ip_addr', 'netmask', 'gateway', 'nameserver']
            self.create_window = ReadMulText(self.maxy, self.maxx, 0,
                                             network_config, '_conf_', items,
                                             None, None, None,
                                             self.validate_static_conf, None,
                                             True)
            result = self.create_window.do_action()
            if not result.success:
                return ActionResult(False, {'goBack': True})

            for i in range(len(items)):
                network_config[keys[i]] = network_config.pop(
                    '_conf_' + str(i), None)
            self.install_config['network'] = network_config
            self.install_config['network']['type'] = 'static'

        elif selection == self.NET_CONFIG_OPTION_VLAN:
            network_config = {}
            result = WindowStringReader(
                self.maxy, self.maxx, 18, 75, 'vlan_id', None, None,
                list(range(48, 58)), NetworkConfigure.validate_vlan_id, None,
                '[!] Configure the network', self.VLAN_READ_STRING, 6,
                network_config, '', True).get_user_string(True)

            if not result.success:
                return ActionResult(False, {'goBack': True})

            self.install_config['network'] = network_config
            self.install_config['network']['type'] = 'vlan'

        return ActionResult(True, {'custom': False})
Exemple #3
0
    def guided_partitions(self, device_index):
        menu_height = 9
        menu_width = 40
        menu_starty = (self.maxy - menu_height) / 2 + 5
        confrim_window = ConfirmWindow(
            menu_height, menu_width, self.maxy, self.maxx, menu_starty,
            'This will erase the disk.\nAre you sure?')
        confirmed = confrim_window.do_action().result['yes']

        if not confirmed:
            return ActionResult(confirmed, None)

        self.progress_bar.initialize('Partitioning...')
        self.progress_bar.show()
        self.progress_bar.show_loading('Partitioning')

        # Do the partitioning
        self.window.clearerror()
        partitions_data = modules.commons.partition_disk(
            self.devices[device_index].path)
        if partitions_data == None:
            self.window.adderror('Partitioning failed, you may try again')
        else:
            self.install_config['disk'] = partitions_data

        self.progress_bar.hide()
        return ActionResult(partitions_data != None, None)
Exemple #4
0
    def guided_partitions(self, params):
        if not 'diskindex' in self.install_config:
            return ActionResult(False, None)

        device_index = self.install_config['diskindex']

        menu_height = 9
        menu_width = 40
        menu_starty = (self.maxy - menu_height) // 2 + 5
        self.install_config['delete_partition'] = True
        confrim_window = ConfirmWindow(menu_height, menu_width, self.maxy,
                                       self.maxx, menu_starty,
                                       'This will erase the disk.\nAre you sure?')
        confirmed = confrim_window.do_action().result['yes']

        if confirmed == False:
            self.install_config['skipPrevs'] = True
            return ActionResult(False, {'goBack':True})

        self.install_config['skipPrevs'] = False
        self.progress_bar.initialize('Partitioning...')
        self.progress_bar.show()
        self.progress_bar.show_loading('Partitioning')

        # Do the partitioning
        if 'partitionsnumber' in self.install_config:
            if int(self.install_config['partitionsnumber']) == 0:
                partitions_data = modules.commons.partition_disk(
                    self.devices[device_index].path, modules.commons.default_partitions)
            else:
                partitions = []
                for i in range(int(self.install_config['partitionsnumber'])):
                    if len(self.install_config[str(i)+'partition_info'+str(0)]) == 0:
                        sizedata = 0
                    else:
                        sizedata = int(self.install_config[str(i) + 'partition_info' + str(0)])
                    mtdata = self.install_config[str(i) + 'partition_info' + str(2)]
                    typedata = self.install_config[str(i) + 'partition_info'+str(1)]

                    partitions = partitions + [{"mountpoint": mtdata,
                                                "size": sizedata,
                                                "filesystem": typedata},]
                partitions_data = modules.commons.partition_disk(
                    self.devices[device_index].path, partitions)
        else:
            partitions_data = modules.commons.partition_disk(
                self.devices[device_index].path, modules.commons.default_partitions)

        if partitions_data == None:
            self.partition_window.adderror('Partitioning failed, you may try again')
        else:
            self.install_config['disk'] = partitions_data
            arch = subprocess.check_output(['uname', '-m'], universal_newlines=True)
            if "x86" in arch:
                self.install_config['boot'] = 'dualboot'
            else:
                self.install_config['boot'] = 'efi'

        self.progress_bar.hide()
        return ActionResult(partitions_data != None, None)
Exemple #5
0
    def do_action(self):
        self.init_text()
        curses.curs_set(1)

        if self.default_string != None:
            self.textwin.addstr(self.y, 0, self.default_string)
            self.str = self.default_string

        while True:
            if len(self.str) > self.visible_text_width:
                curs_loc = self.visible_text_width
            else:
                curs_loc = len(self.str)
            ch = self.textwin.getch(self.y, curs_loc)

            update_text = False
            if ch in [curses.KEY_ENTER, ord('\n')]:
                if self.confirmation_error_msg:
                    if self.str != self.install_config[self.field]:
                        curses.curs_set(0)
                        conf_message_height = 8
                        conf_message_width = 48
                        conf_message_button_y = (self.maxy -
                                                 conf_message_height) / 2 + 5
                        confrim_window = ConfirmWindow(
                            conf_message_height, conf_message_width, self.maxy,
                            self.maxx, conf_message_button_y,
                            self.confirmation_error_msg, True)
                        confrim_window.do_action()
                        return ActionResult(False, {'goBack': True})
                    self.set_field()
                else:
                    if not self.validate_input():
                        continue
                    self.set_field()
                curses.curs_set(0)
                return ActionResult(True, None)
            elif ch in [ord('\t')]:
                curses.curs_set(0)
                return ActionResult(False, None)
            elif ch == 127:
                # Handle the backspace case
                self.str = self.str[:len(self.str) - 1]

                update_text = True

            elif len(self.str) < self.maxlength and ch in self.accepted_chars:
                self.str += chr(ch)
                update_text = True

            if update_text:
                if len(self.str) > self.visible_text_width:
                    text = self.str[-self.visible_text_width:]
                else:
                    text = self.str
                if self.echo_char:
                    text = self.echo_char * len(text)
                # Add the dashes
                text = text + '_' * (self.visible_text_width - len(self.str))
                self.textwin.addstr(self.y, 0, text)
Exemple #6
0
    def guided_partitions(self, device_index):
        menu_height = 9
        menu_width = 40
        menu_starty = (self.maxy - menu_height) / 2 + 5
        confrim_window = ConfirmWindow(
            menu_height, menu_width, self.maxy, self.maxx, menu_starty,
            'This will erase the disk.\nAre you sure?')
        confirmed = confrim_window.do_action().result['yes']

        if not confirmed:
            return ActionResult(confirmed, None)

        #self.install_config['disk'] = self.devices[device_index].path
        #return ActionResult(True, None)

        # Do the partitioning
        self.window.clearerror()
        json_ret = subprocess.check_output([
            'gpartedbin', 'defaultpartitions', self.devices[device_index].path
        ],
                                           stderr=open(os.devnull, 'w'))
        json_dct = json.loads(json_ret)
        if json_dct['success']:
            self.install_config['disk'] = json_dct['data']
        else:
            self.window.adderror('Partitioning failed, you may try again')
        return ActionResult(json_dct['success'], None)
    def display(self):
        if 'ostree' in self.install_config:
            return ActionResult(None, {"inactive_screen": True})

        self.create_available_linux_menu()
        if len(self.menu_items) < 2:
            return ActionResult(None, {"inactive_screen": True})

        self.window.addstr(0, 0, 'Which type of Linux kernel would you like to install?')
        return self.window.do_action()
Exemple #8
0
    def display(self, params):
        if 'skipPrevs' in self.install_config and self.install_config[
                'skipPrevs'] == True:
            self.delete()
            return ActionResult(False, {'goBack': True})
        if 'autopartition' in self.install_config and self.install_config[
                'autopartition'] == True:
            return ActionResult(True, None)
        if 'delete_partition' in self.install_config and self.install_config[
                'delete_partition'] == True:
            self.delete()
            self.install_config['delete_partition'] = False

        self.device_index = self.install_config['diskindex']

        self.disk_buttom_items = []
        self.disk_buttom_items.append(('<Next>', self.next))
        self.disk_buttom_items.append(('<Create New>', self.create_function))
        self.disk_buttom_items.append(('<Delete All>', self.delete_function))
        self.disk_buttom_items.append(('<Go Back>', self.go_back))

        self.text_items = []
        self.text_items.append(('Disk', 20))
        self.text_items.append(('Size', 5))
        self.text_items.append(('Type', 5))
        self.text_items.append(('Mountpoint', 20))
        self.table_space = 5

        title = 'Current partitions:\n'
        self.window.addstr(0, (self.win_width - len(title)) / 2, title)

        info = "Unpartitioned space: " + str(
            self.disk_size[self.device_index][1]) + " MB, Total size: " + str(
                int(self.devices[self.device_index].size) / 1048576) + " MB"

        self.text_pane = TextPane(self.text_starty,
                                  self.maxx,
                                  self.text_width,
                                  "EULA.txt",
                                  self.text_height,
                                  self.disk_buttom_items,
                                  partition=True,
                                  popupWindow=True,
                                  install_config=self.install_config,
                                  text_items=self.text_items,
                                  table_space=self.table_space,
                                  default_start=1,
                                  info=info,
                                  size_left=str(
                                      self.disk_size[self.device_index][1]))

        self.window.set_action_panel(self.text_pane)

        return self.window.do_action()
Exemple #9
0
 def exit_function(self, selected_item_params):
     if selected_item_params[0] == 'ostree_host':
         self.install_config['ostree'] = {}
     else:
         self.install_config.pop('ostree', None)
     self.install_config['packages'] = selected_item_params[1]
     return ActionResult(True, {'custom': False})
Exemple #10
0
    def next(self):
        if self.install_config['partitionsnumber'] == 0:
            window_height = 9
            window_width = 40
            window_starty = (self.maxy - window_height) / 2 + 5
            confirm_window = ConfirmWindow(
                window_height,
                window_width,
                self.maxy,
                self.maxx,
                window_starty,
                'Partition information cannot be empty',
                info=True)
            confirm_window.do_action()
            return self.display(False)
        #must have /
        if not self.has_slash:
            window_height = 9
            window_width = 40
            window_starty = (self.maxy - window_height) / 2 + 5
            confirm_window = ConfirmWindow(window_height,
                                           window_width,
                                           self.maxy,
                                           self.maxx,
                                           window_starty,
                                           'Missing /',
                                           info=True)
            confirm_window.do_action()
            return self.display(False)

        self.window.hide_window()
        self.text_pane.hide()
        return ActionResult(True, {'goNext': True})
Exemple #11
0
    def display(self):
        if self.setup_network and not self.do_setup_network():
            return ActionResult(False, {'goBack': True})

        file_source = {}
        accepted_chars = list(range(ord('a'), ord('z') + 1))
        accepted_chars.extend(range(ord('A'), ord('Z') + 1))
        accepted_chars.extend(range(ord('0'), ord('9') + 1))
        accepted_chars.extend(
            [ord('-'),
             ord('_'),
             ord('.'),
             ord('~'),
             ord(':'),
             ord('/')])
        result = WindowStringReader(self.maxy, self.maxx, 18, 78, 'url', None,
                                    None, accepted_chars, None, None,
                                    self.title, self.intro, 10, file_source,
                                    'https://', True).get_user_string(None)
        if not result.success:
            return result

        status_window = Window(10, 70, self.maxy, self.maxx,
                               'Installing Photon', False)
        status_window.addstr(1, 0, 'Downloading file...')
        status_window.show_window()

        fd, temp_file = tempfile.mkstemp()
        result, msg = CommandUtils.wget(
            file_source['url'],
            temp_file,
            ask_fn=self.ask_proceed_unsafe_download)
        os.close(fd)
        if not result:
            status_window.adderror('Error: ' + msg +
                                   ' Press any key to go back...')
            status_window.content_window().getch()
            status_window.clearerror()
            status_window.hide_window()
            return ActionResult(False, {'goBack': True})

        if 'additional_files' not in self.install_config:
            self.install_config['additional_files'] = []
        copy = {temp_file: self.dest}
        self.install_config['additional_files'].append(copy)

        return ActionResult(True, None)
Exemple #12
0
    def exit_function(self, selected_indexes):
        selected_items = []
        for index in selected_indexes:
            selected_items.append(self.menu_items[index][0])

        self.install_config['packages'] = self.package_list_json[
            "minimal_packages"] + selected_items
        return ActionResult(True, None)
Exemple #13
0
    def unsafe_install(self, params):

        if self.iso_installer:
            self.window.show_window()
            self.progress_bar.initialize('Initializing installation...')
            self.progress_bar.show()

        self.execute_modules(modules.commons.PRE_INSTALL)

        self.initialize_system()

        #install packages
        for rpm in self.rpms_tobeinstalled:
            # We already installed the filesystem in the preparation
            if rpm['package'] == 'filesystem':
                continue
            if self.iso_installer:
                self.progress_bar.update_message('Installing {0}...'.format(
                    rpm['package']))
            return_value = self.install_package(rpm['package'])
            if return_value != 0:
                self.exit_gracefully(None, None)
            if self.iso_installer:
                self.progress_bar.increment(rpm['size'] * self.install_factor)

        if self.iso_installer:
            self.progress_bar.show_loading('Finalizing installation')

        self.finalize_system()

        if not self.install_config['iso_system']:
            # Execute post installation modules
            self.execute_modules(modules.commons.POST_INSTALL)

            # install grub
            process = subprocess.Popen([
                self.setup_grub_command, '-w', self.photon_root,
                self.install_config['disk']['disk'],
                self.install_config['disk']['root']
            ],
                                       stdout=self.output)
            retval = process.wait()

        process = subprocess.Popen(
            [self.unmount_disk_command, '-w', self.photon_root],
            stdout=self.output)
        retval = process.wait()

        if self.iso_installer:
            self.progress_bar.hide()
            self.window.addstr(
                0, 0,
                'Congratulations, Photon has been installed in {0} secs.\n\nPress any key to continue to boot...'
                .format(self.progress_bar.time_elapsed))
            if self.ks_config == None:
                self.window.content_window().getch()

        return ActionResult(True, None)
Exemple #14
0
 def get_user_string(self):
     result = ActionResult(True, None)
     if 'ostree' in self.install_config and not self.install_config[
             'ostree']['default_repo']:
         result = self.wsr.window.do_action()
         if result.success:
             self.install_config['ostree'][self.field] = self.config[
                 self.field]
     return result
Exemple #15
0
    def do_action(self):
        curses.curs_set(1)

        while True:
            ch = self.textwin.getch(self.y, self.x)

            if ch in [curses.KEY_ENTER, ord('\n')]:
                if self.ispassword:
                    err = self.validate_password(self.str)
                    if err != self.str:
                        spaces = ' ' * (self.textwin.getmaxyx()[1] - 1)
                        self.textwin.addstr(self.y + 2, 0, spaces)
                        self.textwin.addstr(self.y + 2, 0, "Error: " + err,
                                            curses.color_pair(4))
                        continue
                    self.install_config[
                        'password'] = self.generate_password_hash(self.str)
                else:
                    if not self.validate_hostname(self.str):
                        self.textwin.addstr(
                            self.y + 2, 0,
                            "It should start with alpha char and ends with alpha-numeric char",
                            curses.color_pair(4))
                        continue
                    self.install_config['hostname'] = self.str
                curses.curs_set(0)
                return ActionResult(True, None)
            elif ch in [ord('\t')]:
                curses.curs_set(0)
                return ActionResult(False, None)
            elif ch == 127:
                # Handle the backspace case
                self.x -= 1
                if self.x < 0:
                    self.x = 0
                self.textwin.addch(self.y, self.x, ord('_'))
                self.str = self.str[:len(self.str) - 1]
            elif self.x < self.maxlength and ch in self.accepted_chars:
                if (self.ispassword):
                    self.textwin.echochar(ord('*'))
                else:
                    self.textwin.echochar(ch)
                self.str += chr(ch)
                self.x += 1
Exemple #16
0
    def exit_function(self, selected_indexes):
        json_wrapper_package_list = JsonWrapper("packages_minimal.json")
        package_list_json = json_wrapper_package_list.read()
        selected_items = []
        for index in selected_indexes:
            selected_items.append(self.menu_items[index][0])

        self.install_config[
            'packages'] = package_list_json["packages"] + selected_items
        return ActionResult(True, None)
Exemple #17
0
    def display(self):
        if 'ostree' in self.install_config:
            return ActionResult(None, {"inactive_screen": True})

        self.window.addstr(
            0, 0, 'The installer has detected that you are installing')
        self.window.addstr(1, 0, 'Photon OS on a VMware hypervisor.')
        self.window.addstr(
            2, 0, 'Which type of Linux kernel would you like to install?')
        return self.window.do_action()
Exemple #18
0
    def next(self):
        if self.cp_config['partitionsnumber'] == 0:
            window_height = 9
            window_width = 40
            window_starty = (self.maxy - window_height) // 2 + 5
            confirm_window = ConfirmWindow(
                window_height,
                window_width,
                self.maxy,
                self.maxx,
                window_starty,
                'Partition information cannot be empty',
                info=True)
            confirm_window.do_action()
            return self.display()
        #must have /
        if not self.has_slash:
            window_height = 9
            window_width = 40
            window_starty = (self.maxy - window_height) // 2 + 5
            confirm_window = ConfirmWindow(window_height,
                                           window_width,
                                           self.maxy,
                                           self.maxx,
                                           window_starty,
                                           'Missing /',
                                           info=True)
            confirm_window.do_action()
            return self.display()

        self.window.hide_window()
        self.partition_pane.hide()

        partitions = []
        for i in range(int(self.cp_config['partitionsnumber'])):
            if len(self.cp_config[str(i) + 'partition_info' + str(0)]) == 0:
                sizedata = 0
            else:
                sizedata = int(self.cp_config[str(i) + 'partition_info' +
                                              str(0)])
            mtdata = self.cp_config[str(i) + 'partition_info' + str(2)]
            typedata = self.cp_config[str(i) + 'partition_info' + str(1)]

            partitions = partitions + [
                {
                    "mountpoint": mtdata,
                    "size": sizedata,
                    "filesystem": typedata
                },
            ]
        self.install_config['partitions'] = partitions

        return ActionResult(True, {'goNext': True})
Exemple #19
0
    def validate_partition(self, pstr):
        if not pstr:
            return ActionResult(False, None)
        sizedata = pstr[0]
        mtdata = pstr[2]
        typedata = pstr[1]
        devicedata = self.devices[self.device_index].path

        #no empty fields unless swap
        if (typedata == 'swap' and
                (len(mtdata) != 0 or len(typedata) == 0 or len(devicedata) == 0)):
            return False, "invalid swap data "

        if (typedata != 'swap' and
                (len(sizedata) == 0 or
                 len(mtdata) == 0 or
                 len(typedata) == 0 or
                 len(devicedata) == 0)):
            if not self.has_empty and mtdata and typedata and devicedata:
                self.has_empty = True
            else:
                return False, "Input cannot be empty"

        if typedata != 'swap' and typedata != 'ext3' and typedata != 'ext4':
            return False, "Invalid type"

        if len(mtdata) != 0 and mtdata[0] != '/':
            return False, "Invalid path"

        if mtdata in self.path_checker:
            return False, "Path already existed"
        #validate disk: must be one of the existing disks
        i = self.device_index

        #valid size: must not exceed memory limit
        curr_size = self.disk_size[i][1]
        if len(sizedata) != 0:
            try:
                int(sizedata)
            except ValueError:
                return False, "invalid device size"

            if int(curr_size) - int(sizedata) < 0:
                return False, "invalid device size"
            #if valid, update the size and return true
            new_size = (self.disk_size[i][0], int(curr_size)- int(sizedata))
            self.disk_size[i] = new_size

        if mtdata == "/":
            self.has_slash = True

        self.path_checker.append(mtdata)
        return True, None
Exemple #20
0
    def _unsafe_install(self):
        """
        Install photon system
        """
        self._setup_install_repo()
        self._initialize_system()
        self._install_packages()
        self._enable_network_in_chroot()
        self._finalize_system()

        self._disable_network_in_chroot()
        self._cleanup_and_exit()
        return ActionResult(True, None)
Exemple #21
0
    def do_action(self):
        while True:
            self.refresh()

            key = self.window.getch()

            if key in [curses.KEY_ENTER, ord('\n')]:
                if self.selector_menu:
                    # send the selected indexes
                    result = self.items[self.position][1](self.selected_items)
                else:
                    result = self.items[self.position][1](self.items[self.position][2])
                if result.success:
                    self.hide()
                    return result

            if key in [ord(' ')] and self.selector_menu:
                if self.position in self.selected_items:
                    self.selected_items.remove(self.position)
                else:
                    self.selected_items.add(self.position)
            elif key in [ord('\t')] and self.can_navigate_outside:
                if not self.tab_enable:
                    continue
                self.refresh(False)
                if self.save_sel:
                    return ActionResult(False, {'diskIndex': self.position})
                else:
                    return ActionResult(False, None)

            elif key == curses.KEY_UP or key == curses.KEY_LEFT:
                if not self.tab_enable and key == curses.KEY_LEFT:
                    if self.save_sel:
                        return ActionResult(False, {'diskIndex': self.position, 'direction':-1})
                    elif self.selector_menu:
                        result = self.items[self.position][1](self.selected_items)
                    else:
                        result = self.items[self.position][1](self.items[self.position][2])
                    return ActionResult(False, {'direction': -1})
                self.navigate(-1)

            elif key == curses.KEY_DOWN or key == curses.KEY_RIGHT:
                if not self.tab_enable and key == curses.KEY_RIGHT:
                    if self.save_sel:
                        return ActionResult(False, {'diskIndex': self.position, 'direction':1})
                    else:
                        return ActionResult(False, {'direction': 1})
                self.navigate(1)

            elif key == curses.KEY_NPAGE:
                self.navigate(self.height)

            elif key == curses.KEY_PPAGE:
                self.navigate(-self.height)

            elif key == curses.KEY_HOME:
                self.navigate(-self.position)
Exemple #22
0
 def _unsafe_install(self):
     """
     Install photon system
     """
     self._format_disk()
     self._setup_install_repo()
     self._initialize_system()
     self._install_packages()
     self._enable_network_in_chroot()
     self._finalize_system()
     self._cleanup_install_repo()
     self._execute_modules(modules.commons.POST_INSTALL)
     self._post_install()
     self._disable_network_in_chroot()
     self._cleanup_and_exit()
     return ActionResult(True, None)
Exemple #23
0
    def display(self):
        self.initialize_devices()

        if 'autopartition' in self.install_config and self.install_config[
                'autopartition'] == True:
            return ActionResult(True, None)

        self.device_index = self.disk_to_index[self.install_config['disk']]

        self.disk_buttom_items = []
        self.disk_buttom_items.append(('<Next>', self.next))
        self.disk_buttom_items.append(('<Create New>', self.create_function))
        self.disk_buttom_items.append(('<Delete All>', self.delete_function))
        self.disk_buttom_items.append(('<Go Back>', self.go_back))

        self.text_items = []
        self.text_items.append(('Disk', 20))
        self.text_items.append(('Size', 5))
        self.text_items.append(('Type', 5))
        self.text_items.append(('Mountpoint', 20))
        self.table_space = 5

        title = 'Current partitions:\n'
        self.window.addstr(0, (self.win_width - len(title)) // 2, title)

        info = ("Unpartitioned space: " +
                str(self.disk_size[self.device_index][1]) +
                " MB, Total size: " +
                str(int(self.devices[self.device_index].size) / 1048576) +
                " MB")

        self.partition_pane = PartitionPane(
            self.text_starty,
            self.maxx,
            self.text_width,
            self.text_height,
            self.disk_buttom_items,
            config=self.cp_config,
            text_items=self.text_items,
            table_space=self.table_space,
            info=info,
            size_left=str(self.disk_size[self.device_index][1]))

        self.window.set_action_panel(self.partition_pane)

        return self.window.do_action()
Exemple #24
0
    def do_action(self):
        self.show_window()
        action_result = self.action_panel.do_action()

        if action_result.success:
            self.hide_window()
            return action_result
        else:
            if (action_result.result != None
                    and 'goBack' in action_result.result
                    and action_result.result['goBack']):
                self.hide_window()
                self.action_panel.hide()
                return action_result
            else:
                #highlight the GoBack and keep going
                self.contentwin.addstr(self.height - 3, 5, '<Go Back>',
                                       curses.color_pair(3))
                self.contentwin.refresh()

        while action_result.success == False:
            key = self.contentwin.getch()
            if key in [curses.KEY_ENTER, ord('\n')]:
                #remove highlight from Go Back
                self.contentwin.addstr(self.height - 3, 5, '<Go Back>')
                self.contentwin.refresh()
                self.hide_window()
                self.action_panel.hide()
                return ActionResult(False, None)
            elif key in [ord('\t')]:
                #remove highlight from Go Back
                self.contentwin.addstr(self.height - 3, 5, '<Go Back>')
                self.contentwin.refresh()
                # go do the action inside the panel
                action_result = self.action_panel.do_action()
                if action_result.success:
                    self.hide_window()
                    return action_result
                else:
                    #highlight the GoBack and keep going
                    self.contentwin.addstr(self.height - 3, 5, '<Go Back>',
                                           curses.color_pair(3))
                    self.contentwin.refresh()
Exemple #25
0
    def unsafe_install(self, params):

        self.prepare_files_rpms_list()

        if self.iso_installer:
            self.window.show_window()

            self.progress_bar.initialize(self.total_size,
                                         'Initializing installation...')
            self.progress_bar.show()

        self.pre_initialize_filesystem()

        #install packages
        for rpm in self.rpms_tobeinstalled:
            # We already installed the filesystem in the preparation
            if rpm['package'] == 'filesystem':
                continue
            if self.iso_installer:
                self.progress_bar.update_message('Installing {0}...'.format(
                    rpm['package']))
            return_value = self.install_package(rpm['package'])
            if return_value != 0:
                self.exit_gracefully(None, None)
            #time.sleep(0.05)
            if self.iso_installer:
                self.progress_bar.increment(rpm['size'] * self.install_factor)

        if self.iso_installer:
            self.progress_bar.show_loading('Finalizing installation')
        #finalize system
        self.finalize_system()
        #time.sleep(5)

        if not self.install_config['iso_system'] and not self.local_install:
            # install grub
            process = subprocess.Popen([
                self.setup_grub_command, '-w', self.photon_root,
                self.install_config['disk']['disk'],
                self.install_config['disk']['root']
            ],
                                       stdout=self.output,
                                       stderr=self.output)
            retval = process.wait()

            #update root password
            self.update_root_password()

            #update hostname
            self.update_hostname()

            #update openssh config
            self.update_openssh_config()

        process = subprocess.Popen(
            [self.unmount_disk_command, '-w', self.photon_root],
            stdout=self.output,
            stderr=self.output)
        retval = process.wait()

        if self.iso_installer:
            self.progress_bar.hide()
            self.window.addstr(
                0, 0,
                'Congratulations, Photon has been installed in {0} secs.\n\nPress any key to continue to boot...'
                .format(self.progress_bar.time_elapsed))
            self.window.content_window().getch()

        return ActionResult(True, None)
Exemple #26
0
    def unsafe_install(self, params):
        self.org_photon_root = self.photon_root
        sysroot_ostree = os.path.join(self.photon_root, "ostree")
        sysroot_boot = os.path.join(self.photon_root, "boot")
        loader0 = os.path.join(sysroot_boot, "loader.0")
        loader1 = os.path.join(sysroot_boot, "loader.1")

        boot0 = os.path.join(sysroot_ostree, "boot.0")
        boot1 = os.path.join(sysroot_ostree, "boot.1")

        boot01 = os.path.join(sysroot_ostree, "boot.0.1")
        boot11 = os.path.join(sysroot_ostree, "boot.1.1")

        self.get_ostree_repo_url()

        self.window.show_window()
        self.progress_bar.initialize("Initializing installation...")
        self.progress_bar.show()

        self.progress_bar.show_loading("Unpacking local OSTree repo")

        if self.default_repo:
            self.run("mkdir repo")
            self.run(
                "tar --warning=none -xf /mnt/cdrom/ostree-repo.tar.gz -C repo")
            self.local_repo_path = "/installer/repo/"
            self.ostree_repo_url = self.repo_config['OSTREEREPOURL']
            self.ostree_ref = self.repo_config['OSTREEREFS']

        self.execute_modules(modules.commons.PRE_INSTALL)

        disk = self.install_config['disk']['disk']
        self.run("sgdisk -d 2 -n 2::+300M -n 3: -p {}".format(disk),
                 "Updating partition table for OSTree")
        self.run("mkfs -t ext4 {}2".format(disk))
        self.run("mkfs -t ext4 {}3".format(disk))
        self.run("mount {}3 {}".format(disk, self.photon_root))
        self.run("mkdir -p {} ".format(sysroot_boot))
        self.run("mount {}2 {}".format(disk, sysroot_boot))

        self.deploy_ostree(self.ostree_repo_url, self.ostree_ref)

        commit_number = self.get_commit_number(self.ostree_ref)
        self.do_systemd_tmpfiles_commands(commit_number)

        self.mount_devices_in_deployment(commit_number)
        deployment = os.path.join(
            self.photon_root,
            "ostree/deploy/photon/deploy/" + commit_number + ".0/")

        deployment_boot = os.path.join(deployment, "boot")
        deployment_sysroot = os.path.join(deployment, "sysroot")

        self.run("mv {} {}".format(loader1, loader0))
        self.run("mv {} {}".format(boot1, boot0))
        self.run("mv {} {}".format(boot11, boot01))
        self.run("mount --bind {} {}".format(sysroot_boot, deployment_boot))
        self.run("mount --bind {} {}".format(self.photon_root,
                                             deployment_sysroot))
        self.run(
            "chroot {} bash -c \"grub2-install /dev/sda\"".format(deployment))
        self.run(
            "chroot {} bash -c \"grub2-mkconfig -o /boot/grub2/grub.cfg\"".
            format(deployment))
        self.run("mv {} {}".format(loader0, loader1))
        self.run("mv {} {}".format(boot0, boot1))
        self.run("mv {} {}".format(boot01, boot11))
        self.run(
            "chroot {} bash -c \"ostree admin instutil set-kargs root=/dev/sda3 \""
            .format(deployment))
        sysroot_grub2_grub_cfg = os.path.join(self.photon_root,
                                              "boot/grub2/grub.cfg")
        self.run("ln -sf ../loader/grub.cfg {}".format(sysroot_grub2_grub_cfg))
        self.run("mv {} {}".format(loader1, loader0))
        self.run("mv {} {}".format(boot1, boot0))
        self.run("mv {} {}".format(boot11, boot01))

        deployment_fstab = os.path.join(deployment, "etc/fstab")
        self.run(
            "echo \"/dev/sda2    /boot    ext4   defaults   1 2  \" >> {} ".
            format(deployment_fstab), "Adding /boot mount point in fstab")
        self.run("mount --bind {} {}".format(deployment, self.photon_root))
        self.progress_bar.update_loading_message(
            "Starting post install modules")
        self.execute_modules(modules.commons.POST_INSTALL)
        self.progress_bar.update_loading_message("Unmounting disks")
        self.run("{} {} {}".format(self.unmount_disk_command, '-w',
                                   self.photon_root))
        self.progress_bar.update_loading_message("Ready to restart")
        self.progress_bar.hide()
        self.window.addstr(
            0, 0,
            'Congratulations, Photon has been installed in {0} secs.\n\nPress any key to continue to boot...'
            .format(self.progress_bar.time_elapsed))
        if self.ks_config == None:
            self.window.content_window().getch()
        return ActionResult(True, None)
Exemple #27
0
 def go_back(self):
     self.delete()
     self.window.hide_window()
     self.partition_pane.hide()
     return ActionResult(False, {'goBack': True})
Exemple #28
0
 def custom_packages(self):
     return ActionResult(True, {'custom': True})
Exemple #29
0
 def exit_function(self, selected_item_params):
     self.install_config['type'] = selected_item_params[0]
     self.install_config['packages'] = selected_item_params[1]
     self.install_config['additional-files'] = selected_item_params[2]
     return ActionResult(True, {'custom': False})
Exemple #30
0
 def next_function(self):
     return ActionResult(True, None)