Sha256: ade2a4e4043c6b30ba84ff2dcee2b69efc15012c239440f45a0130a122e6eaf5

Contents?: true

Size: 961 Bytes

Versions: 13

Compression:

Stored size: 961 Bytes

Contents

module Solokit
  class SSH
    def initialize(ip, user, debug)
      @ip, @user, @debug = ip, user, debug
    end

    def run(command, quiet = true)
      run_command("ssh #{ssh_opts} #{@user}@#{@ip} '#{command}' #{supress_output(quiet)}")
    end

    def rsync(source, target, quiet = false)
      run_command("rsync -e 'ssh #{ssh_opts}' -az #{source} #{@user}@#{@ip}:#{target} #{supress_output(quiet)}")
    end

    def reverse_rsync(source, target, quiet = false)
      run_command("rsync -e 'ssh #{ssh_opts}' -az #{@user}@#{@ip}:#{source} #{target} #{supress_output(quiet)}")
    end

    private

    def supress_output(hide_stdout)
      if @debug
        ""
      else
        "#{hide_stdout ? '2> /dev/null 1> /dev/null' : '2> /dev/null'}"
      end
    end

    def run_command(cmd)
      puts "SSH | #{cmd}" if @debug
      system(cmd)
    end

    def ssh_opts
      "-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
solokit-0.1.17 lib/ssh.rb
solokit-0.1.16 lib/ssh.rb
solokit-0.1.15 lib/ssh.rb
solokit-0.1.14 lib/ssh.rb
solokit-0.1.13 lib/ssh.rb
solokit-0.1.12 lib/ssh.rb
solokit-0.1.11 lib/ssh.rb
solokit-0.1.10 lib/ssh.rb
solokit-0.1.9 lib/ssh.rb
solokit-0.1.8 lib/ssh.rb
solokit-0.1.7 lib/ssh.rb
solokit-0.1.6 lib/ssh.rb
solokit-0.1.5 lib/ssh.rb