home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2000 July / CD 3 / redhat-6.2.iso / RedHat / instimage / usr / lib / anaconda / milo.py < prev    next >
Encoding:
Python Source  |  2000-03-08  |  5.0 KB  |  146 lines

  1. from lilo import LiloConfiguration
  2. import iutil
  3. import isys
  4. import string
  5. import os
  6.  
  7. def onMILO ():
  8.     try:
  9.         f = open ('/proc/cpuinfo', 'r')
  10.     except:
  11.         return
  12.     lines = f.readlines ()
  13.     serial = ""
  14.     for line in lines:
  15.         if string.find (line, "system serial number") >= 0:
  16.             serial = string.strip (string.split (line, ':')[1])
  17.  
  18.     if serial and len (serial) >= 4 and serial[0:4] == "MILO":
  19.         return 1
  20.     else:
  21.         return 0
  22.  
  23. def partitionNum (path):
  24.     i = 0
  25.     while path[i] not in string.digits:
  26.         i = i + 1
  27.     return string.atoi (path[i:])
  28.  
  29. def wholeDevice (path):
  30.     i = 0
  31.     while path[i] not in string.digits:
  32.         i = i + 1
  33.     return path[:i]
  34.  
  35. class MiloInstall:
  36.     def __init__ (self, todo):
  37.         self.todo = todo
  38.  
  39.     def writeAboot (self):
  40.         bootDevice = self.todo.fstab.getBootDevice ()
  41.         rootDevice = self.todo.fstab.getRootDevice ()[0]
  42.         if bootDevice != rootDevice:
  43.             confprefix = self.todo.instPath + "/boot/etc"
  44.             kernelprefix = '/'
  45.             try:
  46.                 os.mkdir (confprefix)
  47.             except:
  48.         pass
  49.             # XXX stat /etc/aboot.conf and do the right thing
  50.             try:
  51.         os.remove(self.todo.instPath + "/etc/aboot.conf")
  52.             except OSError:
  53.                 pass
  54.             os.symlink("../boot/etc/aboot.conf",
  55.                        self.todo.instPath + "/etc/aboot.conf")
  56.  
  57.         else:
  58.             confprefix = self.todo.instPath + "/etc"
  59.             kernelprefix = '/boot/'
  60.             
  61.         partition = partitionNum (bootDevice)
  62.         abootdev = wholeDevice (bootDevice)
  63.  
  64.         if os.access (confprefix + "/aboot.conf", os.R_OK):
  65.             os.rename (confprefix + "/aboot.conf",
  66.                        confprefix + "/aboot.conf.rpmsave")
  67.         f = open (confprefix + "/aboot.conf", 'w')
  68.         f.write ("# aboot default configurations\n")
  69.         if bootDevice != rootDevice:
  70.             f.write ("# NOTICE:  You have a /boot partition.  This means that\n")
  71.             f.write ("#          all kernel paths are relative to /boot/\n")
  72.  
  73.         lines = 0
  74.         for package, tag in (('kernel-smp', 'smp'), ('kernel', '')):
  75.             if (self.todo.hdList.has_key(package) and
  76.                 self.todo.hdList[package].selected):
  77.                 kernel = self.todo.hdList[package]
  78.                 version = "%s-%s" % (kernel['version'], kernel['release'])
  79.                 f.write ("%d:%d%svmlinuz-%s%s root=/dev/%s\n" %
  80.                          (lines, partition, kernelprefix, version, tag, rootDevice))
  81.                 lines = lines + 1
  82.  
  83.         f.close ()
  84.  
  85.         args = ("swriteboot", ("/dev/%s" % abootdev), "/boot/bootlx")
  86.         iutil.execWithRedirect('/sbin/swriteboot',
  87.                                args,
  88.                                stdout = None,
  89.                                root = self.todo.instPath)
  90.         
  91.         args = ("abootconf", ("/dev/%s" % abootdev), str (partition))
  92.         iutil.execWithRedirect('/sbin/abootconf',
  93.                                args,
  94.                                stdout = None,
  95.                                root = self.todo.instPath)
  96.     def writeMilo (self):
  97.         bootDevice = self.todo.fstab.getBootDevice ()
  98.         rootDevice = self.todo.fstab.getRootDevice ()[0]
  99.         
  100.         if bootDevice != rootDevice:
  101.             hasboot = 1
  102.             kernelroot = '/'
  103.             try:
  104.         os.remove(self.todo.instPath + "/etc/milo.conf")
  105.             except OSError:
  106.         pass
  107.             os.symlink("../boot/milo.conf",
  108.                        self.todo.instPath + "/etc/milo.conf")
  109.         else:
  110.             hasboot = 0
  111.             kernelroot = '/boot/'
  112.  
  113.         if os.access (self.todo.instPath + "/etc/milo.conf", os.R_OK):
  114.            os.rename (self.todo.instPath + "/etc/milo.conf",
  115.                       self.todo.instPath + "/etc/milo.conf.rpmsave")
  116.         f = open (self.todo.instPath + "/etc/milo.conf", "w")
  117.         if hasboot:
  118.             f.write ("# NOTICE:  You have a /boot partition.  This means that all\n")
  119.             f.write ("#          paths are relative to /boot/\n")
  120.  
  121.         kernels = []
  122.         for package, tag in (('kernel-smp', 'smp'), ('kernel', '')):
  123.             if (self.todo.hdList.has_key(package) and
  124.                 self.todo.hdList[package].selected):
  125.                 kernel = self.todo.hdList[package]
  126.                 version = "%s-%s" % (kernel['version'], kernel['release'])
  127.                 # if this is UP and we have a kernel (the smp kernel),
  128.                 # then call it linux-up
  129.                 if not tag and kernels:
  130.                     kernels.append ((version, "linux-up"))
  131.                 else:
  132.                     kernels.append ((version, "linux"))
  133.         for version, label in kernels:
  134.             f.write ("image=%svmlinuz-%s\n" % (kernelroot, version))
  135.             f.write ("\tlabel=%s\n" % label)
  136.             f.write ("\troot=/dev/%s" % rootDevice)
  137.                 
  138.     def write (self):
  139.         if onMILO ():
  140.             self.writeMilo ()
  141.         else:
  142.             self.writeAboot ()
  143.  
  144.         
  145.     
  146.