Lines 55-60
Link Here
|
55 |
(self.set_timezone, "Setting timezone"), |
55 |
(self.set_timezone, "Setting timezone"), |
56 |
(self.emerge_kernel_sources, "Emerge kernel sources"), |
56 |
(self.emerge_kernel_sources, "Emerge kernel sources"), |
57 |
(self.build_kernel, "Building kernel"), |
57 |
(self.build_kernel, "Building kernel"), |
|
|
58 |
(self.install_kernel, "Installing a kernel"), |
58 |
(self.install_logging_daemon, "Logger"), |
59 |
(self.install_logging_daemon, "Logger"), |
59 |
(self.install_cron_daemon, "Cron daemon"), |
60 |
(self.install_cron_daemon, "Cron daemon"), |
60 |
(self.install_filesystem_tools, "Installing filesystem tools"), |
61 |
(self.install_filesystem_tools, "Installing filesystem tools"), |
Lines 140-159
Link Here
|
140 |
return GLIUtility.spawn("emerge " + package, display_on_tty8=True, chroot=self._chroot_dir, logfile=self._compile_logfile, append_log=True) |
141 |
return GLIUtility.spawn("emerge " + package, display_on_tty8=True, chroot=self._chroot_dir, logfile=self._compile_logfile, append_log=True) |
141 |
|
142 |
|
142 |
## |
143 |
## |
143 |
# Private Function. Will edit a config file and insert a value or two overwriting the previous value |
144 |
# Private Function. Will edit a config file and insert a value or two |
144 |
# (actually it only just comments out the old one) |
145 |
# overridding the previous value (comments out the old values). |
145 |
# @param filename file to be edited |
146 |
# |
146 |
# @param newvalues a dictionary of VARIABLE:VALUE pairs |
147 |
# @param filename File to be edited. |
147 |
# @param delimeter='=' what is between the key and the value |
148 |
# @param newvalues A dictionary of VARIABLE:VALUE pairs. |
148 |
# @param quotes_around_value=True whether there are quotes around the value or not (ex. "local" vs. localhost) |
149 |
# @param delimeter='=' What is between the key and the value. |
149 |
def _edit_config(self, filename, newvalues, delimeter='=', quotes_around_value=True): |
150 |
# @param quotes_around_value=True Whether there are quotes around the |
150 |
if not GLIUtility.is_file(filename): |
151 |
# value or not (ex. "local" vs. localhost). |
151 |
raise GLIException("NoSuchFileError", 'notice','_edit_config',filename + ' does not exist!') |
152 |
# @param only_value=False Ignore the keys and output only a value. |
152 |
|
153 |
# @param create=True Create the file if it doesn't exist. |
153 |
f = open(filename) |
154 |
def _edit_config(self, filename, newvalues, delimeter='=', quotes_around_value=True, only_value=False, create=True): |
154 |
file = f.readlines() |
155 |
if GLIUtility.is_file(filename): |
155 |
f.close() |
156 |
f = open(filename) |
156 |
|
157 |
file = f.readlines() |
|
|
158 |
f.close() |
159 |
else: |
160 |
# File does not exist, check if creation is not allowed. |
161 |
if not create: |
162 |
raise GLIException("NoSuchFileError", 'notice','_edit_config',filename + ' does not exist!') |
163 |
else: |
164 |
file = [] |
165 |
|
157 |
for key in newvalues.keys(): |
166 |
for key in newvalues.keys(): |
158 |
regexpr = '^\s*#?\s*' + key + '\s*' + delimeter + '.*$' |
167 |
regexpr = '^\s*#?\s*' + key + '\s*' + delimeter + '.*$' |
159 |
regexpr = re.compile(regexpr) |
168 |
regexpr = re.compile(regexpr) |
Lines 162-178
Link Here
|
162 |
if regexpr.match(file[i]): |
171 |
if regexpr.match(file[i]): |
163 |
if not file[i][0] == '#': |
172 |
if not file[i][0] == '#': |
164 |
file[i] = '#' + file[i] |
173 |
file[i] = '#' + file[i] |
165 |
|
174 |
|
166 |
file.append('\n# Added by GLI\n') |
175 |
if key == "SPACER": |
167 |
commentprefix = "" |
176 |
file.append('\n') |
168 |
if newvalues[key] == "COMMENT" or newvalues[key] == "##comment##": |
177 |
elif key == "COMMENT" or key == "##comment##": |
169 |
commentprefix = "#" |
178 |
file.append('# ' + newvalues[key] + '\n') |
170 |
if quotes_around_value: |
|
|
171 |
file.append(commentprefix + key + delimeter + '"' + newvalues[key] + '"\n') |
172 |
else: |
179 |
else: |
173 |
file.append(commentprefix + key + delimeter + newvalues[key]+'\n') |
180 |
if quotes_around_value: |
|
|
181 |
newvalues[key] = '"' + newvalues[key] + '"' |
182 |
# Only the printing of values is required. |
183 |
if only_value: |
184 |
file.append(newvalues[key] + '\n') |
185 |
else: |
186 |
file.append(key + delimeter + newvalues[key]+'\n') |
174 |
|
187 |
|
175 |
f = open(filename,'w') |
188 |
|
|
|
189 |
f = open(filename, 'w') |
176 |
f.writelines(file) |
190 |
f.writelines(file) |
177 |
f.flush() |
191 |
f.flush() |
178 |
f.close() |
192 |
f.close() |
Lines 231-247
Link Here
|
231 |
self._logger.log("Chroot environment ready.") |
245 |
self._logger.log("Chroot environment ready.") |
232 |
|
246 |
|
233 |
## |
247 |
## |
234 |
# Installs a list of packages specified in the profile. Will install any extra software! |
248 |
# Installs a list of packages specified in the profile. Will install also |
235 |
# In the future this function will lead to better things. It may even wipe your ass for you. |
249 |
# any dependencies. |
|
|
250 |
## |
251 |
def set_etc_portage(self): |
252 |
etc_portage = self._install_profile.get_etc_portage() |
253 |
|
254 |
# Loop through the required files. |
255 |
for file in etc_portage: |
256 |
contents = enumerate(etc_portage[file]) |
257 |
self._logger.log("Configuring /etc/portage/" + file) |
258 |
self._edit_config(self._chroot_dir + "/etc/portage/" + file, {"COMMENT": "GLI additions ===>"}) |
259 |
|
260 |
# Set up the contents hash to pass to the config writer. |
261 |
contents = {} |
262 |
for key,value in enumerate(etc_portage[file]): |
263 |
contents[str(key)] = string.strip(value) |
264 |
|
265 |
# Write out the contents in one go. |
266 |
self._edit_config(self._chroot_dir + "/etc/portage/" + file, contents, "", False, True) |
267 |
|
268 |
self._edit_config(self._chroot_dir + "/etc/make.conf", {"COMMENT": "<=== End GLI additions"}) |
269 |
self._logger.log("Finished configuring /etc/portage/" + file) |
270 |
|
271 |
# Installs a list of packages specified in the profile. Will install also |
272 |
# any dependencies. |
236 |
def install_packages(self): |
273 |
def install_packages(self): |
237 |
installpackages = self._install_profile.get_install_packages() |
274 |
installpackages = self._install_profile.get_install_packages() |
|
|
275 |
|
238 |
for package in installpackages: |
276 |
for package in installpackages: |
|
|
277 |
self._logger.log("Starting emerge " + package) |
239 |
status = self._emerge(package) |
278 |
status = self._emerge(package) |
240 |
if not GLIUtility.exitsuccess(status): |
279 |
if not GLIUtility.exitsuccess(status): |
241 |
self._logger.log("Could not emerge " + package + "!") |
280 |
self._logger.log("Could not emerge " + package + "!") |
242 |
# raise GLIException("InstallPackagesError", 'warning', 'install_packages', "Could not emerge " + package + "!") |
281 |
# raise GLIException("InstallPackagesError", 'warning', 'install_packages', "Could not emerge " + package + "!") |
243 |
else: |
282 |
else: |
244 |
self._logger.log("Emerged package: "+package) |
283 |
self._logger.log("Emerged package: " + package) |
245 |
|
284 |
|
246 |
## |
285 |
## |
247 |
# Will set the list of services to runlevel default. This is a temporary solution! |
286 |
# Will set the list of services to runlevel default. This is a temporary solution! |
Lines 349-355
Link Here
|
349 |
def configure_make_conf(self): |
388 |
def configure_make_conf(self): |
350 |
# Get make.conf options |
389 |
# Get make.conf options |
351 |
options = self._install_profile.get_make_conf() |
390 |
options = self._install_profile.get_make_conf() |
352 |
|
391 |
|
|
|
392 |
if options.keys(): |
393 |
self._edit_config(self._chroot_dir + "/etc/make.conf", {"SPACER": ""}) |
394 |
self._edit_config(self._chroot_dir + "/etc/make.conf", {"COMMENT": "GLI additions ===>"}) |
395 |
|
353 |
# For each configuration option... |
396 |
# For each configuration option... |
354 |
for key in options.keys(): |
397 |
for key in options.keys(): |
355 |
|
398 |
|
Lines 357-362
Link Here
|
357 |
self._edit_config(self._chroot_dir + "/etc/make.conf", {key: options[key]}) |
400 |
self._edit_config(self._chroot_dir + "/etc/make.conf", {key: options[key]}) |
358 |
self._logger.log("Make.conf configured") |
401 |
self._logger.log("Make.conf configured") |
359 |
|
402 |
|
|
|
403 |
if options.keys(): |
404 |
self._edit_config(self._chroot_dir + "/etc/make.conf", {"COMMENT": "<=== End GLI additions"}) |
405 |
|
360 |
## |
406 |
## |
361 |
# This will get/update the portage tree. If you want to snapshot or mount /usr/portage use "custom". |
407 |
# This will get/update the portage tree. If you want to snapshot or mount /usr/portage use "custom". |
362 |
def install_portage_tree(self): |
408 |
def install_portage_tree(self): |
Lines 446-451
Link Here
|
446 |
## |
492 |
## |
447 |
# Fetches desired kernel sources, unless you're using a livecd-kernel in which case it does freaky stuff. |
493 |
# Fetches desired kernel sources, unless you're using a livecd-kernel in which case it does freaky stuff. |
448 |
def emerge_kernel_sources(self): |
494 |
def emerge_kernel_sources(self): |
|
|
495 |
self._logger.log("Starting emerge_kernel") |
449 |
|
496 |
|
450 |
kernel_pkg = self._install_profile.get_kernel_source_pkg() |
497 |
kernel_pkg = self._install_profile.get_kernel_source_pkg() |
451 |
# if kernel_pkg: |
498 |
# if kernel_pkg: |
Lines 509-520
Link Here
|
509 |
self._logger.log("Genkernel emerged. Beginning kernel compile.") |
556 |
self._logger.log("Genkernel emerged. Beginning kernel compile.") |
510 |
# Null the genkernel_options |
557 |
# Null the genkernel_options |
511 |
genkernel_options = "" |
558 |
genkernel_options = "" |
512 |
|
559 |
|
513 |
# If the uri for the kernel config is not null, then |
|
|
514 |
if kernel_config_uri != "": |
515 |
GLIUtility.get_uri(kernel_config_uri, self._chroot_dir + "/root/kernel_config") |
516 |
genkernel_options = genkernel_options + " --kernel-config=/root/kernel_config" |
517 |
|
518 |
# Decide whether to use bootsplash or not |
560 |
# Decide whether to use bootsplash or not |
519 |
if self._install_profile.get_kernel_bootsplash(): |
561 |
if self._install_profile.get_kernel_bootsplash(): |
520 |
genkernel_options = genkernel_options + " --bootsplash" |
562 |
genkernel_options = genkernel_options + " --bootsplash" |
Lines 567-575
Link Here
|
567 |
exitstatus = GLIUtility.spawn("rm "+self._chroot_dir+"/root/kernel_script") |
609 |
exitstatus = GLIUtility.spawn("rm "+self._chroot_dir+"/root/kernel_script") |
568 |
#it's not important if this fails. |
610 |
#it's not important if this fails. |
569 |
self._logger.log("Custom kernel complete") |
611 |
self._logger.log("Custom kernel complete") |
570 |
|
612 |
|
|
|
613 |
|
614 |
## |
615 |
# Installs the kernels as defined in the install profile. |
616 |
def install_kernel(self): |
617 |
self._logger.log("Checking for kernels to install.") |
618 |
|
619 |
# Get the kernels to install. |
620 |
kernels = self._install_profile.get_kernels() |
621 |
|
622 |
# Install each kernel. |
623 |
for kernel in kernels: |
624 |
if (kernel['type'] == 'precompiled'): |
625 |
self._install_kernel_precompiled(kernel['kernel']); |
626 |
elif (kernel['type'] == 'emerge'): |
627 |
self._install_kernel_emerge; |
628 |
|
629 |
## |
630 |
# Function to install a precompiled kernel. |
631 |
def _install_kernel_precompiled(self, kernel): |
632 |
self._logger.log("Installing precompiled kernel " + kernel) |
633 |
if (GLIUtility.spawn("emerge -K " + kernel, display_on_tty8=True, chroot=self._chroot_dir, logfile=self._compile_logfile, append_log=True)): |
634 |
raise GLIException("KernelInstallError", 'fatal', 'install_kernel', "Could not install precompiled kernel!") |
635 |
self._logger.log("Kernel install finished.") |
636 |
|
571 |
## |
637 |
## |
572 |
# Installs and sets up logging daemon on the new system. adds to runlevel too. |
638 |
# Installs and sets up logging daemon on the new system. Adds to runlevel |
|
|
639 |
# too. |
573 |
def install_logging_daemon(self): |
640 |
def install_logging_daemon(self): |
574 |
|
641 |
|
575 |
# Get loggin daemon info |
642 |
# Get loggin daemon info |