Exemple #1
0
    def losetup(self):
        cmd = ('losetup --offset %d --sizelimit %d --find --show "%s"' %
               (self.offset, self.size, self.filename))
        try:
            loopdev = get_command_out(cmd)
        except CommandError as e:
            if e.returncode != 1:
                raise
            do('sync')
            loopdev = get_command_out(cmd)

        return loopdev.rstrip('\n')
Exemple #2
0
 def dpkg_get_infos(self, path, fmt):
     """Get dpkg infos for .deb and .dsc file formats"""
     try:
         if path.endswith(".deb"):
             cmd = 'dpkg -f "%s" %s' % (path, " ".join(fmt))
         elif path.endswith(".dsc"):
             cmd = 'grep -E "^(%s):" %s' % ("|".join(fmt), path)
         return get_command_out(cmd).decode("utf-8")
     except CommandError as E:
         self.fail("Failed to get debian infos (%s) for %s:\n%s" %
                   ('|'.join(fmt), path, E))
Exemple #3
0
    def execute_prj(self, buildenv, target, builddir):
        imgname = self.node.et.attrib['img']
        imgpath = os.path.join(builddir, imgname)
        cmd = 'losetup --find --show --partscan "%s"' % imgpath

        loop_dev = get_command_out(cmd).strip()
        try:
            for i in self.node:
                action = ImageFinetuningAction(i)
                action.execute_img(buildenv, target, builddir, loop_dev)
        finally:
            cmd = 'losetup --detach "%s"' % loop_dev
            do(cmd)
Exemple #4
0
    def losetup(self):

        cmd = ('losetup --offset %d --sizelimit %d --find --show "%s"' %
               (self.offset, self.size, self.filename))

        while True:

            try:
                loopdev = get_command_out(cmd)
            except CommandError as e:
                if e.returncode != 1:
                    raise
                do('sync')
                time.sleep(1)
            else:
                break

        return loopdev.decode().rstrip('\n')
Exemple #5
0
    def debootstrap(self, arch="default"):

        # pylint: disable=too-many-statements
        # pylint: disable=too-many-branches

        cleanup = False
        suite = self.xml.prj.text("suite")

        primary_mirror = self.xml.get_primary_mirror(
            self.rfs.fname('/cdrom/targetrepo'))

        if self.xml.prj.has("mirror/primary_proxy"):
            os.environ["no_proxy"] = "10.0.2.2,localhost,127.0.0.1"
            proxy = self.xml.prj.text("mirror/primary_proxy")
            proxy = proxy.strip().replace("LOCALMACHINE", "localhost")
            os.environ["http_proxy"] = proxy
            os.environ["https_proxy"] = proxy
        else:
            os.environ["no_proxy"] = ""
            os.environ["http_proxy"] = ""
            os.environ["https_proxy"] = ""

        os.environ["LANG"] = "C"
        os.environ["LANGUAGE"] = "C"
        os.environ["LC_ALL"] = "C"
        os.environ["DEBIAN_FRONTEND"] = "noninteractive"
        os.environ["DEBONF_NONINTERACTIVE_SEEN"] = "true"

        logging.info("Debootstrap log")

        if arch == "default":
            arch = self.xml.text("project/buildimage/arch", key="arch")

        host_arch = get_command_out("dpkg --print-architecture").strip().decode()

        includepkgs = None
        strapcmd  = 'debootstrap '
        if self.xml.has("target/debootstrapvariant"):
            bootstrapvariant = self.xml.text("target/debootstrapvariant")
            includepkgs = self.xml.node("target/debootstrapvariant").et.get("includepkgs")
            strapcmd += '--variant="%s" ' % bootstrapvariant

        if includepkgs and not "gnupg" in includepkgs.split(','):
            includepkgs += ",gnupg"
        if not includepkgs:
            includepkgs = "gnupg"

        strapcmd += ' --include="%s"' % includepkgs

        if not self.xml.is_cross(host_arch):
            # ignore gpg verification if install from cdrom, cause debootstrap
            # seems to ignore /etc/apt/trusted.gpg.d/elbe-keyring.gpg
            # 01/2017 manut
            if self.xml.has(
                    "project/noauth") or self.xml.has("project/mirror/cdrom"):
                cmd = '%s --no-check-gpg --arch=%s "%s" "%s" "%s"' % (
                    strapcmd, arch, suite, self.rfs.path, primary_mirror)
            else:
                cmd = '%s --arch=%s "%s" "%s" "%s"' % (
                    strapcmd, arch, suite, self.rfs.path, primary_mirror)

            try:
                self.cdrom_mount()
                do(cmd)
            except CommandError:
                cleanup = True
                raise DebootstrapException()
            finally:
                self.cdrom_umount()
                if cleanup:
                    self.rfs.rmtree("/")

            return

        if self.xml.has("project/noauth"):
            cmd = '%s --no-check-gpg --foreign --arch=%s "%s" "%s" "%s"' % (
                strapcmd, arch, suite, self.rfs.path, primary_mirror)
        else:
            if self.xml.has("project/mirror/cdrom"):
                keyring = ' --keyring="%s/targetrepo/elbe-keyring.gpg"' % (
                    self.rfs.fname("cdrom"))
            else:
                keyring = ''

            cmd = '%s --foreign --arch=%s %s "%s" "%s" "%s"' % (
                strapcmd, arch, keyring, suite, self.rfs.path, primary_mirror)

        try:
            self.cdrom_mount()
            do(cmd)

            ui = "/usr/share/elbe/qemu-elbe/" + self.xml.defs["userinterpr"]

            if not os.path.exists(ui):
                ui = "/usr/bin/" + self.xml.defs["userinterpr"]

            do('cp %s %s' % (ui, self.rfs.fname("usr/bin")))

            if self.xml.has("project/noauth"):
                chroot(self.rfs.path,
                       '/debootstrap/debootstrap --no-check-gpg --second-stage')
            else:
                chroot(self.rfs.path,
                       '/debootstrap/debootstrap --second-stage')

            chroot(self.rfs.path, 'dpkg --configure -a')

        except CommandError:
            cleanup = True
            raise DebootstrapException()
        finally:
            self.cdrom_umount()
            if cleanup:
                self.rfs.rmtree("/")
Exemple #6
0
 def losetup(self, f):
     loopdev = get_command_out('losetup --find --show "%s"' % f)
     return loopdev.rstrip('\n')
 def losetup(f):
     loopdev = get_command_out('losetup --find --show "%s"' % f)
     return loopdev.decode().rstrip('\n')
Exemple #8
0
def extract_target(src, xml, dst, cache):

    # pylint: disable=too-many-locals
    # pylint: disable=too-many-branches

    # create filelists describing the content of the target rfs
    if xml.tgt.has("tighten") or xml.tgt.has("diet"):
        pkglist = [
            n.et.text for n in xml.node('target/pkg-list') if n.tag == 'pkg'
        ]
        arch = xml.text("project/buildimage/arch", key="arch")

        if xml.tgt.has("diet"):
            withdeps = []
            for p in pkglist:
                deps = cache.get_dependencies(p)
                withdeps += [d.name for d in deps]
                withdeps += [p]

            pkglist = list(set(withdeps))

        file_list = []
        for line in pkglist:
            file_list += src.cat_file("var/lib/dpkg/info/%s.list" % (line))
            file_list += src.cat_file("var/lib/dpkg/info/%s.conffiles" %
                                      (line))

            file_list += src.cat_file("var/lib/dpkg/info/%s:%s.list" %
                                      (line, arch))
            file_list += src.cat_file("var/lib/dpkg/info/%s:%s.conffiles" %
                                      (line, arch))

        file_list = sorted(set(file_list),
                           key=lambda k: k[4:] if k.startswith('/usr') else k)
        copy_filelist(src, file_list, dst)
    else:
        # first copy most diretories
        for f in src.listdir():
            subprocess.call(["cp", "-a", "--reflink=auto", f, dst.fname('')])

    try:
        dst.mkdir_p("dev")
    except BaseException:
        pass
    try:
        dst.mkdir_p("proc")
    except BaseException:
        pass
    try:
        dst.mkdir_p("sys")
    except BaseException:
        pass

    if xml.tgt.has("setsel"):
        pkglist = [
            n.et.text for n in xml.node('target/pkg-list') if n.tag == 'pkg'
        ]
        psel = 'var/cache/elbe/pkg-selections'

        with open(dst.fname(psel), 'w+') as f:
            for item in pkglist:
                f.write("%s  install\n" % item)

        host_arch = get_command_out("dpkg --print-architecture").strip()
        if xml.is_cross(host_arch):
            ui = "/usr/share/elbe/qemu-elbe/" + str(xml.defs["userinterpr"])
            if not os.path.exists(ui):
                ui = "/usr/bin/" + str(xml.defs["userinterpr"])
            do('cp %s %s' % (ui, dst.fname("usr/bin")))

        cmds = [
            "--clear-selections",
            "--set-selections < %s" % dst.fname(psel), "--purge -a"
        ]
        for cmd in cmds:
            chroot(dst.path, "/usr/bin/dpkg %s" % cmd)
Exemple #9
0
 def get_command_out(self, cmd, **kwargs):
     return get_command_out(cmd, **kwargs)