from installclass import BaseInstallClass from rhpl.translate import N_, _ from constants import * import os import iutil from fsset import * from flags import flags from autopart import getAutopartitionBoot, autoCreatePartitionRequests, autoCreateLVMPartitionRequests import logging log = logging.getLogger("anaconda") import string import partRequests import partedUtils class Script: def __repr__(self): str = ("(s: '%s' i: %s c: %d)") % \ (self.script, self.interp, self.inChroot) return string.replace(str, "\n", "|") def __init__(self, script, interp, inChroot, logfile = None): self.script = script self.interp = interp self.inChroot = inChroot self.logfile = logfile def run(self, chroot, serial): import tempfile import os.path if self.inChroot: scriptRoot = chroot else: scriptRoot = "/" (fd, path) = tempfile.mkstemp("", "sme-script-", scriptRoot + "/tmp") os.write(fd, self.script) os.close(fd) os.chmod(path, 0700) if self.logfile is not None: messages = self.logfile elif serial: messages = "%s.log" % path else: messages = "/dev/tty3" rc = iutil.execWithRedirect(self.interp, ["/tmp/%s" % os.path.basename(path)], stdin = messages, stdout = messages, stderr = messages, root = scriptRoot) if rc != 0: log.error("WARNING - Error code %s encountered running a sme script", rc) os.unlink(path) if serial or self.logfile is not None: os.chmod("%s" % messages, 0600) class InstallClass(BaseInstallClass): id = "smeserver" name = N_("New _SME Server Install") pixmap = "smeserver.png" description = N_("This option performs a new install of " "SME Server. All hard drives, including " "removable media, will be repartitioned and formated.") sortPriority = 1 parentClass = ( _("Install SME Server"), "smeserver.png" ) def requiredDisplayMode(self): return 't' def setSteps(self, dispatch): dispatch.setStepList( "betanag", "language", "keyboard", "findrootparts", "partitionobjinit", "autopartitionexecute", "partitiondone", "bootloadersetup", "timezone", "reposetup", "basepkgsel", "postselection", "confirminstall", "install", "enablefilesystems", "migratefilesystems", "setuptime", "preinstallconfig", "installpackages", "postinstallconfig", "writeconfig", "instbootloader", "writeksconfig", "setfilecon", "copylogs", "methodcomplete", "dopostaction", "complete" ) dispatch.skipStep("bootloader", permanent = 1) # 'partition' can be used on the command line to force # verification of partitions. useful in some cases... dispatch.skipStep("partition", skip = (1,0)[flags.cmdline.has_key("partition")]) def setDefaultPartitioning(self, partitions, clear = CLEARPART_TYPE_LINUX, doClear = 1): diskset = self.anaconda.id.diskset if flags.cmdline.has_key("exclude"): alldrives = filter(lambda x:not (partedUtils.hasProtectedPartitions(x, self.anaconda) or x in flags.cmdline["exclude"].split(",")), diskset.disks.keys()) else: alldrives = filter(lambda x:not partedUtils.hasProtectedPartitions(x, self.anaconda), diskset.disks.keys()) if flags.cmdline.has_key("drives"): if flags.cmdline["drives"] == "all": drives = alldrives else: drives = filter(lambda x:x in flags.cmdline["drives"].split(","), alldrives) else: drives = filter(lambda x:not isys.driveUsesModule(x, ["usb-storage", "ub", "sbp2"]), alldrives) if flags.cmdline.has_key("spares"): if flags.cmdline["spares"] == "none": spares = 0 else: try: spares = max(0,min(int(flags.cmdline["spares"]),len(drives)-2)) except: spares = (len(drives)+4)/7 else: spares = (len(drives)+4)/7 if flags.cmdline.has_key("raid") and flags.cmdline["raid"] in ["none","0","1","5","6"]: if flags.cmdline["raid"] == "none": level = 0 else: level = int(flags.cmdline["raid"]) if level == 0: del drives[1:] spares = 0 if level == 6 and len(drives)-spares < 4: level = 5 if level == 5 and len(drives)-spares < 3: level = 1 if level == 1: if spares > 1 and not flags.cmdline.has_key("spares"): spares = 1 del drives[2+spares:] elif len(drives) > 1 and len(drives) == len(filter(lambda x:x.startswith('mapper/'), alldrives)): level = -1 del drives[1:] spares = 0 else: if len(drives) - spares >= 6: level = 6 elif len(drives) - spares >= 3: level = 5 else: level = 1 if len(drives) >= 1: log.info("Using the following drives: %s" % drives) excluded = filter(lambda x:x not in drives, diskset.disks.keys()) if excluded: log.info("Excluding the following drives: %s" % excluded) skipped = filter(lambda x:x not in diskset.disks.keys(), diskset.driveList()) if skipped: log.info("Skipping the following drives: %s" % skipped) if level >= 1: log.info("Installing using RAID%s" % level) log.info("Using %s spare drives" % spares) elif level < 0: log.warning("Detected BIOS raid (skipping raid)") else: log.warning("Installing without using RAID") fstype = "ext3" if flags.cmdline.has_key("ext4"): fstype = "ext4" (swapMin, swapMax) = iutil.swapSuggestion() if level >= 1: raid1 = [] raid2 = [] raid3 = [] uniqueID = 100 for drive in drives: request = partRequests.PartitionSpec(fileSystemTypeGet("software RAID"), drive=[drive], size=100, primary=1, format=1) request.uniqueID = uniqueID raid1.append(uniqueID) partitions.autoPartitionRequests.append(request) if not flags.cmdline.has_key("nolvm"): if not flags.cmdline.has_key("multipart"): request = partRequests.PartitionSpec(fileSystemTypeGet("software RAID"), size=(swapMin+1536)/(len(drives)-spares-max(0,level-4)), drive=[drive], primary=1, grow=1, format=1) else: request = partRequests.PartitionSpec(fileSystemTypeGet("software RAID"), size=(swapMin+5120)/(len(drives)-spares-max(0,level-4)), drive=[drive], primary=1, grow=1, format=1) request.uniqueID = uniqueID + 50 raid2.append(uniqueID + 50) partitions.autoPartitionRequests.append(request) else: request = partRequests.PartitionSpec(fileSystemTypeGet("software RAID"), drive=[drive], size=swapMin/(len(drives)-spares-max(0,level-4))+10, grow=1, maxSizeMB=swapMax/(len(drives)-spares-max(0,level-4)), format=1, primary=1) request.uniqueID = uniqueID + 30 raid2.append(uniqueID + 30) partitions.autoPartitionRequests.append(request) request = partRequests.PartitionSpec(fileSystemTypeGet("software RAID"), size=1536/(len(drives)-spares-max(0,level-4)), drive=[drive], grow=1, primary=1, format=1) request.uniqueID = uniqueID + 60 raid3.append(uniqueID + 60) partitions.autoPartitionRequests.append(request) uniqueID = uniqueID + 1 partitions.autoPartitionRequests.append(partRequests.RaidRequestSpec(fileSystemTypeGet("ext3"), mountpoint="/boot", raidmembers=raid1, raidlevel="RAID1", raidminor=1, format=1, raidspares=0)) if not flags.cmdline.has_key("nolvm"): request = partRequests.RaidRequestSpec(fileSystemTypeGet("physical volume (LVM)"), raidmembers=raid2, raidlevel="RAID"+str(level), raidminor=2, format=1, raidspares=spares) request.uniqueID = 200 partitions.autoPartitionRequests.append(request) else: partitions.autoPartitionRequests.append(partRequests.RaidRequestSpec(fileSystemTypeGet("swap"), raidmembers=raid2, raidlevel="RAID"+str(level), raidminor=2, format=1, raidspares=spares)) partitions.autoPartitionRequests.append(partRequests.RaidRequestSpec(fileSystemTypeGet(fstype), mountpoint="/", raidmembers=raid3, raidlevel="RAID"+str(level), raidminor=3, format=1, raidspares=spares)) else: for drive in drives: partitions.autoPartitionRequests.append(partRequests.PartitionSpec(fileSystemTypeGet("ext3"), mountpoint="/boot", drive=[drive], size=100, primary=1, format=1)) if not flags.cmdline.has_key("nolvm"): if not flags.cmdline.has_key("multipart"): request = partRequests.PartitionSpec(fileSystemTypeGet("physical volume (LVM)"), drive=[drive], size=swapMin+1536, grow=1, primary=1, format=1) else: request = partRequests.PartitionSpec(fileSystemTypeGet("physical volume (LVM)"), drive=[drive], size=swapMin+5120, grow=1, primary=1, format=1) request.uniqueID = 200 partitions.autoPartitionRequests.append(request) else: partitions.autoPartitionRequests.append(partRequests.PartitionSpec(fileSystemTypeGet(fstype), mountpoint="/", drive=[drive], size=1536, grow=1, primary=1, format=1)) partitions.autoPartitionRequests.append(partRequests.PartitionSpec(fileSystemTypeGet("swap"), drive=[drive], size=swapMin, maxSizeMB=swapMax, grow=1, primary=1, format=1)) if not flags.cmdline.has_key("nolvm"): request = partRequests.VolumeGroupRequestSpec(vgname="main", physvols=[200], pesize=32768, format=1) request.uniqueID = 201 partitions.autoPartitionRequests.append(request) if not flags.cmdline.has_key("multipart"): partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet(fstype), mountpoint="/", size=1536, volgroup=201, lvname="root", grow=1, format=1)) partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("swap"), size=swapMin, maxSizeMB=swapMax, volgroup=201, lvname="swap", grow=1, format=1)) else: partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet(fstype), mountpoint="/", size=2048, maxSizeMB=4096, volgroup=201, lvname="root", grow=1, format=1)) partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet(fstype), mountpoint="/var", size=1024, maxSizeMB=4096, volgroup=201, lvname="var", grow=1, format=1)) partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet(fstype), mountpoint="/home/e-smith/files", size=1024, maxSizeMB=8192, volgroup=201, lvname="files", grow=1, format=1)) partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet(fstype), mountpoint="/tmp", size=1024, maxSizeMB=4096, volgroup=201, lvname="tmp", grow=1, format=1)) partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("swap"), size=swapMin, maxSizeMB=swapMax, volgroup=201, lvname="swap", grow=1, format=1)) partitions.autoClearPartType = CLEARPART_TYPE_ALL partitions.autoClearPartDrives = drives else: log.warning("Not useable drives found. Enabling manual partitioning.") BaseInstallClass.setDefaultPartitioning(self, partitions, clear = CLEARPART_TYPE_ALL, doClear = True) self.anaconda.dispatch.skipStep("parttype", skip = 0) self.anaconda.dispatch.skipStep("partition", skip = 0) def setAsHeadless(self, dispatch, isHeadless = 0): if isHeadless == 0: pass else: dispatch.skipStep("handleX11pkgs", permanent = 1) dispatch.skipStep("videocard", permanent = 1) dispatch.skipStep("monitor", permanent = 1) dispatch.skipStep("xcustom", permanent = 1) dispatch.skipStep("writexconfig", permanent = 1) def postAction(self, anaconda, serial): win = anaconda.intf.waitWindow(_("Post Install Script"), _("The post installation script is running...")) script = ( "#!/bin/sh\nmkdir -p /var/lib/dhcp; /sbin/syslogd ; sleep 2; /sbin/e-smith/signal-event post-install\n" ) s = Script(script, interp="/bin/sh", inChroot=1) log.info("%s", s) s.run(anaconda.rootPath, serial) win.pop() def setInstallData(self, anaconda): BaseInstallClass.setInstallData(self, anaconda) self.anaconda = anaconda self.setSELinux(anaconda.id, SELINUX_DISABLED) def setGroupSelection(self, anaconda): BaseInstallClass.__init__(self, anaconda.backend) anaconda.backend.selectGroup("Base") anaconda.backend.selectGroup("Core") anaconda.backend.selectGroup("Extras") anaconda.backend.selectGroup("SME Server") def __init__(self, expert): BaseInstallClass.__init__(self, expert) self.repopaths = { "base": "%s" %(productPath,) } self.forceTextMode = 1