Sha256: b5ebf19cbec6dbc4764836968ae98a5ffaf13ed3642e5d96a935de4909428366

Contents?: true

Size: 1.1 KB

Versions: 4

Compression:

Stored size: 1.1 KB

Contents

require "fileutils"
require "tempfile"
require "vagrant/util/safe_exec"

require_relative "errors"

module VagrantPlugins
  module LocalExecPush
    class Push < Vagrant.plugin("2", :push)
      def push
        if config.inline
          execute_inline!(config.inline)
        else
          execute_script!(config.script)
        end
      end

      # Execute the inline script by writing it to a tempfile and executing.
      def execute_inline!(inline)
        script = Tempfile.new(["vagrant-local-exec-script", ".sh"])
        script.write(inline)
        script.rewind

        execute_script!(script.path)
      ensure
        if script
          script.close
          script.unlink
        end
      end

      # Execute the script, expanding the path relative to the current env root.
      def execute_script!(path)
        path = File.expand_path(path, env.root_path)
        FileUtils.chmod("+x", path)
        execute!(path)
      end

      # Execute the script, raising an exception if it fails.
      def execute!(*cmd)
        Vagrant::Util::SafeExec.exec(cmd[0], *cmd[1..-1])
      end
    end
  end
end

Version data entries

4 entries across 1 versions & 1 rubygems

Version Path
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-1cf2a8db4ccb/plugins/pushes/local-exec/push.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-272fb27e0536/plugins/pushes/local-exec/push.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-309e896975d1/plugins/pushes/local-exec/push.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-b421af58e8b3/plugins/pushes/local-exec/push.rb