class Kitchen::Provisioner::Shell

Basic shell provisioner.

@author Chris Lundquist (<chris.ludnquist@github.com>)

Public Instance Methods

create_sandbox() click to toggle source

(see Base#create_sandbox)

# File lib/kitchen/provisioner/shell.rb, line 51
def create_sandbox
  super
  prepare_data
  prepare_script
end
init_command() click to toggle source

(see Base#init_command)

# File lib/kitchen/provisioner/shell.rb, line 58
      def init_command
        return nil if config[:command]

        root = config[:root_path]
        data = remote_path_join(root, "data")

        code = if powershell_shell?
                 Util.outdent!(<<-POWERSHELL)
            if (Test-Path "#{data}") {
              Remove-Item "#{data}" -Recurse -Force
            }
            if (-Not (Test-Path "#{root}")) {
              New-Item "#{root}" -ItemType directory | Out-Null
            }
                 POWERSHELL
               else
                 "#{sudo("rm")} -rf #{data} ; mkdir -p #{root}"
               end

        prefix_command(wrap_shell_code(code))
      end
prepare_command() click to toggle source

(see Base#prepare_command)

# File lib/kitchen/provisioner/shell.rb, line 81
def prepare_command
  # On a windows host, the supplied script does not get marked as executable
  # due to windows not having the concept of an executable flag
  #
  # When the guest instance is *nix, `chmod +x` the script in the guest, prior to executing
  return unless unix_os? && config[:script] && !config[:command]

  debug "Marking script as executable"
  script = remote_path_join(
    config[:root_path],
    File.basename(config[:script])
  )
  prefix_command(wrap_shell_code(sudo("chmod +x #{script}")))
end
run_command() click to toggle source

(see Base#run_command)

# File lib/kitchen/provisioner/shell.rb, line 97
def run_command
  return prefix_command(wrap_shell_code(config[:command])) if config[:command]
  return unless config[:script]

  script = remote_path_join(
    config[:root_path],
    File.basename(config[:script])
  )

  if config[:arguments] && !config[:arguments].empty?
    if config[:arguments].is_a?(Array)
      if powershell_shell?
        script = ([script] + config[:arguments]).join(" ")
      else
        script = Shellwords.join([script] + config[:arguments])
      end
    else
      script.concat(" ").concat(config[:arguments].to_s)
    end
  end

  code = powershell_shell? ? %{& #{script}} : sudo(script)

  prefix_command(wrap_shell_code(code))
end

Private Instance Methods

prepare_data() click to toggle source

Creates a data directory in the sandbox directory, if a data directory can be found and copies in the tree.

@api private

# File lib/kitchen/provisioner/shell.rb, line 129
def prepare_data
  return unless config[:data_path]

  info("Preparing data")
  debug("Using data from #{config[:data_path]}")

  tmpdata_dir = File.join(sandbox_path, "data")
  FileUtils.mkdir_p(tmpdata_dir)
  FileUtils.cp_r(Util.list_directory(config[:data_path]), tmpdata_dir)
end
prepare_script() click to toggle source

Copies the executable script to the sandbox directory or creates a stub script if one cannot be found.

@api private

# File lib/kitchen/provisioner/shell.rb, line 144
def prepare_script
  info("Preparing script")

  if config[:script]
    debug("Using script from #{config[:script]}")
    FileUtils.cp_r(config[:script], sandbox_path)
  else
    info("No provisioner script file specified, skipping")
  end
end