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

Contents of /trunk/src/GLIArchitectureTemplate.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 282 - (show annotations) (download) (as text)
Sat Jan 22 08:58:05 2005 UTC (15 years, 10 months ago) by codeman
File MIME type: text/x-python
File size: 28767 byte(s)
added code to allow custom kernel .config.

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

Properties

Name Value
svn:eol-style native

  ViewVC Help
Powered by ViewVC 1.1.20