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
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()
'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()