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

Contents of /trunk/src/GLIArchitectureTemplate.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 361 - (show annotations) (download) (as text)
Wed Mar 16 06:17:35 2005 UTC (13 years, 3 months ago) by codeman
File MIME type: text/x-python
File size: 33361 byte(s)
Removed default values for stage tarball URI and portage tree URI from
  InstallProfile.  These should be set by the FEs.  also added services step to
  ArchTemplate and coldplug/hotplug runlevels to the genkernel step.
  Possibly fixed CC DHCP bug with -n. (thx agaffney)

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

Properties

Name Value
svn:eol-style native

  ViewVC Help
Powered by ViewVC 1.1.20