예제 #1
0
    def _GenerateDPKGFiles(self, template_path):
        """Generates the files needed by dpkg-buildpackage."""

        fleetspeak_enabled = config.CONFIG.Get("Client.fleetspeak_enabled",
                                               context=self.context)
        fleetspeak_bundled = config.CONFIG.Get(
            "ClientBuilder.fleetspeak_bundled", context=self.context)

        if fleetspeak_bundled and not fleetspeak_enabled:
            raise build.BuildError("ClientBuilder.fleetspeak_bundled requires "
                                   "Client.fleetspeak_enabled to be set.")

        # Rename the generated binaries to the correct name.
        template_binary_dir = os.path.join(template_path,
                                           "dist/debian/grr-client")
        package_name = config.CONFIG.Get("ClientBuilder.package_name",
                                         context=self.context)
        target_binary_dir = os.path.join(
            template_path,
            "dist/debian/%s%s" % (package_name,
                                  config.CONFIG.Get("ClientBuilder.target_dir",
                                                    context=self.context)))
        if package_name == "grr-client":
            # Need to rename the template path or the move will fail.
            shutil.move(template_binary_dir,
                        "%s-template" % template_binary_dir)
            template_binary_dir = "%s-template" % template_binary_dir

        utils.EnsureDirExists(os.path.dirname(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.CONFIG.Get("Client.binary_name", context=self.context)))

        deb_in_dir = os.path.join(template_path, "dist/debian/debian.in/")

        if not os.path.isdir(deb_in_dir):
            # This is an universal (fleetspeak + legacy) template.
            # In prior versions, debian.in used to contain different files for a
            # fleetspeak-enabled and legacy template respectively.
            if fleetspeak_enabled:
                deb_in_dir = os.path.join(template_path,
                                          "dist/debian/fleetspeak-debian.in/")
            else:
                deb_in_dir = os.path.join(template_path,
                                          "dist/debian/legacy-debian.in/")

        build_helpers.GenerateDirectory(deb_in_dir,
                                        os.path.join(template_path,
                                                     "dist/debian"),
                                        [("grr-client", package_name)],
                                        context=self.context)

        # Generate directories for the /usr/sbin link.
        utils.EnsureDirExists(
            os.path.join(template_path,
                         "dist/debian/%s/usr/sbin" % package_name))

        if os.path.exists(os.path.join(target_binary_dir, "wrapper.sh.in")):
            build_helpers.GenerateFile(os.path.join(target_binary_dir,
                                                    "wrapper.sh.in"),
                                       os.path.join(target_binary_dir,
                                                    "wrapper.sh"),
                                       context=self.context)
            os.chmod(os.path.join(target_binary_dir, "wrapper.sh"), 0o755)

        if fleetspeak_enabled:
            if fleetspeak_bundled:
                self._GenerateFleetspeakConfig(
                    template_path, "/etc/fleetspeak-client/textservices")
                self._GenerateBundledFleetspeakFiles(
                    os.path.join(template_path, "dist/bundled-fleetspeak"),
                    os.path.join(template_path, "dist/debian", package_name))

                shutil.copy(
                    config.CONFIG.Get("ClientBuilder.fleetspeak_client_config",
                                      context=self.context),
                    os.path.join(template_path, "dist", "debian", package_name,
                                 "etc/fleetspeak-client/client.config"))

            else:
                fleetspeak_service_dir = config.CONFIG.Get(
                    "ClientBuilder.fleetspeak_service_dir",
                    context=self.context)
                self._GenerateFleetspeakConfig(template_path,
                                               fleetspeak_service_dir)
        else:
            # Generate the nanny template.
            # This exists from client version 3.1.2.5 onwards.
            build_helpers.GenerateFile(os.path.join(target_binary_dir,
                                                    "nanny.sh.in"),
                                       os.path.join(target_binary_dir,
                                                    "nanny.sh"),
                                       context=self.context)

            # Generate the upstart template.
            build_helpers.GenerateFile(
                os.path.join(template_path,
                             "dist/debian/upstart.in/grr-client.conf"),
                os.path.join(template_path,
                             "dist/debian/%s.upstart" % package_name),
                context=self.context)

            # Generate the initd template. The init will not run if it detects upstart
            # is present.
            build_helpers.GenerateFile(
                os.path.join(template_path, "dist/debian/initd.in/grr-client"),
                os.path.join(template_path,
                             "dist/debian/%s.init" % package_name),
                context=self.context)

            # Generate the systemd unit file.
            build_helpers.GenerateFile(
                os.path.join(template_path,
                             "dist/debian/systemd.in/grr-client.service"),
                os.path.join(template_path,
                             "dist/debian/%s.service" % package_name),
                context=self.context)

        # Clean up the template dirs.
        # Some of the dirs might be missing in older template versions, so removing
        # conditionally.
        self._RmTreeIfExists(
            os.path.join(template_path, "dist/debian/debian.in"))
        self._RmTreeIfExists(
            os.path.join(template_path, "dist/debian/fleetspeak-debian.in"))
        self._RmTreeIfExists(
            os.path.join(template_path, "dist/debian/legacy-debian.in"))
        self._RmTreeIfExists(
            os.path.join(template_path, "dist/debian/upstart.in"))
        self._RmTreeIfExists(
            os.path.join(template_path, "dist/debian/initd.in"))
        self._RmTreeIfExists(
            os.path.join(template_path, "dist/debian/systemd.in"))
        self._RmTreeIfExists(os.path.join(template_path, "dist/fleetspeak"))
        self._RmTreeIfExists(
            os.path.join(template_path, "dist/bundled-fleetspeak"))
예제 #2
0
    def _GenerateDPKGFiles(self, template_path):
        """Generates the files needed by dpkg-buildpackage."""

        # Rename the generated binaries to the correct name.
        template_binary_dir = os.path.join(template_path,
                                           "dist/debian/grr-client")
        package_name = config.CONFIG.Get("ClientBuilder.package_name",
                                         context=self.context)
        target_binary_dir = os.path.join(
            template_path,
            "dist/debian/%s%s" % (package_name,
                                  config.CONFIG.Get("ClientBuilder.target_dir",
                                                    context=self.context)))
        if package_name == "grr-client":
            # Need to rename the template path or the move will fail.
            shutil.move(template_binary_dir,
                        "%s-template" % template_binary_dir)
            template_binary_dir = "%s-template" % template_binary_dir

        utils.EnsureDirExists(os.path.dirname(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.CONFIG.Get("Client.binary_name", context=self.context)))

        deb_in_dir = os.path.join(template_path, "dist/debian/debian.in/")

        build_helpers.GenerateDirectory(deb_in_dir,
                                        os.path.join(template_path,
                                                     "dist/debian"),
                                        [("grr-client", package_name)],
                                        context=self.context)

        # Generate directories for the /usr/sbin link.
        utils.EnsureDirExists(
            os.path.join(template_path,
                         "dist/debian/%s/usr/sbin" % package_name))

        if config.CONFIG.Get("Client.fleetspeak_enabled",
                             context=self.context):
            self._GenerateFleetspeakConfig(template_path)
            shutil.rmtree(deb_in_dir)
            shutil.rmtree(os.path.join(template_path, "dist", "fleetspeak"))
            return

        # Generate the nanny template. This only exists from client version 3.1.2.5
        # onwards.
        if config.CONFIG["Template.version_numeric"] >= 3125:
            build_helpers.GenerateFile(os.path.join(target_binary_dir,
                                                    "nanny.sh.in"),
                                       os.path.join(target_binary_dir,
                                                    "nanny.sh"),
                                       context=self.context)

        # Generate the upstart template.
        build_helpers.GenerateFile(
            os.path.join(template_path,
                         "dist/debian/upstart.in/grr-client.conf"),
            os.path.join(template_path,
                         "dist/debian/%s.upstart" % package_name),
            context=self.context)

        # Generate the initd template. The init will not run if it detects upstart
        # is present.
        build_helpers.GenerateFile(
            os.path.join(template_path, "dist/debian/initd.in/grr-client"),
            os.path.join(template_path, "dist/debian/%s.init" % package_name),
            context=self.context)

        # Generate the systemd unit file.
        build_helpers.GenerateFile(
            os.path.join(template_path,
                         "dist/debian/systemd.in/grr-client.service"),
            os.path.join(template_path,
                         "dist/debian/%s.service" % package_name),
            context=self.context)

        # Clean up the template dirs.
        shutil.rmtree(deb_in_dir)
        shutil.rmtree(os.path.join(template_path, "dist/debian/upstart.in"))
        shutil.rmtree(os.path.join(template_path, "dist/debian/initd.in"))
        shutil.rmtree(os.path.join(template_path, "dist/debian/systemd.in"))