Example #1
0
    def update_lists(self, progress_callback):
        """
        Refresh list of packages.

        :param progress_callback: Callback function to follow progress
        :type progress_callback: function
        """
        class Progress(AcquireProgress):
            def fetch(self, item):
                progress = int(100 * self.current_items / self.total_items)
                message = f'{progress}%% {item.shortdesc}'
                progress_callback(message=message,
                                  done=self.current_items,
                                  total=self.total_items)

            def stop(self):
                self.done = True

        cache = apt.Cache()
        ack = Progress()
        try:
            cache.update(fetch_progress=ack)
        except apt.cache.FetchFailedException:
            pass

        while not hasattr(ack, 'done'):
            gevent.sleep(1)
def upgradeAPT():
	"""Upgrade system via apt."""
	try:
		import apt
		import apt.cache
		cache = apt.Cache()
		cache.update()
		cache.open(None)
		cache.upgrade()
		for pkg in cache.get_changes():
			logs.log(str((pkg.name, pkg.isupgradeable)), "Info")
		raise NotImplementedError("[CWE-758] - Pocket upgrade upgradeAPT() not implemented. Yet.")
	except Exception as permErr:
		remediation.error_breakpoint(permErr, "upgradeAPT")
		permErr = None
		del(permErr)
	return None
Example #3
0
    def update_lists(self, progress_callback):
        class Progress(AcquireProgress):
            def fetch(self, item):
                message = '%s%% %s' % (int(100 * self.current_items /
                                           self.total_items), item.shortdesc)
                progress_callback(message=message,
                                  done=self.current_items,
                                  total=self.total_items)

            def stop(self):
                self.done = True

        cache = apt.Cache()
        ack = Progress()
        try:
            cache.update(fetch_progress=ack)
        except apt.cache.FetchFailedException:
            pass

        while not hasattr(ack, 'done'):
            gevent.sleep(1)
Example #4
0
    def update_lists(self, progress_callback):
        class Progress(AcquireProgress):
            def fetch(self, item):
                message = '%s%% %s' % (
                    int(100 * self.current_items / self.total_items),
                    item.shortdesc
                )
                progress_callback(message=message, done=self.current_items, total=self.total_items)

            def stop(self):
                self.done = True

        cache = apt.Cache()
        ack = Progress()
        try:
            cache.update(fetch_progress=ack)
        except apt.cache.FetchFailedException:
            pass

        while not hasattr(ack, 'done'):
            gevent.sleep(1)
Example #5
0
def handle_apt_deps(deps):
    # Initialize apt cache
    cache = apt.cache.Cache() 

    cache.update()
    cache.open()

    # For each dependency, check if it is installed. If not, mark it for installation
    for dep in deps:
        name = dep[0][0]
        pkg = cache[name]
        if pkg.is_installed:
            notice("{} dependency already installed".format(name))
        else:
            pkg.mark_install()
            notice("{} dependency marked for installation".format(name))

    # Try to install all dependencies
    try:
        notice("Installing dependencies")
        cache.commit()
    except Exception as e:
        error(e.msg)
        return 2
Example #6
0
import os  # for geteuid

pkg_names = [
    'templar',
]
do_update = False

if os.geteuid() == 0:
    print('you are root, that is good, proceeding...')
else:
    exit("You need to have root privileges to run this script.\nPlease try again, this time using 'sudo'. Exiting.")

cache = apt.cache.Cache()
if do_update:
    print('doing update')
    cache.update()

need_commit = False
for pkg_name in pkg_names:
    pkg = cache[pkg_name]
    if pkg.is_installed:
        print('package [{pkg_name}] already installed'.format(pkg_name=pkg_name))
    else:
        pkg.mark_install()
        need_commit = True

# this actually installs
if need_commit:
    print('doing commit')
    cache.commit()
Example #7
0
pkg_names = [
    'templar',
]
do_update = False

if os.geteuid() == 0:
    print('you are root, that is good, proceeding...')
else:
    exit(
        "You need to have root privileges to run this script.\nPlease try again, this time using 'sudo'. Exiting."
    )

cache = apt.cache.Cache()
if do_update:
    print('doing update')
    cache.update()

need_commit = False
for pkg_name in pkg_names:
    pkg = cache[pkg_name]
    if pkg.is_installed:
        print(
            'package [{pkg_name}] already installed'.format(pkg_name=pkg_name))
    else:
        pkg.mark_install()
        need_commit = True

# this actually installs
if need_commit:
    print('doing commit')
    cache.commit()