Example #1
0
def runInstaller(options, config):
    try:
        sys.path.insert(0, options.installer_path)
        from installer import Installer
        from packageselector import PackageSelector
    except:
        raise ImportError('Installer path incorrect!')
    config["pkg_to_rpm_map_file"] = options.pkg_to_rpm_map_file
    
    # Check the installation type
    option_list_json = Utils.jsonread(options.package_list_file)
    options_sorted = option_list_json.items()

    packages = []
    if 'type' in config:
        for install_option in options_sorted:
            if install_option[0] == config['type']:
                packages = PackageSelector.get_packages_to_install(install_option[1]['packagelist_file'],
                                                               options.generated_data_path)
                break
    else:
        if 'packagelist_file' in config:
            packages = PackageSelector.get_packages_to_install(config['packagelist_file'],
                                                               options.generated_data_path)
        if 'additional_packages' in config:
            packages = packages.extend(config['additional_packages'])

    config['packages'] = packages
    # Run the installer
    package_installer = Installer(config, rpm_path=options.rpm_path,
                                  log_path=options.log_path, log_level=options.log_level)
    return package_installer.install(None)
Example #2
0
    def ks_config(self, options_file, ks_config):
        """Load configuration from file"""
        del options_file
        install_config = ks_config
        install_config['iso_system'] = False
        if self.is_vmware_virtualization() and 'install_linux_esx' not in install_config:
            install_config['install_linux_esx'] = True

        json_wrapper_option_list = JsonWrapper("build_install_options_all.json")
        option_list_json = json_wrapper_option_list.read()
        options_sorted = option_list_json.items()

        base_path = os.path.dirname("build_install_options_all.json")
        package_list = []

        package_list = PackageSelector.get_packages_to_install(options_sorted,
                                                               install_config['type'],
                                                               base_path)
        if 'additional_packages' in install_config:
            package_list.extend(install_config['additional_packages'])
        install_config['packages'] = package_list

        if 'partitions' in install_config:
            partitions = install_config['partitions']
        else:
            partitions = modules.commons.default_partitions

        install_config['disk'] = modules.commons.partition_disk(install_config['disk'], partitions)

        if "hostname" in install_config:
            evalhostname = os.popen('printf ' + install_config["hostname"].strip(" ")).readlines()
            install_config['hostname'] = evalhostname[0]
        if "hostname" not in install_config or install_config['hostname'] == "":
            install_config['hostname'] = "photon-" + self.random_id.strip()

        # crypt the password if needed
        if install_config['password']['crypted']:
            install_config['password'] = install_config['password']['text']
        else:
            install_config['password'] = crypt.crypt(
                install_config['password']['text'],
                "$6$" + "".join([random.choice(
                    string.ascii_letters + string.digits) for _ in range(16)]))
        return install_config
Example #3
0
        config["pkg_to_rpm_map_file"] = options.pkg_to_rpm_map_file
        if 'password' in config:
            # crypt the password if needed
            if config['password']['crypted']:
                config['password'] = config['password']['text']
            else:
                config['password'] = crypt.crypt(config['password']['text'], "$6$" + "".join([random.choice(string.ascii_letters + string.digits) for _ in range(16)]))

        # Check the installation type
        json_wrapper_option_list = JsonWrapper(options.package_list_file)
        option_list_json = json_wrapper_option_list.read()
        options_sorted = option_list_json.items()

        packages = []
        packages = PackageSelector.get_packages_to_install(options_sorted, config['type'], options.output_data_path)

        config['packages'] = packages

        if (os.path.isdir(options.working_directory)):
            process = subprocess.Popen(['rm', '-rf', options.working_directory])
            retval = process.wait()

        process = subprocess.Popen(['mkdir', '-p', os.path.join(options.working_directory, "photon-chroot")])
        retval = process.wait()

        config['working_directory'] = options.working_directory

        # Run the installer
        package_installer = Installer(config, rpm_path = options.rpm_path, log_path = options.log_path)
        package_installer.install(None)
Example #4
0
    # Check the installation type
    json_wrapper_option_list = JsonWrapper(options.package_list_file)
    option_list_json = json_wrapper_option_list.read()
    options_sorted = option_list_json.items()
    base_path = os.path.dirname(options.package_list_file)

    packages = []
    if config['iso_system'] == True:
        for install_option in options_sorted:
            if install_option[0] == "iso":
                json_wrapper_package_list = JsonWrapper(os.path.join(base_path, install_option[1]["file"]))
                package_list_json = json_wrapper_package_list.read()
                packages = package_list_json["packages"]
    else:
        packages = PackageSelector.get_packages_to_install(options_sorted, base_path, config['type'])

    config['packages'] = packages

    # Cleanup the working directory
    if not options.force:
        proceed = query_yes_no("This will remove everything under {0}. Are you sure?".format(options.working_directory))
        if not proceed:
            sys.exit(0)

    if (os.path.isdir(options.working_directory)):
        process = subprocess.Popen(['rm', '-rf', options.working_directory])
        retval = process.wait()
    else:
        process = subprocess.Popen(['mkdir', '-p', options.working_directory])
        retval = process.wait()
Example #5
0
    def add_ui_pages(self, install_config, ui_config, maxy, maxx):
        items = []
        license_agreement = License(maxy, maxx)
        select_disk = SelectDisk(maxy, maxx, install_config)
        custom_partition = CustomPartition(maxy, maxx, install_config)
        package_selector = PackageSelector(maxy, maxx, install_config,
                                           ui_config['options_file'])
        hostname_reader = WindowStringReader(
            maxy,
            maxx,
            10,
            70,
            'hostname',
            None,  # confirmation error msg if it's a confirmation text
            None,  # echo char
            self.hostname_accepted_chars,  # set of accepted chars
            IsoConfig.validate_hostname,  # validation function of the input
            None,  # post processing of the input field
            'Choose the hostname for your system',
            'Hostname:',
            2,
            install_config,
            self.random_hostname,
            True)
        root_password_reader = WindowStringReader(
            maxy,
            maxx,
            10,
            70,
            'shadow_password',
            None,  # confirmation error msg if it's a confirmation text
            '*',  # echo char
            None,  # set of accepted chars
            IsoConfig.validate_password,  # validation function of the input
            None,  # post processing of the input field
            'Set up root password',
            'Root password:'******'shadow_password',
            # confirmation error msg if it's a confirmation text
            "Passwords don't match, please try again.",
            '*',  # echo char
            None,  # set of accepted chars
            None,  # validation function of the input
            CommandUtils.
            generate_password_hash,  # post processing of the input field
            'Confirm root password',
            'Confirm Root password:'******'repo_url',
            None,  # confirmation error msg if it's a confirmation text
            None,  # echo char
            None,  # set of accepted chars
            IsoConfig.
            validate_ostree_url_input,  # validation function of the input
            None,  # post processing of the input field
            'Please provide the URL of OSTree repo',
            'OSTree Repo URL:',
            2,
            install_config,
            "http://")
        ostree_ref_reader = OSTreeWindowStringReader(
            maxy,
            maxx,
            10,
            70,
            'repo_ref',
            None,  # confirmation error msg if it's a confirmation text
            None,  # echo char
            None,  # set of accepted chars
            IsoConfig.
            validate_ostree_refs_input,  # validation function of the input
            None,  # post processing of the input field
            'Please provide the Refspec in OSTree repo',
            'OSTree Repo Refspec:',
            2,
            install_config,
            "photon/3.0/x86_64/minimal")
        confirm_window = ConfirmWindow(
            11, 60, maxy, maxx, (maxy - 11) // 2 + 7,
            'Start installation? All data on the selected disk will be lost.\n\n'
            'Press <Yes> to confirm, or <No> to quit')

        # This represents the installer screens, the bool indicated if
        # I can go back to this window or not
        items.append((license_agreement.display, False))
        items.append((select_disk.display, True))
        items.append((custom_partition.display, False))
        items.append((package_selector.display, True))
        net_cfg = NetworkConfigure(maxy, maxx, install_config)
        items.append((net_cfg.display, True))

        if 'download_screen' in ui_config:
            title = ui_config['download_screen'].get('title', None)
            intro = ui_config['download_screen'].get('intro', None)
            dest = ui_config['download_screen'].get('destination', None)
            fd = FileDownloader(maxy, maxx, install_config, title, intro, dest,
                                True)
            items.append((fd.display, True))

        if CommandUtils.is_vmware_virtualization():
            linux_selector = LinuxSelector(maxy, maxx, install_config)
            items.append((linux_selector.display, True))
        items.append((hostname_reader.get_user_string, True))
        items.append((root_password_reader.get_user_string, True))
        items.append((confirm_password_reader.get_user_string, False))
        items.append((ostree_server_selector.display, True))
        items.append((ostree_url_reader.get_user_string, True))
        items.append((ostree_ref_reader.get_user_string, True))
        items.append((confirm_window.do_action, True))

        return items
Example #6
0
    def add_ui_pages(self, options_file, maxy, maxx, install_config):
        items = []
        license_agreement = License(maxy, maxx)
        select_disk = SelectDisk(maxy, maxx, install_config)
        select_partition = PartitionISO(maxy, maxx, install_config)
        package_selector = PackageSelector(maxy, maxx, install_config,
                                           options_file)
        hostname_reader = WindowStringReader(
            maxy,
            maxx,
            10,
            70,
            'hostname',
            None,  # confirmation error msg if it's a confirmation text
            None,  # echo char
            self.hostname_accepted_chars,  # set of accepted chars
            IsoConfig.validate_hostname,  # validation function of the input
            None,  # post processing of the input field
            'Choose the hostname for your system',
            'Hostname:',
            2,
            install_config,
            self.random_hostname,
            True)
        root_password_reader = WindowStringReader(
            maxy,
            maxx,
            10,
            70,
            'password',
            None,  # confirmation error msg if it's a confirmation text
            '*',  # echo char
            None,  # set of accepted chars
            IsoConfig.validate_password,  # validation function of the input
            None,  # post processing of the input field
            'Set up root password',
            'Root password:'******'password',
            # confirmation error msg if it's a confirmation text
            "Passwords don't match, please try again.",
            '*',  # echo char
            None,  # set of accepted chars
            None,  # validation function of the input
            IsoConfig.
            generate_password_hash,  # post processing of the input field
            'Confirm root password',
            'Confirm Root password:',
            2,
            install_config)

        items.append((license_agreement.display, False))
        items.append((select_disk.display, True))
        items.append((select_partition.display, False))
        items.append((select_disk.guided_partitions, False))
        items.append((package_selector.display, True))
        select_linux_index = -1
        if self.is_vmware_virtualization():
            linux_selector = LinuxSelector(maxy, maxx, install_config)
            items.append((linux_selector.display, True))
            select_linux_index = items.index((linux_selector.display, True))
        items.append((hostname_reader.get_user_string, True))
        items.append((root_password_reader.get_user_string, True))
        items.append((confirm_password_reader.get_user_string, False))
        return items, select_linux_index
Example #7
0
    def ui_install(self, options_file, rpm_path):
        # This represents the installer screen, the bool indicated if I can go back to this window or not
        items = []
        random_id = '%12x' % random.randrange(16**12)
        random_hostname = "photon-" + random_id.strip()
        install_config = {'iso_system': False}
        install_config['ui_install'] = True
        license_agreement = License(self.maxy, self.maxx)
        select_disk = SelectDisk(self.maxy, self.maxx, install_config)
        select_partition = PartitionISO(self.maxy, self.maxx, install_config)
        package_selector = PackageSelector(self.maxy, self.maxx,
                                           install_config, options_file)
        self.alpha_chars = range(65, 91)
        self.alpha_chars.extend(range(97, 123))
        hostname_accepted_chars = list(self.alpha_chars)
        # Adding the numeric chars
        hostname_accepted_chars.extend(range(48, 58))
        # Adding the . and -
        hostname_accepted_chars.extend([ord('.'), ord('-')])

        hostname_reader = WindowStringReader(
            self.maxy,
            self.maxx,
            10,
            70,
            'hostname',
            None,  # confirmation error msg if it's a confirmation text
            None,  # echo char
            hostname_accepted_chars,  # set of accepted chars
            self.validate_hostname,  # validation function of the input
            None,  # post processing of the input field
            'Choose the hostname for your system',
            'Hostname:',
            2,
            install_config,
            random_hostname,
            True)
        root_password_reader = WindowStringReader(
            self.maxy,
            self.maxx,
            10,
            70,
            'password',
            None,  # confirmation error msg if it's a confirmation text
            '*',  # echo char
            None,  # set of accepted chars
            IsoInstaller.validate_password,  # validation function of the input
            None,  # post processing of the input field
            'Set up root password',
            'Root password:'******'password',
            "Passwords don't match, please try again.",  # confirmation error msg if it's a confirmation text
            '*',  # echo char
            None,  # set of accepted chars
            None,  # validation function of the input
            IsoInstaller.
            generate_password_hash,  # post processing of the input field
            'Confirm root password',
            'Confirm Root password:'******'type'] == 'ostree_server':
                        index += 1
            else:
                index -= 1
                while index >= 0 and items[index][1] is False:
                    index -= 1
                if index < 0:
                    index = 0
                #Skip linux select screen for ostree installation.
                if index == select_linux_index:
                    if install_config['type'] == 'ostree_server':
                        index -= 1
Example #8
0
            if config['password']['crypted']:
                config['password'] = config['password']['text']
            else:
                config['password'] = crypt.crypt(
                    config['password']['text'], "$6$" + "".join([
                        random.choice(string.ascii_letters + string.digits)
                        for _ in range(16)
                    ]))

        # Check the installation type
        json_wrapper_option_list = JsonWrapper(options.package_list_file)
        option_list_json = json_wrapper_option_list.read()
        options_sorted = option_list_json.items()

        packages = []
        packages = PackageSelector.get_packages_to_install(
            options_sorted, config['type'], options.output_data_path)

        config['packages'] = packages

        if (os.path.isdir(options.working_directory)):
            process = subprocess.Popen(
                ['rm', '-rf', options.working_directory])
            retval = process.wait()

        process = subprocess.Popen([
            'mkdir', '-p',
            os.path.join(options.working_directory, "photon-chroot")
        ])
        retval = process.wait()

        config['working_directory'] = options.working_directory
Example #9
0
    def __init__(self, stdscreen, options_file):
        self.screen = stdscreen

        # Init the colors
        curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLUE)
        curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_WHITE)
        curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_GREEN)
        curses.init_pair(4, curses.COLOR_RED, curses.COLOR_WHITE)

        self.screen.bkgd(' ', curses.color_pair(1))

        self.maxy, self.maxx = self.screen.getmaxyx()
        self.screen.addstr(self.maxy - 1, 0,
                           '  Arrow keys make selections; <Enter> activates.')
        curses.curs_set(0)

        self.cd_path = None

        kernel_params = subprocess.check_output(['cat', '/proc/cmdline'])

        # check the kickstart param
        ks_config = None
        m = re.match(r".*ks=(\S+)\s*.*\s*", kernel_params)
        if m != None:
            ks_config = self.get_config(m.group(1))

        # check for the repo param
        m = re.match(r".*repo=(\S+)\s*.*\s*", kernel_params)
        if m != None:
            rpm_path = m.group(1)
        else:
            # the rpms should be in the cd
            self.mount_RPMS_cd()
            rpm_path = os.path.join(self.cd_path, "RPMS")

        # This represents the installer screen, the bool indicated if I can go back to this window or not
        items = []
        if not ks_config:
            random_id = '%12x' % random.randrange(16**12)
            random_hostname = "photon-" + random_id.strip()
            install_config = {'iso_system': False}
            install_config['vmware_virt'] = False
            if self.is_vmware_virtualization():
                install_config['vmware_virt'] = True
            license_agreement = License(self.maxy, self.maxx)
            select_disk = SelectDisk(self.maxy, self.maxx, install_config)
            select_partition = PartitionISO(self.maxy, self.maxx,
                                            install_config)
            package_selector = PackageSelector(self.maxy, self.maxx,
                                               install_config, options_file)
            self.alpha_chars = range(65, 91)
            self.alpha_chars.extend(range(97, 123))
            partition_accepted_chars = list(range(48, 58))
            hostname_accepted_chars = list(self.alpha_chars)
            # Adding the numeric chars
            hostname_accepted_chars.extend(range(48, 58))
            # Adding the . and -
            hostname_accepted_chars.extend([ord('.'), ord('-')])

            hostname_reader = WindowStringReader(
                self.maxy,
                self.maxx,
                10,
                70,
                'hostname',
                None,  # confirmation error msg if it's a confirmation text
                None,  # echo char
                hostname_accepted_chars,  # set of accepted chars
                self.validate_hostname,  # validation function of the input
                None,  # post processing of the input field
                'Choose the hostname for your system',
                'Hostname:',
                2,
                install_config,
                random_hostname,
                True)
            root_password_reader = WindowStringReader(
                self.maxy,
                self.maxx,
                10,
                70,
                'password',
                None,  # confirmation error msg if it's a confirmation text
                '*',  # echo char
                None,  # set of accepted chars
                self.validate_password,  # validation function of the input
                None,  # post processing of the input field
                'Set up root password',
                'Root password:'******'password',
                "Passwords don't match, please try again.",  # confirmation error msg if it's a confirmation text
                '*',  # echo char
                None,  # set of accepted chars
                None,  # validation function of the input
                self.
                generate_password_hash,  # post processing of the input field
                'Confirm root password',
                'Confirm Root password:'******'ostree_repo_url',
                None,  # confirmation error msg if it's a confirmation text
                None,  # echo char
                None,  # set of accepted chars
                self.
                validate_ostree_url_input,  # validation function of the input
                None,  # post processing of the input field
                'Please provide the URL of OSTree repo',
                'OSTree Repo URL:',
                2,
                install_config,
                "http://")
            ostree_ref_reader = OSTreeWindowStringReader(
                self.maxy,
                self.maxx,
                10,
                70,
                'ostree_repo_ref',
                None,  # confirmation error msg if it's a confirmation text
                None,  # echo char
                None,  # set of accepted chars
                self.
                validate_ostree_refs_input,  # validation function of the input
                None,  # post processing of the input field
                'Please provide the Refspec in OSTree repo',
                'OSTree Repo Refspec:',
                2,
                install_config,
                "photon/1.0/x86_64/minimal")

            items.append((license_agreement.display, False)),
            items.append((select_disk.display, True))
            items.append((select_partition.display, False))
            items.append((select_disk.guided_partitions, False))
            items.append((package_selector.display, True))
            select_linux_index = -1
            if install_config['vmware_virt'] == True:
                linux_selector = LinuxSelector(self.maxy, self.maxx,
                                               install_config)
                items.append((linux_selector.display, True))
                select_linux_index = items.index(
                    (linux_selector.display, True))
            items.append((hostname_reader.get_user_string, True))
            items.append((root_password_reader.get_user_string, True))
            items.append((confirm_password_reader.get_user_string, False))
            items.append((ostree_server_selector.display, True))
            items.append((ostree_url_reader.get_user_string, True))
            items.append((ostree_ref_reader.get_user_string, True))

        else:
            install_config = ks_config
            install_config['iso_system'] = False

        installer = InstallerContainer(install_config,
                                       self.maxy,
                                       self.maxx,
                                       True,
                                       rpm_path=rpm_path,
                                       log_path="/var/log",
                                       ks_config=ks_config)

        items = items + [(installer.install, False)]

        index = 0
        params = None
        while True:
            result = items[index][0](params)
            if result.success:
                index += 1
                params = result.result
                if index == len(items) - 1:
                    self.screen.clear()
                if index == len(items):
                    break
                #Skip linux select screen for ostree installation.
                if index == select_linux_index:
                    if (install_config['type'] == 'ostree_host'
                            or install_config['type'] == 'ostree_server'):
                        index += 1
            else:
                index -= 1
                while index >= 0 and items[index][1] == False:
                    index -= 1
                if index < 0:
                    index = 0
                #Skip linux select screen for ostree installation.
                if index == select_linux_index:
                    if (install_config['type'] == 'ostree_host'
                            or install_config['type'] == 'ostree_server'):
                        index -= 1