home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2000 July / CD 3 / redhat-6.2.iso / RedHat / instimage / usr / lib / anaconda / todo.py~ < prev    next >
Encoding:
Text File  |  2000-03-08  |  42.8 KB  |  1,364 lines

  1. import rpm, os
  2. rpm.addMacro("_i18ndomains", "redhat-dist");
  3.  
  4. import iutil, isys
  5. from lilo import LiloConfiguration
  6. arch = iutil.getArch ()
  7. if arch == "sparc":
  8.     from silo import SiloInstall
  9. elif arch == "alpha":
  10.     from milo import MiloInstall, onMILO
  11. import string
  12. import socket
  13. import crypt
  14. import whrandom
  15. import pcmcia
  16. import _balkan
  17. import kudzu
  18. from kbd import Keyboard
  19. from simpleconfig import SimpleConfigFile
  20. from mouse import Mouse
  21. from xf86config import XF86Config
  22. import errno
  23. import raid
  24. import fstab
  25. import time
  26. import gettext_rh
  27. from translate import _
  28.  
  29. class LogFile:
  30.     def __init__ (self, serial, reconfigOnly, test):
  31.     if serial or reconfigOnly:
  32.         self.logFile = open("/tmp/install.log", "w")
  33.     elif reconfigOnly:
  34.         self.logFile = open("/tmp/reconfig.log", "w")
  35.     elif test:
  36.         self.logFile = open("/tmp/anaconda-debug.log", "w")
  37.     else:
  38.         self.logFile = open("/dev/tty3", "w")
  39.  
  40.     def __call__ (self, format, *args):
  41.         if args:
  42.             self.logFile.write ("* %s\n" % (format % args))
  43.         else:
  44.             self.logFile.write ("* %s\n" % format)
  45.  
  46.     def getFile (self):
  47.         return self.logFile.fileno ()
  48.             
  49. class NetworkDevice (SimpleConfigFile):
  50.     def __str__ (self):
  51.         s = ""
  52.         s = s + "DEVICE=" + self.info["DEVICE"] + "\n"
  53.         keys = self.info.keys ()
  54.         keys.sort ()
  55.         keys.remove ("DEVICE")
  56.         for key in keys:
  57.             s = s + key + "=" + self.info[key] + "\n"
  58.         return s
  59.  
  60.     def __init__ (self, dev):
  61.         self.info = { "DEVICE" : dev, "ONBOOT" : "yes" }
  62.  
  63. class Network:
  64.     def __init__ (self):
  65.         self.netdevices = {}
  66.         self.gateway = ""
  67.         self.primaryNS = ""
  68.         self.secondaryNS = ""
  69.         self.ternaryNS = ""
  70.         self.domains = []
  71.         self.readData = 0
  72.     self.isConfigured = 0
  73.         self.hostname = "localhost.localdomain"
  74.         try:
  75.             f = open ("/tmp/netinfo", "r")
  76.         except:
  77.             pass
  78.         else:
  79.             lines = f.readlines ()
  80.         f.close ()
  81.             info = {}
  82.         self.isConfigured = 1
  83.             for line in lines:
  84.                 netinf = string.splitfields (line, '=')
  85.                 info [netinf[0]] = string.strip (netinf[1])
  86.             self.netdevices [info["DEVICE"]] = NetworkDevice (info["DEVICE"])
  87.             if info.has_key ("IPADDR"):
  88.                 self.netdevices [info["DEVICE"]].set (("IPADDR", info["IPADDR"]))
  89.             if info.has_key ("NETMASK"):
  90.                 self.netdevices [info["DEVICE"]].set (("NETMASK", info["NETMASK"]))
  91.             if info.has_key ("BOOTPROTO"):
  92.                 self.netdevices [info["DEVICE"]].set (("BOOTPROTO", info["BOOTPROTO"]))
  93.             if info.has_key ("GATEWAY"):
  94.                 self.gateway = info["GATEWAY"]
  95.             if info.has_key ("DOMAIN"):
  96.                 self.domains.append(info["DOMAIN"])
  97.             if info.has_key ("HOSTNAME"):
  98.                 self.hostname = info["HOSTNAME"]
  99.             
  100.             self.readData = 1
  101.     try:
  102.         f = open ("/etc/resolv.conf", "r")
  103.     except:
  104.         pass
  105.     else:
  106.         lines = f.readlines ()
  107.         f.close ()
  108.         for line in lines:
  109.         resolv = string.split (line)
  110.         if resolv[0] == 'nameserver':
  111.             if self.primaryNS == "":
  112.             self.primaryNS = resolv[1]
  113.             elif self.secondaryNS == "":
  114.             self.secondaryNS = resolv[1]
  115.             elif self.ternaryNS == "":
  116.             self.ternaryNS = resolv[1]
  117.  
  118.     def getDevice(self, device):
  119.     return self.netdevices[device]
  120.  
  121.     def available (self):
  122.         f = open ("/proc/net/dev")
  123.         lines = f.readlines()
  124.         f.close ()
  125.         # skip first two lines, they are header
  126.         lines = lines[2:]
  127.         for line in lines:
  128.             dev = string.strip (line[0:6])
  129.             if dev != "lo" and not self.netdevices.has_key (dev):
  130.                 self.netdevices[dev] = NetworkDevice (dev)
  131.         return self.netdevices
  132.  
  133.     def lookupHostname (self):
  134.     # can't look things up if they don't exist!
  135.     if not self.hostname or self.hostname == "localhost.localdomain": return None
  136.  
  137.     if not self.isConfigured:
  138.         for dev in self.netdevices.values():
  139.         if dev.get('bootproto') == "dhcp":
  140.             self.primaryNS = isys.pumpNetDevice(dev.get('device'))
  141.         elif dev.get('ipaddr') and dev.get('netmask'):
  142.             isys.configNetDevice(dev.get('device'),
  143.                 dev.get('ipaddr'), dev.get('netmask'),
  144.                 self.gateway)
  145.  
  146.     if not self.primaryNS: return
  147.  
  148.     f = open("/etc/resolv.conf", "w")
  149.     f.write("nameserver %s\n" % self.primaryNS)
  150.     f.close()
  151.     isys.resetResolv()
  152.     isys.setResolvRetry(2)
  153.  
  154.     try:
  155.         ip = socket.gethostbyname(self.hostname)
  156.     except socket.error:
  157.         return None
  158.  
  159.     return ip
  160.  
  161.     def nameservers (self):
  162.         return [ self.primaryNS, self.secondaryNS, self.ternaryNS ]
  163.  
  164. class Password:
  165.     def __init__ (self):
  166.         self.crypt = None
  167.     self.pure = None
  168.  
  169.     def getPure(self):
  170.     return self.pure
  171.  
  172.     def set (self, password, isCrypted = 0):
  173.     if isCrypted:
  174.         self.crypt = password
  175.         self.pure = None
  176.     else:
  177.             salt = (whrandom.choice (string.letters +
  178.                                      string.digits + './') + 
  179.                     whrandom.choice (string.letters +
  180.                                      string.digits + './'))
  181.             self.crypt = crypt.crypt (password, salt)
  182.         self.pure = password
  183.  
  184.     def getCrypted(self):
  185.     return self.crypt
  186.  
  187. class Desktop (SimpleConfigFile):
  188.     def __init__ (self):
  189.         SimpleConfigFile.__init__ (self)
  190.  
  191.     def set (self, desktop):
  192.         self.info ['DESKTOP'] = desktop
  193.  
  194. class Language (SimpleConfigFile):
  195.     def __init__ (self):
  196.         self.info = {}
  197.  
  198.     if os.access("lang-table", os.R_OK):
  199.         f = open("lang-table", "r")
  200.     elif os.access("/etc/lang-table", os.R_OK):
  201.         f = open("/etc/lang-table", "r")
  202.     else:
  203.         f = open("/usr/lib/anaconda/lang-table", "r")
  204.  
  205.     lines = f.readlines ()
  206.     f.close()
  207.     self.langs = {}
  208.     self.font = {}
  209.     self.map = {}
  210.  
  211.     for line in lines:
  212.         string.strip(line)
  213.         l = string.split(line)
  214.         self.langs[l[0]] = l[4]
  215.         self.font[l[0]] = l[2]
  216.         self.map[l[0]] = l[3]
  217.     
  218.         # kickstart needs this
  219.         self.abbrevMap = {}
  220.         for (key, value) in self.langs.items ():
  221.             self.abbrevMap[value] = key
  222.  
  223.     self.setByAbbrev("en_US")
  224.  
  225.     def available (self):
  226.         return self.langs
  227.  
  228.     def setByAbbrev(self, lang):
  229.     self.set(self.abbrevMap[lang])
  230.     
  231.     def set (self, lang):
  232.         self.lang = self.langs[lang]
  233.         self.info["LANG"] = self.langs[lang]
  234.         os.environ["LANG"] = self.langs[lang]
  235.  
  236.     if self.font[lang] != "None":
  237.         self.info["SYSFONT"] = self.font[lang]
  238.         self.info["SYSFONTACM"] = self.map[lang]
  239.     else:
  240.             if self.info.has_key("SYSFONT"):
  241.                 del self.info["SYSFONT"]
  242.             if self.info.has_key("SYSFONTACM"):
  243.                 del self.info["SYSFONTACM"]
  244.  
  245.     rpm.addMacro("_install_langs", self.langs[lang]);
  246.         os.environ["LINGUAS"] = self.langs[lang]
  247.         
  248.     def get (self):
  249.     return self.lang
  250.  
  251.     def getFont (self, lang):
  252.     return self.font[lang]
  253.  
  254. class Authentication:
  255.     def __init__ (self):
  256.         self.useShadow = 1
  257.         self.useMD5 = 1
  258.         self.useNIS = 0
  259.         self.domain = ""
  260.         self.useBroadcast = 1
  261.         self.server = ""
  262.  
  263. class InstSyslog:
  264.     def __init__ (self, root, log):
  265.         self.pid = os.fork ()
  266.         if not self.pid:
  267.             if os.access ("./anaconda", os.X_OK):
  268.                 path = "./anaconda"
  269.             elif os.access ("/usr/bin/anaconda.real", os.X_OK):
  270.                 path = "/usr/bin/anaconda.real"
  271.             else:
  272.                 path = "/usr/bin/anaconda"
  273.             os.execv (path, ("syslogd", "--syslogd", root, log))
  274.  
  275.     def __del__ (self):
  276.         os.kill (self.pid, 15)
  277.         
  278. class ToDo:
  279.     def __init__(self, intf, method, rootPath, setupFilesystems = 1,
  280.          installSystem = 1, mouse = None, instClass = None, x = None,
  281.          expert = 0, serial = 0, reconfigOnly = 0, test = 0,
  282.          extraModules = []):
  283.     self.intf = intf
  284.     self.method = method
  285.     self.hdList = None
  286.     self.comps = None
  287.     self.instPath = rootPath
  288.     self.setupFilesystems = setupFilesystems
  289.     self.installSystem = installSystem
  290.         self.language = Language ()
  291.     self.serial = serial
  292.     self.fstab = None
  293.         self.reconfigOnly = reconfigOnly
  294.         self.log = LogFile (serial, reconfigOnly, test)
  295.         self.network = Network ()
  296.         self.rootpassword = Password ()
  297.         self.extraModules = extraModules
  298.         if mouse:
  299.             self.mouse = Mouse (xmouseType = mouse)
  300.         else:
  301.             self.mouse = Mouse ()
  302.         self.keyboard = Keyboard ()
  303.         self.auth = Authentication ()
  304.         self.desktop = Desktop ()
  305.         self.ddruidReadOnly = 0
  306.         self.bootdisk = 1
  307.  
  308.     # liloDevice, liloLinear, liloAppend are initialized form the
  309.     # default install class
  310.         arch = iutil.getArch ()
  311.         self.lilo = LiloConfiguration()
  312.     if arch == "sparc":
  313.         self.silo = SiloInstall (self.serial)
  314.         elif arch == "alpha":
  315.             self.milo = MiloInstall (self)
  316.     self.timezone = None
  317.         self.upgrade = 0
  318.     self.ddruidAlreadySaved = 0
  319.         self.initlevel = 3
  320.     self.expert = expert
  321.         self.progressWindow = None
  322.     self.fdDevice = None
  323.     if (not instClass):
  324.         raise TypeError, "installation class expected"
  325.         if x:
  326.             self.x = x
  327.             self.x.setMouse (self.mouse)
  328.         else:
  329.             self.x = XF86Config (mouse = self.mouse)
  330.  
  331.     # This absolutely, positively MUST BE LAST
  332.     self.setClass(instClass)
  333.  
  334.     def setFdDevice(self):
  335.     if self.fdDevice:
  336.         return
  337.     self.fdDevice = "/dev/fd0"
  338.     if iutil.getArch() == "sparc":
  339.         try:
  340.         f = open(self.fdDevice, "r")
  341.         except IOError, (errnum, msg):
  342.         if errno.errorcode[errnum] == 'ENXIO':
  343.             self.fdDevice = "/dev/fd1"
  344.         else:
  345.         f.close()
  346.  
  347.     def writeTimezone(self):
  348.     if (self.timezone):
  349.         (timezone, asUtc, asArc) = self.timezone
  350.             try:
  351.                 iutil.copyFile(self.instPath + "/usr/share/zoneinfo/" + timezone, 
  352.                                self.instPath + "/etc/localtime")
  353.             except OSError, (errno, msg):
  354.                 self.intf.messageWindow(_("Error"),
  355.                                         _("Error copying file: %s") % msg)
  356.     else:
  357.         asUtc = 0
  358.         asArc = 0
  359.  
  360.     f = open(self.instPath + "/etc/sysconfig/clock", "w")
  361.     f.write('ZONE="%s"\n' % timezone)
  362.     f.write("UTC=")
  363.     if (asUtc):
  364.         f.write("true\n")
  365.     else:
  366.         f.write("false\n")
  367.  
  368.     f.write("ARC=")
  369.     if (asArc):
  370.         f.write("true\n")
  371.     else:
  372.         f.write("false\n")
  373.     f.close()
  374.  
  375.     def getTimezoneInfo(self):
  376.     return self.timezone
  377.  
  378.     def setTimezoneInfo(self, timezone, asUtc = 0, asArc = 0):
  379.     self.timezone = (timezone, asUtc, asArc)
  380.  
  381.     def addMount(self, device, location, fsystem, reformat = 1):
  382.         if fsystem == "swap":
  383.             ufs = 0
  384.             try:
  385.                 isys.makeDevInode(device, '/tmp/' + device)
  386.             except:
  387.                 pass
  388.             try:
  389.                 ufs = isys.checkUFS ('/tmp/' + device)
  390.             except:
  391.                 pass
  392.             if not ufs:
  393.                 location = "swap"
  394.                 reformat = 1
  395.         self.mounts[location] = (device, fsystem, reformat)
  396.  
  397.     def writeLanguage(self):
  398.     f = open(self.instPath + "/etc/sysconfig/i18n", "w")
  399.     f.write(str (self.language))
  400.     f.close()
  401.  
  402.     def writeMouse(self):
  403.     if self.serial: return
  404.     f = open(self.instPath + "/etc/sysconfig/mouse", "w")
  405.     f.write(str (self.mouse))
  406.     f.close()
  407.     self.mouse.makeLink(self.instPath)
  408.  
  409.     def writeDesktop(self):
  410.     f = open(self.instPath + "/etc/sysconfig/desktop", "w")
  411.     f.write(str (self.desktop))
  412.     f.close()
  413.  
  414.     def writeKeyboard(self):
  415.     if self.serial: return
  416.     f = open(self.instPath + "/etc/sysconfig/keyboard", "w")
  417.     f.write(str (self.keyboard))
  418.     f.close()
  419.  
  420.     def needBootdisk (self):
  421.     if self.bootdisk or self.fstab.rootOnLoop(): return 1
  422.  
  423.     def makeBootdisk (self):
  424.     # this is faster then waiting on mkbootdisk to fail
  425.     self.setFdDevice()
  426.     device = self.fdDevice[5:]
  427.     file = "/tmp/floppy"
  428.     isys.makeDevInode(device, file)
  429.     try:
  430.         fd = os.open(file, os.O_RDONLY)
  431.     except:
  432.             raise RuntimeError, "boot disk creation failed"
  433.     os.close(fd)
  434.  
  435.     kernel = self.hdList['kernel']
  436.         kernelTag = "-%s-%s" % (kernel['version'], kernel['release'])
  437.  
  438.         w = self.intf.waitWindow (_("Creating"), _("Creating boot disk..."))
  439.     self.setFdDevice ()
  440.         rc = iutil.execWithRedirect("/sbin/mkbootdisk",
  441.                                     [ "/sbin/mkbootdisk",
  442.                                       "--noprompt",
  443.                                       "--device",
  444.                                       self.fdDevice,
  445.                                       kernelTag[1:] ],
  446.                                     stdout = None, stderr = None, 
  447.                     searchPath = 1, root = self.instPath)
  448.         w.pop()
  449.         if rc:
  450.             raise RuntimeError, "boot disk creation failed"
  451.  
  452.     def freeHeaderList(self):
  453.     if (self.hdList):
  454.         self.hdList = None
  455.  
  456.     def getHeaderList(self):
  457.     if (not self.hdList):
  458.         w = self.intf.waitWindow(_("Reading"),
  459.                                      _("Reading package information..."))
  460.         self.hdList = self.method.readHeaders()
  461.         w.pop()
  462.     return self.hdList
  463.  
  464.     def getCompsList(self):
  465.     if (not self.comps):
  466.         self.getHeaderList()
  467.         self.comps = self.method.readComps(self.hdList)
  468.         for comp in self.comps:
  469.         if comp.selected:
  470.             comp.select (1)
  471.     self.comps['Base'].select(1)
  472.  
  473.     self.updateInstClassComps()
  474.             
  475.     return self.comps
  476.  
  477.     def updateInstClassComps(self):
  478.     # don't load it just for this
  479.     if (not self.comps): return
  480.     group = self.instClass.getGroups()
  481.     packages = self.instClass.getPackages()
  482.     if (group == None and packages == None): return 0
  483.     for n in self.comps.keys():
  484.         self.comps[n].unselect(0)
  485.  
  486.     self.comps['Base'].select(1)
  487.     if group:
  488.         for n in group:
  489.         self.comps[n].select(1)
  490.  
  491.     if packages:
  492.         for n in packages:
  493.         self.selectPackage(n)
  494.  
  495.     if self.x.server:
  496.         self.selectPackage('XFree86-' + self.x.server)
  497.  
  498.     def selectPackage(self, package):
  499.     if not self.hdList.packages.has_key(package):
  500.         str = "package %s is not available" % (package,)
  501.         raise ValueError, str
  502.     self.hdList.packages[package].selected = 1
  503.  
  504.     def writeNetworkConfig (self):
  505.         # /etc/sysconfig/network-scripts/ifcfg-*
  506.         for dev in self.network.netdevices.values ():
  507.             device = dev.get ("device")
  508.             f = open (self.instPath + "/etc/sysconfig/network-scripts/ifcfg-" + device, "w")
  509.             f.write (str (dev))
  510.             f.close ()
  511.  
  512.         # /etc/sysconfig/network
  513.  
  514.         f = open (self.instPath + "/etc/sysconfig/network", "w")
  515.         f.write ("NETWORKING=yes\n"
  516.                  "HOSTNAME=")
  517.     if self.network.hostname:
  518.         f.write(self.network.hostname + "\n")
  519.     else:
  520.         f.write("localhost.localdomain" + "\n")
  521.     if self.network.gateway:
  522.         f.write("GATEWAY=" + self.network.gateway + "\n")
  523.         f.close ()
  524.  
  525.         # /etc/hosts
  526.         f = open (self.instPath + "/etc/hosts", "w")
  527.         localline = "127.0.0.1\t\t"
  528.  
  529.         self.log ("self.network.hostname = %s", self.network.hostname)
  530.  
  531.     ip = self.network.lookupHostname()
  532.  
  533.     # If the hostname is not resolvable, tie it to 127.0.0.1
  534.     if not ip and self.network.hostname != "localhost.localdomain":
  535.         localline = localline + self.network.hostname + " "
  536.         l = string.split(self.network.hostname, ".")
  537.         if len(l) > 1:
  538.         localline = localline + l[0] + " "
  539.                 
  540.     localline = localline + "localhost.localdomain localhost\n"
  541.         f.write (localline)
  542.  
  543.     if ip:
  544.         f.write ("%s\t\t%s\n" % (ip, self.network.hostname))
  545.  
  546.     # If the hostname was not looked up, but typed in by the user,
  547.     # domain might not be computed, so do it now.
  548.     if self.network.domains == [ "localdomain" ] or not self.network.domains:
  549.         if '.' in self.network.hostname:
  550.         # chop off everything before the leading '.'
  551.         domain = self.network.hostname[(string.find(self.network.hostname, '.') + 1):]
  552.         self.network.domains = [ domain ]
  553.  
  554.         # /etc/resolv.conf
  555.         f = open (self.instPath + "/etc/resolv.conf", "w")
  556.  
  557.     if self.network.domains != [ 'localdomain' ] and self.network.domains:
  558.         f.write ("search " + string.joinfields (self.network.domains, ' ') 
  559.             + "\n")
  560.  
  561.         for ns in self.network.nameservers ():
  562.             if ns:
  563.                 f.write ("nameserver " + ns + "\n")
  564.  
  565.         f.close ()
  566.  
  567.     def writeRootPassword (self):
  568.     pure = self.rootpassword.getPure()
  569.     if pure:
  570.         self.setPassword("root", pure)
  571.     else:
  572.         # we need to splice in an already crypted password for kickstart
  573.         f = open (self.instPath + "/etc/passwd", "r")
  574.         lines = f.readlines ()
  575.         f.close ()
  576.         index = 0
  577.         for line in lines:
  578.         if line[0:4] == "root":
  579.             entry = string.splitfields (line, ':')
  580.             entry[1] = self.rootpassword.getCrypted ()
  581.             lines[index] = string.joinfields (entry, ':')
  582.             break
  583.         index = index + 1
  584.         f = open (self.instPath + "/etc/passwd", "w")
  585.         f.writelines (lines)
  586.         f.close ()
  587.  
  588.     def setupAuthentication (self):
  589.         args = [ "/usr/sbin/authconfig", "--kickstart", "--nostart" ]
  590.         if self.auth.useShadow:
  591.             args.append ("--useshadow")
  592.         if self.auth.useMD5:
  593.             args.append ("--enablemd5")
  594.         if self.auth.useNIS:
  595.             args.append ("--enablenis")
  596.             args.append ("--nisdomain")
  597.             args.append (self.auth.domain)
  598.             if not self.auth.useBroadcast:
  599.                 args.append ("--nisserver")
  600.                 args.append (self.auth.server)
  601.         iutil.execWithRedirect(args[0], args,
  602.                               stdout = None, stderr = None, searchPath = 1,
  603.                               root = self.instPath)
  604.  
  605.     def copyConfModules (self):
  606.         try:
  607.             inf = open ("/tmp/conf.modules", "r")
  608.         except:
  609.             pass
  610.         else:
  611.             out = open (self.instPath + "/etc/conf.modules", "a")
  612.             out.write (inf.read ())
  613.  
  614.     def verifyDeps (self):
  615.     self.getCompsList()
  616.         if self.upgrade:
  617.             self.fstab.mountFilesystems (self.instPath)
  618.             db = rpm.opendb (0, self.instPath)
  619.             ts = rpm.TransactionSet(self.instPath, db)
  620.         else:
  621.             ts = rpm.TransactionSet()
  622.             
  623.         self.comps['Base'].select (1)
  624.  
  625.     for p in self.hdList.packages.values ():
  626.             if p.selected:
  627.                 ts.add(p.h, (p.h, p.h[rpm.RPMTAG_NAME]))
  628.             else:
  629.                 ts.add(p.h, (p.h, p.h[rpm.RPMTAG_NAME]), "a")
  630.  
  631.     ts.order()
  632.         deps = ts.depcheck()
  633.         rc = []
  634.         if deps:
  635.             for ((name, version, release),
  636.                  (reqname, reqversion),
  637.                  flags, suggest, sense) in deps:
  638.                 if sense == rpm.RPMDEP_SENSE_REQUIRES:
  639.                     if suggest:
  640.                         (header, sugname) = suggest
  641.                     else:
  642.                         sugname = _("no suggestion")
  643.                     if not (name, sugname) in rc:
  644.                         rc.append ((name, sugname))
  645.  
  646.         del ts
  647.         if self.upgrade:
  648.             del db
  649.             self.fstab.umountFilesystems (self.instPath)            
  650.         return rc
  651.  
  652.     def selectDeps (self, deps):
  653.         if deps:
  654.             for (who, dep) in deps:
  655.                 if dep != _("no suggestion"):
  656.                     self.hdList[dep].selected = 1
  657.  
  658.     def upgradeFindRoot (self):
  659.         rootparts = []
  660.         if not self.setupFilesystems: return [ self.instPath ]
  661.         win = self.intf.waitWindow (_("Searching"),
  662.                                     _("Searching for Red Hat Linux installations..."))
  663.         
  664.         drives = self.fstab.driveList()
  665.     mdList = raid.startAllRaid(drives)
  666.  
  667.     for dev in mdList:
  668.             if fstab.isValidExt2 (dev):
  669.                 isys.makeDevInode(dev, '/tmp/' + dev)
  670.                 try:
  671.                     isys.mount('/tmp/' + dev, '/mnt/sysimage')
  672.                 except SystemError, (errno, msg):
  673.                     self.intf.messageWindow(_("Error"),
  674.                                             _("Error mounting ext2 filesystem on %s: %s") % (dev, msg))
  675.                     continue
  676.                 if os.access ('/mnt/sysimage/etc/fstab', os.R_OK):
  677.                     rootparts.append (dev)
  678.                 isys.umount('/mnt/sysimage')
  679.                 os.remove ('/tmp/' + dev)
  680.  
  681.     raid.stopAllRaid(mdList)
  682.     
  683.         for drive in drives:
  684.             isys.makeDevInode(drive, '/tmp/' + drive)
  685.             
  686.             try:
  687.                 table = _balkan.readTable ('/tmp/' + drive)
  688.             except SystemError:
  689.                 pass
  690.             else:
  691.                 for i in range (len (table)):
  692.                     (type, sector, size) = table[i]
  693.                     # 2 is ext2 in balkan speek
  694.                     if size and type == 2:
  695.             # for RAID arrays of format c0d0p1
  696.             if drive [:3] == "rd/" or drive [:4] == "ida/":
  697.                             dev = drive + 'p' + str (i + 1)
  698.             else:
  699.                             dev = drive + str (i + 1)
  700.                         isys.makeDevInode(dev, '/tmp/' + dev)
  701.                         try:
  702.                             isys.mount('/tmp/' + dev, '/mnt/sysimage')
  703.                         except SystemError, (errno, msg):
  704.                             self.intf.messageWindow(_("Error"),
  705.                                                     _("Error mounting ext2 filesystem on %s: %s") % (dev, msg))
  706.                             continue
  707.                         if os.access ('/mnt/sysimage/etc/fstab', os.R_OK):
  708.                             rootparts.append (dev)
  709.                         isys.umount('/mnt/sysimage')
  710.                         os.remove ('/tmp/' + dev)
  711.             os.remove ('/tmp/' + drive)
  712.         win.pop ()
  713.         return rootparts
  714.  
  715.     def upgradeFindPackages (self, root):
  716.         win = self.intf.waitWindow (_("Finding"),
  717.                                     _("Finding packages to upgrade..."))
  718.         if self.setupFilesystems:
  719.             isys.makeDevInode(root, '/tmp/' + root)
  720.         mdList = raid.startAllRaid(self.fstab.driveList())
  721.             isys.mount('/tmp/' + root, '/mnt/sysimage')
  722.         fstab.readFstab('/mnt/sysimage/etc/fstab', self.fstab)
  723.             isys.umount('/mnt/sysimage')        
  724.         raid.stopAllRaid(mdList)
  725.             self.fstab.mountFilesystems (self.instPath)
  726.         self.fstab.turnOnSwap(formatSwap = 0)
  727.         self.getCompsList ()
  728.     self.getHeaderList ()
  729.  
  730.         packages = rpm.findUpgradeSet (self.hdList.hdlist, self.instPath)
  731.  
  732.         # unselect all packages
  733.         for package in self.hdList.packages.values ():
  734.             package.selected = 0
  735.  
  736.         # always upgrade all packages in Base package group
  737.     self.comps['Base'].select(1)
  738.  
  739.         hasX = 0
  740.         hasgmc = 0
  741.         # turn on the packages in the upgrade set
  742.         for package in packages:
  743.             self.hdList[package[rpm.RPMTAG_NAME]].selected = 1
  744.             if package[rpm.RPMTAG_NAME] == "XFree86":
  745.                 hasX = 1
  746.             if package[rpm.RPMTAG_NAME] == "gmc":
  747.                 hasgmc = 1
  748.  
  749.         self.dbpath = "/var/lib/anaconda-rebuilddb" + str(int(time.time()))
  750.         rpm.addMacro("_rebuilddbpath", self.dbpath);
  751.  
  752.         # now, set the system clock so the timestamps will be right:
  753.         iutil.setClock (self.instPath)
  754.         
  755.         # and rebuild the database so we can run the dependency problem
  756.         # sets against the on disk db
  757.         rc = rpm.rebuilddb (self.instPath)
  758.         if rc:
  759.             self.intf.messageWindow(_("Error"),
  760.                                     _("Rebuild of RPM database failed. "
  761.                                       "You may be out of disk space?"))
  762.             raise RuntimeError, "Rebuild of RPM database failed."
  763.  
  764.         # open up the database to check dependencies
  765.         rpm.addMacro("_dbpath", self.dbpath);
  766.         db = rpm.opendb (0, self.instPath)
  767.  
  768.         # if we have X but not gmc, we need to turn on GNOME.  We only
  769.         # want to turn on packages we don't have installed already, though.
  770.         if hasX and not hasgmc:
  771.             self.log ("Has X but not GNOME")
  772.             for package in self.comps['GNOME'].items.keys ():
  773.                 rec = db.findbyname (package.name)
  774.                 if not rec:
  775.                     self.log ("GNOME: Adding %s", package)
  776.                     self.comps['GNOME'].items[package].selected = 1
  777.             
  778.         del db
  779.         self.fstab.umountFilesystems (self.instPath)
  780.  
  781.         # new package dependency fixup
  782.         deps = self.verifyDeps ()
  783.  
  784.         for (name, suggest) in deps:
  785.             self.log ("Upgrade Dependency: %s needs %s, automatically added.", name, suggest)
  786.         self.selectDeps (deps)
  787.         win.pop ()
  788.  
  789.     def rpmError (todo):
  790.         todo.instLog.write (rpm.errorString () + "\n")
  791.  
  792.     def getClass(todo):
  793.     return todo.instClass
  794.  
  795.     def setClass(todo, instClass):
  796.     todo.instClass = instClass
  797.     todo.hostname = todo.instClass.getHostname()
  798.     todo.updateInstClassComps()
  799.     ( useShadow, useMd5, useNIS, nisDomain, nisBroadcast,
  800.               nisServer) = todo.instClass.getAuthentication()
  801.         todo.auth.useShadow = useShadow
  802.         todo.auth.useMD5 = useMd5
  803.         todo.auth.useNIS = useNIS
  804.         todo.auth.domain = nisDomain
  805.         todo.auth.useBroadcast = nisBroadcast
  806.         todo.auth.server = nisServer
  807.     todo.timezone = instClass.getTimezoneInfo()
  808.     todo.bootdisk = todo.instClass.getMakeBootdisk()
  809.     todo.zeroMbr = todo.instClass.zeroMbr
  810.     (where, linear, append) = todo.instClass.getLiloInformation()
  811.  
  812.         arch = iutil.getArch ()
  813.     if arch == "i386":    
  814.         todo.lilo.setDevice(where)
  815.         todo.lilo.setLinear(linear)
  816.         todo.lilo.setAppend(append)
  817.      elif arch == "sparc":
  818.         todo.silo.setDevice(where)
  819.         todo.silo.setAppend(append)
  820.  
  821.     for (mntpoint, (dev, fstype, reformat)) in todo.instClass.fstab:
  822.         todo.addMount(dev, mntpoint, fstype, reformat)
  823.  
  824.     todo.users = []
  825.     if todo.instClass.rootPassword:
  826.         todo.rootpassword.set(todo.instClass.rootPassword,
  827.                   isCrypted = todo.instClass.rootPasswordCrypted)
  828.     if todo.instClass.language:
  829.         todo.language.setByAbbrev(todo.instClass.language)
  830.     if todo.instClass.keyboard:
  831.         todo.keyboard.set(todo.instClass.keyboard)
  832.             if todo.instClass.keyboard != "us":
  833.                 xkb = todo.keyboard.getXKB ()
  834.                 if xkb:
  835.                     apply (todo.x.setKeyboard, xkb)
  836.  
  837.     (bootProto, ip, netmask, gateway, nameserver) = \
  838.         todo.instClass.getNetwork()
  839.     if bootProto:
  840.         todo.network.gateway = gateway
  841.         todo.network.primaryNS = nameserver
  842.  
  843.         devices = todo.network.available ()
  844.         if (devices and bootProto):
  845.         list = devices.keys ()
  846.         list.sort()
  847.         dev = devices[list[0]]
  848.                 dev.set (("bootproto", bootProto))
  849.                 if bootProto == "static":
  850.                     if (ip):
  851.                         dev.set (("ipaddr", ip))
  852.                     if (netmask):
  853.                         dev.set (("netmask", netmask))
  854.  
  855.     if (todo.instClass.x):
  856.         todo.x = todo.instClass.x
  857.  
  858.     if (todo.instClass.mouse):
  859.         (type, device, emulateThreeButtons) = todo.instClass.mouse
  860.         todo.mouse.set(type, emulateThreeButtons, thedev = device)
  861.             todo.x.setMouse(todo.mouse)
  862.             
  863.         if todo.instClass.desktop:
  864.             todo.desktop.set (todo.instClass.desktop)
  865.  
  866.     def getPartitionWarningText(self):
  867.     return self.instClass.clearPartText
  868.  
  869.     # List of (accountName, fullName, password) tupes
  870.     def setUserList(todo, users):
  871.     todo.users = users
  872.  
  873.     def getUserList(todo):
  874.     return todo.users
  875.  
  876.     def setPassword(todo, account, password):
  877.     devnull = os.open("/dev/null", os.O_RDWR)
  878.  
  879.     argv = [ "/usr/bin/passwd", "--stdin", account ]
  880.     p = os.pipe()
  881.     os.write(p[1], password + "\n")
  882.     iutil.execWithRedirect(argv[0], argv, root = todo.instPath, 
  883.                    stdin = p[0], stdout = devnull)
  884.     os.close(p[0])
  885.     os.close(p[1])
  886.     os.close(devnull)
  887.  
  888.     def createAccounts(todo):
  889.     if not todo.users: return
  890.  
  891.     for (account, name, password) in todo.users:
  892.         devnull = os.open("/dev/null", os.O_RDWR)
  893.  
  894.         argv = [ "/usr/sbin/useradd", account ]
  895.         iutil.execWithRedirect(argv[0], argv, root = todo.instPath,
  896.                    stdout = devnull)
  897.  
  898.         argv = [ "/usr/bin/chfn", "-f", name, account]
  899.         iutil.execWithRedirect(argv[0], argv, root = todo.instPath,
  900.                    stdout = devnull)
  901.         
  902.         todo.setPassword(account, password)
  903.  
  904.         os.close(devnull)
  905.  
  906.     def createCdrom(self):
  907.         self.log ("making cd-rom links")
  908.     list = isys.cdromList()
  909.     count = 0
  910.     for device in list:
  911.         cdname = "cdrom"
  912.         if (count):
  913.         cdname = "%s%d" % (cdname, count)
  914.         count = count + 1
  915.  
  916.             self.log ("creating cdrom link for" + device)
  917.             try:
  918.                 os.stat(self.instPath + "/dev/" + cdname)
  919.                 self.log ("link exists, removing")
  920.                 os.unlink(self.instPath + "/dev/" + cdname)
  921.             except OSError:
  922.                 pass
  923.         os.symlink(device, self.instPath + "/dev/" + cdname)
  924.         mntpoint = "/mnt/" + cdname
  925.         self.fstab.addMount(cdname, mntpoint, "iso9660")
  926.  
  927.     def createRemovable(self, rType):
  928.     devDict = isys.floppyDriveDict()
  929.  
  930.     d = isys.hardDriveDict()
  931.     for item in d.keys():
  932.         devDict[item] = d[item]
  933.  
  934.     list = devDict.keys()
  935.     list.sort()
  936.  
  937.     count = 0
  938.     for device in list:
  939.         descript = devDict[device]
  940.         if string.find(string.upper(descript), string.upper(rType)) == -1:
  941.         continue
  942.  
  943.         self.log ("found %s disk, creating link", rType)
  944.  
  945.         try:
  946.         os.stat(self.instPath + "/dev/%s" % rType)
  947.         self.log ("link exists, removing")
  948.         os.unlink(self.instPath + "/dev/%s" % rType)
  949.         except OSError:
  950.         pass
  951.         # the 4th partition of zip/jaz disks is the one that usually
  952.         # contains the DOS filesystem.  We'll guess at using that
  953.         # one, it is a sane default.
  954.         device = device + "4";
  955.         os.symlink(device, self.instPath + "/dev/%s" % rType)
  956.         mntpoint = "/mnt/%s" % rType
  957.         self.fstab.addMount(rType, mntpoint, "auto")
  958.  
  959.     def setDefaultRunlevel (self):
  960.         inittab = open (self.instPath + '/etc/inittab', 'r')
  961.         lines = inittab.readlines ()
  962.         inittab.close ()
  963.         inittab = open (self.instPath + '/etc/inittab', 'w')        
  964.         for line in lines:
  965.             if len (line) > 3 and line[:3] == "id:":
  966.                 fields = string.split (line, ':')
  967.                 fields[1] = str (self.initlevel)
  968.                 line = string.join (fields, ':')
  969.             inittab.write (line)
  970.         inittab.close ()
  971.         
  972.     def instCallback(self, what, amount, total, h, intf):
  973.         if (what == rpm.RPMCALLBACK_TRANS_START):
  974.             # step 6 is the bulk of the transaction set
  975.             # processing time
  976.             if amount == 6:
  977.                 self.progressWindow = \
  978.                    self.intf.progressWindow (_("Processing"),
  979.                                              _("Preparing to install..."),
  980.                                              total)
  981.         if (what == rpm.RPMCALLBACK_TRANS_PROGRESS):
  982.             if self.progressWindow:
  983.                 self.progressWindow.set (amount)
  984.                 
  985.         if (what == rpm.RPMCALLBACK_TRANS_STOP and self.progressWindow):
  986.             self.progressWindow.pop ()
  987.  
  988.         if (what == rpm.RPMCALLBACK_INST_OPEN_FILE):
  989.             intf.setPackage(h)
  990.             intf.setPackageScale(0, 1)
  991.             self.instLog.write (self.modeText % (h[rpm.RPMTAG_NAME],))
  992.             self.instLog.flush ()
  993.             fn = self.method.getFilename(h)
  994.             self.rpmFD = os.open(fn, os.O_RDONLY)
  995.             fn = self.method.unlinkFilename(fn)
  996.             return self.rpmFD
  997.         elif (what == rpm.RPMCALLBACK_INST_PROGRESS):
  998.             if total:
  999.                 intf.setPackageScale(amount, total)
  1000.         elif (what == rpm.RPMCALLBACK_INST_CLOSE_FILE):
  1001.             os.close (self.rpmFD)
  1002.             intf.completePackage(h)
  1003.         else:
  1004.             pass
  1005.  
  1006.     def copyExtraModules(self):
  1007.     kernelVersions = []
  1008.     
  1009.     if (self.hdList.has_key('kernel-smp') and 
  1010.         self.hdList['kernel-smp'].selected):
  1011.         version = (self.hdList['kernel-smp']['version'] + "-" +
  1012.                self.hdList['kernel-smp']['release'] + "smp")
  1013.         kernelVersions.append(version)
  1014.  
  1015.     version = (self.hdList['kernel']['version'] + "-" +
  1016.            self.hdList['kernel']['release'])
  1017.     kernelVersions.append(version)
  1018.  
  1019.         for (path, subdir, name) in self.extraModules:
  1020.         pattern = ""
  1021.         names = ""
  1022.         for n in kernelVersions:
  1023.         pattern = pattern + " " + n + "/" + name + ".o"
  1024.         names = names + " " + name + ".o"
  1025.         command = ("cd %s/lib/modules; gunzip < %s/modules.cgz | " +
  1026.             "%s/bin/cpio  --quiet -iumd %s") % \
  1027.         (self.instPath, path, self.instPath, pattern)
  1028.         self.log("running: '%s'" % (command, ))
  1029.         os.system(command)
  1030.  
  1031.         for n in kernelVersions:
  1032.         fromFile = "%s/lib/modules/%s/%s.o" % (self.instPath, n, name)
  1033.         to = "%s/lib/modules/%s/%s/%s.o" % (self.instPath, n, 
  1034.                             subdir, name)
  1035.  
  1036.         if (os.access(fromFile, os.R_OK)):
  1037.             self.log("copying %s to %s" % (fromFile, to))
  1038.             os.rename(fromFile, to)
  1039.         else:
  1040.             self.log("missing DD module %s (this may be okay)" % 
  1041.                 fromFile)
  1042.  
  1043.     def depmodModules(self):
  1044.     kernelVersions = []
  1045.     
  1046.     if (self.hdList.has_key('kernel-smp') and 
  1047.         self.hdList['kernel-smp'].selected):
  1048.         version = (self.hdList['kernel-smp']['version'] + "-" +
  1049.                self.hdList['kernel-smp']['release'] + "smp")
  1050.         kernelVersions.append(version)
  1051.  
  1052.     version = (self.hdList['kernel']['version'] + "-" +
  1053.            self.hdList['kernel']['release'])
  1054.     kernelVersions.append(version)
  1055.  
  1056.         for version in kernelVersions:
  1057.         iutil.execWithRedirect ("/sbin/depmod",
  1058.                                     [ "/sbin/depmod", "-a", version ],
  1059.                                     root = self.instPath, stderr = '/dev/null')
  1060.  
  1061.     def writeConfiguration(self):
  1062.         self.writeLanguage ()
  1063.         self.writeMouse ()
  1064.         self.writeKeyboard ()
  1065.         self.writeNetworkConfig ()
  1066.         self.setupAuthentication ()
  1067.         self.writeRootPassword ()
  1068.         self.createAccounts ()
  1069.         self.writeTimezone()
  1070.  
  1071.     def doInstall(self):
  1072.     # make sure we have the header list and comps file
  1073.     self.getHeaderList()
  1074.     self.getCompsList()
  1075.  
  1076.         arch = iutil.getArch ()
  1077.  
  1078.         if arch == "alpha":
  1079.             # if were're on alpha with ARC console, set the clock
  1080.             # so that our installed files won't be in the future
  1081.             if onMILO ():
  1082.                 args = ("clock", "-A", "-s")
  1083.                 try:
  1084.                     iutil.execWithRedirect('/usr/sbin/clock', args)
  1085.                 except:
  1086.                     pass
  1087.  
  1088.     # this is NICE and LATE. It lets kickstart/server/workstation
  1089.     # installs detect this properly
  1090.     if (self.hdList.has_key('kernel-smp') and isys.smpAvailable()):
  1091.         self.hdList['kernel-smp'].selected = 1
  1092.  
  1093.     # we *always* need a kernel installed
  1094.     if (self.hdList.has_key('kernel')):
  1095.         self.hdList['kernel'].selected = 1
  1096.  
  1097.         # if NIS is configured, install ypbind and dependencies:
  1098.         if self.auth.useNIS:
  1099.             self.hdList['ypbind'].selected = 1
  1100.             self.hdList['yp-tools'].selected = 1
  1101.             self.hdList['portmap'].selected = 1
  1102.  
  1103.         if self.x.server:
  1104.             self.selectPackage ('XFree86-' + self.x.server)
  1105.  
  1106.         # make sure that all comps that include other comps are
  1107.         # selected (i.e. - recurse down the selected comps and turn
  1108.         # on the children
  1109.         if self.setupFilesystems:
  1110.             if not self.upgrade:
  1111.         if (self.ddruidAlreadySaved):
  1112.             self.fstab.makeFilesystems ()
  1113.         else:
  1114.             self.fstab.savePartitions ()
  1115.             self.fstab.makeFilesystems ()
  1116.             self.fstab.turnOnSwap()
  1117.  
  1118.             self.fstab.mountFilesystems (self.instPath)
  1119.  
  1120.         if self.upgrade and self.dbpath:
  1121.             # move the rebuilt db into place.
  1122.             os.rename (self.instPath + "/var/lib/rpm",
  1123.                        self.instPath + "/var/lib/rpm-old")
  1124.             os.rename (self.instPath + self.dbpath,
  1125.                        self.instPath + "/var/lib/rpm")
  1126.             rpm.addMacro ("_dbpath", "%{_var}/lib/rpm")
  1127.             iutil.rmrf (self.instPath + "/var/lib/rpm-old")
  1128.             # flag this so we only do it once.
  1129.             self.dbpath = None
  1130.  
  1131.         self.method.targetFstab (self.fstab)
  1132.  
  1133.     if not self.installSystem: 
  1134.         return
  1135.  
  1136.     for i in [ '/var', '/var/lib', '/var/lib/rpm', '/tmp', '/dev' ]:
  1137.         try:
  1138.             os.mkdir(self.instPath + i)
  1139.         except os.error, (errno, msg):
  1140.                 # self.intf.messageWindow("Error", "Error making directory %s: %s" % (i, msg))
  1141.                 pass
  1142.  
  1143.         # XXX in case we started out in Upgrade land, we need to
  1144.         # reset this macro to point to the right place.
  1145.         rpm.addMacro ("_dbpath", "%{_var}/lib/rpm")
  1146.     db = rpm.opendb(1, self.instPath)
  1147.     ts = rpm.TransactionSet(self.instPath, db)
  1148.  
  1149.         total = 0
  1150.     totalSize = 0
  1151.  
  1152.         if self.upgrade:
  1153.             how = "u"
  1154.         else:
  1155.             how = "i"
  1156.         
  1157.     for p in self.hdList.selected():
  1158.         ts.add(p.h, p.h, how)
  1159.         total = total + 1
  1160.         totalSize = totalSize + p.h[rpm.RPMTAG_SIZE]
  1161.  
  1162.     ts.order()
  1163.  
  1164.         if self.upgrade:
  1165.             logname = '/tmp/upgrade.log'
  1166.         else:
  1167.             logname = '/tmp/install.log'
  1168.             
  1169.     self.instLog = open(self.instPath + logname, "w+")
  1170.     syslog = InstSyslog (self.instPath, self.instPath + logname)
  1171.  
  1172.     ts.scriptFd = self.instLog.fileno ()
  1173.     # the transaction set dup()s the file descriptor and will close the
  1174.     # dup'd when we go out of scope
  1175.  
  1176.     p = self.intf.packageProgressWindow(total, totalSize)
  1177.  
  1178.         if self.upgrade:
  1179.             self.modeText = _("Upgrading %s.\n")
  1180.         else:
  1181.             self.modeText = _("Installing %s.\n")
  1182.  
  1183.         oldError = rpm.errorSetCallback (self.rpmError)
  1184.  
  1185.         problems = ts.run(0, ~rpm.RPMPROB_FILTER_DISKSPACE,
  1186.                           self.instCallback, p)
  1187.         
  1188.         if problems:
  1189.             needed = {}
  1190.             size = 12
  1191.             for (descr, (type, mount, need)) in problems:
  1192.                 idx = string.find (mount, "/mnt/sysimage")
  1193.                 if idx != -1:
  1194.                     # 13 chars in /mnt/sysimage
  1195.                     mount = mount[13:]
  1196.  
  1197.                 if needed.has_key (mount) and needed[mount] < need:
  1198.                     needed[mount] = need
  1199.                 else:
  1200.                     needed[mount] = need
  1201.                     
  1202.             probs = _("You don't appear to have enough disk space to install "
  1203.                       "the packages you've selected. You need more space on the "
  1204.                       "following filesystems:\n\n")
  1205.             probs = probs + ("%-15s %s\n") % (_("Mount Point"), _("Space Needed"))
  1206.                     
  1207.             for (mount, need) in needed.items ():
  1208.                 if need > (1024*1024):
  1209.                     need = (need + 1024 * 1024 - 1) / (1024 * 1024)
  1210.                     suffix = "M"
  1211.                 else:
  1212.                     need = (need + 1023) / 1024
  1213.                     suffix = "k"
  1214.  
  1215.                 prob = "%-15s %d %c\n" % (mount, need, suffix)
  1216.                 probs = probs + prob
  1217.                 
  1218.             self.intf.messageWindow (_("Disk Space"), probs)
  1219.  
  1220.         del ts
  1221.         del db
  1222.         self.instLog.close()
  1223.         del syslog
  1224.  
  1225.         self.fstab.umountFilesystems(self.instPath)
  1226.             
  1227.             rpm.errorSetCallback (oldError)
  1228.             return 1
  1229.  
  1230.         # This should close the RPM database so that you can
  1231.         # do RPM ops in the chroot in a %post ks script
  1232.         del ts
  1233.         del db
  1234.         rpm.errorSetCallback (oldError)
  1235.         
  1236.         self.method.filesDone ()
  1237.         
  1238.         del p
  1239.  
  1240.         self.instLog.close ()
  1241.  
  1242.         w = self.intf.waitWindow(_("Post Install"), 
  1243.                                  _("Performing post install configuration..."))
  1244.  
  1245.         if not self.upgrade:
  1246.         self.createCdrom()
  1247.         self.createRemovable("zip")
  1248.         self.createRemovable("jaz")
  1249.         self.copyExtraModules()
  1250.         self.setFdDevice()
  1251.             self.fstab.write (self.instPath, fdDevice = self.fdDevice)
  1252.             self.writeConfiguration ()
  1253.             self.writeDesktop ()
  1254.         if (self.instClass.defaultRunlevel):
  1255.         self.initlevel = self.instClass.defaultRunlevel
  1256.         self.setDefaultRunlevel ()
  1257.             
  1258.             # pcmcia is supported only on i386 at the moment
  1259.             if arch == "i386":
  1260.                 pcmcia.createPcmciaConfig(self.instPath + "/etc/sysconfig/pcmcia")
  1261.             self.copyConfModules ()
  1262.             if not self.x.skip and self.x.server:
  1263.         if self.x.server[0:3] == 'Sun':
  1264.                     try:
  1265.                         os.unlink(self.instPath + "/etc/X11/X")
  1266.                     except:
  1267.                         pass
  1268.             script = open(self.instPath + "/etc/X11/X","w")
  1269.             script.write("#!/bin/bash\n")
  1270.             script.write("exec /usr/X11R6/bin/Xs%s -fp unix/:-1 $@\n" % self.x.server[1:])
  1271.             script.close()
  1272.             os.chmod(self.instPath + "/etc/X11/X", 0755)
  1273.         else:
  1274.                     if os.access (self.instPath + "/etc/X11/X", os.R_OK):
  1275.                         os.rename (self.instPath + "/etc/X11/X",
  1276.                                    self.instPath + "/etc/X11/X.rpmsave")
  1277.             os.symlink ("../../usr/X11R6/bin/XF86_" + self.x.server,
  1278.                 self.instPath + "/etc/X11/X")
  1279.         self.x.write (self.instPath + "/etc/X11/XF86Config")
  1280.             self.setDefaultRunlevel ()
  1281.             # go ahead and depmod modules on alpha, as rtc modprobe
  1282.             # will complain loudly if we don't do it now.
  1283.             if arch == "alpha":
  1284.                 self.depmodModules()
  1285.                 
  1286.             # blah.  If we're on a serial mouse, and we have X, we need to
  1287.             # close the mouse device, then run kudzu, then open it again.
  1288.  
  1289.             # turn it off
  1290.             mousedev = None
  1291.  
  1292.             # XXX currently Bad Things (X async reply) happen when doing
  1293.             # Mouse Magic on Sparc (Mach64, specificly)
  1294.             if os.environ.has_key ("DISPLAY") and not arch == "sparc":
  1295.                 import xmouse
  1296.                 try:
  1297.                     mousedev = xmouse.get()[0]
  1298.                 except RuntimeError:
  1299.                     pass
  1300.             if mousedev:
  1301.                 try:
  1302.                     os.rename (mousedev, "/dev/disablemouse")
  1303.                 except OSError:
  1304.                     pass
  1305.                 try:
  1306.                     xmouse.reopen()
  1307.                 except RuntimeError:
  1308.                     pass
  1309.             argv = [ "/usr/sbin/kudzu", "-q" ]
  1310.         devnull = os.open("/dev/null", os.O_RDWR)
  1311.         iutil.execWithRedirect(argv[0], argv, root = self.instPath,
  1312.                    stdout = devnull)
  1313.             # turn it back on            
  1314.             if mousedev:
  1315.                 try:
  1316.                     os.rename ("/dev/disablemouse", mousedev)
  1317.                 except OSError:
  1318.                     pass
  1319.                 try:
  1320.                     xmouse.reopen()
  1321.                 except RuntimeError:
  1322.                     pass
  1323.         
  1324.         # XXX make me "not test mode"
  1325.         if self.setupFilesystems:
  1326.         if arch == "sparc":
  1327.         self.silo.install (self.fstab, self.instPath, self.hdList, 
  1328.                    self.upgrade)
  1329.         elif arch == "i386":
  1330.         self.lilo.install (self.fstab, self.instPath, self.hdList, 
  1331.                    self.upgrade)
  1332.         elif arch == "alpha":
  1333.         self.milo.write ()
  1334.         else:
  1335.         raise RuntimeError, "What kind of machine is this, anyway?!"
  1336.  
  1337.     if self.instClass.postScript:
  1338.         scriptRoot = "/"
  1339.         if self.instClass.postInChroot:
  1340.         scriptRoot = self.instPath    
  1341.  
  1342.         path = scriptRoot + "/tmp/ks-script"
  1343.  
  1344.         f = open(path, "w")
  1345.         f.write("#!/bin/sh\n\n")
  1346.         f.write(self.instClass.postScript)
  1347.         f.close()
  1348.         os.chmod(path, 0700)
  1349.  
  1350.         if self.serial:
  1351.         messages = "/tmp/ks-script.log"
  1352.         else:
  1353.         messages = "/dev/tty3"
  1354.         iutil.execWithRedirect ("/bin/sh", ["/bin/sh", 
  1355.             "/tmp/ks-script" ], stdout = messages,
  1356.             stderr = messages, root = scriptRoot)
  1357.                     
  1358.         os.unlink(path)
  1359.  
  1360.         del syslog
  1361.         
  1362.         w.pop ()
  1363.  
  1364.