#!/usr/bin/python # $Header: $ # This program is licensed under the GPL, version 2 import os,string,sys sys.path.insert(0, "/usr/lib/gentoolkit/pym") sys.path.insert(0, "/usr/lib/portage/pym") from output import * from getopt import getopt,GetoptError __program__ = "glsa-update" __author__ = "Ned Ludd " __version__ = "0.1" nocolor() # delay this for speed increase from glsa import * def fetchpkg(pkg, argv): if os.path.exists("/usr/bin/qmerge"): try: os.system("qmerge -Cf " + pkg + " 2> /dev/null | grep MD5: | grep -q '[OK]'") except: sys.stderr.write("Failed to fetch "+pkg ) pass else: sys.stderr.write("qmerge is not installed; unable to d/l "+pkg ) def installpkg(pkg, argv): a = str.join(" ", argv[1:]) try: os.system("emerge -quk "+ pkg + " " + a) except: sys.stderr.write("failed something") pass def glsa_update(argv): # option parsing params = ["affected"] glsaconfig = checkconfig(portage.config(clone=portage.settings)) # Check that we really have a glsa dir to work on if not (os.path.exists(glsaconfig["GLSA_DIR"]) and os.path.isdir(glsaconfig["GLSA_DIR"])): sys.stderr.write(red("ERROR")+": GLSA_DIR %s doesn't exist. Please fix this.\n" % glsaconfig["GLSA_DIR"]) sys.exit(1) # build glsa lists completelist = get_glsa_list(glsaconfig["GLSA_DIR"], glsaconfig) if os.access(glsaconfig["CHECKFILE"], os.R_OK): checklist = [line.strip() for line in open(glsaconfig["CHECKFILE"], "r").readlines()] else: checklist = [] todolist = [e for e in completelist if e not in checklist] glsalist = [] # maybe this should be todolist instead for this in completelist: try: glsa = Glsa(this, glsaconfig) except (GlsaTypeException, GlsaFormatException), e: continue if glsa.isVulnerable(): glsalist.append(this) # remove invalid parameters for p in params[:]: if not (p in completelist or os.path.exists(p)): #sys.stderr.write(("(removing %s from parameter list as it isn't a valid GLSA specification)\n" % p)) params.remove(p) glsalist.extend([g for g in params if g not in glsalist]) pkglist=[] for this in glsalist: try: glsa = Glsa(this, glsaconfig) except (GlsaTypeException, GlsaFormatException), e: continue for pkg in glsa.packages.keys(): mylist = portage.db["/"]["vartree"].dbapi.match(portage.dep_getkey(pkg)) if len(mylist) > 0: for x in mylist: cpv = portage.catpkgsplit(x) x = cpv[0]+ "/" + cpv[1] if x not in pkglist: pkglist.append(x) else: if pkg not in pkglist: pkglist.append(pkg) for pkg in pkglist: #sys.stdout.write(pkg + "\n") fetchpkg(pkg, argv) installpkg(pkg, argv) glsa_update(sys.argv) sys.exit(0)