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
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
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)
def parse_args(): parser = argparse.ArgumentParser( description= "Setup Clai in a development enviorment to make live changes") parser.add_argument( "action", action="store", type=str, help=f'action for script to perform one of: {" ".join(ACTIONS)}', ) parser.add_argument("-p", "--path", help="path to source directory", dest="path", action="store") parser.add_argument( "-i", "--install-directory", dest="install_path", action="store", type=str, help="The location that clai is installed in", default=f"{os.getenv('HOME', '/home/root')}/.bin/clai/bin") args = parser.parse_args() if args.action not in ACTIONS: print_error( f"Not a valid action: '{args.action}' Valid actions: [{', '.join(ACTIONS)}]" ) sys.exit(1) if args.path is None: print_error("The path flag is required") sys.exit(1) return args
def parse_args(): default_user_destdir = os.path.join( os.path.expanduser('/opt/local/share'), 'clai', ) parser = argparse.ArgumentParser(description='Install CLAI for all users.') parser.add_argument( '--shell', help="if you like to install for different shell", dest='shell', action='store' ) parser.add_argument( '--demo', help="if you like to jump installation restrictions", dest='demo_mode', action='store_true' ) parser.add_argument( '--system', help="if you like install it for all users.", dest='system', action='store_true', default=False ) parser.add_argument( '--unassisted', help="Don't ask to he user for questions or inputs in the install process", dest='unassisted', action='store_true', default=False ) parser.add_argument( '--no-skills', help="Don't install the default skills", dest='no_skills', action='store_true', default=False ) parser.add_argument( '-d', '--destdir', metavar='DIR', default=default_user_destdir, help='set destination to DIR', ) args = parser.parse_args() if not valid_python_version(): print_error('You need install python 3.6 or upper is required.') sys.exit(1) if not is_root_user(args): print_error('You need root privileges for complete the installation process.') sys.exit(1) if is_windows(): print_error("CLAI is not supported on Windows.") sys.exit(1) shell = get_shell(args) if shell not in SUPPORTED_SHELLS: print_error('%s is not supported yet.' % shell) sys.exit(1) if args.system: if args.destdir != default_user_destdir: print_error( 'Custom paths incompatible with --system option.') sys.exit(1) return args
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.")
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." )