Sha256: 6735d4c8d0d5d8e7533cb6ba284455ec689ea90b20a97fe32cfaad8b8b975f20

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

require 'net/ssh'

module SimpleProvision
  class CLI
    attr_reader :profile, :username, :host
    def initialize(args)
      @profile = args[:profile]
      @username = args[:username]
      @host = args[:host]
    end

    def bootstrap
      SimpleProvision::SCP.new(username, host, options).copy_files
    end

    def configure
      Net::SSH.start(host, username) do |ssh|
        ssh.exec! "tar -xzf #{SimpleProvision::SCP::FILENAME}"
        scripts = options.fetch(:scripts).each do |script|
          puts "Execute #{script}"
          ssh.exec!("#{environment_exports} bash -c '#{script}'") do |channel, stream, data|
            print data
          end
        end
      end
    end

    private

    def environment_exports
      @environment_exports ||= begin
                                 if options[:env].nil?
                                   ""
                                 else
                                   options[:env].map { |k, v| [k, Shellwords.escape(v)].join("=") }.join(" ")
                                 end
                               end
    end

    def server
      SimpleProvision::Server.new(@connection, options)
    end

    def options
      @options ||= SimpleProvision::Configuration.new(@profile).options
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
simple_provision-0.99.6 lib/simple_provision/cli.rb