def update(): """Updates system package index""" try: pacman.refresh() logger.success('ctl:pkg:update', 'Index updated') except Exception as e: raise CLIException(str(e))
def arch_linux(): import pacman # lista de programas listt = ['docker', "nmap"] # procura no cache pacman.refresh() banner = ''' ████████╗██╗ ██╗ ██████╗ █████╗ ██████╗ ██████╗██╗ ██╗ ██╗███╗ ██╗███████╗████████╗ █████╗ ██╗ ██╗ ╚══██╔══╝██║ ██║██╔════╝ ██╔══██╗██╔══██╗██╔════╝██║ ██║ ██║████╗ ██║██╔════╝╚══██╔══╝██╔══██╗██║ ██║ ██║ ███████║██║ ███╗█████╗███████║██████╔╝██║ ███████║█████╗██║██╔██╗ ██║███████╗ ██║ ███████║██║ ██║ ██║ ██╔══██║██║ ██║╚════╝██╔══██║██╔══██╗██║ ██╔══██║╚════╝██║██║╚██╗██║╚════██║ ██║ ██╔══██║██║ ██║ ██║ ██║ ██║╚██████╔╝ ██║ ██║██║ ██║╚██████╗██║ ██║ ██║██║ ╚████║███████║ ██║ ██║ ██║███████╗███████╗ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝ ╚═╝╚═╝ ╚═══╝╚══════╝ ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝ ''' print(Fore.BLUE + banner) # faz o check dos programas for i in listt: if pacman.is_installed(i): print("{colorp}{i} =>{color} already installed.".format( colorp=Fore.RED, color=Fore.CYAN, i=i)) else: # instala try: print("Installing {}...".format(i)) pacman.install(i) print("{} installed.".format(i)) except Exception as arg: print("Sorry, package installation failed [{err}]".format( err=str(arg)))
def _operation(self, job, install, remove): if install: try: pacman.refresh() prereqs = pacman.needs_for(install) upgr = (x["id"] for x in pacman.get_installed() if x.get("upgradable")) if sorted(upgr) == sorted(install): # Upgrade msg = "Performing system upgrade..." msg = Notification("info", "Packages", msg) nthread = NotificationThread(id=job.id, message=msg) pacman.upgrade() else: # Install title = "Installing {0} package(s)".format(len(prereqs)) msg = Notification("info", "Packages", ", ".join(prereqs)) nthread = NotificationThread(id=job.id, title=title, message=msg) pacman.install(install) for x in prereqs: try: info = process_info(pacman.get_info(x)) if "installed" not in info: info["installed"] = True push_record("package", info) except: pass except Exception as e: nthread.complete(Notification("error", "Packages", str(e))) return if remove: try: prereqs = pacman.depends_for(remove) title = "Removing {0} package(s)".format(len(prereqs)) msg = Notification("info", "Packages", ", ".join(prereqs)) nthread = NotificationThread(id=job.id, title=title, message=msg) pacman.remove(remove) for x in prereqs: try: info = process_info(pacman.get_info(x)) if "installed" not in info: info["installed"] = False push_record("package", info) except: pass except Exception as e: nthread.complete(Notification("error", "Packages", str(e))) return msg = "Operations completed successfully" nthread.complete(Notification("success", "Packages", msg))
def get(self, id): if request.args.get("refresh", False): pacman.refresh() if id: try: info = process_info(pacman.get_info(id)) return jsonify(package=info) except: abort(404) else: return jsonify(packages=pacman.get_all())
def verify_dependencies(self): verify, error, to_pacman = True, "", [] # If dependency isn't installed, add it to "to install" list # If it can't be installed, mark the app as not loadable and say why for dep in self.dependencies: if dep["type"] == "system": if (dep["binary"] and not find_executable(dep["binary"])) \ or not pacman.is_installed(dep["package"]): to_pacman.append(dep["package"]) if dep.has_key("internal") and dep["internal"]: error = "Restart required" verify = False if dep["type"] == "python": to_pip = "" if dep["module"]: try: __import__(dep["module"]) except ImportError: to_pip = dep["package"] else: if not python.is_installed(dep["package"]): to_pip = dep["package"] if to_pip: try: logger.debug(" *** Installing %s (via pip)..." % to_pip) python.install(to_pip) except: error = "Couldn't install %s" % to_pip verify = False finally: if dep.has_key("internal") and dep["internal"]: error = "Restart required" verify = False # Execute the "to install" list actions if to_pacman: pacman.refresh() for x in to_pacman: try: logger.debug(" *** Installing %s..." % x) pacman.install(x) except: error = "Couldn't install %s" % x verify = False self.loadable = verify self.error = error return verify
def upgrade(yes): """Upgrades all system packages""" try: pacman.refresh() pkgs = pacman.get_installed() pkgs = [x["id"] for x in pkgs if x["upgradable"]] if not pkgs: logger.info('ctl:pkg:upgrade', 'System already up-to-date') else: logger.info( 'ctl:pkg:upgrade', 'The following packages will be upgraded:' ) click.echo(", ".join(pkgs)) if yes or click.confirm("Are you sure you want to upgrade?"): logger.info('ctl:pkg:upgrade', 'Upgrading system...') pacman.upgrade() logger.success('ctl:pkg:upgrade', 'Upgrade complete') except Exception as e: raise CLIException(str(e))
def _operation(self, install, remove): message = Message() if install: try: pacman.refresh() prereqs = pacman.needs_for(install) message.update("info", "Installing %s package(s): %s" % (len(prereqs), ', '.join(prereqs))) pacman.install(install) for x in prereqs: try: info = process_info(pacman.get_info(x)) if not "installed" in info: info["installed"] = True push_record("package", info) except: pass except Exception, e: message.complete("error", str(e)) return
def main(argv): """Run the main logic. Args: argv (list): Command line arguments """ parser = argparse.ArgumentParser( prog='aur-makepkg', description='Build Pacman packages with makepkg from local source or the AUR', epilog='' ) parser.add_argument('-g', '--gid', dest='gid', type=int, default=1000, help="GID of the build user") parser.add_argument('-i', '--install-all-dependencies', action='store_true', dest='install_all_dependencies', default=False, help="Install all dependencies, not only 'make dependencies'") parser.add_argument('-k', '--keyrings', dest='keyrings', default=None, help="Pacman keyrings initialized prior building (comma seperated list)") parser.add_argument('-p', '--pacman-update', action='store_true', dest='pacman_update', default=False, help="Update all installed pacman packages before build") parser.add_argument('-r', '--rebuild', dest='rebuild', type=int, default=0, help="""Rebuild behaviour: 0: Build only new versions of packages (default) 1: Rebuild all explicit listed packages 2: Rebuild all explicit listed packages and their dependencies""") parser.add_argument('--remove-downloaded-source', dest='remove_dowloaded_source', action='store_true', default=False, help="""Remove the source downloaded by 'makepkg' before build. If not the sources will be kept, under the condition that the source is of the same version of the package to be build. (Note: Sources of packages build from a Git repository will always be removed.)""") parser.add_argument('-u', '--uid', dest='uid', type=int, default=1000, help="UID of the build user") parser.add_argument('build_package_names', nargs='+', help="Name fo packages to be build from local source or the AUR") args = parser.parse_args(argv) # create build user and group try: grp.getgrgid(args.gid) except Exception: os.system("groupadd -g {0} build-user".format(args.gid)) try: pwd.getpwuid(args.uid) except Exception: os.system( "useradd -p /makepkg/build -m -g {1} -s /bin/bash -u {0} build-user".format(args.uid, args.gid)) # refresh pacman package database if args.keyrings: printInfo("Initializing pacman keyring...") run_command(['pacman-key', '--init'], print_output=False) rc, out, err = run_command(['pacman-key', '--populate'] + args.keyrings.split(','), print_output=True) if rc != 0: raise Exception("Failed to initialize Pacman keyrings: " + '\n'.join(err)) # refresh pacman package database printInfo("Update pacman package database...") pacman.refresh() global packages_in_cache, packages_in_offical_repositories packages_in_cache = [x for x in os.listdir(pacman_cache_dir) if os.path.isfile(os.path.join(pacman_cache_dir, x))] packages_in_offical_repositories = pacman.get_available() if args.pacman_update: # upgrade installed pacman packages printInfo("Upgrading installed pacman packages...") rc, out, err = run_command(['pacman', '-Su', '--noconfirm', '--force', '--ignore', 'package-query', '--ignore', 'pacman-mirrorlist', '--cachedir', pacman_cache_dir], print_output=True) if rc != 0: raise Exception("Failed to upgrade Pacman packages: " + '\n'.join(err)) pkg_dict = dict() build_package_names = [x.lower() for x in args.build_package_names] # look for local package sources locally_available_package_sources = [] if os.path.exists(local_source_dir) and \ os.path.isdir(local_source_dir): for d in os.listdir(local_source_dir): pkgbuild_file_path = os.path.join(d, "PKGBUILD") if os.path.exists(pkgbuild_file_path) and \ os.path.isfile(pkgbuild_file_path): locally_available_package_sources.append(os.path.basename(d)) # get packages and their dependencies for pkg_name in build_package_names: printInfo("Collecting information about {0}...".format(pkg_name)) get_package_recursive(pkg_name, True, pkg_dict, locally_available_package_sources, args.remove_dowloaded_source, False) # build packages if pkg_name in pkg_dict: build_package_recursive(pkg_name, pkg_dict, args.rebuild, args.install_all_dependencies, args.uid, args.gid) # print build statistics printInfo("\nBuild Statistics:") for pkg_name in build_package_names: if pkg_name in pkg_dict: print_build_log(pkg_name, pkg_dict)
def main(argv): """Run the main logic. Args: argv (list): Command line arguments """ parser = argparse.ArgumentParser( prog='aur-makepkg', description= 'Build Pacman packages with makepkg from local source or the AUR', epilog='') parser.add_argument('-g', '--gid', dest='gid', type=int, default=1000, help="GID of the build user") parser.add_argument( '-i', '--install-all-dependencies', action='store_true', dest='install_all_dependencies', default=False, help="Install all dependencies, not only 'make dependencies'") parser.add_argument( '-k', '--keyrings', dest='keyrings', default=None, help="Pacman keyrings initialized prior building (comma seperated list)" ) parser.add_argument( '-p', '--pacman-update', action='store_true', dest='pacman_update', default=False, help="Update all installed pacman packages before build") parser.add_argument('-r', '--rebuild', dest='rebuild', type=int, default=0, help="""Rebuild behaviour: 0: Build only new versions of packages (default) 1: Rebuild all explicit listed packages 2: Rebuild all explicit listed packages and their dependencies""" ) parser.add_argument( '--remove-downloaded-source', dest='remove_dowloaded_source', action='store_true', default=False, help="""Remove the source downloaded by 'makepkg' before build. If not the sources will be kept, under the condition that the source is of the same version of the package to be build. (Note: Sources of packages build from a Git repository will always be removed.)""") parser.add_argument('-u', '--uid', dest='uid', type=int, default=1000, help="UID of the build user") parser.add_argument( 'build_package_names', nargs='+', help="Name fo packages to be build from local source or the AUR") args = parser.parse_args(argv) # create build user and group try: grp.getgrgid(args.gid) except Exception: os.system("groupadd -g {0} build-user".format(args.gid)) try: pwd.getpwuid(args.uid) except Exception: os.system( "useradd -p /makepkg/build -m -g {1} -s /bin/bash -u {0} build-user" .format(args.uid, args.gid)) # refresh pacman package database if args.keyrings: printInfo("Initializing pacman keyring...") run_command(['pacman-key', '--init'], print_output=False) rc, out, err = run_command(['pacman-key', '--populate'] + args.keyrings.split(','), print_output=True) if rc != 0: raise Exception("Failed to initialize Pacman keyrings: " + '\n'.join(err)) # refresh pacman package database printInfo("Update pacman package database...") pacman.refresh() global packages_in_cache, packages_in_offical_repositories packages_in_cache = [ x for x in os.listdir(pacman_cache_dir) if os.path.isfile(os.path.join(pacman_cache_dir, x)) ] packages_in_offical_repositories = pacman.get_available() if args.pacman_update: # upgrade installed pacman packages printInfo("Upgrading installed pacman packages...") rc, out, err = run_command([ 'pacman', '-Su', '--noconfirm', '--force', '--ignore', 'package-query', '--ignore', 'pacman-mirrorlist', '--cachedir', pacman_cache_dir ], print_output=True) if rc != 0: raise Exception("Failed to upgrade Pacman packages: " + '\n'.join(err)) pkg_dict = dict() build_package_names = [x.lower() for x in args.build_package_names] # look for local package sources locally_available_package_sources = [] if os.path.exists(local_source_dir) and \ os.path.isdir(local_source_dir): for d in os.listdir(local_source_dir): pkgbuild_file_path = os.path.join(d, "PKGBUILD") if os.path.exists(pkgbuild_file_path) and \ os.path.isfile(pkgbuild_file_path): locally_available_package_sources.append(os.path.basename(d)) # get packages and their dependencies for pkg_name in build_package_names: printInfo("Collecting information about {0}...".format(pkg_name)) get_package_recursive(pkg_name, True, pkg_dict, locally_available_package_sources, args.remove_dowloaded_source, False) # build packages if pkg_name in pkg_dict: build_package_recursive(pkg_name, pkg_dict, args.rebuild, args.install_all_dependencies, args.uid, args.gid) # print build statistics printInfo("\nBuild Statistics:") for pkg_name in build_package_names: if pkg_name in pkg_dict: print_build_log(pkg_name, pkg_dict)
def scan(verify=True, cry=True): """ Search app directory for applications, load them and store metadata. Also contacts arkOS repo servers to obtain current list of available apps, and merges in any updates as necessary. :param bool verify: Verify app dependencies as the apps are scanned :param bool cry: Raise exception on dependency install failure? :return: list of Application objects :rtype: list """ signals.emit("apps", "pre_scan") logger.debug("Apps", "Scanning for applications") app_dir = config.get("apps", "app_dir") if not os.path.exists(app_dir): os.makedirs(app_dir) pacman.refresh() logger.debug("Apps", "Getting system/python/ruby installed list") inst_list = { "sys": pacman.get_installed(), "py": python.get_installed(), "py2": python.get_installed(py2=True), "rb": ruby.get_installed() } # Get paths for installed apps, metadata for available ones installed_apps = [x for x in os.listdir(app_dir) if not x.startswith(".")] api_url = ("https://{0}/api/v1/apps" .format(config.get("general", "repo_server"))) logger.debug("Apps", "Fetching available apps: {0}".format(api_url)) try: available_apps = api(api_url) except Exception as e: available_apps = [] logger.error("Apps", "Could not get available apps from GRM.") logger.error("Apps", str(e)) if available_apps: available_apps = available_apps["applications"] else: available_apps = [] # Create objects for installed apps with appropriate metadata for x in installed_apps: try: with open(os.path.join(app_dir, x, "manifest.json"), "r") as f: data = json.loads(f.read()) except ValueError: warn_str = "Failed to load {0} due to a JSON parsing error" logger.warning("Apps", warn_str.format(x)) continue except IOError: warn_str = "Failed to load {0}: manifest file inaccessible "\ "or not present" logger.warning("Apps", warn_str.format(x)) continue logger.debug("Apps", " *** Loading {0}".format(data["id"])) app = App(**data) app.installed = True for y in enumerate(available_apps): if app.id == y[1]["id"] and app.version != y[1]["version"]: app.upgradable = y[1]["version"] if app.id == y[1]["id"]: app.assets = y[1]["assets"] available_apps[y[0]]["installed"] = True app.load(verify=verify, cry=cry, installed=inst_list) storage.applications[app.id] = app # Convert available apps payload to objects for x in available_apps: if not x.get("installed"): app = App(**x) app.installed = False storage.applications[app.id] = app if verify: verify_app_dependencies() signals.emit("apps", "post_scan") return storage.applications
def verify_dependencies(self, cry, installed): """ Verify that the associated dependencies are all properly installed. Checks system-level packages, Python packages and arkOS Apps for installed status. Sets ``self.loadable`` with verify status and ``self.error`` with error message encountered on check. :returns: True if all verify checks passed :rtype: bool """ verify, error = True, "" # If dependency isn't installed, add it to "to install" list # If it can't be installed, mark the app as not loadable and say why if not installed: pacman.refresh() installed["sys"] = pacman.get_installed() installed["py"] = python.get_installed() installed["py2"] = python.get_installed(py2=True) installed["rb"] = ruby.get_installed() for dep in self.dependencies: if dep["type"] == "system": pack = next( filter(lambda x: x["id"] == dep["package"], installed["sys"]), None ) invalid_ver = False if pack and dep.get("version"): invalid_ver = compare_versions( pack["version"], "lt", dep["version"] ) if not pack or invalid_ver: logger.debug( "Apps", "{0} not found. Attempting install..." .format(dep["package"])) try: pacman.install(dep["package"]) except: error = "Couldn't install {0}".format(dep["package"]) verify = False if cry: raise AppDependencyError(dep["package"], "system") if dep.get("internal"): error = "Reload required" verify = False if dep["type"] == "python": ilist = installed["py2"] if dep.get("py2") else installed["py"] pack = next( filter(lambda x: x["id"].lower() == dep["package"].lower(), ilist), None ) invalid_ver = False if pack and dep.get("version"): invalid_ver = compare_versions( pack["version"], "lt", dep["version"] ) if not pack or invalid_ver: logger.debug( "Apps", "{0} not found. Attempting install..." .format(dep["package"])) try: python.install( dep["package"], version=dep.get("version"), py2=True if dep.get("py2") else False ) except: error = "Couldn't install {0}".format(dep["package"]) verify = False if cry: raise AppDependencyError(dep["package"], "python") if dep.get("internal"): error = "Reload required" verify = False if dep["type"] == "ruby": pack = next( filter(lambda x: x["id"] == dep["package"], installed["rb"]), None ) invalid_ver = False if pack and dep.get("version"): invalid_ver = compare_versions( pack["version"], "lt", dep["version"] ) if not pack or invalid_ver: logger.debug( "Apps", "{0} not found. Attempting install..." .format(dep["package"])) try: ruby.install( dep["package"], version=dep.get("version") ) except: error = "Couldn't install {0}".format(dep["package"]) verify = False if cry: raise AppDependencyError(dep["package"], "ruby") if dep.get("internal"): error = "Reload required" verify = False self.loadable = verify self.error = error return verify