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

Contents of /trunk/src/GLIArchitectureTemplate.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 223 - (show annotations) (download) (as text)
Fri Jan 7 07:38:08 2005 UTC (13 years, 7 months ago) by codeman
File MIME type: text/x-python
File size: 26790 byte(s)
forgot about the set_root_password

1 """
2 Gentoo Linux Installer
3
4 $Id: GLIArchitectureTemplate.py,v 1.31 2005/01/07 07:38: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.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.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 pass
220
221 def fetch_sources_from_cd(self):
222 "Gets sources from CD (required for non-network installation)"
223 if not GLIUtility.is_file(self._chroot_dir+"/usr/portage/distfiles"):
224 exitstatus = GLIUtility.spawn("mkdir -p /usr/portage/distfiles",chroot=self._chroot_dir)
225 if exitstatus != 0:
226 raise GLIException("MkdirError", 'fatal','install_portage_tree',"Making the distfiles directory failed.")
227 exitstatus = GLIUtility.spawn("cp /mnt/cdrom/distfiles/* "+self._chroot_dir+"/usr/portage/distfiles/")
228 if exitstatus != 0:
229 raise GLIException("PortageError", 'fatal','install_portage_tree',"Failed to copy the distfiles to the new system")
230
231 def fetch_grp_from_cd(self):
232 "Gets grp binary packages from CD (required for non-network binary installation)"
233 pass
234
235 def configure_make_conf(self):
236 "Configures make.conf"
237
238 # Get make.conf options
239 options = self._install_profile.get_make_conf()
240
241 # For each configuration option...
242 for key in options.keys():
243
244 # Add/Edit it into make.conf
245 self._edit_config(self._chroot_dir + "/etc/make.conf", {key: options[key]})
246
247 def install_portage_tree(self):
248 "Get/update the portage tree"
249
250 # Check the type of portage tree fetching we'll do
251 # If it is custom, follow the path to the custom tarball and unpack it
252 if self._install_profile.get_portage_tree_sync_type() == "custom":
253
254 # Get portage tree info
255 portage_tree_snapshot_uri = self._install_profile.get_portage_tree_snapshot_uri()
256 if portage_tree_snapshot_uri:
257 # Fetch and unpack the tarball
258 GLIUtility.fetch_and_unpack_tarball(portage_tree_snapshot_uri, self._chroot_dir + "/usr/", self._chroot_dir + "/")
259 # FIXME TEMPORARY FIX FOR NON-GRP SETTING
260 self.fetch_sources_from_cd()
261 # If the type is webrsync, then run emerge-webrsync
262 elif self._install_profile.get_portage_tree_sync_type() == "webrsync":
263 exitstatus = GLIUtility.spawn("emerge-webrsync", chroot=self._chroot_dir)
264 if exitstatus != 0:
265 raise GLIException("EmergeWebRsyncError", 'fatal','install_portage_tre', "Failed to retrieve portage tree!")
266
267 # Otherwise, just run emerge sync
268 else:
269 exitstatus = self._emerge("sync")
270 if exitstatus != 0:
271 raise GLIException("EmergeSyncError", 'fatal','install_portage_tree', "Failed to retrieve portage tree!")
272
273 def set_timezone(self):
274 "Sets the timezone for the new environment"
275 # Set symlink
276 if not os.access(self._chroot_dir + "/etc/localtime", os.W_OK):
277 os.symlink(self._chroot_dir + "/usr/share/zoneinfo/" + self._install_profile.get_time_zone(), self._chroot_dir + "/etc/localtime")
278 if not (self._install_profile.get_time_zone() == "UTC"):
279 self._edit_config(self._chroot_dir + "/etc/rc.conf", {"CLOCK":"local"})
280
281 def configure_fstab(self):
282 "Configures fstab"
283 newfstab = ""
284 #partitions = self._install_profile.get_fstab()
285 parts = self._install_profile.get_partition_tables()
286 for device in parts:
287 #in parts['/dev/hda']
288 for partition in parts[device]:
289 #print parts[device][partition]
290 mountpoint = parts[device][partition]['mountpoint']
291 minor = str(parts[device][partition]['minor'])
292 partition_type = parts[device][partition]['type']
293 mountopts = parts[device][partition]['mountopts']
294 if mountpoint:
295 if not GLIUtility.is_file(self._chroot_dir+mountpoint):
296 exitstatus = GLIUtility.spawn("mkdir -p " + self._chroot_dir + mountpoint)
297 if exitstatus != 0:
298 raise GLIException("MkdirError", 'fatal','configure_fstab', "Making the mount point failed!")
299 newfstab += device+minor+"\t "+mountpoint+"\t "+partition_type+"\t "+mountopts+"\t\t "
300 if mountpoint == "/boot":
301 newfstab += "1 2\n"
302 elif mountpoint == "/":
303 newfstab += "0 1\n"
304 else:
305 newfstab += "0 0\n"
306 if partition_type == "linux-swap":
307 newfstab += device+minor+"\t none swap sw 0 0\n"
308 #for partition in partitions:
309 # if not GLIUtility.is_file(self._chroot_dir+partition):
310 # exitstatus = GLIUtility.spawn("mkdir " + self._chroot_dir + partition)
311 # if exitstatus != 0:
312 # raise GLIException("MkdirError", 'fatal','configure_fstab', "Making the mount point failed!")
313 # newfstab += partitions[partition][0] + "\t " + partition + "\t " + partitions[partition][1]
314 # newfstab += "\t " + partitions[partition][2] + "\t "
315 # if partition == "/boot":
316 # newfstab += "1 2\n"
317 # elif partition == "/":
318 # newfstab += "0 1\n"
319 # else:
320 # newfstab += "0 0\n"
321 newfstab += "none /proc proc defaults 0 0\n"
322 newfstab += "none /dev/shm tmpfs defaults 0 0\n"
323 if GLIUtility.is_device("/dev/cdroms/cdrom0"):
324 newfstab += "/dev/cdroms/cdrom0 /mnt/cdrom auto noauto,user 0 0\n"
325
326 for netmount in self._install_profile.get_network_mounts():
327 if netmount['type'] == "nfs":
328 newfstab += netmount['host'] + ":" + netmount['export'] + "\t" + netmount['mountpoint'] + "\tnfs\t" + netmount['mountopts'] + "\t0 0\n"
329
330 file_name = self._chroot_dir + "/etc/fstab"
331 try:
332 shutil.move(file_name, file_name + ".OLDdefault")
333 except:
334 pass
335 f = open(file_name, 'w')
336 f.writelines(newfstab)
337 f.close()
338
339
340 def emerge_kernel_sources(self):
341 "Fetches desired kernel sources"
342 exitstatus = self._emerge(self._install_profile.get_kernel_source_pkg())
343 if exitstatus != 0:
344 raise GLIException("EmergeKernelSourcesError", 'warning','emerge_kernel_sources',"Could not retrieve kernel sources!")
345 try:
346 os.stat(self._chroot_dir + "/usr/src/linux")
347 except:
348 kernels = os.listdir(self._chroot_dir+"/usr/src")
349 found_a_kernel = False
350 counter = 0
351 while not found_a_kernel:
352 if kernels[counter][0:6]=="linux-":
353 exitstatus = GLIUtility.spawn("ln -s /usr/src/"+kernels[counter]+ " /usr/src/linux",chroot=self._chroot_dir)
354 found_a_kernel = True
355 else:
356 counter = counter + 1
357
358 def build_kernel(self):
359 "Builds kernel"
360 exitstatus = self._emerge("genkernel")
361 if exitstatus != 0:
362 raise GLIException("EmergeGenKernelError", 'warning','build_kernel', "Could not emerge genkernel!")
363
364 # Null the genkernel_options
365 genkernel_options = ""
366
367 # Get the uri to the kernel config
368 kernel_config_uri = self._install_profile.get_kernel_config_uri()
369
370 # If the uri for the kernel config is not null, then
371 if kernel_config_uri != "":
372 GLIUtility.get_uri(kernel_config_uri, self._chroot_dir + "/root/kernel_config")
373 genkernel_options = genkernel_options + " --kernel-config=/root/kernel_config"
374
375 # Decide whether to use bootsplash or not
376 if self._install_profile.get_kernel_bootsplash():
377 genkernel_options = genkernel_options + " --bootsplash"
378 else:
379 genkernel_options = genkernel_options + " --no-bootsplash"
380
381 # This is code to choose whether or not genekernel will build an initrd or not
382 # Genkernel currently does not support this
383 #if self._install_profile.get_kernel_initrd():
384 # pass
385 #else:
386 # pass
387
388 # Run genkernel in chroot
389 print "genkernel all " + genkernel_options
390 exitstatus = GLIUtility.spawn("genkernel all " + genkernel_options, chroot=self._chroot_dir)
391 if exitstatus != 0:
392 raise GLIException("KernelBuildError", 'fatal', 'build_kernel', "Could not build kernel!")
393
394 def install_logging_daemon(self):
395 "Installs and sets up logger"
396 # Get loggin daemon info
397 logging_daemon_pkg = self._install_profile.get_logging_daemon_pkg()
398 if logging_daemon_pkg:
399 # Emerge Logging Daemon
400 exitstatus = self._emerge(logging_daemon_pkg)
401 if exitstatus != 0:
402 raise GLIException("LoggingDaemonError", 'warning','install_logging_daemon', "Could not emerge " + logging_daemon_pkg + "!")
403
404 # Add Logging Daemon to default runlevel
405 self._add_to_runlevel(logging_daemon_pkg)
406
407 def install_cron_daemon(self):
408 "Installs and sets up cron"
409 # Get cron daemon info
410 cron_daemon_pkg = self._install_profile.get_cron_daemon_pkg()
411 if cron_daemon_pkg:
412 # Emerge Cron Daemon
413 exitstatus = self._emerge(cron_daemon_pkg)
414 if exitstatus != 0:
415 raise GLIException("CronDaemonError", 'warning', 'install_cron_daemon', "Could not emerge " + cron_daemon_pkg + "!")
416
417 # Add Cron Daemon to default runlevel
418 self._add_to_runlevel(cron_daemon_pkg)
419
420 # If the Cron Daemon is not vixie-cron, run crontab
421 if cron_daemon_pkg != "vixie-cron":
422 exitstatus = GLIUtility.spawn("crontab /etc/crontab", chroot=self._chroot_dir)
423 if exitstatus != 0:
424 raise GLIException("CronDaemonError", 'warning', 'install_cron_daemon', "Failure making crontab!")
425
426 def install_filesystem_tools(self):
427 "Installs and sets up fstools"
428 # Get the list of file system tools to be installed
429 filesystem_tools = self._install_profile.get_filesystem_tools_pkgs()
430
431 # If the fstools var is a str, convert it to a list
432 if type(filesystem_tools) == str:
433 filesystem_tools = [ filesystem_tools ]
434
435 # For each fstool package in the list, install it
436 for package in filesystem_tools:
437 exitstatus = self._emerge(package)
438 if exitstatus != 0:
439 raise GLIException("FilesystemToolsError", 'warning', 'install_filesystem_tools', "Could not emerge " + package + "!")
440
441 def install_rp_pppoe(self):
442 "Installs rp-pppoe"
443 # If user wants us to install rp-pppoe, then do so
444 if self._install_profile.get_install_rp_pppoe():
445 exitstatus = self._emerge("rp-pppoe")
446 if exitstatus != 0:
447 raise GLIException("RP_PPPOEError", 'warning', 'install_rp_pppoe', "Could not emerge rp-pppoe!")
448
449 # Should we add a section here to automatically configure rp-pppoe?
450 # I think it should go into the setup_network_post section
451 # What do you guys think?
452
453 def install_pcmcia_cs(self):
454 "Installs and sets up pcmcia-cs"
455 # If user wants us to install pcmcia-cs, then do so
456 if self._install_profile.get_install_pcmcia_cs():
457 exitstatus = self._emerge("pcmcia-cs")
458 if exitstatus != 0:
459 raise GLIException("PCMCIA_CSError", 'warning', 'install_pcmcia_cs', "Could not emerge pcmcia-cs!")
460
461 # Add pcmcia-cs to the default runlevel
462 self._add_to_runlevel(pcmcia)
463
464 def update_config_files(self):
465 "Runs etc-update (overwriting all config files), then re-configures the modified ones"
466 # Run etc-update overwriting all config files
467 status = GLIUtility.spawn('echo "-5" | chroot '+self._chroot_dir+' etc-update')
468 if not GLIUtility.exitsuccess(status):
469 raise GLIException("EtcUpdateError", 'warning', 'update_config_files', "Could not update config files!")
470
471 self.configure_make_conf()
472 self.configure_fstab()
473
474 def configure_rc_conf(self):
475 "Configures rc.conf"
476 # Get make.conf options
477 options = self._install_profile.get_rc_conf()
478
479 # For each configuration option...
480 for key in options.keys():
481
482 # Add/Edit it into rc.conf
483 self._edit_config(self._chroot_dir + "/etc/rc.conf", {key: options[key]})
484
485 def setup_network_post(self):
486 "Sets up the network for the first boot"
487 # Get hostname, domainname and nisdomainname
488 hostname = self._install_profile.get_hostname()
489 domainname = self._install_profile.get_domainname()
490 nisdomainname = self._install_profile.get_nisdomainname()
491
492 # Write the hostname to the hostname file
493 open(self._chroot_dir + "/etc/hostname", "w").write(hostname + "\n")
494
495 # Write the domainname to the nisdomainname file
496 if domainname:
497 open(self._chroot_dir + "/etc/dnsdomainname", "w").write(domainname + "\n")
498
499 # Write the nisdomainname to the nisdomainname file
500 if nisdomainname:
501 open(self._chroot_dir + "/etc/nisdomainname", "w").write(nisdomainname + "\n")
502
503 #
504 # EDIT THE /ETC/HOSTS FILE
505 #
506
507 # The address we are editing is 127.0.0.1
508 hosts_ip = "127.0.0.1"
509
510 # If the hostname is localhost
511 if hostname == "localhost":
512 # If a domainname is set
513 if domainname:
514 hosts_line = hostname + "." + domainname + "\t" + hostname
515 else:
516 hosts_line = hostname
517 # If the hostname is not localhost
518 else:
519 # If a domainname is set
520 if domainname:
521 hosts_line = hostname + "." + domainname + "\t" + hostname + "\tlocalhost"
522 else:
523 hosts_line = "localhost\t" + hostname
524
525 # Write to file
526 self._edit_config(self._chroot_dir + "/etc/hosts", {hosts_ip: hosts_line}, delimeter='\t', quotes_around_value=False)
527
528 #
529 # SET DEFAULT GATEWAY
530 #
531
532 # Get default gateway
533 default_gateway = self._install_profile.get_default_gateway()
534
535 # If the default gateway exists, add it
536 if default_gateway:
537 self._edit_config(self._chroot_dir + "/etc/conf.d/net", {"gateway": default_gateway})
538
539 #
540 # SET RESOLV INFO
541 #
542
543 # Get dns servers
544 dns_servers = self._install_profile.get_dns_servers()
545
546 # Clear the list
547 resolv_output = []
548
549 # If dns servers are set
550 if dns_servers:
551
552
553 # Parse each dns server
554 for dns_server in dns_servers:
555 # Add the server to the output
556 resolv_output.append("nameserver " + dns_server +"\n")
557
558 # If the domainname is set, then also output it
559 if domainname:
560 resolv_output.append("search " + domainname + "\n")
561
562 # Output to file
563 resolve_conf = open(self._chroot_dir + "/etc/resolv.conf", "w")
564 resolve_conf.writelines(resolv_output)
565 resolve_conf.close()
566
567 #
568 # PARSE INTERFACES
569 #
570
571 # Fetch interfaces
572 interfaces = self._install_profile.get_network_interfaces()
573
574 # Parse each interface
575 for interface in interfaces.keys():
576
577 # If we are going to load the network at boot...
578 if interfaces[interface][2]:
579
580 # Add it to the default runlevel
581 self._add_to_runlevel("net."+interface)
582
583 # Set what kind of interface it is
584 interface_type = interface[:3]
585
586 # Check to see if there is a startup script for this interface, if there isn't link to the proper script
587 try:
588 os.stat(self._chroot_dir + "/etc/init.d/net." + interface)
589 except:
590 os.symlink(self._chroot_dir + "/etc/init.d/net." + interface_type + "0", self._chroot_dir + "/etc/init.d/net." + interface)
591
592 #
593 # ETHERNET
594 #
595 if interface_type == "eth":
596
597 #
598 # STATIC IP
599 #
600 # If the post-install device info is not None, then it is a static ip addy
601 if interfaces[interface][1]:
602 ip = interfaces[interface][0]
603 broadcast = interfaces[interface][1]
604 netmask = interfaces[interface][2]
605 # aliases = interfaces[interface][1][3]
606 # alias_ips = []
607 # alias_broadcasts = []
608 # alias_netmasks = []
609
610 # Write the static ip config to /etc/conf.d/net
611 self._edit_config(self._chroot_dir + "/etc/conf.d/net", {"iface_" + interface: ip + " broadcast " + broadcast + " netmask " + netmask})
612
613 # If aliases are set
614 # if aliases:
615
616 # Parse aliases to format alias info
617 # for alias in aliases:
618 # alias_ips.append(alias[0])
619 # alias_broadcasts.append(alias[1])
620 # alias_netmasks.append(allias[2])
621
622 # Once the alias info has been gathered, then write it out
623 # Alias ips first
624 # self._edit_config(self._chroot_dir + "/etc/conf.d/net", "alias_" + interface, string.join(alias_ips))
625 # Alias broadcasts next
626 # self._edit_config(self._chroot_dir + "/etc/conf.d/net", "broadcast_" + interface, string.join(alias_broadcasts))
627 # Alias netmasks last
628 # self._edit_config(self._chroot_dir + "/etc/conf.d/net", "netmask_" + interface, string.join(alias_netmasks))
629
630 #
631 # DHCP IP
632 #
633 else:
634 self._edit_config(self._chroot_dir + "/etc/conf.d/net", {"iface_" + interface: "dhcp"})
635
636 def set_root_password(self):
637 "Sets the root password"
638 status = GLIUtility.spawn('echo "root:' + self._install_profile.get_root_pass_hash() + '" | chroot '+self._chroot_dir+' chpasswd -e')
639 if not GLIUtility.exit_success(status):
640 raise GLIException("SetRootPasswordError", 'warning', 'set_root_password', "Failure to set root password!")
641
642 def set_users(self):
643 "Sets up the new users for the system"
644 # Loop for each user
645 for user in self._install_profile.get_users():
646
647 # Get values from the tuple
648 username = user[0]
649 password_hash = user[1]
650 groups = user[2]
651 shell = user[3]
652 home_dir = user[4]
653 uid = user[5]
654 comment = user[6]
655
656 options = [ "-m", "-p " + password_hash ]
657
658 # If the groups are specified
659 if groups:
660
661 # If just one group is listed as a string, make it a list
662 if groups == str:
663 groups = [ groups ]
664
665 # If only 1 group is listed
666 if len(groups) == 1:
667 options.append("-G " + groups[0])
668
669 # If there is more than one group
670 elif len(groups) > 1:
671 options.append('-G "' + string.join(groups, ",") + '"')
672
673 # If a shell is specified
674 if shell:
675 options.append("-s " + shell)
676
677 # If a home dir is specified
678 if home_dir:
679 options.append("-d " + home_dir)
680
681 # If a UID is specified
682 if uid:
683 options.append("-u " + str(uid))
684
685 # If a comment is specified
686 if comment:
687 options.append('-c "' + comment + '"')
688
689 # Add the user
690 exitstatus = GLIUtility.spawn('useradd ' + string.join(options) + ' ' + username, chroot=self._chroot_dir)
691 if not GLIUtility.exit_success(exitstatus):
692 raise GLIException("AddUserError", 'warning', 'set_users', "Failure to add user " + username)
693
694 def install_bootloader(self):
695 "THIS FUNCTION MUST BE DONE BY THE INDIVIDUAL ARCH"
696 pass

Properties

Name Value
svn:eol-style native

  ViewVC Help
Powered by ViewVC 1.1.20