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

Diff of /trunk/src/GLIArchitectureTemplate.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 86 Revision 102
1""" 1"""
2Gentoo Linux Installer 2Gentoo Linux Installer
3 3
4$Id: GLIArchitectureTemplate.py,v 1.2 2004/08/31 15:34:34 samyron Exp $ 4$Id: GLIArchitectureTemplate.py,v 1.3 2004/11/06 05:04:00 samyron Exp $
5Copyright 2004 Gentoo Technologies Inc. 5Copyright 2004 Gentoo Technologies Inc.
6 6
7 7
8The ArchitectureTemplate is largely meant to be an abstract class and an 8The ArchitectureTemplate is largely meant to be an abstract class and an
9interface (yes, it is both at the same time!). The purpose of this is to create 9interface (yes, it is both at the same time!). The purpose of this is to create
11The only definitions that are filled in here are architecture independent. 11The only definitions that are filled in here are architecture independent.
12 12
13""" 13"""
14 14
15import GLIUtility 15import GLIUtility
16from signal import SIGUSR1
16from GLIExceptions import * 17from GLIExceptions import *
17 18
18class ArchitectureTemplate: 19class ArchitectureTemplate:
19 20
20 def __init__(self,configuration=None, install_profile=None): 21 def __init__(self,configuration=None, install_profile=None):
21 self._configuration = configuration 22 self._configuration = configuration
22 self._install_profile = install_profile 23 self._install_profile = install_profile
24
25 # This will get used a lot, so it's probably
26 # better to store it in a variable than to call
27 # this method 100000 times.
28 self._chroot_dir = self._configuration.get_root_mount_point()
23 29
24 # These must be filled in by the subclass. _steps is a list of 30 # These must be filled in by the subclass. _steps is a list of
25 # functions, that will carry out the installation. They must be 31 # functions, that will carry out the installation. They must be
26 # in order. 32 # in order.
27 # 33 #
97 raise MountError('fatal','preinstall','Could not mount /proc') 103 raise MountError('fatal','preinstall','Could not mount /proc')
98 104
99 # Set USE flags here 105 # Set USE flags here
100 # might want to rewrite/use _edit_config from the GLIInstallTemplate 106 # might want to rewrite/use _edit_config from the GLIInstallTemplate
101 # Then you should be done... at least with the preinstall. 107 # Then you should be done... at least with the preinstall.
108
109 def notify_frontend(self):
110 os.kill(os.getpid(), SIGUSR1)
111
112 def install_packages(self):
113 "Will install any extra software!"
114 # Dependency checking
115 self._depends("emerge system")
116 installpackages = self._install_profile.get_install_packages()
117 for package in installpackages:
118 status = GLIUtility.emerge(package)
119 if not GLIUtility.exit_success(status):
120 raise "InstallPackagesError", "Could not emerge " + package + "!"
102 121
103 # This is part of the interface... subclasses MUST 122 # This is part of the interface... subclasses MUST
104 # provide these methods filled in. 123 # provide these methods filled in.
105 def stage3(self): 124 def stage3(self):
106 # This should probably start with building the kernel, 125 # This should probably start with building the kernel,
111 def postinstall(self): 130 def postinstall(self):
112 pass 131 pass
113 132
114 def partition(self): 133 def partition(self):
115 pass 134 pass
135
136# **************************************************************************************
137
138 def _add_to_runlevel(self, script_name, runlevel="default"):
139 "Adds the script named 'script_name' to the runlevel 'runlevel' in the chroot environement"
140
141 # Do it
142 status = GLIUtility._run("rc-update add " + script_name + " " + runlevel, chroot=self._chroot_dir)
143 if not GLIUtility.exit_success(status):
144 raise "RunlevelAddError", "Failure adding " + script_name + " to runlevel " + runlevel + "!"
145
146 def mount_local_partitions(self):
147 "Mounts all partitions that are on the local machine"
148 # Dependency checking
149 self._depends("partition_local_drives")
150
151 def mount_network_shares(self):
152 "Mounts all network shares to the local machine"
153 # Dependency checking
154 self._depends([ "setup_network_pre", "mount_local_partitions" ])
155
156 def fetch_sources_from_cd(self):
157 "Gets sources from CD (required for non-network installation)"
158 # Dependency checking
159 self._depends("unpack_tarball")
160
161 def fetch_grp_from_cd(self):
162 "Gets grp binary packages from CD (required for non-network binary installation)"
163 # Dependency checking
164 self._depends("unpack_tarball")
165
166 def configure_make_conf(self):
167 "Configures make.conf"
168 # Dependency checking
169 self._depends("prepare_chroot")
170
171 # Get make.conf options
172 options = self._install_profile.get_make_conf()
173
174 # For each configuration option...
175 for key in options.keys():
176
177 # Add/Edit it into make.conf
178 GLIUtility.edit_config(self._chroot_dir + "/etc/make.conf", key, options[key])
179
180 def install_portage_tree(self):
181 "Get/update the portage tree"
182 # Dependency checking
183 self._depends("prepare_chroot")
184
185 # Check the type of portage tree fetching we'll do
186 # If it is custom, follow the path to the custom tarball and unpack it
187 if self._install_profile.get_portage_tree_sync_type() == "custom":
188
189 # Get portage tree info
190 portage_tree_snapshot_uri = self._install_profile.get_portage_tree_snapshot_uri()
191
192 # Fetch and unpack the tarball
193 self._fetch_and_unpack_tarball(portage_tree_snapshot_uri, self._client_configuration.get_root_mount_point() + "/usr/", self._client_configuration.get_root_mount_point() + "/")
194 if not GLIUtility.is_file(self._client_configuration.get_root_mount_point()+"/usr/portage/distfiles"):
195 exitstatus = self._run("mkdir /usr/portage/distfiles",True)
196 if exitstatus != 0:
197 raise "MkdirError","Making the distfiles directory failed."
198 exitstatus = self._run("cp /mnt/cdrom/distfiles/* "+self._client_configuration.get_root_mount_point()+"/usr/portage/distfiles/")
199 if exitstatus != 0:
200 raise "PortageError","Failed to copy the distfiles to the new system"
201 # If the type is webrsync, then run emerge-webrsync
202 elif self._install_profile.get_portage_tree_sync_type() == "webrsync":
203 exitstatus = self._run("emerge-webrsync", True)
204 if exitstatus != 0:
205 raise "EmergeWebRsyncError", "Failed to retrieve portage tree!"
206
207 # Otherwise, just run emerge sync
208 else:
209 exitstatus = self._emerge("sync")
210 if exitstatus != 0:
211 raise "EmergeSyncError", "Failed to retrieve portage tree!"
212
213 def set_timezone(self):
214 "Sets the timezone for the new environment"
215
216 # Dependency checking
217 self._depends("unpack_tarball")
218 #self._process_desc("Setting the timezone")
219
220 # Set symlink
221 if not os.access(self._client_configuration.get_root_mount_point() + "/etc/localtime", os.W_OK):
222 os.symlink(self._client_configuration.get_root_mount_point() + "/usr/share/zoneinfo/" + self._install_profile.get_time_zone(), self._client_configuration.get_root_mount_point() + "/etc/localtime")
223 if not (self._install_profile.get_time_zone() == "UTC"):
224 self._edit_config(self._client_configuration.get_root_mount_point() + "/etc/rc.conf", "CLOCK", "local")
225
226 def configure_fstab(self):
227 "Configures fstab"
228 # Dependency checking
229 self._depends("unpack_tarball")
230 newfstab = ""
231 partitions = self._install_profile.get_fstab()
232 for partition in partitions:
233 if not GLIUtility.is_file(self._client_configuration.get_root_mount_point()+partition):
234 exitstatus = self._run("mkdir " + partition, True)
235 if exitstatus != 0:
236 raise "MkdirError", "Making the mount point failed!"
237 newfstab += partitions[partition][0] + "\t " + partition + "\t " + partitions[partition][1]
238 newfstab += "\t " + partitions[partition][2] + "\t "
239 if partition == "/boot":
240 newfstab += "1 2\n"
241 elif partition == "/":
242 newfstab += "0 1\n"
243 else:
244 newfstab += "0 0\n"
245 newfstab += "none /proc proc defaults 0 0\n"
246 newfstab += "none /dev/shm tmpfs defaults 0 0\n"
247 if GLIUtility.is_device("/dev/cdroms/cdrom0"):
248 newfstab += "/dev/cdroms/cdrom0 /mnt/cdrom auto noauto,user 0 0\n"
249
250 file_name = self._client_configuration.get_root_mount_point() + "/etc/fstab"
251 try:
252 shutil.move(file_name, file_name + ".OLDdefault")
253 except:
254 pass
255 f = open(file_name, 'w')
256 f.writelines(newfstab)
257 f.close()
258
259
260 def emerge_kernel_sources(self):
261 "Fetches desired kernel sources"
262 # Dependency checking
263 self._depends("emerge_system")
264 exitstatus = self._emerge(self._install_profile.get_kernel_source_pkg())
265 if exitstatus != 0:
266 raise "EmergeKernelSourcesError", "Could not retrieve kernel sources!"
267 try:
268 os.stat(self._client_configuration.get_root_mount_point() + "/usr/src/linux")
269 except:
270 kernels = os.listdir(self._client_configuration.get_root_mount_point()+"/usr/src")
271 found_a_kernel = False
272 counter = 0
273 while not found_a_kernel:
274 if kernels[counter][0:6]=="linux-":
275 exitstatus = self._run("ln -s /usr/src/"+kernels[counter]+ " /usr/src/linux",True)
276 found_a_kernel = True
277 else:
278 counter = counter + 1
279
280 def build_kernel(self):
281 "Builds kernel"
282 # Dependency checking
283 self._depends("emerge_kernel_sources")
284
285 exitstatus = self._emerge("genkernel")
286 if exitstatus != 0:
287 raise "EmergeGenKernelError", "Could not emerge genkernel!"
288
289
290 # Null the genkernel_options
291 genkernel_options = ""
292
293 # Get the uri to the kernel config
294 kernel_config_uri = self._install_profile.get_kernel_config_uri()
295
296 # If the uri for the kernel config is not null, then
297 if kernel_config_uri != "":
298 self._get_uri(kernel_config_uri, self._client_configuration.get_root_mount_point() + "/root/kernel_config")
299 genkernel_options = genkernel_options + " --kernel-config=/root/kernel_config"
300
301 # Decide whether to use bootsplash or not
302 if self._install_profile.get_kernel_bootsplash():
303 genkernel_options = genkernel_options + " --bootsplash"
304 else:
305 genkernel_options = genkernel_options + " --no-bootsplash"
306
307 # This is code to choose whether or not genekernel will build an initrd or not
308 # Genkernel currently does not support this
309 #if self._install_profile.get_kernel_initrd():
310 # pass
311 #else:
312 # pass
313
314 # Run genkernel in chroot
315 print "genkernel all " + genkernel_options
316 exitstatus = self._run("genkernel all " + genkernel_options, True)
317 if exitstatus != 0:
318 raise "KernelBuildError", "Could not build kernel!"
319
320 def install_logging_daemon(self):
321 "Installs and sets up logger"
322 # Dependency checking
323 self._depends("emerge_system")
324
325 # Get loggin daemon info
326 logging_daemon_pkg = self._install_profile.get_logging_daemon_pkg()
327 if logging_daemon_pkg:
328 # Emerge Logging Daemon
329 exitstatus = self._emerge(logging_daemon_pkg)
330 if exitstatus != 0:
331 raise "LoggingDaemonError", "Could not emerge " + logging_daemon_pkg + "!"
332
333 # Add Logging Daemon to default runlevel
334 self._add_to_runlevel(logging_daemon_pkg)
335
336 def install_cron_daemon(self):
337 "Installs and sets up cron"
338 # Dependency checking
339 self._depends("emerge_system")
340
341 # Get cron daemon info
342 cron_daemon_pkg = self._install_profile.get_cron_daemon_pkg()
343 if cron_daemon_pkg:
344 # Emerge Cron Daemon
345 exitstatus = self._emerge(cron_daemon_pkg)
346 if exitstatus != 0:
347 raise "CronDaemonError", "Could not emerge " + cron_daemon_pkg + "!"
348
349 # Add Cron Daemon to default runlevel
350 self._add_to_runlevel(cron_daemon_pkg)
351
352 # If the Cron Daemon is not vixie-cron, run crontab
353 if cron_daemon_pkg != "vixie-cron":
354 exitstatus = self._run("crontab /etc/crontab", True)
355 if exitstatus != 0:
356 raise "CronDaemonError", "Failure making crontab!"
357
358 def install_filesystem_tools(self):
359 "Installs and sets up fstools"
360 # Dependency checking
361 self._depends("emerge_system")
362
363 # Get the list of file system tools to be installed
364 filesystem_tools = self._install_profile.get_filesystem_tools_pkgs()
365
366 # If the fstools var is a str, convert it to a list
367 if type(filesystem_tools) == str:
368 filesystem_tools = [ filesystem_tools ]
369
370 # For each fstool package in the list, install it
371 for package in filesystem_tools:
372 exitstatus = self._emerge(package)
373 if exitstatus != 0:
374 raise "FilesystemToolsError", "Could not emerge " + package + "!"
375
376 def install_rp_pppoe(self):
377 "Installs rp-pppoe"
378 # Dependency checking
379 self._depends("emerge_system")
380
381 # If user wants us to install rp-pppoe, then do so
382 if self._install_profile.get_install_rp_pppoe():
383 exitstatus = self._emerge("rp-pppoe")
384 if exitstatus != 0:
385 raise "RP-PPPOEError", "Could not emerge rp-pppoe!"
386
387 # Should we add a section here to automatically configure rp-pppoe?
388 # I think it should go into the setup_network_post section
389 # What do you guys think?
390
391 def install_pcmcia_cs(self):
392 "Installs and sets up pcmcia-cs"
393 # Dependency checking
394 self._depends("build_kernel")
395
396 # If user wants us to install pcmcia-cs, then do so
397 if self._install_profile.get_install_pcmcia_cs():
398 exitstatus = self._emerge("pcmcia-cs")
399 if exitstatus != 0:
400 raise "PCMCIA-CSError", "Could not emerge pcmcia-cs!"
401
402 # Add pcmcia-cs to the default runlevel
403 exitstatus = self._run("rc-update add pcmcia default", True)
404 if exitstatus != 0:
405 raise "PCMCIA-CSError", "Could not add pcmcia-cs to the default runlevel!"
406
407 def install_bootloader(self):
408 "Installs and configures bootloader"
409 #
410 # THIS IS ARCHITECTURE DEPENDANT!!!
411 # This is the x86 way.. it uses grub
412 # Dependency checking
413 self._depends("build_kernel")
414
415 if self._install_profile.get_boot_loader_pkg():
416 exitstatus = self._emerge(self._install_profile.get_boot_loader_pkg())
417 if exitstatus != 0:
418 raise "BootLoaderEmergeError", "Could not emerge bootloader!"
419 else:
420 pass
421
422 boot_device = ""
423 boot_minor = ""
424 root_device = ""
425 root_minor = ""
426 grub_root_minor = ""
427 grub_boot_minor = ""
428 grub_boot_drive = ""
429 grub_root_drive = ""
430 minornum = 0
431 #Assign root to the root mount point to make lines more readable
432 root = self._client_configuration.get_root_mount_point()
433 file_name = root + "/boot/grub/bootdevice"
434 file_name1 = root + "/boot/grub/rootdevice"
435 file_name2 = root + "/boot/grub/device.map"
436 file_name3 = root + "/boot/grub/kernel_name"
437 foundboot = False
438 partitions = self._install_profile.get_fstab()
439 for partition in partitions:
440 #if find a /boot then stop.. else we'll take a / and overwrite with a /boot if we find it too.
441 if (partition == "/boot"):
442 #try to get the drive LETTER from /dev/hdc1 8th character
443 boot_minor = partitions[partition][0][8]
444 grub_boot_minor = str(int(boot_minor) - 1)
445 boot_device = partitions[partition][0][0:8]
446 foundboot = True
447 if ( (partition == "/") and (not foundboot) ):
448 boot_minor = partitions[partition][0][8]
449 grub_boot_minor = str(int(boot_minor) - 1)
450 boot_device = partitions[partition][0][0:8]
451 #Foundboot IS STILL FALSE
452 if partition == "/":
453 root_minor = partitions[partition][0][8]
454 grub_root_minor = str(int(root_minor) - 1)
455 root_device = partitions[partition][0][0:8]
456
457 exitstatus0 = self._run("ls -l " + boot_device + " > " + file_name)
458 exitstatus1 = self._run("ls -l " + root_device + " > " + file_name1)
459 exitstatus2 = self._run("echo quit | "+ root+"/sbin/grub --device-map="+file_name2)
460 exitstatus3 = self._run("ls "+root+"/boot/kernel-* > "+file_name3)
461 exitstatus4 = self._run("ls "+root+"/boot/initrd-* >> "+file_name3)
462 if (exitstatus0 != 0) or (exitstatus1 != 0) or (exitstatus2 != 0) or (exitstatus3 != 0) or (exitstatus4 != 0):
463 raise "Bootloadererror", "Error in one of THE FOUR run commands"
464
465 """
466 read the device map. sample looks like this:
467 (fd0) /dev/floppy/0
468 (hd0) /dev/ide/host2/bus0/target0/lun0/disc
469 (hd1) /dev/ide/host0/bus0/target0/lun0/disc
470 (hd2) /dev/ide/host0/bus0/target1/lun0/disc
471 """
472 e = open(file_name) #Looking for the boot device
473 ls_output = e.readlines()
474 e.close()
475 # looks like lr-xr-xr-x 1 root root 32 Oct 1 16:09 /dev/hda -> ide/host0/bus0/target0/lun0/disc
476 ls_output = ls_output[0].split(">")[-1]
477 ls_output = ls_output[1:]
478
479 eb = open(file_name1) #Looking for the root device
480 ls_outputb = eb.readlines()
481 eb.close()
482 ls_outputb = ls_outputb[0].split(">")[-1]
483 ls_outputb = ls_outputb[1:]
484
485 # Search for the key
486 f = open(file_name2)
487 file = f.readlines()
488 f.close()
489 for i in range(len(file)):
490 if file[i][11:] == ls_output:
491 #eurika we found the drivenum
492 grub_boot_drive = file[i][1:4]
493 if file[i][11:] == ls_outputb:
494 grub_root_drive = file[i][1:4]
495 if (not grub_root_drive) or (not grub_boot_drive):
496 raise "BootloaderError","Couldn't find the drive num in the list from the device.map"
497
498 g = open(file_name3)
499 kernel_name = g.readlines()
500 g.close()
501 if not kernel_name[0]:
502 raise "BootloaderError","Error: We have no kernel in /boot to put in the grub.conf file!"
503 kernel_name = map(string.strip, kernel_name)
504 kernel_name[0] = kernel_name[0].split(root)[1]
505 kernel_name[1] = kernel_name[1].split(root)[1]
506 #-------------------------------------------------------------
507 #OK, now that we have all the info, let's build that grub.conf
508 newgrubconf = ""
509 newgrubconf += "default 0\ntimeout 30\n"
510 if foundboot: #we have a /boot
511 newgrubconf += "splashimage=(" + grub_boot_drive + "," + grub_boot_minor + ")/grub/splash.xpm.gz\n"
512 else: #we have / and /boot needs to be included
513 newgrubconf += "splashimage=(" + grub_boot_drive + "," + grub_boot_minor + ")/boot/grub/splash.xpm.gz\n"
514
515 newgrubconf += "title=Gentoo Linux\n"
516 newgrubconf += "root (" + grub_boot_drive + "," + grub_boot_minor + ")\n"
517 if foundboot:
518 newgrubconf += "kernel " + kernel_name[0][5:] + " root=/dev/ram0 init=/linuxrc ramdisk=8192 real_root="
519 newgrubconf += root_device + root_minor + "\n"
520 newgrubconf += "initrd " + kernel_name[1][5:] + "\n"
521 else:
522 newgrubconf += "kernel /boot" + kernel_name[0][5:] + " root=/dev/ram0 init=/linuxrc ramdisk=8192 real_root="
523 newgrubconf += root_device + root_minor + "\n"
524 newgrubconf += "initrd /boot" + kernel_name[1][5:] + "\n"
525
526 #-------------------------------------------------------------
527 #OK, now that the file is built. Install grub.
528 #cp /proc/mounts /etc/mtab
529 #grub-install --root-directory=/boot /dev/hda
530 #shutil.copy("/proc/mounts",root +"/etc/mtab")
531 grubinstallstring = "echo -en 'root ("+grub_boot_drive + "," + grub_boot_minor + ")\n"
532 if not self._install_profile.get_boot_loader_mbr():
533 grubinstallstring +="setup ("+grub_boot_drive + "," + grub_boot_minor + ")\n"
534 else:
535 grubinstallstring +="setup ("+grub_boot_drive+")\n"
536 grubinstallstring += "quit\n' | "+root+"/sbin/grub"
537 print grubinstallstring
538 exitstatus = self._run(grubinstallstring,True)
539 if exitstatus != 0:
540 raise "GrubInstallError", "Could not install grub!"
541
542 #now make the grub.conf file
543 file_name = root + "/boot/grub/grub.conf"
544 try:
545 shutil.move(file_name, file_name + ".OLDdefault")
546 except:
547 pass
548 f = open(file_name, 'w')
549 f.writelines(newgrubconf)
550 f.close()
551
552 def update_config_files(self):
553 "Runs etc-update (overwriting all config files), then re-configures the modified ones"
554 # Dependency checking
555 self._depends("emerge_system")
556
557 # Run etc-update overwriting all config files
558 status = GLIUtility.spawn('echo "-5" | etc-update', chroot=self._chroot_dir)
559 if not GLIUtility.exit_success(status):
560 raise "EtcUpdateError", "Could not update config files!"
561
562 self.configure_make_conf()
563 self.configure_fstab()
564
565 def configure_rc_conf(self):
566 "Configures rc.conf"
567 # Dependency checking
568 self._depends("update_config_files")
569
570 # Get make.conf options
571 options = self._install_profile.get_rc_conf()
572
573 # For each configuration option...
574 for key in options.keys():
575
576 # Add/Edit it into rc.conf
577 self._edit_config(self._client_configuration.get_root_mount_point() + "/etc/rc.conf", key, option[key])
578
579 def setup_network_post(self):
580 "Sets up the network for the first boot"
581 # Dependency checking
582 self._depends("unpack_tarball")
583
584 # Get hostname, domainname and nisdomainname
585 hostname = self._install_profile.get_hostname()
586 domainname = self._install_profile.get_domainname()
587 nisdomainname = self._install_profile.get_nisdomainname()
588
589 # Write the hostname to the hostname file
590 open(self._client_configuration.get_root_mount_point() + "/etc/hostname", "w").write(hostname + "\n")
591
592 # Write the domainname to the nisdomainname file
593 if domainname:
594 open(self._client_configuration.get_root_mount_point() + "/etc/dnsdomainname", "w").write(domainname + "\n")
595
596 # Write the nisdomainname to the nisdomainname file
597 if nisdomainname:
598 open(self._client_configuration.get_root_mount_point() + "/etc/nisdomainname", "w").write(nisdomainname + "\n")
599
600 #
601 # EDIT THE /ETC/HOSTS FILE
602 #
603
604 # The address we are editing is 127.0.0.1
605 hosts_ip = "127.0.0.1"
606
607 # If the hostname is localhost
608 if hostname == "localhost":
609 # If a domainname is set
610 if domainname:
611 hosts_line = hostname + "." + domainname + "\t" + hostname
612 else:
613 hosts_line = hostname
614 # If the hostname is not localhost
615 else:
616 # If a domainname is set
617 if domainname:
618 hosts_line = hostname + "." + domainname + "\t" + hostname + "\tlocalhost"
619 else:
620 hosts_line = "localhost\t" + hostname
621
622 # Write to file
623 self._edit_config(self._client_configuration.get_root_mount_point() + "/etc/hosts", hosts_ip, hosts_line, True, '\t', False)
624
625 #
626 # SET DEFAULT GATEWAY
627 #
628
629 # Get default gateway
630 default_gateway = self._install_profile.get_default_gateway()
631
632 # If the default gateway exists, add it
633 if default_gateway:
634 self._edit_config(self._client_configuration.get_root_mount_point() + "/etc/conf.d/net", "gateway", default_gateway)
635
636 #
637 # SET RESOLV INFO
638 #
639
640 # Get dns servers
641 dns_servers = self._install_profile.get_dns_servers()
642
643 # Clear the list
644 resolv_output = []
645
646 # If dns servers are set
647 if dns_servers:
648
649
650 # Parse each dns server
651 for dns_server in dns_servers:
652 # Add the server to the output
653 resolv_output.append("nameserver " + dns_server +"\n")
654
655 # If the domainname is set, then also output it
656 if domainname:
657 resolv_output.append("search " + domainname + "\n")
658
659 # Output to file
660 resolve_conf = open(self._client_configuration.get_root_mount_point() + "/etc/resolv.conf", "w")
661 resolve_conf.writelines(resolv_output)
662 resolve_conf.close()
663
664 #
665 # PARSE INTERFACES
666 #
667
668 # Fetch interfaces
669 interfaces = self._install_profile.get_network_interfaces()
670
671 # Parse each interface
672 for interface in interfaces.keys():
673
674 # If we are going to load the network at boot...
675 if interfaces[interface][2]:
676
677 # Add it to the default runlevel
678 exitstatus = self._run("rc-update add net." + interface + " default", True)
679 if exitstatus != 0:
680 raise "NetStartupError", "Cannot add interface " + interface + " to the default runlevel!"
681
682 # Set what kind of interface it is
683 interface_type = interface[:3]
684
685 # Check to see if there is a startup script for this interface, if there isn't link to the proper script
686 try:
687 os.stat(self._client_configuration.get_root_mount_point() + "/etc/init.d/net." + interface)
688 except:
689 os.symlink(self._client_configuration.get_root_mount_point() + "/etc/init.d/net." + interface_type + "0", self._client_configuration.get_root_mount_point() + "/etc/init.d/net." + interface)
690
691 #
692 # ETHERNET
693 #
694 if interface_type == "eth":
695
696 #
697 # STATIC IP
698 #
699 # If the post-install device info is not None, then it is a static ip addy
700 if interfaces[interface][1]:
701 ip = interfaces[interface][0]
702 broadcast = interfaces[interface][1]
703 netmask = interfaces[interface][2]
704 # aliases = interfaces[interface][1][3]
705 # alias_ips = []
706 # alias_broadcasts = []
707 # alias_netmasks = []
708
709 # Write the static ip config to /etc/conf.d/net
710 self._edit_config(self._client_configuration.get_root_mount_point() + "/etc/conf.d/net", "iface_" + interface, ip + " broadcast " + broadcast + " netmask " + netmask)
711
712 # If aliases are set
713 # if aliases:
714
715 # Parse aliases to format alias info
716 # for alias in aliases:
717 # alias_ips.append(alias[0])
718 # alias_broadcasts.append(alias[1])
719 # alias_netmasks.append(allias[2])
720
721 # Once the alias info has been gathered, then write it out
722 # Alias ips first
723 # self._edit_config(self._client_configuration.get_root_mount_point() + "/etc/conf.d/net", "alias_" + interface, string.join(alias_ips))
724 # Alias broadcasts next
725 # self._edit_config(self._client_configuration.get_root_mount_point() + "/etc/conf.d/net", "broadcast_" + interface, string.join(alias_broadcasts))
726 # Alias netmasks last
727 # self._edit_config(self._client_configuration.get_root_mount_point() + "/etc/conf.d/net", "netmask_" + interface, string.join(alias_netmasks))
728
729 #
730 # DHCP IP
731 #
732 else:
733 self._edit_config(self._client_configuration.get_root_mount_point() + "/etc/conf.d/net", "iface_" + interface, "dhcp")
734
735 def set_root_password(self):
736 "Sets the root password"
737 # Dependency checking
738 self._depends("emerge_system")
739
740 status = GLIUtility.spawn('echo "root:' + self._install_profile.get_root_pass_hash() + '" | chpasswd -e', chroot=self._chroot_dir)
741 if not GLIUtility.exit_success(status):
742 raise "SetRootPasswordError", "Failure to set root password!"
743
744 def set_users(self):
745 "Sets up the new users for the system"
746 # Dependency checking
747 self._depends("emerge_system")
748
749 # Loop for each user
750 for user in self._install_profile.get_users():
751
752 # Get values from the tuple
753 username = user[0]
754 password_hash = user[1]
755 groups = user[2]
756 shell = user[3]
757 home_dir = user[4]
758 uid = user[5]
759 comment = user[6]
760
761 options = [ "-m", "-p " + password_hash ]
762
763 # If the groups are specified
764 if groups:
765
766 # If just one group is listed as a string, make it a list
767 if groups == str:
768 groups = [ groups ]
769
770 # If only 1 group is listed
771 if len(groups) == 1:
772 options.append("-G " + groups[0])
773
774 # If there is more than one group
775 elif len(groups) > 1:
776 options.append('-G "' + string.join(groups, ",") + '"')
777
778 # If a shell is specified
779 if shell:
780 options.append("-s " + shell)
781
782 # If a home dir is specified
783 if home_dir:
784 options.append("-d " + home_dir)
785
786 # If a UID is specified
787 if uid:
788 options.append("-u " + str(uid))
789
790 # If a comment is specified
791 if comment:
792 options.append('-c "' + comment + '"')
793
794 # Add the user
795 exitstatus = GLIUtility.spawn('useradd ' + string.join(options) + ' ' + username, chroot=self._chroot_dir)
796 if not GLIUtility.exit_success(exitstatus):
797 raise "AddUserError", "Failure to add user " + username

Legend:
Removed from v.86  
changed lines
  Added in v.102

  ViewVC Help
Powered by ViewVC 1.1.20