2009-08-27 07:19:49 +00:00
|
|
|
#
|
|
|
|
# __init__.py
|
2010-01-12 11:45:54 +00:00
|
|
|
#
|
|
|
|
# Copyright (C) 2009 Red Hat, Inc.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
2010-02-23 13:20:05 +00:00
|
|
|
# Red Hat Author(s): Martin Gracik <mgracik@redhat.com>
|
|
|
|
# David Cantrell <dcantrell@redhat.com>
|
2009-08-27 07:19:49 +00:00
|
|
|
#
|
|
|
|
|
2009-04-22 13:01:28 +00:00
|
|
|
import sys
|
2008-09-13 02:04:02 +00:00
|
|
|
import os
|
2009-09-23 10:21:33 +00:00
|
|
|
import ConfigParser
|
2009-12-15 14:26:01 +00:00
|
|
|
import glob
|
2009-04-22 13:01:28 +00:00
|
|
|
import time
|
2009-08-19 14:51:32 +00:00
|
|
|
import datetime
|
2009-12-15 14:26:01 +00:00
|
|
|
import shutil
|
2008-09-13 02:04:02 +00:00
|
|
|
|
2009-12-15 14:26:01 +00:00
|
|
|
import yum
|
|
|
|
import yum.callbacks
|
|
|
|
import yum.rpmtrans
|
2008-10-05 04:44:28 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
from base import BaseLoraxClass
|
2009-09-23 10:21:33 +00:00
|
|
|
import output
|
2009-06-04 13:36:56 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
import insttree
|
|
|
|
import images
|
|
|
|
from sysutils import *
|
2009-06-04 13:36:56 +00:00
|
|
|
|
2009-09-23 10:21:33 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
# basearch efiarch 64bit
|
|
|
|
ARCHMAP = {"i386": ["i386", "IA32", False],
|
|
|
|
"i586": ["i386", "IA32", False],
|
|
|
|
"i686": ["i386", "IA32", False],
|
|
|
|
"x86_64": ["x86_64", "X64", True],
|
|
|
|
"ppc": ["ppc", "", False],
|
|
|
|
"ppc64": ["ppc", "", True],
|
|
|
|
"s390": ["s390", "", False],
|
|
|
|
"s390x": ["s390x", "", True],
|
|
|
|
"sparc": ["sparc", "", False],
|
|
|
|
"sparc64": ["sparc", "", True],
|
|
|
|
"ia64": ["ia64", "IA64", True]}
|
2009-06-04 13:36:56 +00:00
|
|
|
|
2009-12-15 14:26:01 +00:00
|
|
|
LIB32 = "lib"
|
|
|
|
LIB64 = "lib64"
|
2009-06-04 13:36:56 +00:00
|
|
|
|
2008-09-12 00:21:12 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
class Lorax(BaseLoraxClass):
|
2009-09-23 10:21:33 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
def __init__(self, yb, installtree, outputdir,
|
|
|
|
product, version, release,
|
|
|
|
workdir="/tmp", variant="", bugurl="", updatesdir=None):
|
2008-09-13 02:04:02 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
BaseLoraxClass.__init__(self)
|
2009-09-23 10:21:33 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
# XXX check if we have root privileges
|
|
|
|
assert os.geteuid() == self.const.ROOT_UID, "no root privileges"
|
2009-09-23 10:21:33 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
# XXX check if we have a yumbase object
|
|
|
|
assert isinstance(yb, yum.YumBase), "not an yum base object"
|
2009-09-23 10:21:33 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
# setup yum and the install tree
|
2009-12-15 14:26:01 +00:00
|
|
|
self.yum = YumHelper(yb)
|
2010-02-23 13:20:05 +00:00
|
|
|
self.installtree = insttree.InstallTree(yum=self.yum,
|
|
|
|
rootdir=installtree,
|
|
|
|
updatesdir=updatesdir)
|
|
|
|
|
|
|
|
# create the output directory
|
|
|
|
self.outputdir = outputdir
|
|
|
|
makedirs_(self.outputdir)
|
2008-09-13 02:04:02 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
# required parameters
|
|
|
|
self.product = product
|
|
|
|
self.version = version
|
|
|
|
self.release = release
|
2009-04-22 13:01:28 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
# create the working director
|
|
|
|
self.workdir = workdir
|
|
|
|
makedirs_(self.workdir)
|
2009-04-22 13:01:28 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
# optional parameters
|
|
|
|
self.variant = variant
|
|
|
|
self.bugurl = bugurl
|
2009-04-22 13:01:28 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
# setup the output
|
2009-12-15 14:26:01 +00:00
|
|
|
output_level = output.INFO
|
|
|
|
if self.conf.debug:
|
|
|
|
output_level = output.DEBUG
|
2009-04-22 13:01:28 +00:00
|
|
|
|
2009-12-15 14:26:01 +00:00
|
|
|
self.output.basic_config(colors=self.conf.colors,
|
|
|
|
encoding=self.conf.encoding,
|
2010-02-23 13:20:05 +00:00
|
|
|
output_level=output_level)
|
2009-09-23 10:21:33 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
ignore_errors = set()
|
|
|
|
if os.path.isfile(self.conf.ignore_errors):
|
|
|
|
with open(self.conf.ignore_errors, "r") as f:
|
|
|
|
for line in f:
|
|
|
|
line = line.strip()
|
|
|
|
if line and not line.startswith("#"):
|
|
|
|
ignore_errors.add(line)
|
2009-09-23 10:21:33 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
self.output.ignore = ignore_errors
|
2009-09-23 10:21:33 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
def run(self):
|
|
|
|
# check if we have all required commands
|
|
|
|
for cmd in self.cmd.values():
|
|
|
|
if not os.path.isfile(cmd):
|
|
|
|
err = "required command <b>{0}</b> does not exist"
|
|
|
|
self.pwarning(err.format(cmd))
|
2009-09-23 10:21:33 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
# set the build architecture
|
|
|
|
self.pinfo(":: setting the build architecture")
|
|
|
|
self.conf.buildarch = self.get_buildarch()
|
|
|
|
basearch, efiarch, is64 = ARCHMAP[self.conf.buildarch]
|
2009-09-23 10:21:33 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
self.conf.basearch = basearch
|
|
|
|
self.conf.efiarch = efiarch
|
2009-09-23 10:21:33 +00:00
|
|
|
|
2009-12-15 14:26:01 +00:00
|
|
|
# set the libdir
|
|
|
|
self.conf.libdir = LIB32
|
2010-02-23 13:20:05 +00:00
|
|
|
if is64:
|
2009-12-15 14:26:01 +00:00
|
|
|
self.conf.libdir = LIB64
|
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
# read the configuration files
|
|
|
|
self.pinfo(":: reading the configuration files")
|
|
|
|
c = self.get_config()
|
|
|
|
packages, modules, initrd_template, install_template = c
|
2009-12-15 14:26:01 +00:00
|
|
|
|
|
|
|
# add the branding
|
2010-02-23 13:20:05 +00:00
|
|
|
packages.add("{0}-logos".format(self.product.lower()))
|
|
|
|
packages.add("{0}-release".format(self.product.lower()))
|
|
|
|
|
|
|
|
# prepare the install tree
|
|
|
|
self.pinfo(":: preparing the install tree")
|
|
|
|
self.installtree.install_packages(packages=packages)
|
|
|
|
self.installtree.run_ldconfig()
|
|
|
|
self.installtree.copy_updates()
|
|
|
|
self.installtree.fix_problems()
|
|
|
|
|
|
|
|
# check the anaconda runtime directory
|
|
|
|
anarun = os.path.join(self.installtree.rootdir,
|
|
|
|
self.const.ANACONDA_RUNTIME)
|
|
|
|
|
|
|
|
if not os.path.isdir(anarun):
|
|
|
|
self.pcritical("no anaconda runtime directory found")
|
2009-12-15 14:26:01 +00:00
|
|
|
sys.exit(1)
|
2008-09-13 02:04:02 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
# prepare the output directory
|
|
|
|
self.pinfo(":: preparing the output directory")
|
|
|
|
ok = self.prepare_outputdir()
|
|
|
|
if not ok:
|
|
|
|
self.pcritical("unable to prepare the output directory")
|
2009-12-15 14:26:01 +00:00
|
|
|
sys.exit(1)
|
2008-09-13 02:04:02 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
# write the treeinfo, discinfo and buildstamp
|
|
|
|
self.pinfo(":: creating the treeinfo, discinfo and buildstamp")
|
2009-12-15 14:26:01 +00:00
|
|
|
self.conf.treeinfo = self.write_treeinfo()
|
|
|
|
self.conf.discinfo = self.write_discinfo()
|
|
|
|
self.conf.buildstamp = self.write_buildstamp()
|
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
# create the initrd images for all kernels in install tree
|
|
|
|
initrd = images.InitRD(self.installtree, modules, initrd_template,
|
|
|
|
self.workdir)
|
|
|
|
|
2010-02-25 09:54:02 +00:00
|
|
|
# get all kernels and initrds
|
|
|
|
kernel_normal, kernel_pae, kernel_xen = [], [], []
|
2010-02-23 13:20:05 +00:00
|
|
|
for kernel, initrd in initrd.create():
|
2010-02-25 09:54:02 +00:00
|
|
|
if kernel.is_pae:
|
|
|
|
kernel_pae.append((kernel, initrd))
|
|
|
|
elif kernel.is_xen:
|
|
|
|
kernel_xen.append((kernel, initrd))
|
|
|
|
else:
|
|
|
|
kernel_normal.append((kernel, initrd))
|
|
|
|
|
|
|
|
# if we have a normal kernel, set it as the main kernel
|
|
|
|
kernels = []
|
|
|
|
try:
|
|
|
|
kernels.append(kernel_normal.pop(0))
|
|
|
|
except IndexError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
# add pae and xen kernels to the list of kernels
|
|
|
|
kernels.extend(kernel_pae)
|
|
|
|
kernels.extend(kernel_xen)
|
|
|
|
|
|
|
|
# check if we have at least one kernel
|
|
|
|
if not kernels:
|
|
|
|
self.pcritical("no kernel images found")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
# main kernel
|
|
|
|
kernel, initrd = kernels.pop(0)
|
|
|
|
kernelfile = "vmlinuz"
|
|
|
|
initrdfile = "initrd.img"
|
|
|
|
|
|
|
|
# add images section to treeinfo
|
|
|
|
section = "images-{0}".format(self.conf.basearch)
|
|
|
|
data = {"kernel": "images/pxeboot/{0}".format(kernelfile),
|
|
|
|
"initrd": "images/pxeboot/{0}".format(initrdfile)}
|
|
|
|
self.treeinfo_add_section(self.conf.treeinfo, section, data)
|
2010-02-25 14:17:39 +00:00
|
|
|
|
|
|
|
if self.conf.basearch == "i386":
|
|
|
|
# add the xen section for x86
|
|
|
|
section = "images-xen"
|
|
|
|
data = {"kernel": "images/pxeboot/{0}".format(kernelfile),
|
|
|
|
"initrd": "images/pxeboot/{0}".format(initrdfile)}
|
|
|
|
self.treeinfo_add_section(self.conf.treeinfo, section, data)
|
2010-02-25 09:54:02 +00:00
|
|
|
|
|
|
|
# copy the kernel and initrd image to the isolinux directory
|
|
|
|
kdst = os.path.join(self.conf.isodir, kernelfile)
|
|
|
|
idst = os.path.join(self.conf.isodir, initrdfile)
|
|
|
|
shutil.copy2(kernel.path, kdst)
|
|
|
|
shutil.copy2(initrd, idst)
|
|
|
|
|
|
|
|
# copy the kernel and initrd image to the pxe directory
|
|
|
|
kdst = os.path.join(self.conf.pxedir, kernelfile)
|
|
|
|
idst = os.path.join(self.conf.pxedir, initrdfile)
|
|
|
|
shutil.copy2(kernel.path, kdst)
|
|
|
|
shutil.copy2(initrd, idst)
|
|
|
|
|
|
|
|
# create the efi images
|
|
|
|
if self.installtree.do_efi:
|
|
|
|
efi = images.EFI(self.installtree, kernel, initrd,
|
|
|
|
self.product, self.version, self.workdir)
|
|
|
|
|
|
|
|
efiboot, efidisk = efi.create()
|
|
|
|
|
|
|
|
# copy the efi images to the images directory
|
|
|
|
shutil.copy2(efiboot, self.conf.imgdir)
|
|
|
|
shutil.copy2(efidisk, self.conf.imgdir)
|
|
|
|
|
|
|
|
# other kernels
|
|
|
|
for kernel, initrd in kernels:
|
2010-02-23 13:20:05 +00:00
|
|
|
if kernel.is_pae:
|
|
|
|
kernelfile = "vmlinuz-PAE"
|
|
|
|
initrdfile = "initrd-PAE.img"
|
2010-02-25 09:54:02 +00:00
|
|
|
# XXX add images section to treeinfo
|
2010-02-23 13:20:05 +00:00
|
|
|
section = "images-xen"
|
2010-02-25 09:54:02 +00:00
|
|
|
data = {"kernel": "images/pxeboot/{0}".format(kernelfile),
|
|
|
|
"initrd": "images/pxeboot/{0}".format(initrdfile)}
|
2010-02-23 13:20:05 +00:00
|
|
|
self.treeinfo_add_section(self.conf.treeinfo, section, data)
|
|
|
|
elif kernel.is_xen:
|
|
|
|
kernelfile = "vmlinuz-xen"
|
|
|
|
initrdfile = "initrd-xen.img"
|
2010-02-25 09:54:02 +00:00
|
|
|
# XXX add images section to treeinfo
|
|
|
|
section = "images-xen"
|
|
|
|
data = {"kernel": "images/pxeboot/{0}".format(kernelfile),
|
|
|
|
"initrd": "images/pxeboot/{0}".format(initrdfile)}
|
2010-02-23 13:20:05 +00:00
|
|
|
self.treeinfo_add_section(self.conf.treeinfo, section, data)
|
|
|
|
|
|
|
|
# copy the kernel and initrd image to the pxe directory
|
|
|
|
kdst = os.path.join(self.conf.pxedir, kernelfile)
|
|
|
|
idst = os.path.join(self.conf.pxedir, initrdfile)
|
|
|
|
shutil.copy2(kernel.path, kdst)
|
|
|
|
shutil.copy2(initrd, idst)
|
2008-09-13 02:04:02 +00:00
|
|
|
|
2009-12-15 14:26:01 +00:00
|
|
|
# create the install image
|
2010-02-23 13:20:05 +00:00
|
|
|
install = images.Install(self.installtree, install_template,
|
|
|
|
self.workdir)
|
2008-09-13 02:04:02 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
installimg = install.create()
|
|
|
|
if not installimg:
|
|
|
|
self.perror("unable to create the install image")
|
2009-12-15 14:26:01 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
# add stage2 section to the treeinfo
|
|
|
|
section = "stage2"
|
|
|
|
data = {"mainimage": "images/install.img"}
|
|
|
|
self.treeinfo_add_section(self.conf.treeinfo, section, data)
|
2009-12-15 14:26:01 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
# move the install image to the images directory
|
|
|
|
shutil.move(installimg, self.conf.imgdir)
|
2009-12-15 14:26:01 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
# create the boot iso image
|
|
|
|
boot = images.Boot(self.product, self.workdir)
|
|
|
|
bootiso = boot.create()
|
|
|
|
|
|
|
|
# add boot iso to the images section in treeinfo
|
|
|
|
section = "images-{0}".format(self.conf.basearch)
|
|
|
|
data = {"boot.iso": "images/boot.iso"}
|
|
|
|
self.treeinfo_add_section(self.conf.treeinfo, section, data)
|
2009-12-15 14:26:01 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
# move the boot iso to the images directory
|
|
|
|
shutil.move(bootiso, self.conf.imgdir)
|
2009-12-15 14:26:01 +00:00
|
|
|
|
|
|
|
# copy the treeinfo and discinfo to the output directory
|
2010-02-23 13:20:05 +00:00
|
|
|
shutil.copy2(self.conf.treeinfo, self.outputdir)
|
|
|
|
shutil.copy2(self.conf.discinfo, self.outputdir)
|
2009-12-15 14:26:01 +00:00
|
|
|
|
|
|
|
# cleanup
|
|
|
|
self.cleanup()
|
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
def get_buildarch(self):
|
2009-12-15 14:26:01 +00:00
|
|
|
# get the architecture of the anaconda package
|
2010-02-23 13:20:05 +00:00
|
|
|
installed, available = self.yum.search(self.const.ANACONDA_PACKAGE)
|
|
|
|
|
|
|
|
if installed:
|
|
|
|
anaconda = installed[0]
|
|
|
|
if available:
|
|
|
|
anaconda = available[0]
|
|
|
|
|
2008-10-10 03:04:13 +00:00
|
|
|
try:
|
2010-02-23 13:20:05 +00:00
|
|
|
buildarch = anaconda.arch
|
2009-06-04 13:36:56 +00:00
|
|
|
except:
|
2009-12-15 14:26:01 +00:00
|
|
|
# fallback to the system architecture
|
2010-02-23 13:20:05 +00:00
|
|
|
self.pwarning("using system architecture")
|
|
|
|
buildarch = os.uname()[4]
|
2009-06-04 13:36:56 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
return buildarch
|
2009-09-23 10:21:33 +00:00
|
|
|
|
2009-12-15 14:26:01 +00:00
|
|
|
def get_config(self):
|
|
|
|
generic = os.path.join(self.conf.confdir, "config.noarch")
|
|
|
|
specific = os.path.join(self.conf.confdir,
|
2010-02-23 13:20:05 +00:00
|
|
|
"config.{0}".format(self.conf.basearch))
|
2009-08-19 14:51:32 +00:00
|
|
|
|
2009-12-15 14:26:01 +00:00
|
|
|
packages, modules = set(), set()
|
2010-02-23 13:20:05 +00:00
|
|
|
initrd_template, install_template = None, None
|
2009-06-04 13:36:56 +00:00
|
|
|
|
2009-12-15 14:26:01 +00:00
|
|
|
for f in (generic, specific):
|
|
|
|
if not os.path.isfile(f):
|
|
|
|
continue
|
2009-08-25 16:26:52 +00:00
|
|
|
|
2009-12-15 14:26:01 +00:00
|
|
|
c = ConfigParser.ConfigParser()
|
|
|
|
c.read(f)
|
|
|
|
|
|
|
|
if c.has_option("lorax", "packages"):
|
|
|
|
list = c.get("lorax", "packages").split()
|
|
|
|
for name in list:
|
|
|
|
if name.startswith("-"):
|
|
|
|
packages.discard(name)
|
|
|
|
else:
|
|
|
|
packages.add(name)
|
|
|
|
|
|
|
|
if c.has_option("lorax", "modules"):
|
|
|
|
list = c.get("lorax", "modules").split()
|
|
|
|
for name in list:
|
|
|
|
if name.startswith("-"):
|
|
|
|
modules.discard(name)
|
|
|
|
else:
|
|
|
|
modules.add(name)
|
|
|
|
|
|
|
|
if c.has_option("lorax", "initrd_template"):
|
|
|
|
initrd_template = c.get("lorax", "initrd_template")
|
|
|
|
initrd_template = os.path.join(self.conf.confdir,
|
|
|
|
initrd_template)
|
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
if c.has_option("lorax", "install_template"):
|
|
|
|
install_template = c.get("lorax", "install_template")
|
|
|
|
install_template = os.path.join(self.conf.confdir,
|
|
|
|
install_template)
|
2009-12-15 14:26:01 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
return packages, modules, initrd_template, install_template
|
2009-08-25 16:26:52 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
def prepare_outputdir(self):
|
|
|
|
imgdir = os.path.join(self.outputdir, "images")
|
|
|
|
makedirs_(imgdir)
|
2009-12-15 14:26:01 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
# write the images/README file
|
|
|
|
text = """
|
|
|
|
This directory contains image files that can be used to create media
|
|
|
|
capable of starting the {0} installation process.
|
2009-06-04 13:36:56 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
The boot.iso file is an ISO 9660 image of a bootable CD-ROM. It is useful
|
|
|
|
in cases where the CD-ROM installation method is not desired, but the
|
|
|
|
CD-ROM's boot speed would be an advantage.
|
2009-09-23 10:21:33 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
To use this image file, burn the file onto CD-R (or CD-RW) media as you
|
|
|
|
normally would.
|
|
|
|
"""
|
2009-12-15 14:26:01 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
text = text.format(self.product)
|
|
|
|
with open(os.path.join(imgdir, "README"), "w") as f:
|
|
|
|
f.write(text)
|
2009-12-15 14:26:01 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
pxedir = os.path.join(imgdir, "pxeboot")
|
|
|
|
makedirs_(pxedir)
|
2008-10-06 01:08:38 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
# write the images/pxeboot/README file
|
|
|
|
text = """
|
|
|
|
The files in this directory are useful for booting a machine via PXE.
|
2009-06-04 13:36:56 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
The following files are available:
|
|
|
|
vmlinuz - the kernel used for the installer
|
|
|
|
initrd.img - an initrd with support for all install methods and
|
|
|
|
drivers supported for installation of {0}
|
|
|
|
"""
|
2009-12-15 14:26:01 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
text = text.format(self.product)
|
|
|
|
with open(os.path.join(pxedir, "README"), "w") as f:
|
|
|
|
f.write(text)
|
2009-09-23 10:21:33 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
efidir = os.path.join(self.outputdir, "EFI/BOOT")
|
|
|
|
makedirs_(efidir)
|
2008-10-04 01:46:01 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
isodir = os.path.join(self.outputdir, "isolinux")
|
|
|
|
makedirs_(isodir)
|
2009-12-15 14:26:01 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
self.conf.imgdir = imgdir
|
|
|
|
self.conf.pxedir = pxedir
|
|
|
|
self.conf.efidir = efidir
|
|
|
|
self.conf.isodir = isodir
|
2009-08-19 14:51:32 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
isolinuxbin = os.path.join(self.installtree.rootdir,
|
|
|
|
self.const.ISOLINUXBIN)
|
|
|
|
syslinuxcfg = os.path.join(self.installtree.rootdir,
|
|
|
|
self.const.SYSLINUXCFG)
|
2009-08-19 14:51:32 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
if not os.path.isfile(isolinuxbin):
|
|
|
|
self.perror("no isolinux binary found")
|
|
|
|
return False
|
2009-08-19 14:51:32 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
# copy the isolinux.bin file
|
|
|
|
shutil.copy2(isolinuxbin, self.conf.isodir)
|
2009-08-19 14:51:32 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
# copy the syslinux.cfg
|
|
|
|
isolinuxcfg = os.path.join(self.conf.isodir, "isolinux.cfg")
|
|
|
|
shutil.copy2(syslinuxcfg, isolinuxcfg)
|
2009-08-19 14:51:32 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
# set the product and version in isolinux.cfg
|
|
|
|
replace_(isolinuxcfg, r"@PRODUCT@", self.product)
|
|
|
|
replace_(isolinuxcfg, r"@VERSION@", self.version)
|
2009-12-15 14:26:01 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
# set up the label for finding stage2 with a hybrid iso
|
|
|
|
replace_(isolinuxcfg, r"initrd=initrd.img",
|
|
|
|
'initrd=initrd.img stage2=hd:LABEL="{0}"'.format(self.product))
|
2009-12-15 14:26:01 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
# copy the .msg files
|
|
|
|
msgfiles = os.path.join(self.const.ANACONDA_BOOTDIR, "*.msg")
|
|
|
|
msgfiles = os.path.join(self.installtree.rootdir, msgfiles)
|
|
|
|
for fname in glob.iglob(msgfiles):
|
|
|
|
shutil.copy2(fname, self.conf.isodir)
|
|
|
|
path = os.path.join(self.conf.isodir, os.path.basename(fname))
|
|
|
|
replace_(path, r"@VERSION@", self.version)
|
2009-08-19 14:51:32 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
# copy the memtest
|
|
|
|
memtest = os.path.join(self.const.BOOTDIR, "memtest*")
|
|
|
|
memtest = os.path.join(self.installtree.rootdir, memtest)
|
|
|
|
for fname in glob.iglob(memtest):
|
|
|
|
shutil.copy2(fname, os.path.join(self.conf.isodir, "memtest"))
|
2009-12-15 14:26:01 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
text = """label memtest86
|
|
|
|
menu label ^Memory test
|
|
|
|
kernel memtest
|
|
|
|
append -
|
2009-12-15 14:26:01 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
"""
|
2009-12-15 14:26:01 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
with open(isolinuxcfg, "a") as f:
|
|
|
|
f.write(text)
|
2009-12-15 14:26:01 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
break
|
2009-12-15 14:26:01 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
# copy the grub.conf
|
|
|
|
grubconf = os.path.join(self.installtree.rootdir,
|
|
|
|
self.const.ANACONDA_BOOTDIR, "grub.conf")
|
|
|
|
shutil.copy2(grubconf, isodir)
|
2009-08-25 16:26:52 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
# copy the splash files
|
|
|
|
vesasplash = os.path.join(self.installtree.rootdir,
|
|
|
|
self.const.VESASPLASH)
|
|
|
|
vesamenu = os.path.join(self.installtree.rootdir,
|
|
|
|
self.const.VESAMENU)
|
|
|
|
|
|
|
|
splashtools = os.path.join(self.installtree.rootdir,
|
|
|
|
self.const.SPLASHTOOLS)
|
|
|
|
syslinuxsplash = os.path.join(self.installtree.rootdir,
|
|
|
|
self.const.SYSLINUXSPLASH)
|
|
|
|
splashlss = os.path.join(self.installtree.rootdir,
|
|
|
|
self.const.SPLASHLSS)
|
|
|
|
|
|
|
|
if os.path.isfile(vesasplash):
|
|
|
|
shutil.copy2(vesasplash, os.path.join(isodir, "splash.jpg"))
|
|
|
|
shutil.copy2(vesamenu, isodir)
|
|
|
|
replace_(isolinuxcfg, r"default linux", "default vesamenu.c32")
|
|
|
|
replace_(isolinuxcfg, r"prompt 1", "#prompt 1")
|
|
|
|
else:
|
|
|
|
if os.path.isfile(splashtools):
|
|
|
|
cmd = "{0} {1} {2}".format(splashtools,
|
|
|
|
syslinuxsplash,
|
|
|
|
splashlss)
|
2009-08-25 16:26:52 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
err, stdout = commands.getstatusoutput(cmd)
|
|
|
|
if err:
|
|
|
|
self.pwarning(stdout)
|
2009-09-29 12:41:39 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
if os.path.isfile(splashlss):
|
|
|
|
shutil.copy2(splashlss, isodir)
|
2009-09-23 10:21:33 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
return True
|
2009-08-25 16:26:52 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
def write_treeinfo(self, discnum=1, totaldiscs=1, packagedir=""):
|
|
|
|
outfile = os.path.join(self.workdir, ".treeinfo")
|
2009-08-25 16:26:52 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
c = ConfigParser.ConfigParser()
|
2009-12-15 14:26:01 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
variant = self.variant
|
|
|
|
if variant is None:
|
|
|
|
variant = ""
|
2009-12-15 14:26:01 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
section = "general"
|
|
|
|
data = {"timestamp": time.time(),
|
|
|
|
"family": self.product,
|
|
|
|
"version": self.version,
|
|
|
|
"variant": variant,
|
|
|
|
"arch": self.conf.basearch,
|
|
|
|
"discnum": discnum,
|
|
|
|
"totaldiscs": totaldiscs,
|
|
|
|
"packagedir": packagedir}
|
2009-12-15 14:26:01 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
c.add_section(section)
|
|
|
|
map(lambda (key, value): c.set(section, key, value), data.items())
|
2009-12-15 14:26:01 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
with open(outfile, "w") as f:
|
|
|
|
c.write(f)
|
2009-12-15 14:26:01 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
return outfile
|
2009-12-15 14:26:01 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
def treeinfo_add_section(self, treeinfo, section, data):
|
|
|
|
c = ConfigParser.ConfigParser()
|
|
|
|
c.read(treeinfo)
|
2009-12-15 14:26:01 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
if not c.has_section(section):
|
|
|
|
c.add_section(section)
|
2009-12-15 14:26:01 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
map(lambda (key, value): c.set(section, key, value), data.items())
|
2009-12-15 14:26:01 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
with open(treeinfo, "w") as f:
|
|
|
|
c.write(f)
|
2009-08-25 16:26:52 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
def write_discinfo(self, discnum="ALL"):
|
|
|
|
outfile = os.path.join(self.workdir, ".discinfo")
|
|
|
|
|
|
|
|
with open(outfile, "w") as f:
|
|
|
|
f.write("{0:f}\n".format(time.time()))
|
|
|
|
f.write("{0}\n".format(self.release))
|
|
|
|
f.write("{0}\n".format(self.conf.basearch))
|
|
|
|
f.write("{0}\n".format(discnum))
|
2009-09-04 11:34:04 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
return outfile
|
2009-09-29 12:41:39 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
def write_buildstamp(self):
|
|
|
|
outfile = os.path.join(self.workdir, ".buildstamp")
|
2009-09-29 12:41:39 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
now = datetime.datetime.now()
|
|
|
|
uuid = "{0}.{1}"
|
|
|
|
uuid = uuid.format(now.strftime("%Y%m%d%H%M"), self.conf.buildarch)
|
|
|
|
|
|
|
|
with open(outfile, "w") as f:
|
|
|
|
f.write("{0}\n".format(uuid))
|
|
|
|
f.write("{0}\n".format(self.product))
|
|
|
|
f.write("{0}\n".format(self.version))
|
|
|
|
f.write("{0}\n".format(self.bugurl))
|
|
|
|
|
|
|
|
return outfile
|
2010-01-14 13:26:55 +00:00
|
|
|
|
2009-12-15 14:26:01 +00:00
|
|
|
def cleanup(self):
|
2010-02-23 13:20:05 +00:00
|
|
|
# TODO
|
|
|
|
pass
|
2009-08-19 14:51:32 +00:00
|
|
|
|
|
|
|
|
2009-12-15 14:26:01 +00:00
|
|
|
class YumHelper(object):
|
2009-08-19 14:51:32 +00:00
|
|
|
|
2009-12-15 14:26:01 +00:00
|
|
|
def __init__(self, yb):
|
|
|
|
self.yb = yb
|
2009-08-19 14:51:32 +00:00
|
|
|
|
2009-12-15 14:26:01 +00:00
|
|
|
def install(self, pattern):
|
|
|
|
try:
|
|
|
|
self.yb.install(name=pattern)
|
|
|
|
except yum.Errors.InstallError:
|
|
|
|
try:
|
|
|
|
self.yb.install(pattern=pattern)
|
|
|
|
except yum.Errors.InstallError:
|
|
|
|
return False
|
2009-08-19 14:51:32 +00:00
|
|
|
|
2009-12-15 14:26:01 +00:00
|
|
|
return True
|
2009-08-19 14:51:32 +00:00
|
|
|
|
2009-12-15 14:26:01 +00:00
|
|
|
def process_transaction(self):
|
|
|
|
self.yb.resolveDeps()
|
|
|
|
self.yb.buildTransaction()
|
2009-08-19 14:51:32 +00:00
|
|
|
|
2009-12-15 14:26:01 +00:00
|
|
|
cb = yum.callbacks.ProcessTransBaseCallback()
|
|
|
|
rpmcb = RpmCallback()
|
2008-09-13 02:04:02 +00:00
|
|
|
|
2009-12-15 14:26:01 +00:00
|
|
|
self.yb.processTransaction(callback=cb, rpmDisplay=rpmcb)
|
2009-08-25 16:26:52 +00:00
|
|
|
|
2009-12-15 14:26:01 +00:00
|
|
|
self.yb.closeRpmDB()
|
|
|
|
self.yb.close()
|
2009-08-25 16:26:52 +00:00
|
|
|
|
2009-12-15 14:26:01 +00:00
|
|
|
def search(self, pattern):
|
|
|
|
pl = self.yb.doPackageLists(patterns=[pattern])
|
|
|
|
return pl.installed, pl.available
|
2009-08-25 16:26:52 +00:00
|
|
|
|
2009-09-23 10:21:33 +00:00
|
|
|
|
2009-12-15 14:26:01 +00:00
|
|
|
class RpmCallback(yum.rpmtrans.SimpleCliCallBack):
|
2009-08-25 16:26:52 +00:00
|
|
|
|
2009-12-15 14:26:01 +00:00
|
|
|
def __init__(self):
|
|
|
|
yum.rpmtrans.SimpleCliCallBack.__init__(self)
|
2010-02-23 13:20:05 +00:00
|
|
|
self.output = output.LoraxOutput()
|
|
|
|
|
|
|
|
self.termwidth = 79
|
2008-10-10 03:04:13 +00:00
|
|
|
|
2009-12-15 14:26:01 +00:00
|
|
|
def event(self, package, action, te_current, te_total,
|
2010-02-23 13:20:05 +00:00
|
|
|
ts_current, ts_total):
|
|
|
|
|
|
|
|
info = "({0:3d}/{1:3d}) [{2:3.0f}%] {3} "
|
|
|
|
info = info.format(ts_current, ts_total,
|
|
|
|
float(te_current) / float(te_total) * 100,
|
|
|
|
self.action[action])
|
|
|
|
|
|
|
|
pkg = "{0}".format(package)
|
2009-12-15 14:26:01 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
infolen = len(info)
|
|
|
|
pkglen = len(pkg)
|
|
|
|
if (infolen + pkglen) > self.termwidth:
|
|
|
|
pkg = "{0}...".format(pkg[:self.termwidth-infolen-3])
|
2009-12-15 14:26:01 +00:00
|
|
|
|
2010-02-23 13:20:05 +00:00
|
|
|
msg = "{0}<b>{1}</b>\r".format(info, pkg)
|
2009-12-15 14:26:01 +00:00
|
|
|
self.output.write(msg)
|
|
|
|
if te_current == te_total:
|
|
|
|
self.output.write("\n")
|