Esempio n. 1
0
def main(distribution):
    xenial = distribution == 'xenial'

    apt_install_packages('apt-transport-https')

    logging.info('Updating system')
    apt_update_sources()
    apt_upgrade_system()
    apt_autoremove_packages()
    apt_clean_system()

    # update submodules
    git_output, git_code = execute_shell_command_get_return_code('(cd ../../ && git submodule foreach "git pull")')
    if git_code != 0:
        raise InstallationError('Failed to update submodules\n{}'.format(git_output))

    # make bin dir
    with suppress(FileExistsError):
        os.mkdir('../bin')

    # install python3 and general build stuff
    apt_install_packages('python3', 'python3-dev', 'build-essential', 'automake', 'autoconf', 'libtool', 'git', 'unzip')
    if not xenial:
        pip3_install_packages('testresources')

    # get a bugfree recent pip version
    apt_remove_packages('python3-pip', 'python3-setuptools', 'python3-wheel')
    apt_autoremove_packages()
    install_pip('python3')

    # install python2
    apt_install_packages('python', 'python-dev')
    apt_remove_packages('python-pip')
    apt_autoremove_packages()
    install_pip('python2')

    # install general python dependencys
    apt_install_packages('libmagic-dev')
    apt_install_packages('libffi-dev', 'libfuzzy-dev')
    pip3_install_packages('psutil')
    pip3_install_packages('pytest==3.5.1', 'pytest-cov', 'pytest-pep8', 'pylint', 'python-magic', 'xmltodict', 'yara-python==3.7.0', 'appdirs')
    pip3_install_packages('ssdeep')
    pip3_install_packages('lief')
    pip3_install_packages('requests')

    # install python mongo bindings
    pip3_install_packages('pymongo', 'pyyaml')

    # VarietyJS (is executed by update_statistic.py)
    try:
        install_github_project('variety/variety', ['git checkout 2f4d815', 'mv -f variety.js ../../bin', 'mv -f spec ../../bin'])
    except InstallationError as installation_error:
        if 'Directory not empty' not in str(installation_error):
            raise installation_error
        logging.warning('variety spec not overwritten')

    #  installing common code modules
    pip3_install_packages('hurry.filesize')
    pip3_install_packages('git+https://github.com/fkie-cad/common_helper_files.git')
    pip3_install_packages('git+https://github.com/fkie-cad/common_helper_mongo.git')
    pip3_install_packages('git+https://github.com/mass-project/common_helper_encoder.git')
    pip3_install_packages('git+https://github.com/fkie-cad/common_helper_filter.git')

    with OperateInDirectory('../../'):
        with suppress(FileNotFoundError):
            Path('start_all_installed_fact_components').unlink()
        Path('start_all_installed_fact_components').symlink_to('src/start_fact.py')

    return 0
Esempio n. 2
0
def main(distribution):  # pylint: disable=too-many-statements
    apt_install_packages('apt-transport-https')

    logging.info('Updating system')
    apt_update_sources()
    apt_upgrade_system()
    apt_autoremove_packages()
    apt_clean_system()

    # execute_shell_command_get_return_code 返回的值为 output, return_code两个值
    # output 从 stdout 和 stderr 读取数据,直到文件结束符 返回一个 (stdout_data, stderr_data) 元组
    # return_code None —— 子进程尚未结束; ==0 子进程正常退出; > 0 子进程异常退出,returncode对应于出错码; <0 子进程被信号杀掉了
    _, is_repository = execute_shell_command_get_return_code('git status')
    if is_repository == 0:
        # update submodules
        git_output, git_code = execute_shell_command_get_return_code(
            '(cd ../../ && git submodule foreach "git pull")')
        if git_code != 0:
            raise InstallationError(
                'Failed to update submodules\n{}'.format(git_output))
    else:
        logging.warning(
            'FACT is not set up using git. Note that *adding submodules* won\'t work!!'
        )

    # make bin dir 在src目录下
    with suppress(FileExistsError):
        os.mkdir('../bin')

    # install python3 and general build stuff
    apt_install_packages('python3', 'python3-dev', 'build-essential',
                         'automake', 'autoconf', 'libtool', 'git', 'unzip')
    if not distribution == 'xenial':
        pip3_install_packages('testresources')

    # get a bugfree recent pip version
    apt_remove_packages('python3-pip', 'python3-setuptools', 'python3-wheel')
    apt_autoremove_packages()
    install_pip('python3')

    # install python2
    apt_install_packages('python', 'python-dev')
    apt_remove_packages('python-pip')
    apt_autoremove_packages()
    install_pip('python2')

    # install general python dependencys
    apt_install_packages('libmagic-dev')
    apt_install_packages('libfuzzy-dev')
    apt_install_packages('python3-tlsh')
    pip3_install_packages(
        'git+https://github.com/fkie-cad/fact_helper_file.git')
    pip3_install_packages('psutil')
    pip3_install_packages('pytest==3.5.1', 'pytest-cov', 'pytest-pep8',
                          'pylint', 'python-magic', 'xmltodict',
                          'yara-python==3.7.0', 'appdirs')
    pip3_install_packages('ssdeep')
    pip3_install_packages('lief')
    pip3_install_packages('requests')

    # install python mongo bindings
    pip3_install_packages('pymongo', 'pyyaml')

    # VarietyJS (is executed by update_statistic.py)
    try:
        install_github_project('variety/variety', [
            'git checkout 2f4d815', 'mv -f variety.js ../../bin',
            'mv -f spec ../../bin'
        ])
    except InstallationError as installation_error:
        if 'Directory not empty' not in str(installation_error):
            raise installation_error
        logging.warning('variety spec not overwritten')

    #  installing common code modules
    pip3_install_packages('hurry.filesize')
    pip3_install_packages(
        'git+https://github.com/fkie-cad/common_helper_files.git')
    pip3_install_packages(
        'git+https://github.com/fkie-cad/common_helper_mongo.git')
    pip3_install_packages(
        'git+https://github.com/mass-project/common_helper_encoder.git')
    pip3_install_packages(
        'git+https://github.com/fkie-cad/common_helper_filter.git')
    pip3_install_packages(
        'git+https://github.com/fkie-cad/common_helper_process.git')

    with OperateInDirectory('../../'):
        with suppress(FileNotFoundError):
            Path('start_all_installed_fact_components').unlink()
        Path('start_all_installed_fact_components').symlink_to(
            'src/start_fact.py')

    return 0