baptize 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 11dedf7433eb9c33188a68b80a8d1b79b1a9bf1f
4
- data.tar.gz: 5af048e9e82eeafa942d46194b2cc77c72ccf089
3
+ metadata.gz: 631c1cbd594a828aed8fbc7e6bfdc187460c2be0
4
+ data.tar.gz: c1e6b3abadd41e0aadcb82c23daa96f9bfd02096
5
5
  SHA512:
6
- metadata.gz: 2da09b4fb58133cfa2756fbd78aaf06c67bb99f4aa6fa426f38f938dc8ec5c1eb6e8ac0bd133ef41bccc518195aaf80bd3a2f2de43544248f8fec0a62fca5998
7
- data.tar.gz: 1c4a577daa8bf401a315587cc610e08957dffad5903ed520596879e7063d7adf32a9d9e1a323bea4985f107085b35e0b6798b1876cea3e098fbcc453b28c99ca
6
+ metadata.gz: 44943b561ce0f265ae8f7a231b88f56320de66f4ad9714790fdbe126072625264ba708a3f6135aa070a6f501556895e0d798872f6498d8de149b886cd22d434a
7
+ data.tar.gz: 269aac58005c16f1d619357058458c690c9c5ae0b70c6597717b7e1403cc196afb91848767ae3b55fee9ea20a204d6fd3255171913ab31b54deadf78d35a55fb
@@ -35,6 +35,32 @@ module Baptize
35
35
  call_current_ssh_connection :test, command
36
36
  end
37
37
 
38
+ def upload(local, remote, options = {})
39
+ if fetch(:use_sudo)
40
+ # perform the transfer in two steps if we're using sudo
41
+ final = remote
42
+ remote = "/tmp/baptize_#{File.basename(remote)}"
43
+ end
44
+ ssh = fetch(:current_ssh_connection)
45
+ old_verbosity = nil
46
+ if fetch(:ssh_verbose)
47
+ old_verbosity = SSHKit.config.output_verbosity
48
+ SSHKit.config.output_verbosity = Logger::DEBUG
49
+ end
50
+ begin
51
+ ssh.upload! local, remote, options
52
+ ensure
53
+ SSHKit.config.output_verbosity = old_verbosity if old_verbosity
54
+ end
55
+ if fetch(:use_sudo)
56
+ remote_execute "mv #{remote.shellescape} #{final.shellescape}"
57
+ end
58
+ end
59
+
60
+ def put(buffer, remote, options = {})
61
+ upload StringIO.new(buffer), remote, options
62
+ end
63
+
38
64
  private
39
65
  def call_current_ssh_connection(action, *args)
40
66
  ssh = fetch(:current_ssh_connection)
@@ -45,7 +71,7 @@ module Baptize
45
71
  end
46
72
  begin
47
73
  if fetch(:use_bash)
48
- args = ["bash -c " + args.join(" ; ").shellescape]
74
+ args = ["bash -c " + args.join(" ; ").dump]
49
75
  end
50
76
  args.unshift(:sudo) if fetch(:use_sudo)
51
77
  ssh.send(action, *args)
@@ -0,0 +1,31 @@
1
+ module Baptize
2
+ module Plugins
3
+
4
+ module Helpers
5
+
6
+ def asset_path(asset)
7
+ File.expand_path(File.join("assets", asset))
8
+ end
9
+
10
+ def md5_of_file(path, md5)
11
+ remote_assert "test $(md5sum #{path.shellescape} | cut -f1 -d' ') = #{md5.shellescape}"
12
+ end
13
+
14
+ def escape_sed_arg(s)
15
+ s.gsub("'", "'\\\\''").gsub("\n", '\n').gsub("/", "\\\\/").gsub('&', '\\\&')
16
+ end
17
+
18
+ def replace_text(pattern, replacement, path)
19
+ remote_execute "sed -i 's/#{escape_sed_arg(pattern)}/#{escape_sed_arg(replacement)}/g' #{path.shellescape}"
20
+ end
21
+
22
+ def render(path, locals = {})
23
+ require 'erb'
24
+ require 'ostruct'
25
+ ERB.new(File.read(path)).result(locals.kind_of?(Binding) ? locals : OpenStruct.new(locals).instance_eval { binding })
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+ end
@@ -2,8 +2,36 @@ module Baptize
2
2
  module Plugins
3
3
 
4
4
  module Verifications
5
- def fail_verification
6
- raise VerificationFailure.new
5
+ def fail_verification(message = "Verification failed")
6
+ raise VerificationFailure.new(message)
7
+ end
8
+
9
+ def has_file(path)
10
+ remote_assert("test -e #{path.shellescape}") or fail_verification("Remote file #{path} does not exist")
11
+ end
12
+
13
+ def has_directory(path)
14
+ remote_assert("test -d #{path.shellescape}") or fail_verification("Remote directory #{path} does not exist")
15
+ end
16
+
17
+ def file_contains(path, text, options = {})
18
+ options = {:mode => :text}.merge(options)
19
+ if options[:mode] == :text
20
+ command = Array(text.strip.split("\n")).flatten.map {|line| "grep --fixed-strings #{line.shellescape} #{path.shellescape}" }.join(" && ")
21
+ elsif options[:mode] == :perl
22
+ command = "grep --perl-regexp #{text.shellescape} #{path.shellescape}"
23
+ else
24
+ command = "grep --basic-regexp #{text.shellescape} #{path.shellescape}"
25
+ end
26
+ remote_assert command
27
+ end
28
+
29
+ def has_executable(path)
30
+ remote_assert("which #{path.shellescape}") or fail_verification("No executable #{path} found")
31
+ end
32
+
33
+ def has_user(name)
34
+ remote_assert("id -u #{name.to_s.shellescape}") or fail_verification("No user #{name}")
7
35
  end
8
36
  end
9
37
 
data/lib/baptize/rake.rb CHANGED
@@ -1,21 +1,18 @@
1
- Rake.application.in_namespace('baptize') do
2
-
3
- Rake::Task.define_task(:list) do
4
- Baptize::Registry.packages.values.each do |package|
5
- puts [package.name, "\t", package.description].join
6
- end
1
+ Rake::Task.define_task(:list) do
2
+ puts "Available packages"
3
+ Baptize::Registry.packages.values.each do |package|
4
+ puts [package.name, "\t", package.description].join
7
5
  end
6
+ end
8
7
 
9
- Rake::Task.define_task(:apply) do
10
- Baptize::Registry.policies.keys.each do |role|
11
- on roles(role), in: :parallel do |host|
12
- Baptize::Registry.apply_policy role, host, self
13
- end
8
+ Rake::Task.define_task(:apply) do
9
+ Baptize::Registry.policies.keys.each do |role|
10
+ on roles(role), in: :parallel do |host|
11
+ Baptize::Registry.apply_policy role, host, self
14
12
  end
15
13
  end
16
-
17
14
  end
18
15
 
19
16
  Rake::Task.define_task(:default) do
20
- Rake::Task['baptize:list'].invoke
17
+ Rake::Task['list'].invoke
21
18
  end
@@ -1,3 +1,3 @@
1
1
  module Baptize
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end # module Baptize
data/lib/baptize.rb CHANGED
@@ -8,6 +8,7 @@ require 'baptize/registry'
8
8
  require 'baptize/package_definition'
9
9
  require 'baptize/execution_scope'
10
10
  require 'baptize/verification_failure'
11
+ require 'baptize/plugins/helpers'
11
12
  require 'baptize/plugins/verifications'
12
13
  require 'baptize/plugins/execution'
13
14
  require 'baptize/plugins/apt'
@@ -15,6 +16,7 @@ require 'baptize/dsl'
15
16
  require 'baptize/application'
16
17
 
17
18
  Baptize::Registry.plugins << Capistrano::DSL::Env
19
+ Baptize::Registry.plugins << Baptize::Plugins::Helpers
18
20
  Baptize::Registry.plugins << Baptize::Plugins::Verifications
19
21
  Baptize::Registry.plugins << Baptize::Plugins::Execution
20
22
  Baptize::Registry.plugins << Baptize::Plugins::Apt
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baptize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Troels Knak-Nielsen
@@ -57,6 +57,7 @@ files:
57
57
  - lib/baptize/plugins/apt.rb
58
58
  - lib/baptize/plugins/env.rb
59
59
  - lib/baptize/plugins/execution.rb
60
+ - lib/baptize/plugins/helpers.rb
60
61
  - lib/baptize/plugins/variables.rb
61
62
  - lib/baptize/plugins/verifications.rb
62
63
  - lib/baptize/rake.rb