[elbe-devel] [PATCH v3 3/8] debinstaller: implement download of vmlinuz and initrd.gz

Torben Hohn torben.hohn at linutronix.de
Mon Oct 15 15:18:01 CEST 2018


the debinstaller module shall replace elbe-bootstrap.
it downloads debian installer linux kernel and initrd.gz from
a debian mirror. It does that in a secure manner, iE validating
Release.gpg and SHA256SUMS on the way.

filenames on the mirror:
/debian/dists/jessie/main/installer-amd64/current/images/netboot/debian-installer/amd64/linux
/debian/dists/jessie/main/installer-amd64/current/images/netboot/debian-installer/amd64/initrd.gz
/debian/dists/jessie/main/installer-amd64/current/images/cdrom/initrd.gz

Although this functionality is also provided by apt,
we implement it here in pure python, because outside
of the initvm, we can not rely on apt being available.

The initrd and vmlinuz are stored in the initvm in /var/cache/elbe/installer.
Also put them on bin-cdrom.iso, and reuse them, when an elbe build
is run from cdrom.

since elbe uses elbepack.debinstaller outside of the initvm now,
the non-virtap fallback code is not needed anymore.
Remove it and make pkgutils.py pylint clean.
Also rename the, now moved to debinstaller, NoKinitrdException
to NoPackageException.

Also remove code dealing with elbe bootstrap in packagelists and
xmldefaults.

Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
---
 debian/python-elbe-common.install  |   1 +
 debian/python3-elbe-common.install |   1 +
 elbepack/cdroms.py                 |  18 +--
 elbepack/commands/init.py          |   4 +-
 elbepack/debinstaller.py           | 247 +++++++++++++++++++++++++++++++++++++
 elbepack/dump.py                   |   6 -
 elbepack/init/Makefile.mako        |   2 +
 elbepack/init/init-elbe.sh.mako    |   4 +
 elbepack/pkgutils.py               | 193 ++++-------------------------
 elbepack/xmldefaults.py            |   1 -
 10 files changed, 288 insertions(+), 189 deletions(-)
 create mode 100644 elbepack/debinstaller.py

diff --git a/debian/python-elbe-common.install b/debian/python-elbe-common.install
index 1c71ab61..e4edc8f9 100644
--- a/debian/python-elbe-common.install
+++ b/debian/python-elbe-common.install
@@ -9,6 +9,7 @@
 ./usr/lib/python2.*/*-packages/elbepack/aptprogress.py
 ./usr/lib/python2.*/*-packages/elbepack/archivedir.py
 ./usr/lib/python2.*/*-packages/elbepack/config.py
+./usr/lib/python2.*/*-packages/elbepack/debinstaller.py
 ./usr/lib/python2.*/*-packages/elbepack/default-preseed.xml
 ./usr/lib/python2.*/*-packages/elbepack/directories.py
 ./usr/lib/python2.*/*-packages/elbepack/dosunix.py
diff --git a/debian/python3-elbe-common.install b/debian/python3-elbe-common.install
index 744a3342..94398a51 100644
--- a/debian/python3-elbe-common.install
+++ b/debian/python3-elbe-common.install
@@ -9,6 +9,7 @@
 ./usr/lib/python3.*/*-packages/elbepack/aptprogress.py
 ./usr/lib/python3.*/*-packages/elbepack/archivedir.py
 ./usr/lib/python3.*/*-packages/elbepack/config.py
+./usr/lib/python3.*/*-packages/elbepack/debinstaller.py
 ./usr/lib/python3.*/*-packages/elbepack/default-preseed.xml
 ./usr/lib/python3.*/*-packages/elbepack/directories.py
 ./usr/lib/python3.*/*-packages/elbepack/dosunix.py
diff --git a/elbepack/cdroms.py b/elbepack/cdroms.py
index 9e267228..d7207e44 100644
--- a/elbepack/cdroms.py
+++ b/elbepack/cdroms.py
@@ -7,6 +7,7 @@
 # SPDX-License-Identifier: GPL-3.0-or-later
 
 import os
+from shutil import copyfile
 
 from apt.package import FetchError
 from apt import Cache
@@ -96,11 +97,7 @@ def mk_source_cdrom(
         if pkg.name in forbiddenPackages:
             continue
         try:
-            p = cache[pkg.name]
-            if pkg.name == 'elbe-bootstrap':
-                pkgver = p.versions[0]
-            else:
-                pkgver = p.installed
+            pkgver = cache[pkg.name].installed
 
             dsc = pkgver.fetch_source(
                 '/var/cache/elbe/sources',
@@ -162,10 +159,7 @@ def mk_binary_cdrom(
         for pkg in pkglist:
             try:
                 p = cache[pkg.name]
-                if pkg.name == 'elbe-bootstrap':
-                    pkgver = p.versions[0]
-                else:
-                    pkgver = p.installed
+                pkgver = p.installed
                 deb = pkgver.fetch_binary('/var/cache/elbe/binaries/main',
                                           ElbeAcquireProgress(cb=None))
                 repo.includedeb(deb, 'main')
@@ -258,6 +252,12 @@ def mk_binary_cdrom(
     # write source xml onto cdrom
     xml.xml.write(repo_fs.fname('source.xml'))
 
+    # copy initvm-cdrom.gz and vmlinuz
+    copyfile('/var/cache/elbe/installer/initrd-cdrom.gz',
+             repo_fs.fname('initrd-cdrom.gz'))
+    copyfile('/var/cache/elbe/installer/vmlinuz',
+             repo_fs.fname('vmlinuz'))
+
     target_repo_fs = Filesystem(target_repo_path)
     target_repo_fs.write_file(".aptignr", 0o644, "")
 
diff --git a/elbepack/commands/init.py b/elbepack/commands/init.py
index 9445c69d..61a30447 100644
--- a/elbepack/commands/init.py
+++ b/elbepack/commands/init.py
@@ -15,7 +15,7 @@ from optparse import OptionParser
 
 from elbepack.treeutils import etree
 from elbepack.validate import validate_xml
-from elbepack.pkgutils import copy_kinitrd, NoKinitrdException
+from elbepack.debinstaller import copy_kinitrd, NoKinitrdException
 from elbepack.xmldefaults import ElbeDefaults
 from elbepack.version import elbe_version
 from elbepack.templates import write_template, get_initvm_preseed
@@ -165,7 +165,7 @@ def run_command(argv):
         os.putenv("no_proxy", "localhost,127.0.0.1")
 
     try:
-        copy_kinitrd(xml.node("/initvm"), out_path, defs, arch="amd64")
+        copy_kinitrd(xml.node("/initvm"), out_path)
     except NoKinitrdException as e:
         print("Failure to download kernel/initrd debian Package:")
         print("")
diff --git a/elbepack/debinstaller.py b/elbepack/debinstaller.py
new file mode 100644
index 00000000..d251f202
--- /dev/null
+++ b/elbepack/debinstaller.py
@@ -0,0 +1,247 @@
+# ELBE - Debian Based Embedded Rootfilesystem Builder
+# Copyright (c) 2018 Torben Hohn <torben.hohn at linutronix.de>
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+from __future__ import print_function
+
+import sys
+import os
+import re
+
+# different module names in python 2 and 3
+try:
+    import urllib.request
+
+    # when running inside pylint this import fails
+    # disable no-member here
+    #
+    # pylint: disable=no-member
+
+    urlopen = urllib.request.urlopen
+except ImportError:
+    import urllib2
+    urlopen = urllib2.urlopen
+
+from shutil import copyfileobj, copyfile
+from gpgme import Context
+
+from elbepack.filesystem import TmpdirFilesystem
+from elbepack.gpg import OverallStatus, check_signature
+from elbepack.shellhelper import CommandError, system
+from elbepack.hashes import HashValidator, HashValidationFailed
+
+
+class InvalidSignature(Exception):
+    pass
+
+
+class NoKinitrdException(Exception):
+    pass
+
+
+class ReleaseFile(HashValidator):
+    def __init__(self, base_url, fname, fname_list):
+
+        HashValidator.__init__(self, base_url)
+
+        header_re = re.compile(r'(\w+):(.*)')
+        hash_re = re.compile(r' ([0-9a-f]+)\s+([0-9]+)\s+(\S+)')
+        current_header = ''
+
+        with open(fname, 'r') as fp:
+            for l in fp.readlines():
+                m = header_re.match(l)
+                if m:
+                    # line contains an rfc822 Header,
+                    # remember it.
+                    current_header = m.group(1)
+                    continue
+
+                m = hash_re.match(l)
+                if m:
+                    # line contains a hash entry.
+                    # check filename, whether we are interested in it
+                    if m.group(3) in fname_list:
+                        self.insert_fname_hash(current_header,
+                                               m.group(3),
+                                               m.group(1))
+
+
+class SHA256SUMSFile(HashValidator):
+    def __init__(self, base_url, fname, fname_list):
+
+        HashValidator.__init__(self, base_url)
+
+        hash_re = re.compile(r'([0-9a-f]+)\s+(\S+)')
+
+        with open(fname, 'r') as fp:
+            for l in fp.readlines():
+                m = hash_re.match(l)
+                if m:
+                    # line contains a hash entry.
+                    # check filename, whether we are interested in it
+                    if m.group(2) in fname_list:
+                        self.insert_fname_hash("SHA256",
+                                               m.group(2),
+                                               m.group(1))
+
+
+def setup_apt_keyring(gpg_home, keyring_fname):
+    ring_path = os.path.join(gpg_home, keyring_fname)
+    if not os.path.isdir("/etc/apt/trusted.gpg.d"):
+        print("/etc/apt/trusted.gpg.d doesn't exist")
+        print("apt-get install debian-archive-keyring may "
+              "fix this problem")
+        sys.exit(20)
+
+    if os.path.exists("/etc/apt/trusted.gpg"):
+        system('cp /etc/apt/trusted.gpg "%s"' % ring_path)
+
+    gpg_options = '--keyring "%s" --no-auto-check-trustdb ' \
+                  '--trust-model always --no-default-keyring ' \
+                  '--homedir "%s"' % (ring_path, gpg_home)
+
+    trustkeys = os.listdir("/etc/apt/trusted.gpg.d")
+    for key in trustkeys:
+        print("Import %s: " % key)
+        try:
+            system('gpg %s --import "%s"' % (
+                gpg_options,
+                os.path.join("/etc/apt/trusted.gpg.d", key)))
+        except CommandError:
+            print('adding keyring "%s" to keyring "%s" failed' % (key,
+                                                                  ring_path))
+
+
+def download(url, local_fname):
+    try:
+        rf = urlopen(url, None, 10)
+        with open(local_fname, "w") as wf:
+            copyfileobj(rf, wf)
+    finally:
+        rf.close()
+
+
+def download_release(tmp, base_url):
+
+    # setup gpg context, for verifying
+    # the Release.gpg signature.
+    os.environ['GNUPGHOME'] = tmp.fname('/')
+    ctx = Context()
+
+    # download the Relase file to a tmp file,
+    # because we need it 2 times
+    download(base_url + "Release", tmp.fname('Release'))
+
+    # validate signature.
+    # open downloaded plaintext file, and
+    # use the urlopen object of the Release.gpg
+    # directtly.
+    try:
+        sig = urlopen(base_url + 'Release.gpg', None, 10)
+        with tmp.open("Release", "r") as signed:
+
+            overall_status = OverallStatus()
+
+            # verify detached signature
+            sigs = ctx.verify(sig, signed, None)
+
+            for s in sigs:
+                status = check_signature(ctx, s)
+                overall_status.add(status)
+
+            if overall_status.to_exitcode():
+                raise InvalidSignature('Failed to verify Release file')
+    finally:
+        sig.close()
+
+
+def download_kinitrd(tmp, suite, mirror):
+    base_url = "%s/dists/%s/" % (
+        mirror.replace("LOCALMACHINE", "localhost"), suite)
+    installer_path = "main/installer-amd64/current/images/"
+
+    setup_apt_keyring(tmp.fname('/'), 'pubring.gpg')
+
+    # download release file and check
+    # signature
+    download_release(tmp, base_url)
+
+    # parse Release file, and remember hashvalues
+    # we are interested in
+    interesting = [installer_path + 'SHA256SUMS']
+    release_file = ReleaseFile(base_url, tmp.fname('Release'), interesting)
+
+    # now download and validate SHA256SUMS
+    release_file.download_and_validate_file(
+            installer_path + 'SHA256SUMS',
+            tmp.fname('SHA256SUMS'))
+
+    # now we have a valid SHA256SUMS file
+    # parse it
+    interesting = ['./cdrom/initrd.gz',
+                   './cdrom/vmlinuz',
+                   './netboot/debian-installer/amd64/initrd.gz',
+                   './netboot/debian-installer/amd64/linux']
+    sha256_sums = SHA256SUMSFile(
+            base_url + installer_path,
+            tmp.fname('SHA256SUMS'),
+            interesting)
+
+    # and then download the files we actually want
+    for p, ln in zip(interesting, ['initrd-cdrom.gz',
+                                   'linux-cdrom',
+                                   'initrd.gz',
+                                   'vmlinuz']):
+        sha256_sums.download_and_validate_file(
+                p,
+                tmp.fname(ln))
+
+
+def get_primary_mirror(prj):
+    if prj.has("mirror/primary_host"):
+        m = prj.node("mirror")
+
+        mirror = m.text("primary_proto") + "://"
+        mirror += m.text("primary_host") + "/"
+        mirror += m.text("primary_path")
+    else:
+        raise NoKinitrdException("Broken xml file: "
+                                 "no cdrom and no primary host")
+
+    return mirror
+
+
+def copy_kinitrd(prj, target_dir):
+
+    suite = prj.text("suite")
+
+    try:
+        tmp = TmpdirFilesystem()
+        if prj.has("mirror/cdrom"):
+            system('7z x -o%s "%s" initrd-cdrom.gz vmlinuz' %
+                   (tmp.fname('/'), prj.text("mirror/cdrom")))
+
+            # initrd.gz needs to be cdrom version !
+            copyfile(tmp.fname("initrd-cdrom.gz"),
+                     os.path.join(target_dir, "initrd.gz"))
+        else:
+            mirror = get_primary_mirror(prj)
+            download_kinitrd(tmp, suite, mirror)
+
+            copyfile(tmp.fname("initrd.gz"),
+                     os.path.join(target_dir, "initrd.gz"))
+
+        copyfile(tmp.fname("initrd-cdrom.gz"),
+                 os.path.join(target_dir, "initrd-cdrom.gz"))
+
+        copyfile(tmp.fname("vmlinuz"),
+                 os.path.join(target_dir, "vmlinuz"))
+
+    except IOError as e:
+        raise NoKinitrdException('IoError %s' % e.message)
+    except InvalidSignature as e:
+        raise NoKinitrdException('InvalidSignature %s' % e.message)
+    except HashValidationFailed as e:
+        raise NoKinitrdException('HashValidationFailed %s' % e.message)
diff --git a/elbepack/dump.py b/elbepack/dump.py
index cce60315..377a18e9 100644
--- a/elbepack/dump.py
+++ b/elbepack/dump.py
@@ -23,12 +23,6 @@ def get_initvm_pkglist():
         cache = Cache()
         cache.open()
         pkglist = [APTPackage(p) for p in cache if p.is_installed]
-        try:
-            eb = APTPackage(cache['elbe-bootstrap'])
-            pkglist.append(eb)
-        # elbe bootstrap is not installed on pc running elbe
-        except KeyError:
-            pass
 
     return pkglist
 
diff --git a/elbepack/init/Makefile.mako b/elbepack/init/Makefile.mako
index 06c0e0e5..4c2f323b 100644
--- a/elbepack/init/Makefile.mako
+++ b/elbepack/init/Makefile.mako
@@ -62,6 +62,8 @@ all: .stamps/stamp-install-initial-image
 	cp .elbe-in/source.xml tmp-tree/
 	mkdir -p tmp-tree/usr/share/keyrings
 	-cp .elbe-in/*.gpg tmp-tree/usr/share/keyrings
+	cp .elbe-in/initrd-cdrom.gz tmp-tree/
+	cp .elbe-in/vmlinuz tmp-tree/
 % if opt.devel:
 	cp .elbe-in/elbe-devel.tar.bz2 tmp-tree/
 % endif
diff --git a/elbepack/init/init-elbe.sh.mako b/elbepack/init/init-elbe.sh.mako
index 4234ec74..b29480dc 100644
--- a/elbepack/init/init-elbe.sh.mako
+++ b/elbepack/init/init-elbe.sh.mako
@@ -24,6 +24,10 @@ cp /etc/apt/apt.conf /buildenv/etc/apt/apt.conf.d/50elbe
 ln -s /lib/systemd/system/serial-getty at .service /buildenv/etc/systemd/system/getty.target.wants/serial-getty at ttyS0.service
 % endif
 
+mkdir /buildenv/var/cache/elbe/installer
+cp initrd-cdrom.gz /buildenv/var/cache/elbe/installer
+cp vmlinuz /buildenv/var/cache/elbe/installer
+
 % if opt.devel:
    mkdir /buildenv/var/cache/elbe/devel
    tar xj -f elbe-devel.tar.bz2 -C /buildenv/var/cache/elbe/devel
diff --git a/elbepack/pkgutils.py b/elbepack/pkgutils.py
index 0a68a819..0c4e97fb 100644
--- a/elbepack/pkgutils.py
+++ b/elbepack/pkgutils.py
@@ -7,51 +7,18 @@
 
 from __future__ import print_function
 
-# different module names in python 2 and 3
-try:
-    import urllib.request
-
-    # when running inside pylint this import fails
-    # disable no-member here
-    #
-    # pylint: disable=no-member
-
-    urlopen = urllib.request.urlopen
-except ImportError:
-    import urllib2
-    urlopen = urllib2.urlopen
-
 import os
-import hashlib
 
 from tempfile import mkdtemp
 
-from pkg_resources import parse_version as V
+from apt_pkg import TagFile
 from elbepack.shellhelper import CommandError, system
+from elbepack.virtapt import get_virtaptcache
+from elbepack.hashes import validate_sha256, HashValidationFailed
 
-try:
-    # this can not be grouped properly
-    # because we can fallback of apt_pkg is not available
-    #
-    # pylint: disable=ungrouped-imports
-
-    from apt_pkg import TagFile
-    from elbepack.virtapt import get_virtaptcache
-    virtapt_imported = True
-except ImportError as e:
-    print(e)
-    print("WARNING - python-apt not available:")
-    print("If there are multiple versions of elbe-bootstrap packages on the "
-          "mirror(s) elbe selects the first package it has found.")
-    print("There is no guarantee that the latest package is used.")
-    print("To ensure this, the python-apt package needs to be installed.")
-    virtapt_imported = False
-
-
-class NoKinitrdException(Exception):
+class NoPackageException(Exception):
     pass
 
-
 def get_sources_list(prj, defs):
 
     suite = prj.text("suite")
@@ -65,13 +32,6 @@ def get_sources_list(prj, defs):
         slist += "deb %s %s main\n" % (mirror, suite)
         slist += "deb-src %s %s main\n" % (mirror, suite)
 
-    if prj.has("mirror/cdrom"):
-        tmpdir = mkdtemp()
-        kinitrd = prj.text("buildimage/kinitrd", default=defs, key="kinitrd")
-        system('7z x -o%s "%s" pool/main/%s/%s dists' %
-               (tmpdir, prj.text("mirror/cdrom"), kinitrd[0], kinitrd))
-        slist += "deb file://%s %s main\n" % (tmpdir, suite)
-
     if prj.node("mirror/url-list"):
         for n in prj.node("mirror/url-list"):
             if n.has("binary"):
@@ -95,77 +55,6 @@ def get_key_list(prj):
     return retval
 
 
-def get_initrd_pkg(prj, defs):
-    initrdname = prj.text("buildimage/kinitrd", default=defs, key="kinitrd")
-
-    return initrdname
-
-
-def get_url(arch, suite, target_pkg, mirror, comp='main'):
-
-    # pylint: disable=too-many-locals
-
-    try:
-        pack_url = "%s/dists/%s/%s/binary-%s/Packages" % (
-            mirror.replace("LOCALMACHINE", "localhost"), suite, comp, arch)
-        packages = urllib2.urlopen(pack_url, None, 10)
-
-        packages = packages.readlines()
-        packages = [x for x in packages if x.startswith("Filename")]
-        packages = [x for x in packages if x.find(target_pkg) != -1]
-
-        # detect package with latest version number
-        latest_version_str = '0+deb0u0+deb8'
-        latest_version_pos = 0
-        cnt = 0
-        for x in packages:
-            # extract version from path/name_version_arch
-            version = x.split('_')[1]
-            subcount = 0
-            # iterate over all parts of the version seperated by '+'
-            # this is enough for elbe-bootstrap package, however '~', etc.
-            # should be considered for official debian packages..
-            for subv in version.split('+'):
-                try:
-                    if V(subv) >= V(latest_version_str.split('+')[subcount]):
-                        subcount = subcount + 1
-                    else:
-                        break
-                # current version has more parts then the reference version
-                except IndexError:
-                    subcount = subcount + 1
-            # if iteration over all parts of the version string suceeded,
-            # a new latest_version is detected
-            if subcount == len(version.split('+')):
-                latest_version_pos = cnt
-                latest_version_str = version
-            cnt = cnt + 1
-
-        urla = packages[latest_version_pos].split()
-        url = "%s/%s" % (mirror.replace("LOCALMACHINE", "localhost"), urla[1])
-    except IOError:
-        url = ""
-    except IndexError:
-        url = ""
-
-    return url
-
-
-def get_uri_nonvirtapt(apt_sources, target_pkg, arch):
-    for apts in apt_sources.splitlines():
-        apts_split = apts.strip().split(' ')
-        if apts_split[0] != 'deb':
-            continue
-
-        for comp in apts_split[2:]:
-            pkg = get_url(arch, apts_split[2], target_pkg, apts_split[1], comp)
-
-            if pkg:
-                return [(target_pkg, pkg, "")]
-
-    return [(target_pkg, "nonexistent://" + target_pkg, "")]
-
-
 def get_uri(prj, defs, arch, target_pkg, incl_deps=False):
     if arch == "default":
         arch = prj.text("buildimage/arch", default=defs, key="arch")
@@ -174,26 +63,15 @@ def get_uri(prj, defs, arch, target_pkg, incl_deps=False):
     apt_sources = get_sources_list(prj, defs)
     apt_keys = get_key_list(prj)
 
-    if virtapt_imported:
-        try:
-            if arch == "default":
-                arch = prj.text("buildimage/arch", default=defs, key="arch")
-            suite = prj.text("suite")
-            v = get_virtaptcache(arch, suite, apt_sources, "", apt_keys)
-        except Exception as e:
-            print("python-apt failed, using fallback code: %s" % e)
-            return get_uri_nonvirtapt(apt_sources, target_pkg, arch)
-
-        ret = v.get_uri(target_pkg, incl_deps)
-        return ret
-
-    return get_uri_nonvirtapt(apt_sources, target_pkg, arch)
+    if arch == "default":
+        arch = prj.text("buildimage/arch", default=defs, key="arch")
+    suite = prj.text("suite")
+    v = get_virtaptcache(arch, suite, apt_sources, "", apt_keys)
 
+    ret = v.get_uri(target_pkg, incl_deps)
+    return ret
 
 def get_dsc_size(fname):
-    if not virtapt_imported:
-        return 0
-
     tf = TagFile(fname)
 
     sz = os.path.getsize(fname)
@@ -206,7 +84,6 @@ def get_dsc_size(fname):
 
     return sz
 
-
 def download_pkg(prj,
                  target_dir,
                  defs,
@@ -222,14 +99,14 @@ def download_pkg(prj,
     try:
         urilist = get_uri(prj, defs, arch, package, incl_deps)
     except KeyError:
-        raise NoKinitrdException('no package %s available' % package)
+        raise NoPackageException('no package %s available' % package)
     except SystemError:
-        raise NoKinitrdException('a configured mirror is not reachable')
+        raise NoPackageException('a configured mirror is not reachable')
     except CommandError:
-        raise NoKinitrdException("couldn't download package %s" % package)
+        raise NoPackageException("couldn't download package %s" % package)
 
     if not urilist:
-        raise NoKinitrdException("couldn't download package %s" % package)
+        raise NoPackageException("couldn't download package %s" % package)
 
     for u in urilist:
         sha256 = u[2]
@@ -242,19 +119,17 @@ def download_pkg(prj,
             elif uri.startswith("http://") or uri.startswith("ftp://"):
                 system('wget -O "%s" "%s"' % (dest, uri))
             else:
-                raise NoKinitrdException('could not retreive %s' % uri)
+                raise NoPackageException('could not retreive %s' % uri)
         except CommandError:
-            raise NoKinitrdException("couldn't download package %s" % package)
+            raise NoPackageException("couldn't download package %s" % package)
 
         if sha256:
-            m = hashlib.sha256()
-            with open(dest, "rb") as f:
-                buf = f.read(65536)
-                while len(buf) > 0:
-                    m.update(buf)
-                    buf = f.read(65536)
-            if m.hexdigest() != sha256:
-                raise NoKinitrdException('%s failed to verify !!!' % package)
+            try:
+                validate_sha256(dest, sha256)
+            except HashValidationFailed as e:
+                raise NoPackageException('%s failed to verify: %s' %
+                        package,
+                        e.message)
         else:
             if log:
                 log.printo("WARNING: Using untrusted %s package" % package)
@@ -287,27 +162,3 @@ def extract_pkg(prj, target_dir, defs, package, arch="default",
                 system('ar p "%s" data.tar.xz | tar xJ -C "%s"' % (ppath,
                                                                    target_dir))
         system('rm -f "%s"' % ppath)
-
-
-def copy_kinitrd(prj, target_dir, defs, arch="default"):
-
-    target_pkg = get_initrd_pkg(prj, defs)
-
-    try:
-        tmpdir = mkdtemp()
-        extract_pkg(prj, tmpdir, defs, target_pkg, arch)
-
-        # copy is done twice, because paths in elbe-bootstarp_1.0 and 0.9
-        # differ
-        initrd = os.path.join(tmpdir, 'var', 'lib', 'elbe', 'initrd')
-        if prj.has("mirror/cdrom"):
-            system('cp "%s" "%s"' % (os.path.join(initrd, 'initrd-cdrom.gz'),
-                                     os.path.join(target_dir, "initrd.gz")))
-        else:
-            system('cp "%s" "%s"' % (os.path.join(initrd, 'initrd.gz'),
-                                     os.path.join(target_dir, "initrd.gz")))
-
-        system('cp "%s" "%s"' % (os.path.join(initrd, 'vmlinuz'),
-                                 os.path.join(target_dir, "vmlinuz")))
-    finally:
-        system('rm -rf "%s"' % tmpdir)
diff --git a/elbepack/xmldefaults.py b/elbepack/xmldefaults.py
index a42df002..3a9e8684 100644
--- a/elbepack/xmldefaults.py
+++ b/elbepack/xmldefaults.py
@@ -138,7 +138,6 @@ i386_defaults = {
 }
 
 archindep_defaults = {
-    "kinitrd": "elbe-bootstrap",
     "name": "elbe-buildenv",
     "size": "20G",
     "img": "qcow2",
-- 
2.11.0




More information about the elbe-devel mailing list