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 |
str = ("(s: '%s' i: %s c: %d)") % \ |
17 |
(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 |
sortPriority = 1 |
63 |
|
64 |
parentClass = ( _("Install SME Server"), "smeserver.png" ) |
65 |
|
66 |
def requiredDisplayMode(self): |
67 |
return 't' |
68 |
|
69 |
def setSteps(self, dispatch): |
70 |
dispatch.setStepList( |
71 |
"language", |
72 |
"keyboard", |
73 |
"findrootparts", |
74 |
#"betanag", |
75 |
"installtype", |
76 |
"partitionobjinit", |
77 |
"autopartitionexecute", |
78 |
"partition", |
79 |
"partitiondone", |
80 |
"bootloadersetup", |
81 |
"languagesupport", |
82 |
"timezone", |
83 |
"readcomps", |
84 |
"selectlangpackages", |
85 |
"checkdeps", |
86 |
"dependencies", |
87 |
"install", |
88 |
"enablefilesystems", |
89 |
"migratefilesystems", |
90 |
"setuptime", |
91 |
"preinstallconfig", |
92 |
"installpackages", |
93 |
"postinstallconfig", |
94 |
"writeconfig", |
95 |
"instbootloader", |
96 |
"dopostaction", |
97 |
"writeksconfig", |
98 |
"methodcomplete", |
99 |
"copylogs", |
100 |
"setfilecon", |
101 |
"complete" |
102 |
) |
103 |
|
104 |
# 'partition' can be used on the command line to force |
105 |
# verification of partitions. useful in some cases... |
106 |
cmdline = open("/proc/cmdline", "r").read() |
107 |
cmdline = cmdline.split() |
108 |
if "partition" in cmdline: |
109 |
dispatch.skipStep("partition", skip = 0) |
110 |
else: |
111 |
dispatch.skipStep("partition", skip = 1) |
112 |
|
113 |
def setDefaultPartitioning(self, partitions, clear = CLEARPART_TYPE_LINUX, doClear = 1): |
114 |
uniqueID = 100 |
115 |
(swapMin, swapMax) = iutil.swapSuggestion() |
116 |
diskset = partedUtils.DiskSet() |
117 |
drives = diskset.driveList() |
118 |
usedDrives = [] |
119 |
|
120 |
spares = 0 |
121 |
useable = 0 |
122 |
for drive in drives: |
123 |
if not isys.driveIsRemovable(drive): |
124 |
useable = useable + 1 |
125 |
|
126 |
if useable >= 1: |
127 |
if "noraid" in cmdline: |
128 |
for drive in drives: |
129 |
if not isys.driveIsRemovable(drive): |
130 |
filesystem = fileSystemTypeGet("ext3") |
131 |
request = partRequests.PartitionSpec(filesystem, mountpoint="/boot", drive=[drive], |
132 |
size=100, primary=1, format=1) |
133 |
partitions.autoPartitionRequests.append(request) |
134 |
usedDrives.append(drive); |
135 |
|
136 |
if "nolvm" in cmdline: |
137 |
filesystem = fileSystemTypeGet("ext3") |
138 |
request = partRequests.PartitionSpec(filesystem, mountpoint="/", drive=[drive], |
139 |
size=1300, grow=1, primary=1, format=1) |
140 |
partitions.autoPartitionRequests.append(request) |
141 |
|
142 |
filesystem = fileSystemTypeGet("swap") |
143 |
request = partRequests.PartitionSpec(filesystem, drive=[drive], size=swapMin, |
144 |
maxSizeMB=swapMax, grow=1, primary=1, format=1) |
145 |
partitions.autoPartitionRequests.append(request) |
146 |
|
147 |
else: |
148 |
filesystem = fileSystemTypeGet("physical volume (LVM)") |
149 |
request = partRequests.PartitionSpec(filesystem, drive=[drive], size=swapMin+1500, |
150 |
grow=1, primary=1, format=1) |
151 |
request.uniqueID = 200 |
152 |
partitions.autoPartitionRequests.append(request) |
153 |
|
154 |
break |
155 |
|
156 |
else: |
157 |
raid1 = [] |
158 |
raid2 = [] |
159 |
raid3 = [] |
160 |
|
161 |
if useable >= 3 and "nospare" not in cmdline: |
162 |
useable = useable - 1 |
163 |
spares = 1 |
164 |
|
165 |
if "raid1" in cmdline and useable >= 1: |
166 |
useable = 1 |
167 |
raidLevel = "RAID1" |
168 |
else: |
169 |
if useable >= 6: |
170 |
useable = useable - 2 |
171 |
raidLevel = "RAID6" |
172 |
elif useable >= 2: |
173 |
useable = useable - 1 |
174 |
if useable >= 2: |
175 |
raidLevel = "RAID5" |
176 |
else: |
177 |
raidLevel = "RAID1" |
178 |
else: |
179 |
raidLevel = "RAID1" |
180 |
|
181 |
for drive in drives: |
182 |
if not isys.driveIsRemovable(drive): |
183 |
filesystem = fileSystemTypeGet("software RAID") |
184 |
request = partRequests.PartitionSpec(filesystem, drive=[drive], size=100, primary=1, format=1) |
185 |
request.uniqueID = uniqueID |
186 |
raid1.append(uniqueID) |
187 |
partitions.autoPartitionRequests.append(request) |
188 |
usedDrives.append(drive); |
189 |
|
190 |
if "nolvm" in cmdline: |
191 |
filesystem = fileSystemTypeGet("software RAID") |
192 |
request = partRequests.PartitionSpec(filesystem, drive=[drive], size=swapMin/useable+10, |
193 |
maxSizeMB=swapMax/useable, grow=1, primary=1, format=1) |
194 |
request.uniqueID = uniqueID + 30 |
195 |
raid2.append(uniqueID + 30) |
196 |
partitions.autoPartitionRequests.append(request) |
197 |
|
198 |
filesystem = fileSystemTypeGet("software RAID") |
199 |
request = partRequests.PartitionSpec(filesystem, drive=[drive], size=1500/useable, |
200 |
grow=1, primary=1, format=1) |
201 |
request.uniqueID = uniqueID + 60 |
202 |
raid3.append(uniqueID + 60) |
203 |
partitions.autoPartitionRequests.append(request) |
204 |
|
205 |
else: |
206 |
filesystem = fileSystemTypeGet("software RAID") |
207 |
if "multipart" in cmdline: |
208 |
request = partRequests.PartitionSpec(filesystem, drive=[drive], size=(swapMin+3000)/useable, |
209 |
grow=1, format=1) |
210 |
else: |
211 |
request = partRequests.PartitionSpec(filesystem, drive=[drive], size=(swapMin+1500)/useable, |
212 |
grow=1, format=1) |
213 |
request.uniqueID = uniqueID + 50 |
214 |
raid2.append(uniqueID + 50) |
215 |
partitions.autoPartitionRequests.append(request) |
216 |
|
217 |
uniqueID = uniqueID + 1 |
218 |
|
219 |
if "raid1" in cmdline and len(raid1)-spares >= 2: |
220 |
break |
221 |
|
222 |
filesystem = fileSystemTypeGet("ext3") |
223 |
request = partRequests.RaidRequestSpec(filesystem, mountpoint="/boot", raidminor=1, |
224 |
raidmembers=raid1, raidlevel="RAID1", format=1, raidspares=spares) |
225 |
partitions.autoPartitionRequests.append(request) |
226 |
|
227 |
if "nolvm" in cmdline: |
228 |
filesystem = fileSystemTypeGet("swap") |
229 |
request = partRequests.RaidRequestSpec(filesystem, raidmembers=raid2, raidminor=2, |
230 |
raidlevel=raidLevel, format=1, raidspares=spares) |
231 |
partitions.autoPartitionRequests.append(request) |
232 |
|
233 |
filesystem = fileSystemTypeGet("ext3") |
234 |
request = partRequests.RaidRequestSpec(filesystem, mountpoint="/", raidmembers=raid3, raidminor=3, |
235 |
raidlevel=raidLevel, format=1, raidspares=spares) |
236 |
partitions.autoPartitionRequests.append(request) |
237 |
|
238 |
else: |
239 |
filesystem = fileSystemTypeGet("physical volume (LVM)") |
240 |
request = partRequests.RaidRequestSpec(filesystem, raidmembers=raid2, raidminor=2, |
241 |
raidlevel=raidLevel, format=1, raidspares=spares) |
242 |
request.uniqueID = 200 |
243 |
partitions.autoPartitionRequests.append(request) |
244 |
|
245 |
if not "nolvm" in cmdline: |
246 |
request = partRequests.VolumeGroupRequestSpec(vgname="main", physvols=[200], |
247 |
pesize=32768, format=1) |
248 |
request.uniqueID = 201 |
249 |
partitions.autoPartitionRequests.append(request) |
250 |
|
251 |
if "multipart" in cmdline: |
252 |
filesystem = fileSystemTypeGet("ext3") |
253 |
request = partRequests.LogicalVolumeRequestSpec(filesystem, mountpoint="/", size=2048, |
254 |
maxSizeMB=4096, volgroup=201, lvname="root", grow=1, format=1) |
255 |
partitions.autoPartitionRequests.append(request) |
256 |
|
257 |
filesystem = fileSystemTypeGet("ext3") |
258 |
request = partRequests.LogicalVolumeRequestSpec(filesystem, mountpoint="/var", size=1024, |
259 |
maxSizeMB=4096, volgroup=201, lvname="var", grow=1, format=1) |
260 |
partitions.autoPartitionRequests.append(request) |
261 |
|
262 |
filesystem = fileSystemTypeGet("ext3") |
263 |
request = partRequests.LogicalVolumeRequestSpec(filesystem, mountpoint="/home/e-smith/files", size=1024, |
264 |
maxSizeMB=8192, volgroup=201, lvname="files", grow=1, format=1) |
265 |
partitions.autoPartitionRequests.append(request) |
266 |
|
267 |
filesystem = fileSystemTypeGet("ext3") |
268 |
request = partRequests.LogicalVolumeRequestSpec(filesystem, mountpoint="/tmp", size=512, |
269 |
maxSizeMB=4096, volgroup=201, lvname="tmp", grow=1, format=1) |
270 |
partitions.autoPartitionRequests.append(request) |
271 |
|
272 |
filesystem = fileSystemTypeGet("swap") |
273 |
request = partRequests.LogicalVolumeRequestSpec(filesystem, size=swapMin, maxSizeMB=swapMax, |
274 |
volgroup=201, lvname="swap", grow=1, format=1) |
275 |
partitions.autoPartitionRequests.append(request) |
276 |
else: |
277 |
filesystem = fileSystemTypeGet("ext3") |
278 |
request = partRequests.LogicalVolumeRequestSpec(filesystem, mountpoint="/", size=1300, |
279 |
volgroup=201, lvname="root", grow=1, format=1) |
280 |
partitions.autoPartitionRequests.append(request) |
281 |
|
282 |
filesystem = fileSystemTypeGet("swap") |
283 |
request = partRequests.LogicalVolumeRequestSpec(filesystem, size=swapMin, maxSizeMB=swapMax, |
284 |
volgroup=201, lvname="swap", grow=1, format=1) |
285 |
partitions.autoPartitionRequests.append(request) |
286 |
|
287 |
partitions.autoClearPartDrives = usedDrives |
288 |
else: |
289 |
BaseInstallClass.setDefaultPartitioning(self, partitions, clear, doClear) |
290 |
|
291 |
def setAsHeadless(self, dispatch, isHeadless = 0): |
292 |
if isHeadless == 0: |
293 |
pass |
294 |
else: |
295 |
dispatch.skipStep("handleX11pkgs", permanent = 1) |
296 |
dispatch.skipStep("videocard", permanent = 1) |
297 |
dispatch.skipStep("monitor", permanent = 1) |
298 |
dispatch.skipStep("xcustom", permanent = 1) |
299 |
dispatch.skipStep("writexconfig", permanent = 1) |
300 |
|
301 |
def setGroupSelection(self, grpset, intf): |
302 |
grpset.unselectAll() |
303 |
grpset.selectGroup("Base") |
304 |
|
305 |
def postAction(self, rootPath, serial, intf): |
306 |
win = intf.waitWindow(_("Post Install Script"), |
307 |
_("The post installation script is running...")) |
308 |
|
309 |
script = ( "/sbin/syslogd &\n" |
310 |
"sleep 2\n" |
311 |
"/sbin/e-smith/signal-event post-install\n" ) |
312 |
s = Script(script, interp="/bin/sh", inChroot=1) |
313 |
log("%s", s) |
314 |
s.run(rootPath, serial) |
315 |
win.pop() |
316 |
|
317 |
def setInstallData(self, id, intf = None): |
318 |
BaseInstallClass.setInstallData(self, id) |
319 |
self.setAuthentication(id, useShadow=1, salt="md5") |
320 |
self.setRootPassword(id, pw="ThisIsGoingToBeDisabledAnyway", isCrypted=0) |
321 |
self.setZeroMbr(id, zeroMbr=1) |
322 |
self.setClearParts(id, clear=CLEARPART_TYPE_ALL, initAll=1) |
323 |
self.setDefaultPartitioning(id.partitions, doClear=0) |
324 |
self.setBootloader(id, useLilo=0, location="mbr", linear=1) |
325 |
|
326 |
def __init__(self, expert): |
327 |
BaseInstallClass.__init__(self, expert) |