cloudler 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/cloudler.gemspec +1 -1
  2. data/lib/cloudler.rb +27 -7
  3. metadata +1 -1
data/cloudler.gemspec CHANGED
@@ -2,7 +2,7 @@ require './lib/cloudler.rb'
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'cloudler'
5
- s.version = '0.1.1'
5
+ s.version = Cloudler::VERSION
6
6
  s.authors = ["Bruce Spang"]
7
7
  s.date = Time.now.utc.strftime("%Y-%m-%d")
8
8
  s.email = %q{bruce@brucespang.com}
data/lib/cloudler.rb CHANGED
@@ -2,6 +2,9 @@ require 'net/ssh'
2
2
  require 'net/scp'
3
3
 
4
4
  class Cloudler
5
+
6
+ VERSION = '0.1.2'
7
+
5
8
  def self.hosts= hosts
6
9
  @hosts = hosts
7
10
  end
@@ -30,20 +33,32 @@ class Cloudler
30
33
  @precommands = precommands
31
34
  end
32
35
 
36
+ def self.path= path
37
+ @path = path
38
+ end
39
+
33
40
  def self.run
34
41
  @files ||= []
35
42
  @gems ||= []
36
43
  @precommands ||= []
44
+ @path ||=
45
+ if @username == 'root'
46
+ '/root/.cloudler'
47
+ else
48
+ "/home/#{@username}/.cloudler"
49
+ end
37
50
 
38
51
  @hosts.each do |host|
39
52
  Net::SSH.start(host, @username, :password => @password) do |ssh|
40
53
  puts "Uploading files..."
41
- ssh.exec! "rm -rf /home/#{@username}/.cloudler"
42
- ssh.exec! "mkdir /home/#{@username}/.cloudler"
54
+ ssh.exec! "rm -rf #{@path}"
55
+ ssh.exec! "mkdir #{@path}"
43
56
  if @files.length > 0
44
- ssh.scp.upload(@files.join(' '), "/home/#{@username}/.cloudler", :recursive => true)
57
+ @files.each do |file|
58
+ ssh.scp.upload(file, "#{@path}", :recursive => true)
59
+ end
45
60
  else
46
- ssh.scp.upload!('.', "/home/#{@username}/.cloudler", :recursive => true)
61
+ ssh.scp.upload!('.', "#{@path}", :recursive => true)
47
62
  end
48
63
 
49
64
  puts "Files uploaded."
@@ -59,7 +74,7 @@ class Cloudler
59
74
  if @precommands.length > 0
60
75
  puts "Executing pre-commands"
61
76
  @precommands.each do |command|
62
- ssh.exec "cd /home/#{@username}/.cloudler && #{command}" do |ch,stream,data|
77
+ ssh.exec "cd #{@path} && #{command}" do |ch,stream,data|
63
78
  puts data
64
79
  end
65
80
  end
@@ -67,11 +82,11 @@ class Cloudler
67
82
  end
68
83
 
69
84
  puts "Executing command..."
70
- ssh.exec! "cd /home/#{@username}/.cloudler && #{@command}" do |ch, stream, data|
85
+ ssh.exec! "cd #{@path} && #{@command}" do |ch, stream, data|
71
86
  puts data
72
87
  end
73
88
  puts "Command finished."
74
- end
89
+ end
75
90
  end
76
91
  end
77
92
 
@@ -81,6 +96,7 @@ class Cloudler
81
96
  host 'HOSTNAME' # or for multiple servers, use ['HOST1', 'HOST2', ...]
82
97
  username 'USERNAME'
83
98
  password 'PASSWORD'
99
+ path 'PATH' # Optional path to upload the files to. By default it is /root/.cloudler, or /home/[username]/.cloudler
84
100
  precommands [] # Optional list of commands to run before executing the main command
85
101
  command 'COMMAND'
86
102
  files [] # Optional list of files to upload
@@ -121,3 +137,7 @@ end
121
137
  def precommands array
122
138
  Cloudler.precommands = array
123
139
  end
140
+
141
+ def path string
142
+ Cloudler.path = string
143
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: cloudler
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.1
5
+ version: 0.1.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Bruce Spang