Class: Remote
- Inherits:
-
Object
- Object
- Remote
- Defined in:
- lib/ssport/remote.rb
Instance Method Summary collapse
- #check?(keys) ⇒ Boolean
- #genCommand(keys) ⇒ Object
- #genScript ⇒ Object
-
#initialize(options) ⇒ Remote
constructor
A new instance of Remote.
- #ssh ⇒ Object
Constructor Details
#initialize(options) ⇒ Remote
Returns a new instance of Remote.
8 9 10 |
# File 'lib/ssport/remote.rb', line 8 def initialize() = end |
Instance Method Details
#check?(keys) ⇒ Boolean
12 13 14 15 16 17 18 19 20 |
# File 'lib/ssport/remote.rb', line 12 def check?(keys) keys.each do |key| if ![key] puts "#! Please set :server".colorize(:red) return false end end return true end |
#genCommand(keys) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ssport/remote.rb', line 22 def genCommand(keys) command = "ssport -c #{@options[:config]}" keys.each do |key| if [key] if [key] == true command += " --#{key} " else if key == :port command += " -b #{@options[key]}" else command += " --#{key} #{@options[key]}" end end end end return command end |
#genScript ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ssport/remote.rb', line 40 def genScript command = genCommand [:password , :method, :port, :config, :install] script = %Q{ if ! [ -x "$(command -v ssport)" ]; then if ! [ -x "$(command -v ruby)" ]; then gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB curl -sSL https://get.rvm.io | bash -s stable --ruby fi gem install ssport else if [ `ssport -v` != "#{Ssport::VERSION}" ]; then gem update ssport fi fi #{command} ssserver -c #{@options[:config]} -d restart } script end |
#ssh ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/ssport/remote.rb', line 60 def ssh if !check?([:server, :username, :pass, :config]) return end puts "Begin Connect #{@options[:server]}...".colorize(:yellow) output = "" script = genScript server = [:server] port = nil if server.include?(":") server, port = server.split(":") end params = {:password => [:pass]} if port params[:port] = port end Net::SSH.start(server, [:username], params) do |ssh| # capture all stderr and stdout output from a remote process output = ssh.exec!(script) end puts '----------------Remote---------------'.colorize(:yellow) puts output puts '------------------End------------------'.colorize(:yellow) end |