Viewing file: elilocfg.py (6.41 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
#!/usr/bin/python # elilo updating code for Update Agent # Copyright (c) 2001-2002 Red Hat, Inc. Distributed under GPL. # # Author: Adrian Likins <alikins@redhat.com> """module for updating the eli boot loaders config file for the up2date agent"""
import os,sys import lilo, iutil from rhpl.translate import _, N_ import time
import up2dateLog from bootloadercfg import makeInitrd import bootloadercfg
list_of_directives = [] default_directives = ['read-only'] other_directives = ['initrd'] ignore_directives = []
global TEST TEST=0
class ELiloConfParseError(bootloadercfg.Error): """Raise when we encounter a config directive we dont understand""" def __repr__(self): msg = _("elilo options that are not supported by up2date are used in the default elilo.conf. This file will not be modified. The options include:\n") + self.errmsg return msg
def findDefault(config,imagelist): default = imagelist[0] (type, default_image,image_path,other) = config.getImage(default) defaultIsOther = None return (default,type, default_image,image_path,other,defaultIsOther)
def addImage(newimage, initrd, label,config,default_image,setdefault=None): path = "%s" % newimage sl = lilo.LiloConfigFile(imageType = "image", path=path) for i in list_of_directives: tmp = default_image.getEntry(i) if tmp: sl.addEntry(i, tmp)
entries = default_image.listEntries() # remove all the standard entries from entried # also remove stuff we dont want to copy, like 'alias' known_directives = default_directives+list_of_directives+other_directives+ignore_directives tmp_entries = {} for i in entries.keys(): if i in known_directives: pass else: tmp_entries[i] = entries[i] # the ones we always add, ie "read-only" for i in default_directives: sl.addEntry(i)
for i in tmp_entries.keys(): sl.addEntry(i, tmp_entries[i])
# FIXME (gen the initrd, first...) if initrd: sl.addEntry("initrd", initrd)
if label: sl.addEntry("label", label)
config.addImage(sl,setdefault)
def backupName(labelName,imagelist): #this could be smarter backup = labelName+".bak" if backup in imagelist: backup = backup+"_" else: backup = labelName+".bak" # truncate long names. if len(backup) > 32: backup = labelName[:28]+".bak" return backup
def installNewImages(imageList, test=0, filename = None): # parse the existing config file # we use the lilo config file parser for elilo as well log = up2dateLog.initLog() config = lilo.LiloConfigFile() global TEST TEST=test
label = "linux"
if not filename: filename = "/boot/efi/elilo.conf"
# if there is no existing elilo.conf, I'm not smart enough to create one if not os.access(filename, os.R_OK): return None
config.read(filename) if len(config.unsupported): raise ELiloConfParseError("\n" + "%s" % config.unsupported)
imagelist = config.listImages() # look at the default entry # assume it's valid and good, if not... uh, sorry, what else # can I do? (default, type, default_image,image_path,other,defaultIsOther) = findDefault(config,imagelist)
defaultType = None if image_path[-3:] == "smp": defaultType = "smp" elif image_path[-10:] == "enterprise": defaultType = "enterprise" elif image_path[-4:] == "BOOT": defaultType = "BOOT" else: defaultType = None rootDev = default_image.getEntry("root")
for (newimage,imageType) in imageList: (initrd,initrdExists) = makeInitrd(newimage, "/")
if imageType and imageType != defaultType: # linux-smp.linux-BOOT, etc label = "linux-"+imageType elif not imageType and defaultType: label = "linux-up" else: label = "linux" if not initrdExists: initrd = None
if label in imagelist: (tmpType, old_image, tmp_path,other) = config.getImage(label) new_old_label = backupName(label,imagelist) old_image.addEntry("label", new_old_label) log.log_me("renaming the lilo.conf entry for %s to %s" % (label,new_old_label)) # uh huh.. if defaultType: if imageType: if defaultType == imageType: setdefault = 1 else: setdefault = 0 else: setdefault = 0 else: if imageType: setdefault = 0 else: setdefault = 1
addImage(newimage, initrd, label, config, default_image,setdefault)
backupfile = filename + ".up2date-" + repr(time.time()) # first, see if there are existing backup files # if so, choose-another while os.access(backupfile, os.F_OK): backupfile = backupfile + "_"
TEST = 1 if TEST: print config if __name__ == "__main__":
import getopt
filename = None arglist = sys.argv[1:] try: optlist, args = getopt.getopt(arglist, 'a:d:', ['add=','del=', 'file=','default']) except getopt.error, e: print("Error parsing command line arguments: %s") % e sys.exit(1)
addimage = 0 delimage = 0 setdefault = 0 for opt in optlist: if opt[0] == '-a' or opt[0] == '--add': addimage = 1 newimage = opt[1] if opt[0] == '-d' or opt[0] == '--del': delimage = 1 if opt[0] == '--default': setdefault = 1 if opt[0] == '--file': filename = opt[1]
kernel_list = [('2.4.2-0.1.49BOOT', "BOOT"), ('2.4.2-0.1.49enterprise', "enterprise"), ('2.4.2-0.1.49smp', "smp"), ('2.4.2-0.1.49', None)]
kernel_list2 = [('2.4.2-0.1.49',None), ('2.4.2-0.1.49enterprise', "enterprise"), ('2.4.2-0.1.49smp', "smp"), ('2.4.2-0.1.49BOOT', "BOOT")] kernel_list3 = [('2.4.2-0.1.49',None)]
kernel_list4 = [('2.4.2-0.1.49smp', "smp"), ('2.4.2-0.1.49', None)]
foo = installNewImages(kernel_list4, filename=filename,test=1,) sys.exit(1)
|