Exemple #1
0
def execute(args):
    bin_path = os.getenv('CLAI_PATH', None)

    if "-h" in args or "--help" in args:
        print("usage: uninstall.py [-h] [--help] [--user]\n \
            \nUninstall CLAI.\n \
            \noptional arguments: \
            \n-h, --help            show this help message and exit \
            \n--user                Uninstalls a local installation of clai for the current user"
              )
        sys.exit(0)

    path = clai_installed(get_setup_file())
    if not path or bin_path is None:
        print_error("CLAI is not installed.")
        sys.exit(1)

    stat_uninstall(path)
    users = unregister_the_user(path)

    if "--user" in args or is_user_install(bin_path):
        remove_system_folder(bin_path)
    elif not users:
        remove_system_folder()

    remove_setup_file(get_setup_file())
    remove_setup_register()

    print_complete(
        "CLAI has been uninstalled correctly, you will need to restart your shell."
    )

    return 0
Exemple #2
0
def main(args: list):
    action = args.action
    repo_path = args.path
    install_path = args.install_path

    if action == "install":
        install(repo_path, install_path)
    elif action == "uninstall":
        path = clai_installed(get_setup_file())
        if not path:
            print_error("CLAI is not installed.")
            sys.exit(1)

        # revert file permissions back to normal
        revert(install_path)
        uninstall(["--user"])

        # revert plugins config
        with open(f"{repo_path}/configPlugins.json", "w") as file:
            file.write(
                json.dumps({
                    "selected": {
                        "user": [""]
                    },
                    "default": [""],
                    "default_orchestrator": "max_orchestrator",
                    "installed": [],
                    "report_enable": False,
                }))

    return 0
Exemple #3
0
def execute():
    path = clai_installed(get_setup_file())
    if not path:
        print_error('CLAI is not installed.')
        sys.exit(1)

    stat_uninstall(path)
    users = unregister_the_user(path)
    if not users:
        remove_system_folder()

    remove_setup_file(get_setup_file())
    remove_setup_register()

    print_complete(
        "CLAI has been uninstalled correctly, you need restart your shell.")

    sys.exit(0)
Exemple #4
0
def install(repo_path: str, install_path: str):
    createInstallDir(install_path)

    required_scripts = os.listdir(os.path.join(repo_path, "scripts"))
    required_dirs = ["bin", "clai"]
    required_files = [
        file for file in os.listdir(repo_path) if file.endswith(".json")
    ]

    print("Linking all needed files to install directory")

    try:
        for script in required_scripts:
            link(
                os.path.join(repo_path, f"scripts/{script}"),
                os.path.join(install_path, script),
            )
            os.system(f"chmod 775 {os.path.join(install_path, script)}")

        for directory in required_dirs:
            link(
                os.path.join(repo_path, directory),
                os.path.join(install_path, directory),
            )
            if directory == "bin":
                os.system(
                    f"chmod -R 777 {os.path.join(install_path, directory)}")

        for file in required_files:
            link(os.path.join(repo_path, file),
                 os.path.join(install_path, file))
            os.system(f"chmod 666 {os.path.join(install_path, file)}")

    except Exception as e:
        print(e)
        sys.exit(1)

    download_file(URL_BASH_PREEXEC,
                  filename="%s/%s" % (install_path, BASH_PREEXEC))

    register_the_user(install_path, False)
    append_setup_to_file(get_setup_file(), install_path, DEFAULT_PORT)
    register_file(False)

    install_orchestration(install_path)

    install_plugins(install_path, False)

    print_complete(
        "CLAI has been installed correctly, you need restart your shell.")
Exemple #5
0
def execute(args):
    unassisted = args.unassisted
    no_skills = args.no_skills
    demo_mode = args.demo_mode
    bin_path = os.path.join(args.destdir, 'bin')
    code_path = os.path.join(bin_path, 'clai')
    cli_path = os.path.join(bin_path, 'bin')
    temp_path = '~/tmp'
    mkdir(f"{temp_path}/")

    create_rc_file_if_not_exist(args.system)

    if clai_installed(get_setup_file()):
        print_error('CLAI is already in you system. You should execute uninstall first')
        sys.exit(1)

    if not binary_installed(bin_path):
        mkdir(bin_path)
        mkdir(code_path)

        cp_tree('./clai', code_path)
        cp_tree('./bin', cli_path)
        copy('./scripts/clai.sh', bin_path)
        copy('./scripts/saveFilesChanges.sh', bin_path)
        copy('./configPlugins.json', bin_path)
        copy('./usersInstalled.json', bin_path)
        copy('./anonymize.json', bin_path)
        copy('./scripts/fileExist.sh', bin_path)

        os.system(f'chmod 775 {bin_path}/saveFilesChanges.sh')
        os.system(f'chmod 775 {bin_path}/fileExist.sh')
        os.system(f'chmod -R 777 {code_path}/server/plugins')
        os.system(f'chmod 777 {bin_path}/clai.sh')
        os.system(f'chmod 666 {bin_path}/configPlugins.json')
        os.system(f'chmod 666 {bin_path}/anonymize.json')
        os.system(f'chmod -R 777 {bin_path}')
        cli_executable(cli_path)

        download_file(URL_BASH_PREEXEC, filename='%s/%s' % (temp_path, BASH_PREEXEC))
        copy('%s/%s' % (temp_path, BASH_PREEXEC), bin_path)

    register_the_user(bin_path, args.system)
    append_setup_to_file(get_setup_file(), bin_path)
    register_file(args.system)

    if not no_skills:
        agent_datasource = AgentDatasource(
            config_storage=ConfigStorage(alternate_path=f'{bin_path}/configPlugins.json'))
        plugins = agent_datasource.all_plugins()
        for plugin in plugins:
            if plugin.default:
                installed = install_plugins_dependencies(bin_path, plugin.pkg_name)
                if installed:
                    agent_datasource.mark_plugins_as_installed(plugin.name, None)

        save_report_info(unassisted, agent_datasource, bin_path, demo_mode)

    remove(f"{temp_path}/")

    os.system(f'chmod -R 777 /var/tmp')

    print_complete("CLAI has been installed correctly, you need restart your shell.")
Exemple #6
0
def execute(args):
    unassisted = args.unassisted
    no_skills = args.no_skills
    demo_mode = args.demo_mode
    user_install = args.user_install
    bin_path = os.path.join(args.destdir, 'bin')

    code_path = os.path.join(bin_path, 'clai')
    cli_path = os.path.join(bin_path, 'bin')
    temp_path = "./tmp"
    mkdir(f"{temp_path}/")

    create_rc_file_if_not_exist(args.system)

    if clai_installed(get_setup_file()):
        print_error(
            'CLAI is already in you system. You should execute uninstall first'
        )
        sys.exit(1)

    if not binary_installed(bin_path):
        mkdir(bin_path)
        mkdir(code_path)

        cp_tree('./clai', code_path)
        cp_tree('./bin', cli_path)
        copy('./scripts/clai.sh', bin_path)
        copy('./scripts/saveFilesChanges.sh', bin_path)
        copy('./configPlugins.json', bin_path)
        copy('./usersInstalled.json', bin_path)
        copy('./anonymize.json', bin_path)
        copy('./scripts/fileExist.sh', bin_path)
        copy('./scripts/installOrchestrator.sh', bin_path)

        os.system(f'chmod 775 {bin_path}/saveFilesChanges.sh')
        os.system(f'chmod 775 {bin_path}/fileExist.sh')
        os.system(f'chmod 775 {bin_path}/installOrchestrator.sh')
        os.system(f'chmod -R 777 {code_path}/server/plugins')
        os.system(f'chmod 777 {bin_path}/clai.sh')
        os.system(f'chmod 666 {bin_path}/configPlugins.json')
        os.system(f'chmod 666 {bin_path}/anonymize.json')
        os.system(f'chmod -R 777 {bin_path}')
        cli_executable(cli_path)

        download_file(URL_BASH_PREEXEC,
                      filename='%s/%s' % (temp_path, BASH_PREEXEC))
        copy('%s/%s' % (temp_path, BASH_PREEXEC), bin_path)
        if is_zos():
            os.system(f'chtag -tc 819 {bin_path}/{BASH_PREEXEC}')

    if user_install:
        mark_user_flag(bin_path, True)
    else:
        mark_user_flag(bin_path, False)

    register_the_user(bin_path, args.system)
    append_setup_to_file(get_setup_file(), bin_path, args.port)
    register_file(args.system)

    install_orchestration(bin_path)
    if not no_skills:
        save_report_info(unassisted, install_plugins(bin_path, user_install),
                         bin_path, demo_mode)

    remove(f"{temp_path}")

    if not user_install:
        os.system(f'chmod -R 777 /var/tmp')

    print_complete(
        "CLAI has been installed correctly, you will need to restart your shell."
    )