/[gli]/trunk/src/GLIArchitectureTemplate.py
Gentoo

Contents of /trunk/src/GLIArchitectureTemplate.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 235 - (show annotations) (download) (as text)
Fri Jan 14 06:31:08 2005 UTC (12 years, 11 months ago) by codeman
File MIME type: text/x-python
File size: 27918 byte(s)
Added lilo code and cleaned up lilo code.  also do_partitioning renamed to partition

1 """
2 Gentoo Linux Installer
3
4 $Id: GLIArchitectureTemplate.py,v 1.33 2005/01/14 06:31:08 codeman Exp $
5 Copyright 2004 Gentoo Technologies Inc.
6
7
8 The ArchitectureTemplate is largely meant to be an abstract class and an
9 interface (yes, it is both at the same time!). The purpose of this is to create
10 subclasses that populate all the methods with working methods for that architecture.
11 The only definitions that are filled in here are architecture independent.
12
13 """
14
15 import GLIUtility, os, string, sys, shutil, re
16 from GLIException import *
17 # Until I switch my partition code to GLIUtility.spawn()
18 import commands
19
20 class ArchitectureTemplate:
21 def __init__(self,configuration=None, install_profile=None, client_controller=None):
22 self._client_configuration = configuration
23 self._install_profile = install_profile
24 self._cc = client_controller
25
26 # This will get used a lot, so it's probably
27 # better to store it in a variable than to call
28 # this method 100000 times.
29 self._chroot_dir = self._client_configuration.get_root_mount_point()
30
31 # These must be filled in by the subclass. _steps is a list of
32 # functions, that will carry out the installation. They must be
33 # in order.
34 #
35 # For example, self._steps might be: [preinstall, stage1, stage2, stage3, postinstall],
36 # where each entry is a function (with no arguments) that carries out the desired actions.
37 # Of course, steps will be different depending on the install_profile
38
39 self._architecture_name = "generic"
40 #self._install_steps = [ (self.partition, "Partition"), TEMPORARY thing only.
41 self._install_steps = [
42 (self.mount_local_partitions, "Mount local partitions"),
43 (self.mount_network_shares, "Mount network (NFS) shares"),
44 (self.unpack_stage_tarball, "Unpack stage tarball"),
45 (self.configure_make_conf, "Configure /etc/make.conf"),
46 (self.set_root_password, "Set the root password"),
47 (self.install_portage_tree, "Portage tree voodoo"),
48 (self.prepare_chroot, "Preparing chroot"),
49 (self.stage1, "Performing bootstrap"),
50 (self.stage2, "Performing 'emerge system'"),
51 (self.set_timezone, "Setting timezone"),
52 (self.emerge_kernel_sources, "Emerge kernel sources"),
53 (self.build_kernel, "Building kernel"),
54 (self.install_logging_daemon, "Logger"),
55 (self.install_cron_daemon, "Cron daemon"),
56 (self.install_filesystem_tools, "Installing filesystem tools"),
57 (self.setup_network_post, "Configuring post-install networking"),
58 (self.install_bootloader, "Configuring and installing bootloader"),
59 (self.update_config_files, "Updating config files"),
60 (self.configure_rc_conf, "Updating /etc/rc.conf"),
61 (self.set_users, "Add additional users.")
62 ]
63
64
65 def get_install_steps(self):
66 return self._install_steps
67
68 def notify_frontend(self, type, data):
69 self._cc.addNotification(type, data)
70
71 # It is possible to override these methods in each Arch Template.
72 # It might be necessary to do so, if the arch needs something 'weird'.
73
74 def _add_to_runlevel(self, script_name, runlevel="default"):
75 "Adds the script named 'script_name' to the runlevel 'runlevel' in the chroot environement"
76
77 # Do it
78 status = GLIUtility.spawn("rc-update add " + script_name + " " + runlevel, chroot=self._chroot_dir)
79 if not GLIUtility.exitsuccess(status):
80 raise GLIException("RunlevelAddError", 'warning', '_add_to_runlevel', "Failure adding " + script_name + " to runlevel " + runlevel + "!")
81
82 def _emerge(self, package, binary=False, binary_only=False):
83 if binary_only:
84 return GLIUtility.spawn("emerge -K " + package, display_on_tty8=True, chroot=self._chroot_dir)
85 elif binary:
86 return GLIUtility.spawn("emerge -k " + package, display_on_tty8=True, chroot=self._chroot_dir)
87 else:
88 return GLIUtility.spawn("emerge " + package, display_on_tty8=True, chroot=self._chroot_dir)
89
90 def _edit_config(self, filename, newvalues, delimeter='=', quotes_around_value=True):
91 """
92 filename = file to be editted
93 newvlaues = a dictionary of VARIABLE:VALUE pairs
94 """
95 if not GLIUtility.is_file(filename):
96 raise GLIException("NoSuchFileError", 'notice','_edit_config',filename + ' does not exist!')
97
98 f = open(filename)
99 file = f.readlines()
100 f.close()
101
102 for key in newvalues.keys():
103 regexpr = '^\s*#?\s*' + key + '\s*' + delimeter + '.*$'
104 regexpr = re.compile(regexpr)
105
106 for i in range(0, len(file)):
107 if regexpr.match(file[i]):
108 if not file[i][0] == '#':
109 file[i] = '#' + file[i]
110
111 file.append('\n# Added by GLI\n')
112 if quotes_around_value:
113 file.append(key + delimeter + '"' + newvalues[key] + '"\n')
114 else:
115 file.append(key + delimeter + newvalues[key]+'\n')
116
117 f = open(filename,'w')
118 f.writelines(file)
119 f.flush()
120 f.close()
121
122
123 def stage1(self):
124 "Stage 1 install -- bootstraping"
125
126 # If we are doing a stage 1 install, then bootstrap
127 if self._install_profile.get_install_stage() == 1:
128 exitstatus = GLIUtility.spawn("/usr/portage/scripts/bootstrap.sh", chroot=self._chroot_dir)
129 if not GLIUtility.exitsuccess(exitstatus):
130 raise GLIException("Stage1Error", 'fatal','stage1', "Bootstrapping failed!")
131
132 def stage2(self):
133 # If we are doing a stage 1 or 2 install, then emerge system
134 if self._install_profile.get_install_stage() in [ 1, 2 ]:
135 exitstatus = self._emerge("system")
136 if not GLIUtility.exitsuccess(exitstatus):
137 raise GLIException("Stage2Error", 'fatal','stage2', "Building the system failed!")
138
139 def unpack_stage_tarball(self):
140 if not os.path.isdir(self._chroot_dir):
141 os.makedirs(self._chroot_dir)
142 GLIUtility.fetch_and_unpack_tarball(self._install_profile.get_stage_tarball_uri(), self._chroot_dir, temp_directory=self._chroot_dir, keep_permissions=True)
143
144 def prepare_chroot(self):
145 # Copy resolv.conf to new env
146 try:
147 shutil.copy("/etc/resolv.conf", self._chroot_dir + "/etc/resolv.conf")
148 except:
149 pass
150 ret = GLIUtility.spawn("mount -t proc none "+self._chroot_dir+"/proc")
151 if not GLIUtility.exitsuccess(ret):
152 raise GLIException("MountError", 'fatal','prepare_chroot','Could not mount /proc')
153 ret = GLIUtility.spawn("mount -o bind /dev " + self._chroot_dir + "/dev")
154 if not GLIUtility.exitsuccess(ret):
155 raise GLIException("MountError", 'fatal','prepare_chroot','Could not mount /dev')
156
157 # Set USE flags here
158 # might want to rewrite/use _edit_config from the GLIInstallTemplate
159 # Then you should be done... at least with the preinstall.
160
161 def install_packages(self):
162 "Will install any extra software!"
163
164 installpackages = self._install_profile.get_install_packages()
165 for package in installpackages:
166 status = self._emerge(package)
167 if not GLIUtility.exitsuccess(status):
168 raise GLIException("InstallPackagesError", 'warning', 'install_packages', "Could not emerge " + package + "!")
169
170 # **************************************************************************************
171
172
173 def mount_local_partitions(self):
174 "Mounts all partitions that are on the local machine"
175 #{ 1: { 'end': 1999871, 'format': False, 'mb': 0,
176 #'mountopts': '', 'mountpoint': '', 'start': 63, 'type': 'linux-swap'},
177 #2: { 'end': 240121727, 'format': False, 'mb': 0, 'mountopts': '',
178 #'mountpoint': '', 'start': 1999872, 'type': 'ext3'}}
179
180 parts = self._install_profile.get_partition_tables()
181 parts_to_mount = {}
182 for device in parts:
183 #in parts['/dev/hda']
184 for partition in parts[device]:
185 #print parts[device][partition]
186 mountpoint = parts[device][partition]['mountpoint']
187 mountopts = parts[device][partition]['mountopts']
188 minor = str(parts[device][partition]['minor'])
189 partition_type = parts[device][partition]['type']
190 if mountpoint:
191 if mountopts:
192 mountopts = "-o "+mountopts+" "
193 if partition_type:
194 partition_type = "-t "+partition_type+" "
195 parts_to_mount[mountpoint]= {0: mountopts, 1: partition_type, 2: minor}
196
197 if partition_type == "linux-swap":
198 ret = GLIUtility.spawn("swapon "+device+minor)
199 if not GLIUtility.exitsuccess(ret):
200 raise GLIException("MountError", 'warning','mount_local_partitions','Could not activate swap')
201 sorted_list = []
202 for key in parts_to_mount.keys(): sorted_list.append(key)
203 sorted_list.sort()
204
205 for mountpoint in sorted_list:
206 mountopts = parts_to_mount[mountpoint][0]
207 partition_type = parts_to_mount[mountpoint][1]
208 minor = parts_to_mount[mountpoint][2]
209 if not GLIUtility.is_file(self._chroot_dir+mountpoint):
210 exitstatus = GLIUtility.spawn("mkdir -p " + self._chroot_dir + mountpoint)
211 if exitstatus != 0:
212 raise GLIException("MkdirError", 'fatal','mount_local_partitions', "Making the mount point failed!")
213 ret = GLIUtility.spawn("mount "+partition_type+mountopts+device+minor+" "+self._chroot_dir+mountpoint)
214 if not GLIUtility.exitsuccess(ret):
215 raise GLIException("MountError", 'warning','mount_local_partitions','Could not mount a partition')
216
217 def mount_network_shares(self):
218 "Mounts all network shares to the local machine"
219 """
220 <agaffney> it'll be much easier than mount_local_partitions
221 <agaffney> make sure /etc/init.d/portmap is started
222 <agaffney> then mount each one: mount -t nfs -o <mountopts> <host>:<export> <mountpoint>
223 """
224 nfsmounts = self._install_profile.get_network_mounts()
225 for netmount in nfsmounts:
226 if nfsmounts[netmount]['type'] == "NFS" or nfsmounts[netmount]['type'] == "nfs":
227 mountopts = nfsmounts[netmount]['mountopts']
228 if mountopts:
229 mountopts = "-o "+mountopts
230 host = nfsmounts[netmount]['host']
231 export = nfsmounts[netmount]['export']
232 mountpoint = nfsmounts[netmount]['mountpoint']
233 if not GLIUtility.is_file(self._chroot_dir+mountpoint):
234 exitstatus = GLIUtility.spawn("mkdir -p " + self._chroot_dir + mountpoint)
235 if exitstatus != 0:
236 raise GLIException("MkdirError", 'fatal','mount_network_shares', "Making the mount point failed!")
237 ret = GLIUtility.spawn("mount -t nfs "+mountopts+" "+host+":"+export+" "+self._chroot_dir+mountpoint)
238 if not GLIUtility.exitsuccess(ret):
239 raise GLIException("MountError", 'warning','mount_network_shares','Could not mount an NFS partition')
240
241 def fetch_sources_from_cd(self):
242 "Gets sources from CD (required for non-network installation)"
243 if not GLIUtility.is_file(self._chroot_dir+"/usr/portage/distfiles"):
244 exitstatus = GLIUtility.spawn("mkdir -p /usr/portage/distfiles",chroot=self._chroot_dir)
245 if exitstatus != 0:
246 raise GLIException("MkdirError", 'fatal','install_portage_tree',"Making the distfiles directory failed.")
247 exitstatus = GLIUtility.spawn("cp /mnt/cdrom/distfiles/* "+self._chroot_dir+"/usr/portage/distfiles/")
248 if exitstatus != 0:
249 raise GLIException("PortageError", 'fatal','install_portage_tree',"Failed to copy the distfiles to the new system")
250
251 def fetch_grp_from_cd(self):
252 "Gets grp binary packages from CD (required for non-network binary installation)"
253 pass
254
255 def configure_make_conf(self):
256 "Configures make.conf"
257
258 # Get make.conf options
259 options = self._install_profile.get_make_conf()
260
261 # For each configuration option...
262 for key in options.keys():
263
264 # Add/Edit it into make.conf
265 self._edit_config(self._chroot_dir + "/etc/make.conf", {key: options[key]})
266
267 def install_portage_tree(self):
268 "Get/update the portage tree"
269
270 # Check the type of portage tree fetching we'll do
271 # If it is custom, follow the path to the custom tarball and unpack it
272 if self._install_profile.get_portage_tree_sync_type() == "custom":
273
274 # Get portage tree info
275 portage_tree_snapshot_uri = self._install_profile.get_portage_tree_snapshot_uri()
276 if portage_tree_snapshot_uri:
277 # Fetch and unpack the tarball
278 GLIUtility.fetch_and_unpack_tarball(portage_tree_snapshot_uri, self._chroot_dir + "/usr/", self._chroot_dir + "/")
279 # FIXME TEMPORARY FIX FOR NON-GRP SETTING
280 self.fetch_sources_from_cd()
281 # If the type is webrsync, then run emerge-webrsync
282 elif self._install_profile.get_portage_tree_sync_type() == "webrsync":
283 exitstatus = GLIUtility.spawn("emerge-webrsync", chroot=self._chroot_dir)
284 if exitstatus != 0:
285 raise GLIException("EmergeWebRsyncError", 'fatal','install_portage_tre', "Failed to retrieve portage tree!")
286
287 # Otherwise, just run emerge sync
288 else:
289 exitstatus = self._emerge("sync")
290 if exitstatus != 0:
291 raise GLIException("EmergeSyncError", 'fatal','install_portage_tree', "Failed to retrieve portage tree!")
292
293 def set_timezone(self):
294 "Sets the timezone for the new environment"
295 # Set symlink
296 if not os.access(self._chroot_dir + "/etc/localtime", os.W_OK):
297 os.symlink(self._chroot_dir + "/usr/share/zoneinfo/" + self._install_profile.get_time_zone(), self._chroot_dir + "/etc/localtime")
298 if not (self._install_profile.get_time_zone() == "UTC"):
299 self._edit_config(self._chroot_dir + "/etc/rc.conf", {"CLOCK":"local"})
300
301 def configure_fstab(self):
302 "Configures fstab"
303 newfstab = ""
304 #partitions = self._install_profile.get_fstab()
305 parts = self._install_profile.get_partition_tables()
306 for device in parts:
307 #in parts['/dev/hda']
308 for partition in parts[device]:
309 #print parts[device][partition]
310 mountpoint = parts[device][partition]['mountpoint']
311 minor = str(parts[device][partition]['minor'])
312 partition_type = parts[device][partition]['type']
313 mountopts = parts[device][partition]['mountopts']
314 if mountpoint:
315 if not GLIUtility.is_file(self._chroot_dir+mountpoint):
316 exitstatus = GLIUtility.spawn("mkdir -p " + self._chroot_dir + mountpoint)
317 if exitstatus != 0:
318 raise GLIException("MkdirError", 'fatal','configure_fstab', "Making the mount point failed!")
319 newfstab += device+minor+"\t "+mountpoint+"\t "+partition_type+"\t "+mountopts+"\t\t "
320 if mountpoint == "/boot":
321 newfstab += "1 2\n"
322 elif mountpoint == "/":
323 newfstab += "0 1\n"
324 else:
325 newfstab += "0 0\n"
326 if partition_type == "linux-swap":
327 newfstab += device+minor+"\t none swap sw 0 0\n"
328 #for partition in partitions:
329 # if not GLIUtility.is_file(self._chroot_dir+partition):
330 # exitstatus = GLIUtility.spawn("mkdir " + self._chroot_dir + partition)
331 # if exitstatus != 0:
332 # raise GLIException("MkdirError", 'fatal','configure_fstab', "Making the mount point failed!")
333 # newfstab += partitions[partition][0] + "\t " + partition + "\t " + partitions[partition][1]
334 # newfstab += "\t " + partitions[partition][2] + "\t "
335 # if partition == "/boot":
336 # newfstab += "1 2\n"
337 # elif partition == "/":
338 # newfstab += "0 1\n"
339 # else:
340 # newfstab += "0 0\n"
341 newfstab += "none /proc proc defaults 0 0\n"
342 newfstab += "none /dev/shm tmpfs defaults 0 0\n"
343 if GLIUtility.is_device("/dev/cdroms/cdrom0"):
344 newfstab += "/dev/cdroms/cdrom0 /mnt/cdrom auto noauto,user 0 0\n"
345
346 for netmount in self._install_profile.get_network_mounts():
347 if netmount['type'] == "nfs":
348 newfstab += netmount['host'] + ":" + netmount['export'] + "\t" + netmount['mountpoint'] + "\tnfs\t" + netmount['mountopts'] + "\t0 0\n"
349
350 file_name = self._chroot_dir + "/etc/fstab"
351 try:
352 shutil.move(file_name, file_name + ".OLDdefault")
353 except:
354 pass
355 f = open(file_name, 'w')
356 f.writelines(newfstab)
357 f.close()
358
359
360 def emerge_kernel_sources(self):
361 "Fetches desired kernel sources"
362 exitstatus = self._emerge(self._install_profile.get_kernel_source_pkg())
363 if exitstatus != 0:
364 raise GLIException("EmergeKernelSourcesError", 'warning','emerge_kernel_sources',"Could not retrieve kernel sources!")
365 try:
366 os.stat(self._chroot_dir + "/usr/src/linux")
367 except:
368 kernels = os.listdir(self._chroot_dir+"/usr/src")
369 found_a_kernel = False
370 counter = 0
371 while not found_a_kernel:
372 if kernels[counter][0:6]=="linux-":
373 exitstatus = GLIUtility.spawn("ln -s /usr/src/"+kernels[counter]+ " /usr/src/linux",chroot=self._chroot_dir)
374 found_a_kernel = True
375 else:
376 counter = counter + 1
377
378 def build_kernel(self):
379 "Builds kernel"
380 exitstatus = self._emerge("genkernel")
381 if exitstatus != 0:
382 raise GLIException("EmergeGenKernelError", 'warning','build_kernel', "Could not emerge genkernel!")
383
384 # Null the genkernel_options
385 genkernel_options = ""
386
387 # Get the uri to the kernel config
388 kernel_config_uri = self._install_profile.get_kernel_config_uri()
389
390 # If the uri for the kernel config is not null, then
391 if kernel_config_uri != "":
392 GLIUtility.get_uri(kernel_config_uri, self._chroot_dir + "/root/kernel_config")
393 genkernel_options = genkernel_options + " --kernel-config=/root/kernel_config"
394
395 # Decide whether to use bootsplash or not
396 if self._install_profile.get_kernel_bootsplash():
397 genkernel_options = genkernel_options + " --bootsplash"
398 else:
399 genkernel_options = genkernel_options + " --no-bootsplash"
400
401 # This is code to choose whether or not genekernel will build an initrd or not
402 # Genkernel currently does not support this
403 #if self._install_profile.get_kernel_initrd():
404 # pass
405 #else:
406 # pass
407
408 # Run genkernel in chroot
409 print "genkernel all " + genkernel_options
410 exitstatus = GLIUtility.spawn("genkernel all " + genkernel_options, chroot=self._chroot_dir)
411 if exitstatus != 0:
412 raise GLIException("KernelBuildError", 'fatal', 'build_kernel', "Could not build kernel!")
413
414 def install_logging_daemon(self):
415 "Installs and sets up logger"
416 # Get loggin daemon info
417 logging_daemon_pkg = self._install_profile.get_logging_daemon_pkg()
418 if logging_daemon_pkg:
419 # Emerge Logging Daemon
420 exitstatus = self._emerge(logging_daemon_pkg)
421 if exitstatus != 0:
422 raise GLIException("LoggingDaemonError", 'warning','install_logging_daemon', "Could not emerge " + logging_daemon_pkg + "!")
423
424 # Add Logging Daemon to default runlevel
425 self._add_to_runlevel(logging_daemon_pkg)
426
427 def install_cron_daemon(self):
428 "Installs and sets up cron"
429 # Get cron daemon info
430 cron_daemon_pkg = self._install_profile.get_cron_daemon_pkg()
431 if cron_daemon_pkg:
432 # Emerge Cron Daemon
433 exitstatus = self._emerge(cron_daemon_pkg)
434 if exitstatus != 0:
435 raise GLIException("CronDaemonError", 'warning', 'install_cron_daemon', "Could not emerge " + cron_daemon_pkg + "!")
436
437 # Add Cron Daemon to default runlevel
438 self._add_to_runlevel(cron_daemon_pkg)
439
440 # If the Cron Daemon is not vixie-cron, run crontab
441 if cron_daemon_pkg != "vixie-cron":
442 exitstatus = GLIUtility.spawn("crontab /etc/crontab", chroot=self._chroot_dir)
443 if exitstatus != 0:
444 raise GLIException("CronDaemonError", 'warning', 'install_cron_daemon', "Failure making crontab!")
445
446 def install_filesystem_tools(self):
447 "Installs and sets up fstools"
448 # Get the list of file system tools to be installed
449 filesystem_tools = self._install_profile.get_filesystem_tools_pkgs()
450
451 # If the fstools var is a str, convert it to a list
452 if type(filesystem_tools) == str:
453 filesystem_tools = [ filesystem_tools ]
454
455 # For each fstool package in the list, install it
456 for package in filesystem_tools:
457 exitstatus = self._emerge(package)
458 if exitstatus != 0:
459 raise GLIException("FilesystemToolsError", 'warning', 'install_filesystem_tools', "Could not emerge " + package + "!")
460
461 def install_rp_pppoe(self):
462 "Installs rp-pppoe"
463 # If user wants us to install rp-pppoe, then do so
464 if self._install_profile.get_install_rp_pppoe():
465 exitstatus = self._emerge("rp-pppoe")
466 if exitstatus != 0:
467 raise GLIException("RP_PPPOEError", 'warning', 'install_rp_pppoe', "Could not emerge rp-pppoe!")
468
469 # Should we add a section here to automatically configure rp-pppoe?
470 # I think it should go into the setup_network_post section
471 # What do you guys think?
472
473 def install_pcmcia_cs(self):
474 "Installs and sets up pcmcia-cs"
475 # If user wants us to install pcmcia-cs, then do so
476 if self._install_profile.get_install_pcmcia_cs():
477 exitstatus = self._emerge("pcmcia-cs")
478 if exitstatus != 0:
479 raise GLIException("PCMCIA_CSError", 'warning', 'install_pcmcia_cs', "Could not emerge pcmcia-cs!")
480
481 # Add pcmcia-cs to the default runlevel
482 self._add_to_runlevel(pcmcia)
483
484 def update_config_files(self):
485 "Runs etc-update (overwriting all config files), then re-configures the modified ones"
486 # Run etc-update overwriting all config files
487 status = GLIUtility.spawn('echo "-5" | chroot '+self._chroot_dir+' etc-update')
488 if not GLIUtility.exitsuccess(status):
489 raise GLIException("EtcUpdateError", 'warning', 'update_config_files', "Could not update config files!")
490
491 self.configure_make_conf()
492 self.configure_fstab()
493
494 def configure_rc_conf(self):
495 "Configures rc.conf"
496 # Get make.conf options
497 options = self._install_profile.get_rc_conf()
498
499 # For each configuration option...
500 for key in options.keys():
501
502 # Add/Edit it into rc.conf
503 self._edit_config(self._chroot_dir + "/etc/rc.conf", {key: options[key]})
504
505 def setup_network_post(self):
506 "Sets up the network for the first boot"
507 # Get hostname, domainname and nisdomainname
508 hostname = self._install_profile.get_hostname()
509 domainname = self._install_profile.get_domainname()
510 nisdomainname = self._install_profile.get_nisdomainname()
511
512 # Write the hostname to the hostname file
513 open(self._chroot_dir + "/etc/hostname", "w").write(hostname + "\n")
514
515 # Write the domainname to the nisdomainname file
516 if domainname:
517 open(self._chroot_dir + "/etc/dnsdomainname", "w").write(domainname + "\n")
518
519 # Write the nisdomainname to the nisdomainname file
520 if nisdomainname:
521 open(self._chroot_dir + "/etc/nisdomainname", "w").write(nisdomainname + "\n")
522
523 #
524 # EDIT THE /ETC/HOSTS FILE
525 #
526
527 # The address we are editing is 127.0.0.1
528 hosts_ip = "127.0.0.1"
529
530 # If the hostname is localhost
531 if hostname == "localhost":
532 # If a domainname is set
533 if domainname:
534 hosts_line = hostname + "." + domainname + "\t" + hostname
535 else:
536 hosts_line = hostname
537 # If the hostname is not localhost
538 else:
539 # If a domainname is set
540 if domainname:
541 hosts_line = hostname + "." + domainname + "\t" + hostname + "\tlocalhost"
542 else:
543 hosts_line = "localhost\t" + hostname
544
545 # Write to file
546 self._edit_config(self._chroot_dir + "/etc/hosts", {hosts_ip: hosts_line}, delimeter='\t', quotes_around_value=False)
547
548 #
549 # SET DEFAULT GATEWAY
550 #
551
552 # Get default gateway
553 default_gateway = self._install_profile.get_default_gateway()
554
555 # If the default gateway exists, add it
556 if default_gateway:
557 self._edit_config(self._chroot_dir + "/etc/conf.d/net", {"gateway": default_gateway})
558
559 #
560 # SET RESOLV INFO
561 #
562
563 # Get dns servers
564 dns_servers = self._install_profile.get_dns_servers()
565
566 # Clear the list
567 resolv_output = []
568
569 # If dns servers are set
570 if dns_servers:
571
572
573 # Parse each dns server
574 for dns_server in dns_servers:
575 # Add the server to the output
576 resolv_output.append("nameserver " + dns_server +"\n")
577
578 # If the domainname is set, then also output it
579 if domainname:
580 resolv_output.append("search " + domainname + "\n")
581
582 # Output to file
583 resolve_conf = open(self._chroot_dir + "/etc/resolv.conf", "w")
584 resolve_conf.writelines(resolv_output)
585 resolve_conf.close()
586
587 #
588 # PARSE INTERFACES
589 #
590
591 # Fetch interfaces
592 interfaces = self._install_profile.get_network_interfaces()
593
594 # Parse each interface
595 for interface in interfaces.keys():
596
597 # If we are going to load the network at boot...
598 if interfaces[interface][2]:
599
600 # Add it to the default runlevel
601 self._add_to_runlevel("net."+interface)
602
603 # Set what kind of interface it is
604 interface_type = interface[:3]
605
606 # Check to see if there is a startup script for this interface, if there isn't link to the proper script
607 try:
608 os.stat(self._chroot_dir + "/etc/init.d/net." + interface)
609 except:
610 os.symlink(self._chroot_dir + "/etc/init.d/net." + interface_type + "0", self._chroot_dir + "/etc/init.d/net." + interface)
611
612 #
613 # ETHERNET
614 #
615 if interface_type == "eth":
616
617 #
618 # STATIC IP
619 #
620 # If the post-install device info is not None, then it is a static ip addy
621 if interfaces[interface][1]:
622 ip = interfaces[interface][0]
623 broadcast = interfaces[interface][1]
624 netmask = interfaces[interface][2]
625 # aliases = interfaces[interface][1][3]
626 # alias_ips = []
627 # alias_broadcasts = []
628 # alias_netmasks = []
629
630 # Write the static ip config to /etc/conf.d/net
631 self._edit_config(self._chroot_dir + "/etc/conf.d/net", {"iface_" + interface: ip + " broadcast " + broadcast + " netmask " + netmask})
632
633 # If aliases are set
634 # if aliases:
635
636 # Parse aliases to format alias info
637 # for alias in aliases:
638 # alias_ips.append(alias[0])
639 # alias_broadcasts.append(alias[1])
640 # alias_netmasks.append(allias[2])
641
642 # Once the alias info has been gathered, then write it out
643 # Alias ips first
644 # self._edit_config(self._chroot_dir + "/etc/conf.d/net", "alias_" + interface, string.join(alias_ips))
645 # Alias broadcasts next
646 # self._edit_config(self._chroot_dir + "/etc/conf.d/net", "broadcast_" + interface, string.join(alias_broadcasts))
647 # Alias netmasks last
648 # self._edit_config(self._chroot_dir + "/etc/conf.d/net", "netmask_" + interface, string.join(alias_netmasks))
649
650 #
651 # DHCP IP
652 #
653 else:
654 self._edit_config(self._chroot_dir + "/etc/conf.d/net", {"iface_" + interface: "dhcp"})
655
656 def set_root_password(self):
657 "Sets the root password"
658 status = GLIUtility.spawn('echo "root:' + self._install_profile.get_root_pass_hash() + '" | chroot '+self._chroot_dir+' chpasswd -e')
659 if not GLIUtility.exit_success(status):
660 raise GLIException("SetRootPasswordError", 'warning', 'set_root_password', "Failure to set root password!")
661
662 def set_users(self):
663 "Sets up the new users for the system"
664 # Loop for each user
665 for user in self._install_profile.get_users():
666
667 # Get values from the tuple
668 username = user[0]
669 password_hash = user[1]
670 groups = user[2]
671 shell = user[3]
672 home_dir = user[4]
673 uid = user[5]
674 comment = user[6]
675
676 options = [ "-m", "-p " + password_hash ]
677
678 # If the groups are specified
679 if groups:
680
681 # If just one group is listed as a string, make it a list
682 if groups == str:
683 groups = [ groups ]
684
685 # If only 1 group is listed
686 if len(groups) == 1:
687 options.append("-G " + groups[0])
688
689 # If there is more than one group
690 elif len(groups) > 1:
691 options.append('-G "' + string.join(groups, ",") + '"')
692
693 # If a shell is specified
694 if shell:
695 options.append("-s " + shell)
696
697 # If a home dir is specified
698 if home_dir:
699 options.append("-d " + home_dir)
700
701 # If a UID is specified
702 if uid:
703 options.append("-u " + str(uid))
704
705 # If a comment is specified
706 if comment:
707 options.append('-c "' + comment + '"')
708
709 # Add the user
710 exitstatus = GLIUtility.spawn('useradd ' + string.join(options) + ' ' + username, chroot=self._chroot_dir)
711 if not GLIUtility.exit_success(exitstatus):
712 raise GLIException("AddUserError", 'warning', 'set_users', "Failure to add user " + username)
713
714 def install_bootloader(self):
715 "THIS FUNCTION MUST BE DONE BY THE INDIVIDUAL ARCH"
716 pass

Properties

Name Value
svn:eol-style native

  ViewVC Help
Powered by ViewVC 1.1.20