ztk 1.6.0 → 1.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,13 +19,20 @@ module ZTK
19
19
  #
20
20
  # @param [String] content What to render out to the bootstrap file we will
21
21
  # execute.
22
- # @param [Boolean] use_sudo Whether or not we should prefix *sudo*
23
- # on our command.
24
- def bootstrap(content, use_sudo=true)
22
+ # @param [Hash] options The options hash. This will also accept options
23
+ # for #exec in order to better control the bootstrapping execution.
24
+ # @option options [String] :use_sudo True if we should execute the
25
+ # bootstrap via sudo; False to execute it as the defined user.
26
+ def bootstrap(content, options={})
27
+ options = {
28
+ :silence => true,
29
+ :use_sudo => true
30
+ }.merge(options)
31
+
25
32
  tempfile = Tempfile.new("bootstrap")
26
33
 
27
34
  local_tempfile = tempfile.path
28
- remote_tempfile = ::File.join("/tmp", ::File.basename(local_tempfile))
35
+ remote_tempfile = ::File.join("/", "tmp", ::File.basename(local_tempfile))
29
36
 
30
37
  ::File.open(local_tempfile, 'w') do |file|
31
38
  file.puts(content)
@@ -35,12 +42,13 @@ module ZTK
35
42
  self.upload(local_tempfile, remote_tempfile)
36
43
 
37
44
  command = Array.new
38
- command << %(sudo) if (use_sudo == true)
45
+ command << %(sudo) if (options[:use_sudo] == true)
39
46
  command << %(/bin/bash)
40
47
  command << remote_tempfile
41
48
  command = command.join(' ')
42
49
 
43
- self.exec(command, :silence => true)
50
+ result = self.exec(command, options)
51
+ result
44
52
  end
45
53
 
46
54
  end
data/lib/ztk/ssh/file.rb CHANGED
@@ -30,19 +30,20 @@ module ZTK
30
30
  tempfile = Tempfile.new("tempfile")
31
31
 
32
32
  local_tempfile = tempfile.path
33
- remote_tempfile = ::File.join("/tmp", ::File.basename(local_tempfile))
33
+ remote_tempfile = ::File.join("/", "tmp", ::File.basename(local_tempfile))
34
34
 
35
35
  ::File.open(local_tempfile, 'w') do |file|
36
36
  yield(file)
37
+ file.respond_to?(:flush) and file.flush
37
38
  end
38
39
 
39
- ZTK::RescueRetry.try(:tries => 2, :on_retry => method(:on_retry)) do
40
- upload(local_tempfile, remote_tempfile)
40
+ ZTK::RescueRetry.try(:tries => 3, :on_retry => method(:on_retry)) do
41
+ self.upload(local_tempfile, remote_tempfile)
41
42
 
42
- exec(%(sudo mv -v #{remote_tempfile} #{target}), :silence => true)
43
+ self.exec(%(sudo mv -fv #{remote_tempfile} #{target}), :silence => true)
43
44
 
44
- exec(%(sudo chown -v #{chown} #{target}), :silence => true) if !chown.nil?
45
- exec(%(sudo chmod -v #{chmod} #{target}), :silence => true) if !chmod.nil?
45
+ chown.nil? or self.exec(%(sudo chown -v #{chown} #{target}), :silence => true)
46
+ chmod.nil? or self.exec(%(sudo chmod -v #{chmod} #{target}), :silence => true)
46
47
  end
47
48
 
48
49
  true
data/lib/ztk/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module ZTK
2
2
 
3
3
  # ZTK Version String
4
- VERSION = "1.6.0"
4
+ VERSION = "1.6.1"
5
5
 
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ztk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.6.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-16 00:00:00.000000000 Z
12
+ date: 2013-06-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -263,18 +263,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
263
263
  - - ! '>='
264
264
  - !ruby/object:Gem::Version
265
265
  version: '0'
266
- segments:
267
- - 0
268
- hash: -126748681246947343
269
266
  required_rubygems_version: !ruby/object:Gem::Requirement
270
267
  none: false
271
268
  requirements:
272
269
  - - ! '>='
273
270
  - !ruby/object:Gem::Version
274
271
  version: '0'
275
- segments:
276
- - 0
277
- hash: -126748681246947343
278
272
  requirements: []
279
273
  rubyforge_project:
280
274
  rubygems_version: 1.8.25