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

Contents of /trunk/src/GLIArchitectureTemplate.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 220 - (show annotations) (download) (as text)
Fri Jan 7 07:00:13 2005 UTC (15 years, 10 months ago) by agaffney
File MIME type: text/x-python
File size: 26672 byte(s)
partition code move

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

Properties

Name Value
svn:eol-style native

  ViewVC Help
Powered by ViewVC 1.1.20