Sha256: 18ab934c2d09d77493dbff25d53abbb7723e0e2ece207e3acb069b2dcabf07a2

Contents?: true

Size: 1.11 KB

Versions: 82

Compression:

Stored size: 1.11 KB

Contents

module Specinfra
  module Backend
    class Jexec < Exec
      def initialize(config = {})
        super(config)
        jname = get_config(:jail_name)
        jroot = `jls -j #{jname} path`.strip
        fail 'fail to get jail path!' if jroot.to_s.empty?
        set_config(:jail_root, jroot)
      end

      def send_file(from, to)
        jroot = get_config(:jail_root)
        FileUtils.cp(from, "#{jroot}/#{to}")
      end

      def send_directory(from, to)
        jroot = get_config(:jail_root)
        FileUtils.cp_r(from, "#{jroot}/#{to}")
      end

      def build_command(cmd)
        shell = get_config(:shell) || '/bin/sh'
        cmd = cmd.shelljoin if cmd.is_a?(Array)
        shell = shell.shellescape

        if get_config(:interactive_shell)
          shell << " -i"
        end

        if get_config(:login_shell)
          shell << " -l"
        end

        cmd = "#{shell} -c #{cmd.to_s.shellescape}"

        path = get_config(:path)
        if path
          cmd = %Q{env PATH="#{path}" #{cmd}}
        end

        jname = get_config(:jail_name)
        "jexec #{jname} #{cmd}"
      end
    end
  end
end

Version data entries

82 entries across 82 versions & 1 rubygems

Version Path
specinfra-2.91.0 lib/specinfra/backend/jexec.rb
specinfra-2.90.1 lib/specinfra/backend/jexec.rb
specinfra-2.90.0 lib/specinfra/backend/jexec.rb
specinfra-2.89.0 lib/specinfra/backend/jexec.rb
specinfra-2.88.2 lib/specinfra/backend/jexec.rb
specinfra-2.88.1 lib/specinfra/backend/jexec.rb
specinfra-2.88.0 lib/specinfra/backend/jexec.rb
specinfra-2.87.2 lib/specinfra/backend/jexec.rb
specinfra-2.87.1 lib/specinfra/backend/jexec.rb
specinfra-2.87.0 lib/specinfra/backend/jexec.rb
specinfra-2.86.0 lib/specinfra/backend/jexec.rb
specinfra-2.85.1 lib/specinfra/backend/jexec.rb
specinfra-2.85.0 lib/specinfra/backend/jexec.rb
specinfra-2.84.1 lib/specinfra/backend/jexec.rb
specinfra-2.84.0 lib/specinfra/backend/jexec.rb
specinfra-2.83.4 lib/specinfra/backend/jexec.rb
specinfra-2.83.3 lib/specinfra/backend/jexec.rb
specinfra-2.83.2 lib/specinfra/backend/jexec.rb
specinfra-2.83.1 lib/specinfra/backend/jexec.rb
specinfra-2.83.0 lib/specinfra/backend/jexec.rb