Exemplo n.º 1
0
    def build_label(self, builder, label):
        """
        Build the relevant label.
        """

        self.ensure_dirs(builder, label)

        tag = label.tag

        if (tag == utils.LabelTag.PreConfig):
            # Nothing to do.
            pass
        elif (tag == utils.LabelTag.Configured):
            pass
        elif (tag == utils.LabelTag.Built):
            pass
        elif (tag == utils.LabelTag.Installed):
            # Concoct a suitable dpkg command.
            inv = builder

            # Extract into the object directory .. so I can depend on them later.
            # - actually, Debian packaging doesn't work like that. Rats.
            #  - rrw 2009-11-24
            #extract_into_obj(inv, self.co_name, label, self.pkg_file)

            inst_dir = inv.package_install_path(label)
            tmp = Label(utils.LabelType.Checkout, self.co_name, domain=label.domain)
            co_dir = inv.checkout_path(tmp)

            # Using dpkg doesn't work here for many reasons.
            dpkg_cmd = ["dpkg-deb", "-X", os.path.join(co_dir, self.pkg_file),
                        inst_dir]
            utils.run0(dpkg_cmd)

            # Pick up any instructions that got left behind
            instr_file = self.instr_name
            if (instr_file is None):
                instr_file = "%s.instructions.xml"%(label.name)

            instr_path = os.path.join(co_dir, instr_file)

            if (os.path.exists(instr_path)):
                # We have instructions ..
                ifile = db.InstructionFile(instr_path)
                ifile.get()
                builder.instruct(label.name, label.role, ifile)
        elif (tag == utils.LabelTag.PostInstalled):
            if self.post_install_makefile is not None:
                inv = builder
                tmp = Label(utils.LabelType.Checkout, self.co_name, domain=label.domain)
                co_path = inv.checkout_path(tmp)
                with Directory(co_path):
                    utils.run0(["make", "-f", self.post_install_makefile,
                                "%s-postinstall"%label.name])
        elif (tag == utils.LabelTag.Clean or tag == utils.LabelTag.DistClean):#
            inv = builder
            admin_dir = os.path.join(inv.package_obj_path(label))
            utils.recursively_remove(admin_dir)
        else:
            raise utils.MuddleBug("Invalid tag specified for deb pkg %s"%(label))
Exemplo n.º 2
0
    def deploy(self, builder, label):
        deploy_dir = builder.deploy_path(label)
        # First off, delete the target directory
        utils.recursively_remove(deploy_dir)
        utils.ensure_dir(deploy_dir)

        for role, domain in self.roles:
            if domain:
                print "> %s: Deploying role %s in domain %s .. "%(label.name, role, domain)
            else:
                print "> %s: Deploying role %s .. "%(label.name, role)
            install_dir = builder.role_install_path(role, domain = domain)
            utils.recursively_copy(install_dir, deploy_dir, object_exactly=True)

        # This is somewhat tricky as it potentially requires privilege elevation.
        # Privilege elevation is done by hooking back into ourselves via a
        # build command to a label we registered earlier.
        #
        # Note that you cannot split instruction application - once the first
        # privilege-requiring instruction is executed, all further instructions
        # may require privilege even if they didn't before (e.g. a chmod after
        # chown)

        # First off, do we need to at all?
        need_root_for = set()
        for role, domain in self.roles:
            lbl = depend.Label(utils.LabelType.Package, "*", role, "*", domain=domain)
            install_dir = builder.role_install_path(role, domain = label.domain)
            instr_list = builder.load_instructions(lbl)
            for (lbl, fn, instr_file) in instr_list:
                # Obey this instruction?
                for instr in instr_file:
                    iname = instr.outer_elem_name()
                    if iname in self.app_dict:
                        if self.app_dict[iname].needs_privilege(builder, instr, role, install_dir):
                            need_root_for.add(iname)
                    # Deliberately do not break - we want to check everything for
                    # validity before acquiring privilege.
                    else:
                        raise utils.GiveUp("File deployments don't know about " +
                                            "instruction %s"%iname +
                                            " found in label %s (filename %s)"%(lbl, fn))

        print "Rerunning muddle to apply instructions .. "

        permissions_label = depend.Label(utils.LabelType.Deployment,
                                         label.name, None, # XXX label.role,
                                         utils.LabelTag.InstructionsApplied,
                                         domain = label.domain)

        if need_root_for:
            print "I need root to do %s - sorry! - running sudo .."%(', '.join(sorted(need_root_for)))
            utils.run0("sudo %s buildlabel '%s'"%(builder.muddle_binary,
                                                  permissions_label))
        else:
            utils.run0("%s buildlabel '%s'"%(builder.muddle_binary,
                                             permissions_label))
Exemplo n.º 3
0
 def build_label(self, builder, label):
     if (label.type == utils.LabelType.Deployment
             and (label.tag == utils.LabelTag.Clean
                  or label.tag == utils.LabelTag.DistClean)):
         deploy_path = builder.deploy_path(label)
         print "> Remove %s" % deploy_path
         utils.recursively_remove(deploy_path)
         builder.kill_label(label.copy_with_tag(utils.LabelTag.Deployed))
     else:
         raise utils.GiveUp("Attempt to invoke CleanDeploymentBuilder on "
                            "unrecognised label %s" % label)
Exemplo n.º 4
0
 def build_label(self, builder, label):
     if (label.type == utils.LabelType.Deployment and
         (label.tag == utils.LabelTag.Clean or
         label.tag == utils.LabelTag.DistClean)):
         deploy_path = builder.deploy_path(label)
         print "> Remove %s"%deploy_path
         utils.recursively_remove(deploy_path)
         builder.kill_label(label.copy_with_tag(utils.LabelTag.Deployed))
     else:
         raise utils.GiveUp("Attempt to invoke CleanDeploymentBuilder on "
                             "unrecognised label %s"%label)
Exemplo n.º 5
0
    def build_label(self, builder, label):
        """
        Actually install the dev package.
        """
        self.ensure_dirs(builder, label)

        tag = label.tag

        if (tag == utils.LabelTag.PreConfig):
            # Nothing to do
            pass
        elif (tag == utils.LabelTag.Configured):
            pass
        elif (tag == utils.LabelTag.Built):
            pass
        elif (tag == utils.LabelTag.Installed):
            # Extract into /obj
            inv = builder
            extract_into_obj(inv, self.co_name, label, self.pkg_file)
            if (self.nonDevPkgFile is not None):
                extract_into_obj(inv, self.nonDevCoName, label,
                                 self.nonDevPkgFile)

            # Now we rewrite all the absolute links to be relative to the install
            # directory.
            rewrite_links(inv, label)

        elif (tag == utils.LabelTag.PostInstalled):
            if self.post_install_makefile is not None:
                inv = builder
                tmp = Label(utils.LabelType.Checkout,
                            self.co_name,
                            domain=label.domain)
                co_path = inv.checkout_path(tmp)
                with Directory(co_path):
                    utils.run0([
                        "make", "-f", self.post_install_makefile,
                        "%s-postinstall" % (label.name)
                    ])

            # .. and now we rewrite any pkgconfig etc. files left lying
            # about.
            obj_path = builder.package_obj_path(label)
            print "> Rewrite .pc and .la files in %s" % (obj_path)
            rewrite.fix_up_pkgconfig_and_la(builder, obj_path)

        elif (tag == utils.LabelTag.Clean or tag == utils.LabelTag.DistClean):
            # Just remove the object directory.
            inv = builder
            utils.recursively_remove(inv.package_obj_path(label))
        else:
            raise utils.MuddleBug("Invalid tag specified for deb pkg %s" %
                                  (label))
Exemplo n.º 6
0
    def build_label(self, builder, label):
        """
        Actually install the dev package.
        """
        self.ensure_dirs(builder, label)

        tag = label.tag

        if (tag == utils.LabelTag.PreConfig):
            # Nothing to do
            pass
        elif (tag == utils.LabelTag.Configured):
            pass
        elif (tag == utils.LabelTag.Built):
            pass
        elif (tag == utils.LabelTag.Installed):
            # Extract into /obj
            inv = builder
            extract_into_obj(inv, self.co_name, label, self.pkg_file)
            if (self.nonDevPkgFile is not None):
                extract_into_obj(inv, self.nonDevCoName, label, self.nonDevPkgFile)

            # Now we rewrite all the absolute links to be relative to the install
            # directory.
            rewrite_links(inv, label)


        elif (tag == utils.LabelTag.PostInstalled):
            if self.post_install_makefile is not None:
                inv = builder
                tmp = Label(utils.LabelType.Checkout, self.co_name, domain=label.domain)
                co_path = inv.checkout_path(tmp)
                with Directory(co_path):
                    utils.run0(["make", "-f", self.post_install_makefile,
                                "%s-postinstall"%(label.name)])

            # .. and now we rewrite any pkgconfig etc. files left lying
            # about.
            obj_path = builder.package_obj_path(label)
            print "> Rewrite .pc and .la files in %s"%(obj_path)
            rewrite.fix_up_pkgconfig_and_la(builder, obj_path)

        elif (tag == utils.LabelTag.Clean or tag == utils.LabelTag.DistClean):
            # Just remove the object directory.
            inv = builder
            utils.recursively_remove(inv.package_obj_path(label))
        else:
            raise utils.MuddleBug("Invalid tag specified for deb pkg %s"%(label))
Exemplo n.º 7
0
    def deploy(self, builder, label):
        deploy_dir = builder.deploy_path(label)

        utils.recursively_remove(deploy_dir)
        utils.ensure_dir(deploy_dir)

        for role in self.dependent_roles:
            print "> %s: Deploying role %s .."%(label.name, role)
            install_dir = builder.role_install_path(role,
                                                               domain = label.domain)
            # We do want an exact copy here - this is a copy from the install
            #  set to the role deployment and therefore may include symlinks
            #  hardwired to MUDDLE_TARGET_INSTALL. If it were a copy to the install
            #  directory, we'd want an inexact copy.
            # - rrw 2009-11-09
            utils.recursively_copy(install_dir, deploy_dir, object_exactly = True)
Exemplo n.º 8
0
    def deploy(self, builder, label):
        deploy_dir = builder.deploy_path(label)

        utils.recursively_remove(deploy_dir)
        utils.ensure_dir(deploy_dir)

        for role in self.dependent_roles:
            print "> %s: Deploying role %s .." % (label.name, role)
            install_dir = builder.role_install_path(role, domain=label.domain)
            # We do want an exact copy here - this is a copy from the install
            #  set to the role deployment and therefore may include symlinks
            #  hardwired to MUDDLE_TARGET_INSTALL. If it were a copy to the install
            #  directory, we'd want an inexact copy.
            # - rrw 2009-11-09
            utils.recursively_copy(install_dir,
                                   deploy_dir,
                                   object_exactly=True)
Exemplo n.º 9
0
    def build_label(self, builder, label):
        """
        Copy everything to a temporary directory and then mksquashfs it.
        """

        if self.my_tmp is None:
            self.my_tmp = tempfile.mkdtemp();

        print "Deploying to %s .. \n"%self.my_tmp

        if label.tag == utils.LabelTag.Deployed:
            self.apply_instructions(builder, label, True, self.my_tmp)
            self.deploy(builder, label, self.my_tmp)
            self.do_mksquashfs(builder, label, self.my_tmp)
            utils.recursively_remove(self.my_tmp)
        else:
            raise utils.GiveUp("Attempt to build a deployment with an unexpected tag in label %s"%(label))
Exemplo n.º 10
0
    def build_label(self, builder, label):
        """
        Copy everything to a temporary directory and then mksquashfs it.
        """

        if self.my_tmp is None:
            self.my_tmp = tempfile.mkdtemp()

        print "Deploying to %s .. \n" % self.my_tmp

        if label.tag == utils.LabelTag.Deployed:
            self.apply_instructions(builder, label, True, self.my_tmp)
            self.deploy(builder, label, self.my_tmp)
            self.do_mksquashfs(builder, label, self.my_tmp)
            utils.recursively_remove(self.my_tmp)
        else:
            raise utils.GiveUp(
                "Attempt to build a deployment with an unexpected tag in label %s"
                % (label))
Exemplo n.º 11
0
    def deploy(self, builder, label):
        deploy_dir = builder.deploy_path(label)
        # First off, delete the target directory
        utils.recursively_remove(deploy_dir)
        utils.ensure_dir(deploy_dir)

        for role, domain in self.roles:
            if domain:
                print "> %s: Deploying role %s in domain %s .. " % (
                    label.name, role, domain)
            else:
                print "> %s: Deploying role %s .. " % (label.name, role)
            install_dir = builder.role_install_path(role, domain=domain)
            utils.recursively_copy(install_dir,
                                   deploy_dir,
                                   object_exactly=True)

        # This is somewhat tricky as it potentially requires privilege elevation.
        # Privilege elevation is done by hooking back into ourselves via a
        # build command to a label we registered earlier.
        #
        # Note that you cannot split instruction application - once the first
        # privilege-requiring instruction is executed, all further instructions
        # may require privilege even if they didn't before (e.g. a chmod after
        # chown)

        # First off, do we need to at all?
        need_root_for = set()
        for role, domain in self.roles:
            lbl = depend.Label(utils.LabelType.Package,
                               "*",
                               role,
                               "*",
                               domain=domain)
            install_dir = builder.role_install_path(role, domain=label.domain)
            instr_list = builder.load_instructions(lbl)
            for (lbl, fn, instr_file) in instr_list:
                # Obey this instruction?
                for instr in instr_file:
                    iname = instr.outer_elem_name()
                    if iname in self.app_dict:
                        if self.app_dict[iname].needs_privilege(
                                builder, instr, role, install_dir):
                            need_root_for.add(iname)
                    # Deliberately do not break - we want to check everything for
                    # validity before acquiring privilege.
                    else:
                        raise utils.GiveUp(
                            "File deployments don't know about " +
                            "instruction %s" % iname +
                            " found in label %s (filename %s)" % (lbl, fn))

        print "Rerunning muddle to apply instructions .. "

        permissions_label = depend.Label(
            utils.LabelType.Deployment,
            label.name,
            None,  # XXX label.role,
            utils.LabelTag.InstructionsApplied,
            domain=label.domain)

        if need_root_for:
            print "I need root to do %s - sorry! - running sudo .." % (
                ', '.join(sorted(need_root_for)))
            utils.run0("sudo %s buildlabel '%s'" %
                       (builder.muddle_binary, permissions_label))
        else:
            utils.run0("%s buildlabel '%s'" %
                       (builder.muddle_binary, permissions_label))
Exemplo n.º 12
0
    def build_label(self, builder, label):
        """
        Build the relevant label.
        """

        self.ensure_dirs(builder, label)

        tag = label.tag

        if (tag == utils.LabelTag.PreConfig):
            # Nothing to do.
            pass
        elif (tag == utils.LabelTag.Configured):
            pass
        elif (tag == utils.LabelTag.Built):
            pass
        elif (tag == utils.LabelTag.Installed):
            # Concoct a suitable dpkg command.
            inv = builder

            # Extract into the object directory .. so I can depend on them later.
            # - actually, Debian packaging doesn't work like that. Rats.
            #  - rrw 2009-11-24
            #extract_into_obj(inv, self.co_name, label, self.pkg_file)

            inst_dir = inv.package_install_path(label)
            tmp = Label(utils.LabelType.Checkout,
                        self.co_name,
                        domain=label.domain)
            co_dir = inv.checkout_path(tmp)

            # Using dpkg doesn't work here for many reasons.
            dpkg_cmd = [
                "dpkg-deb", "-X",
                os.path.join(co_dir, self.pkg_file), inst_dir
            ]
            utils.run0(dpkg_cmd)

            # Pick up any instructions that got left behind
            instr_file = self.instr_name
            if (instr_file is None):
                instr_file = "%s.instructions.xml" % (label.name)

            instr_path = os.path.join(co_dir, instr_file)

            if (os.path.exists(instr_path)):
                # We have instructions ..
                ifile = db.InstructionFile(instr_path)
                ifile.get()
                builder.instruct(label.name, label.role, ifile)
        elif (tag == utils.LabelTag.PostInstalled):
            if self.post_install_makefile is not None:
                inv = builder
                tmp = Label(utils.LabelType.Checkout,
                            self.co_name,
                            domain=label.domain)
                co_path = inv.checkout_path(tmp)
                with Directory(co_path):
                    utils.run0([
                        "make", "-f", self.post_install_makefile,
                        "%s-postinstall" % label.name
                    ])
        elif (tag == utils.LabelTag.Clean
              or tag == utils.LabelTag.DistClean):  #
            inv = builder
            admin_dir = os.path.join(inv.package_obj_path(label))
            utils.recursively_remove(admin_dir)
        else:
            raise utils.MuddleBug("Invalid tag specified for deb pkg %s" %
                                  (label))
Exemplo n.º 13
0
    def build_label(self, builder, label):
        our_dir = builder.package_obj_path(label)

        dirlist = []
        tag = label.tag

        if (tag == utils.LabelTag.Built or tag == utils.LabelTag.Installed):
            for (l, s) in self.components:
                tmp = Label(utils.LabelType.Package,
                            l.name,
                            l.role,
                            domain=label.domain)
                root_dir = builder.package_install_path(tmp)
                dirlist.append((root_dir, s))

                print "dirlist:"
                for (x, y) in dirlist:
                    print "%s=%s \n" % (x, y)

        if (tag == utils.LabelTag.PreConfig):
            pass
        elif (tag == utils.LabelTag.Configured):
            pass
        elif (tag == utils.LabelTag.Built):
            # OK. Building. This is ghastly ..
            utils.recursively_remove(our_dir)
            utils.ensure_dir(our_dir)
            # Now we need to copy all the subdirs in ..
            for (root, sub) in dirlist:
                utils.ensure_dir(utils.rel_join(our_dir, sub))
                # Only bother to copy kernel modules.
                names = utils.find_by_predicate(utils.rel_join(root, sub),
                                                predicate_is_kernel_module)
                utils.copy_name_list_with_dirs(names,
                                               utils.rel_join(root, sub),
                                               utils.rel_join(our_dir, sub))

            # .. and run depmod.
            depmod = "depmod"
            if (self.custom_depmod is not None):
                depmod = self.custom_depmod

            # Because depmod is brain-dead, we need to give it explicit versions.
            names = os.listdir(utils.rel_join(our_dir, "lib/modules"))
            our_re = re.compile(r'\d+\.\d+\..*')
            for n in names:
                if (our_re.match(n) is not None):
                    print "Found kernel version %s in %s .. " % (n, our_dir)
                    utils.run0("%s -b %s %s" % (depmod, our_dir, n))

        elif (tag == utils.LabelTag.Installed):
            # Now we find all the modules.* files in our_dir and copy them over
            # to our install directory
            names = utils.find_by_predicate(our_dir, predicate_is_module_db)
            tgt_dir = builder.package_install_path(label)
            utils.copy_name_list_with_dirs(names, our_dir, tgt_dir)
            for n in names:
                new_n = utils.replace_root_name(our_dir, tgt_dir, n)
                print "Installed: %s" % (new_n)

        elif (tag == utils.LabelTag.Clean):
            utils.recursively_remove(our_dir)
        elif (tag == utils.LabelTag.DistClean):
            utils.recursively_remove(our_dir)
Exemplo n.º 14
0
    def build_label(self, builder, label):
        our_dir = builder.package_obj_path(label)

        dirlist = [ ]
        tag = label.tag

        if (tag == utils.LabelTag.Built or tag == utils.LabelTag.Installed):
            for (l,s) in self.components:
                tmp = Label(utils.LabelType.Package, l.name, l.role, domain=label.domain)
                root_dir = builder.package_install_path(tmp)
                dirlist.append( (root_dir, s) )

                print "dirlist:"
                for (x,y) in dirlist:
                    print "%s=%s \n"%(x,y)


        if (tag == utils.LabelTag.PreConfig):
            pass
        elif (tag == utils.LabelTag.Configured):
            pass
        elif (tag == utils.LabelTag.Built):
            # OK. Building. This is ghastly ..
            utils.recursively_remove(our_dir)
            utils.ensure_dir(our_dir)
            # Now we need to copy all the subdirs in ..
            for (root, sub) in dirlist:
                utils.ensure_dir(utils.rel_join(our_dir, sub))
                # Only bother to copy kernel modules.
                names = utils.find_by_predicate(utils.rel_join(root, sub),
                                                predicate_is_kernel_module)
                utils.copy_name_list_with_dirs(names,
                                               utils.rel_join(root,sub),
                                               utils.rel_join(our_dir, sub))


            # .. and run depmod.
            depmod = "depmod"
            if (self.custom_depmod is not None):
                depmod = self.custom_depmod

            # Because depmod is brain-dead, we need to give it explicit versions.
            names = os.listdir(utils.rel_join(our_dir, "lib/modules"))
            our_re = re.compile(r'\d+\.\d+\..*')
            for n in names:
                if (our_re.match(n) is not None):
                    print "Found kernel version %s in %s .. "%(n, our_dir)
                    utils.run0("%s -b %s %s"%(depmod, our_dir, n))

        elif (tag == utils.LabelTag.Installed):
            # Now we find all the modules.* files in our_dir and copy them over
            # to our install directory
            names = utils.find_by_predicate(our_dir, predicate_is_module_db)
            tgt_dir = builder.package_install_path(label)
            utils.copy_name_list_with_dirs(names, our_dir, tgt_dir)
            for n in names:
                new_n = utils.replace_root_name(our_dir, tgt_dir, n)
                print "Installed: %s"%(new_n)

        elif (tag == utils.LabelTag.Clean):
            utils.recursively_remove(our_dir)
        elif (tag == utils.LabelTag.DistClean):
            utils.recursively_remove(our_dir)