/[smeserver]/cdrom.image/sme7/product/installclasses/smeinstallclass.py
ViewVC logotype

Annotation of /cdrom.image/sme7/product/installclasses/smeinstallclass.py

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.5 - (hide annotations) (download) (as text)
Mon Nov 30 23:46:26 2009 UTC (15 years ago) by slords
Branch: MAIN
Changes since 1.4: +18 -9 lines
Content type: text/x-python
Lower requirements for minimum drive size

1 slords 1.1 from installclass import BaseInstallClass
2     from rhpl.translate import N_, _
3     from constants import *
4     import os
5     import iutil
6     from fsset import *
7    
8     from autopart import getAutopartitionBoot, autoCreatePartitionRequests, autoCreateLVMPartitionRequests
9     from rhpl.log import log
10     import string
11     import partRequests
12     import partedUtils
13    
14     class Script:
15     def __repr__(self):
16 slords 1.3 str = ("(s: '%s' i: %s c: %d)") % \
17 slords 1.1 (self.script, self.interp, self.inChroot)
18     return string.replace(str, "\n", "|")
19    
20     def __init__(self, script, interp, inChroot, logfile = None):
21     self.script = script
22     self.interp = interp
23     self.inChroot = inChroot
24     self.logfile = logfile
25    
26     def run(self, chroot, serial):
27     scriptRoot = "/"
28     if self.inChroot:
29     scriptRoot = chroot
30    
31     path = scriptRoot + "/tmp/sme-script"
32    
33     f = open(path, "w")
34     f.write(self.script)
35     f.close()
36     os.chmod(path, 0700)
37    
38     if self.logfile is not None:
39     messages = self.logfile
40     elif serial:
41     messages = "/tmp/sme-script.log"
42     else:
43     messages = "/dev/tty3"
44    
45     rc = iutil.execWithRedirect(self.interp,
46     [self.interp,"/tmp/sme-script"],
47     stdout = messages, stderr = messages,
48     root = scriptRoot)
49    
50     if rc != 0:
51     log("WARNING - Error code %s encountered running a sme script", rc)
52    
53     os.unlink(path)
54    
55     class InstallClass(BaseInstallClass):
56     id = "smeserver"
57     name = N_("New _SME Server Install")
58     pixmap = "smeserver.png"
59     description = N_("This option performs a new install of "
60     "SME Server. All attached hard drives "
61     "will be repartitioned and formated.")
62 slords 1.2
63 slords 1.1 sortPriority = 1
64 slords 1.3 doPartition = False
65 slords 1.2 cmdline = {}
66 slords 1.1
67     parentClass = ( _("Install SME Server"), "smeserver.png" )
68    
69     def requiredDisplayMode(self):
70     return 't'
71    
72 slords 1.2 def createCmdlineDict(self):
73     cmdlineDict = {}
74     cmdline = open("/proc/cmdline", "r").read().strip()
75    
76     for i in cmdline.split():
77     try:
78     (key, val) = i.split("=", 1)
79     except:
80     key = i
81     val = True
82    
83     cmdlineDict[key] = val
84    
85     return cmdlineDict
86    
87     def mediaPresent(self, device):
88     try:
89     fd = os.open("/dev/%s" % device, os.O_RDONLY)
90     except OSError, (errno, strerror):
91     # error 123 = No medium found
92     if errno == 123:
93     return False
94     else:
95     return True
96     else:
97     os.close(fd)
98     return True
99    
100 slords 1.1 def setSteps(self, dispatch):
101     dispatch.setStepList(
102     "language",
103     "keyboard",
104     "findrootparts",
105     "betanag",
106     "installtype",
107     "partitionobjinit",
108     "autopartitionexecute",
109     "partition",
110     "partitiondone",
111 slords 1.2 "bootloadersetup",
112 slords 1.1 "languagesupport",
113     "timezone",
114     "readcomps",
115     "selectlangpackages",
116     "checkdeps",
117     "dependencies",
118     "install",
119     "enablefilesystems",
120     "migratefilesystems",
121     "setuptime",
122     "preinstallconfig",
123     "installpackages",
124     "postinstallconfig",
125     "writeconfig",
126     "instbootloader",
127     "dopostaction",
128     "writeksconfig",
129     "methodcomplete",
130     "copylogs",
131     "setfilecon",
132     "complete"
133     )
134    
135 slords 1.2 # 'partition' can be used on the command line to force
136 slords 1.1 # verification of partitions. useful in some cases...
137 slords 1.2 if self.doPartition or self.cmdline.has_key("partition"):
138 slords 1.1 dispatch.skipStep("partition", skip = 0)
139     else:
140     dispatch.skipStep("partition", skip = 1)
141    
142     def setDefaultPartitioning(self, partitions, clear = CLEARPART_TYPE_LINUX, doClear = 1):
143 slords 1.2 self.cmdline = self.createCmdlineDict()
144 slords 1.1 diskset = partedUtils.DiskSet()
145    
146 slords 1.4 if self.cmdline.has_key("exclude"):
147     alldrives = filter(lambda x:not x in self.cmdline["exclude"].split(","), diskset.driveList())
148     else:
149     alldrives = diskset.driveList()
150    
151 slords 1.2 if self.cmdline.has_key("drives"):
152 slords 1.4 if self.cmdline["drives"] == "all":
153     drives = filter(lambda x:self.mediaPresent(x), alldrives)
154     else:
155     drives = filter(lambda x:self.mediaPresent(x) and
156     x in self.cmdline["drives"].split(","), alldrives)
157 slords 1.2 else:
158     drives = filter(lambda x:not isys.driveIsRemovable(x) and
159     self.mediaPresent(x) and
160     not isys.driveUsesModule(x, ["usb-storage", "ub", "sbp2"]), alldrives)
161 slords 1.1
162 slords 1.2 if self.cmdline.has_key("spares"):
163 slords 1.4 if self.cmdline["spares"] == "none":
164     spares = 0
165     else:
166     try:
167     spares = max(0,min(int(self.cmdline["spares"]),len(drives)-2))
168     except:
169     spares = (len(drives)+4)/7
170 slords 1.2 else:
171     spares = (len(drives)+4)/7
172 slords 1.1
173 slords 1.2 if self.cmdline.has_key("raid") and self.cmdline["raid"] in ["none","0","1","5","6"]:
174     if self.cmdline["raid"] == "none":
175     level = 0
176     else:
177     level = int(self.cmdline["raid"])
178     if level == 0:
179     del drives[1:]
180     spares = 0
181     if level == 6 and len(drives)-spares < 4:
182     level = 5
183     if level == 5 and len(drives)-spares < 3:
184     level = 1
185     if level == 1:
186     if spares > 1 and not self.cmdline.has_key("spares"):
187     spares = 1
188     del drives[2+spares:]
189     else:
190     if len(drives) - spares >= 6:
191     level = 6
192     elif len(drives) - spares >= 3:
193     level = 5
194     else:
195     level = 1
196 slords 1.1
197 slords 1.2 if len(drives) >= 1:
198 slords 1.4 excluded = filter(lambda x:x not in drives, diskset.driveList())
199 slords 1.2 log("Using the following drives: %s" % drives)
200 slords 1.4 log("Excluding the following drives: %s" % excluded)
201 slords 1.2 if level >= 1:
202     log("Installing using RAID%s" % level)
203     log("Using %s spare drives" % spares)
204 slords 1.1 else:
205 slords 1.2 log("Installing without using RAID")
206    
207     (swapMin, swapMax) = iutil.swapSuggestion()
208     if level >= 1:
209 slords 1.1 raid1 = []
210     raid2 = []
211     raid3 = []
212 slords 1.2 uniqueID = 100
213 slords 1.1
214 slords 1.2 for drive in drives:
215     request = partRequests.PartitionSpec(fileSystemTypeGet("software RAID"),
216     drive=[drive], size=100, primary=1, format=1)
217     request.uniqueID = uniqueID
218     raid1.append(uniqueID)
219     partitions.autoPartitionRequests.append(request)
220 slords 1.1
221 slords 1.2 if not self.cmdline.has_key("nolvm"):
222 slords 1.5 if not self.cmdline.has_key("multipart"):
223     request = partRequests.PartitionSpec(fileSystemTypeGet("software RAID"),
224     size=(swapMin+1536)/(len(drives)-spares-max(0,level-4)),
225     drive=[drive], primary=1, grow=1, format=1)
226     else:
227     request = partRequests.PartitionSpec(fileSystemTypeGet("software RAID"),
228     size=(swapMin+5120)/(len(drives)-spares-max(0,level-4)),
229     drive=[drive], primary=1, grow=1, format=1)
230 slords 1.2 request.uniqueID = uniqueID + 50
231     raid2.append(uniqueID + 50)
232     partitions.autoPartitionRequests.append(request)
233 slords 1.1 else:
234 slords 1.2 request = partRequests.PartitionSpec(fileSystemTypeGet("software RAID"),
235     drive=[drive], size=swapMin/(len(drives)-spares-max(0,level-4))+10, grow=1,
236     maxSizeMB=swapMax/(len(drives)-spares-max(0,level-4)), format=1, primary=1)
237     request.uniqueID = uniqueID + 30
238     raid2.append(uniqueID + 30)
239     partitions.autoPartitionRequests.append(request)
240 slords 1.1
241 slords 1.2 request = partRequests.PartitionSpec(fileSystemTypeGet("software RAID"),
242 slords 1.5 size=1536/(len(drives)-spares-max(0,level-4)),
243 slords 1.2 drive=[drive], grow=1, primary=1, format=1)
244     request.uniqueID = uniqueID + 60
245     raid3.append(uniqueID + 60)
246 slords 1.1 partitions.autoPartitionRequests.append(request)
247    
248 slords 1.2 uniqueID = uniqueID + 1
249 slords 1.1
250 slords 1.2 partitions.autoPartitionRequests.append(partRequests.RaidRequestSpec(fileSystemTypeGet("ext3"),
251     mountpoint="/boot", raidmembers=raid1, raidlevel="RAID1", raidminor=1, format=1,
252     raidspares=0))
253    
254     if not self.cmdline.has_key("nolvm"):
255     request = partRequests.RaidRequestSpec(fileSystemTypeGet("physical volume (LVM)"),
256     raidmembers=raid2, raidlevel="RAID"+str(level), raidminor=2, format=1,
257     raidspares=spares)
258     request.uniqueID = 200
259 slords 1.1 partitions.autoPartitionRequests.append(request)
260 slords 1.2 else:
261     partitions.autoPartitionRequests.append(partRequests.RaidRequestSpec(fileSystemTypeGet("swap"),
262     raidmembers=raid2, raidlevel="RAID"+str(level), raidminor=2, format=1, raidspares=spares))
263 slords 1.1
264 slords 1.2 partitions.autoPartitionRequests.append(partRequests.RaidRequestSpec(fileSystemTypeGet("ext3"),
265 slords 1.3 mountpoint="/", raidmembers=raid3, raidlevel="RAID"+str(level), raidminor=3, format=1,
266 slords 1.2 raidspares=spares))
267    
268     else:
269     for drive in drives:
270     partitions.autoPartitionRequests.append(partRequests.PartitionSpec(fileSystemTypeGet("ext3"),
271 slords 1.3 mountpoint="/boot", drive=[drive], size=100, primary=1, format=1))
272 slords 1.2
273     if not self.cmdline.has_key("nolvm"):
274 slords 1.5 if not self.cmdline.has_key("multipart"):
275     request = partRequests.PartitionSpec(fileSystemTypeGet("physical volume (LVM)"),
276     drive=[drive], size=swapMin+1536, grow=1, primary=1, format=1)
277     else:
278     request = partRequests.PartitionSpec(fileSystemTypeGet("physical volume (LVM)"),
279     drive=[drive], size=swapMin+5120, grow=1, primary=1, format=1)
280 slords 1.2 request.uniqueID = 200
281     partitions.autoPartitionRequests.append(request)
282     else:
283     partitions.autoPartitionRequests.append(partRequests.PartitionSpec(fileSystemTypeGet("ext3"),
284 slords 1.5 mountpoint="/", drive=[drive], size=1536, grow=1, primary=1, format=1))
285 slords 1.1
286 slords 1.2 partitions.autoPartitionRequests.append(partRequests.PartitionSpec(fileSystemTypeGet("swap"),
287     drive=[drive], size=swapMin, maxSizeMB=swapMax, grow=1, primary=1, format=1))
288 slords 1.1
289 slords 1.2 if not self.cmdline.has_key("nolvm"):
290     request = partRequests.VolumeGroupRequestSpec(vgname="main", physvols=[200], pesize=32768, format=1)
291 slords 1.1 request.uniqueID = 201
292     partitions.autoPartitionRequests.append(request)
293    
294 slords 1.2 if not self.cmdline.has_key("multipart"):
295     partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("ext3"),
296 slords 1.5 mountpoint="/", size=1536, volgroup=201, lvname="root", grow=1, format=1))
297 slords 1.1
298 slords 1.2 partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("swap"),
299     size=swapMin, maxSizeMB=swapMax, volgroup=201, lvname="swap", grow=1, format=1))
300     else:
301     partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("ext3"),
302     mountpoint="/", size=2048, maxSizeMB=4096, volgroup=201, lvname="root", grow=1, format=1))
303 slords 1.1
304 slords 1.2 partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("ext3"),
305     mountpoint="/var", size=1024, maxSizeMB=4096, volgroup=201, lvname="var", grow=1, format=1))
306 slords 1.1
307 slords 1.2 partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("ext3"),
308     mountpoint="/home/e-smith/files", size=1024, maxSizeMB=8192, volgroup=201, lvname="files", grow=1, format=1))
309 slords 1.1
310 slords 1.2 partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("ext3"),
311 slords 1.5 mountpoint="/tmp", size=1024, maxSizeMB=4096, volgroup=201, lvname="tmp", grow=1, format=1))
312 slords 1.1
313 slords 1.2 partitions.autoPartitionRequests.append(partRequests.LogicalVolumeRequestSpec(fileSystemTypeGet("swap"),
314     size=swapMin, maxSizeMB=swapMax, volgroup=201, lvname="swap", grow=1, format=1))
315 slords 1.1
316 slords 1.2 partitions.autoClearPartType = CLEARPART_TYPE_ALL
317     partitions.autoClearPartDrives = drives
318     self.doPartition = False
319 slords 1.1 else:
320 slords 1.2 log("Not useable drives found. Enabling manual partitioning.")
321     self.doPartition = True
322 slords 1.1 BaseInstallClass.setDefaultPartitioning(self, partitions, clear, doClear)
323    
324     def setAsHeadless(self, dispatch, isHeadless = 0):
325     if isHeadless == 0:
326     pass
327     else:
328     dispatch.skipStep("handleX11pkgs", permanent = 1)
329     dispatch.skipStep("videocard", permanent = 1)
330     dispatch.skipStep("monitor", permanent = 1)
331     dispatch.skipStep("xcustom", permanent = 1)
332     dispatch.skipStep("writexconfig", permanent = 1)
333    
334     def setGroupSelection(self, grpset, intf):
335     grpset.unselectAll()
336     grpset.selectGroup("Base")
337    
338     def postAction(self, rootPath, serial, intf):
339     win = intf.waitWindow(_("Post Install Script"),
340     _("The post installation script is running..."))
341    
342     script = ( "/sbin/syslogd &\n"
343     "sleep 2\n"
344     "/sbin/e-smith/signal-event post-install\n" )
345     s = Script(script, interp="/bin/sh", inChroot=1)
346     log("%s", s)
347     s.run(rootPath, serial)
348     win.pop()
349    
350     def setInstallData(self, id, intf = None):
351     BaseInstallClass.setInstallData(self, id)
352     self.setAuthentication(id, useShadow=1, salt="md5")
353     self.setRootPassword(id, pw="ThisIsGoingToBeDisabledAnyway", isCrypted=0)
354     self.setZeroMbr(id, zeroMbr=1)
355     self.setClearParts(id, clear=CLEARPART_TYPE_ALL, initAll=1)
356     self.setDefaultPartitioning(id.partitions, doClear=0)
357     self.setBootloader(id, useLilo=0, location="mbr", linear=1)
358    
359     def __init__(self, expert):
360     BaseInstallClass.__init__(self, expert)

admin@koozali.org
ViewVC Help
Powered by ViewVC 1.2.1 RSS 2.0 feed