Example #1
0
    def testGenClientConfig(self):
        plugins = ["plugin1", "plugin2"]
        config_lib.CONFIG.Set("Client.plugins", plugins)

        deployer = build.ClientDeployer()
        data = deployer.GetClientConfig(["Client Context"], validate=True)

        parser = config_lib.YamlParser(data=data)
        raw_data = parser.RawData()

        self.assertIn("Client.build_time", raw_data)
        self.assertIn("Client.plugins", raw_data)

        self.assertEqual(raw_data["Client.plugins"], plugins)
Example #2
0
  def testGenClientConfig(self):
    plugins = ["plugin1", "plugin2"]
    with test_lib.ConfigOverrider({"Client.plugins": plugins,
                                   "Client.build_environment": "test_env"}):

      deployer = build.ClientDeployer()
      data = deployer.GetClientConfig(["Client Context"], validate=True)

      parser = config_lib.YamlParser(data=data)
      raw_data = parser.RawData()

      self.assertIn("Client.deploy_time", raw_data)
      self.assertIn("Client.plugins", raw_data)

      self.assertEqual(raw_data["Client.plugins"], plugins)
Example #3
0
File: osx.py Project: redBorder/grr
    def BuildInstallerPkg(self, output_file):
        """Builds a package (.pkg) using PackageMaker."""
        build_files_dir = os.path.join(self.build_src_dir, "config", "macosx",
                                       "client")
        pmdoc_dir = os.path.join(build_files_dir, "grr.pmdoc")

        client_name = config_lib.CONFIG.Get("Client.name",
                                            context=self.context)
        plist_name = config_lib.CONFIG.Get("Client.plist_filename",
                                           context=self.context)

        out_build_files_dir = build_files_dir.replace(self.build_src_dir,
                                                      self.build_dir)
        out_pmdoc_dir = os.path.join(self.build_dir, "%s.pmdoc" % client_name)

        self.EnsureDirExists(out_build_files_dir)
        self.EnsureDirExists(out_pmdoc_dir)
        self.EnsureDirExists(
            config_lib.CONFIG.Get("ClientBuilder.package_dir",
                                  context=self.context))

        self.GenerateFile(input_filename=os.path.join(build_files_dir,
                                                      "grr.plist.in"),
                          output_filename=os.path.join(self.build_dir,
                                                       plist_name))
        self.GenerateFile(input_filename=os.path.join(pmdoc_dir,
                                                      "index.xml.in"),
                          output_filename=os.path.join(out_pmdoc_dir,
                                                       "index.xml"))
        self.GenerateFile(input_filename=os.path.join(pmdoc_dir,
                                                      "01grr.xml.in"),
                          output_filename=os.path.join(
                              out_pmdoc_dir, "01%s.xml" % client_name))
        self.GenerateFile(input_filename=os.path.join(pmdoc_dir,
                                                      "01grr-contents.xml"),
                          output_filename=os.path.join(
                              out_pmdoc_dir,
                              "01%s-contents.xml" % client_name))
        self.GenerateFile(input_filename=os.path.join(pmdoc_dir,
                                                      "02com.xml.in"),
                          output_filename=os.path.join(out_pmdoc_dir,
                                                       "02com.xml"))
        self.GenerateFile(input_filename=os.path.join(pmdoc_dir,
                                                      "02com-contents.xml"),
                          output_filename=os.path.join(out_pmdoc_dir,
                                                       "02com-contents.xml"))

        self.GenerateFile(input_filename=os.path.join(build_files_dir,
                                                      "preinstall.sh.in"),
                          output_filename=os.path.join(self.build_dir,
                                                       "preinstall.sh"))
        self.GenerateFile(input_filename=os.path.join(build_files_dir,
                                                      "postinstall.sh.in"),
                          output_filename=os.path.join(self.build_dir,
                                                       "postinstall.sh"))

        output_basename = config_lib.CONFIG.Get(
            "ClientBuilder.output_basename", context=self.context)

        # Rename the generated binaries to the correct name.
        template_binary_dir = os.path.join(
            config_lib.CONFIG.Get("PyInstaller.distpath",
                                  context=self.context), "grr-client")
        target_binary_dir = os.path.join(self.build_dir,
                                         "%s" % output_basename)

        if template_binary_dir != target_binary_dir:
            shutil.move(template_binary_dir, target_binary_dir)

        shutil.move(
            os.path.join(target_binary_dir, "grr-client"),
            os.path.join(
                target_binary_dir,
                config_lib.CONFIG.Get("Client.binary_name",
                                      context=self.context)))

        deployer = build.ClientDeployer(context=self.context)
        deployer.context = self.context

        # Generate a config file.
        with open(
                os.path.join(
                    target_binary_dir,
                    config_lib.CONFIG.Get("ClientBuilder.config_filename",
                                          context=self.context)), "wb") as fd:
            fd.write(
                deployer.GetClientConfig(["Client Context"] + self.context,
                                         validate=False))

        print "Fixing file ownership and permissions"

        command = [
            "sudo", "/usr/sbin/chown", "-R", "root:wheel", self.build_dir
        ]
        # Change the owner, group and permissions of the binaries
        print "Running: %s" % " ".join(command)
        subprocess.call(command)

        command = ["sudo", "/bin/chmod", "-R", "755", self.build_dir]

        print "Running: %s" % " ".join(command)
        subprocess.call(command)

        print "Building a package with PackageMaker"
        pkg = "%s-%s.pkg" % (config_lib.CONFIG.Get("Client.name",
                                                   context=self.context),
                             config_lib.CONFIG.Get("Client.version_string",
                                                   context=self.context))

        output_pkg_path = os.path.join(self.pkg_dir, pkg)
        command = [
            config_lib.CONFIG.Get("ClientBuilder.package_maker_path",
                                  context=self.context), "--doc",
            out_pmdoc_dir, "--out", output_pkg_path
        ]

        print "Running: %s " % " ".join(command)
        ret = subprocess.call(command)
        if ret != 0:
            msg = "PackageMaker returned an error (%d)." % ret
            print msg
            raise RuntimeError(msg)

        print "Copying output to templates location: %s -> %s" % (
            output_pkg_path, output_file)
        self.EnsureDirExists(os.path.dirname(output_file))
        shutil.copyfile(output_pkg_path, output_file)

        # Change the owner, group and permissions of the binaries back.
        command = [
            "sudo", "/usr/sbin/chown", "-R",
            "%s:staff" % getpass.getuser(), self.build_dir
        ]
        print "Running: %s" % " ".join(command)
        subprocess.call(command)