#!/usr/bin/python # # mk-rescueimage.i386 - builds a rescue image from an existing tree # which can be converted into a isolinux bootable # iso and used as a sysadmin rescue image. # # # Usage: mk-rescueimage.i386 # # the rescue image will be created as /i386-rescueimage # import os import sys import string def usage(): print "usage: mk-rescueimage.i386 " sys.exit(0) if len(sys.argv) < 5: usage() sys.exit(1) if not os.access("%s/i386" % (sys.argv[2],), os.F_OK): print "ERROR - Destination directory %s does not contain an i386 directory!" % (srcdir,) sys.exit(1) srcdir = sys.argv[1] destdir = sys.argv[2]+"/i386-rescueimage" productname = sys.argv[3] default = sys.argv[4] # clean and create destination directory os.system("rm -rf %s" % (destdir,)) os.system("mkdir %s" % (destdir,)) # copy documentation for pat in ["*eula*", "*EULA*", "README*", "RELEASE*", "GPL", "RPM-*"]: try: os.system("cp -p %s/%s %s/" % (srcdir, pat, destdir)) except: print "Unable to find pattern %s" % (pat,) # cp isolinux boot image os.system("cp -a %s/isolinux %s/" % (srcdir, destdir)) # cp stage image os.system("mkdir -p %s/%s/base" % (destdir,default)) os.system("cp -a %s/%s/base/stage2.img %s/%s/base" % (srcdir, default, destdir,default,)) # munge syslinux config to have a default of rescue mode cfgfile = open("%s/isolinux/isolinux.cfg" % (destdir,), "r") cfglines = cfgfile.readlines() cfgfile.close() # backup old one os.system("cp %s/isolinux/isolinux.cfg %s/isolinux/isolinux.cfg.backup" % (destdir,destdir)) cfgfile = open("%s/isolinux/isolinux.cfg" % (destdir,), "w+") fndit = 0 indefault = 0 defaultimg = None for l in cfglines: if string.find(l, "default ") != -1: defaultimg = string.strip(string.split(l,' ')[1]) cfgfile.write("default rescue\n") continue elif string.find(l, "label ") != -1: # see if we've left default stanza and entered a new one if fndit and indefault: indefault = 0 cfgfile.write(rescuestanza) if defaultimg is not None: curimg = string.strip(string.split(l, ' ')[1]) if curimg == defaultimg: fndit = 1 indefault = 1 # build up the rescue stanza based on whats in the # default stanza as we echo it out rescuestanza = "label rescue\n" # if we fall through then write it out cfgfile.write(l) else: # we're writing out the matching stanza - if we hit the append # line put rescue on the end of it, otherwise just echo line if fndit and indefault: if string.find(l, "append ") != -1: rescuestanza = rescuestanza + string.rstrip(l)+" rescue\n" else: rescuestanza = rescuestanza + l cfgfile.write(l) cfgfile.close() if not fndit: print "Could not find default stanza, did not modify isolinux.cfg" os.system("mv -f %s/isolinux/isolinux.cfg.backup %s/isolinux/isolinux.cfg" % (destdir,destdir)) else: os.system("rm -f %s/isolinux/isolinux.cfg.backup" % (destdir,)) # synthesize a new syslinux screen # msgfile = open("%s/isolinux/boot.msg" % (destdir,), "w+") msgfile.write(" \n") msgfile.write("splash.lss\n") # make "Red Hat" RED! idx = string.find(productname, "Red Hat") if idx != -1: productstr = productname[:idx] productstr = productstr + "02Red Hat07" productstr = productstr + productname[idx+7:] else: productstr = productname msgfile.write("This is the %s Rescue CD.\n" % (productstr,)) msgfile.write("\n") msgfile.write(" - To enter rescue mode press the 0f07 key.\n") msgfile.write("\n") msgfile.write(" - To install or upgrade %s type \"linux\" and then the 0f07 key.\n" % (productstr, )) msgfile.write("\n") msgfile.write(" - Use the function keys listed below for more information.\n") msgfile.write("\n") msgfile.write("02[F1-Main] [F2-Options] [F3-General] [F4-Kernel] [F5-Rescue]07\n") msgfile.close()