producer-stdlib 0.0.7 → 0.0.8

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.
@@ -15,10 +15,12 @@ module Producer
15
15
  end
16
16
 
17
17
  require 'producer/stdlib/fs'
18
+ require 'producer/stdlib/debian'
18
19
  require 'producer/stdlib/freebsd'
19
20
  require 'producer/stdlib/freebsd/ports'
20
21
  require 'producer/stdlib/git'
21
22
  require 'producer/stdlib/ssh'
22
23
  require 'producer/stdlib/version'
24
+ require 'producer/stdlib/yaml'
23
25
  end
24
26
  end
@@ -0,0 +1,15 @@
1
+ module Producer
2
+ module STDLib
3
+ module Debian
4
+ STDLib.define_test(:apt_pkg?) do |pkg|
5
+ sh "dpkg-query -l #{pkg} > /dev/null 2>&1"
6
+ end
7
+
8
+ STDLib.define_macro :apt_install do |pkg|
9
+ condition { no_apt_pkg? pkg }
10
+
11
+ sh "env DEBIAN_FRONTEND=noninteractive apt-get install --quiet --yes #{pkg}"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -13,10 +13,14 @@ module Producer
13
13
  STDLib.compose_macro :loader_conf, :file_write_once, LOADER_CONF_PATH
14
14
 
15
15
  STDLib.compose_macro :rc_conf, :file_write_once, RC_CONF_PATH
16
+ STDLib.compose_macro :rc_conf_append, :file_append_once, RC_CONF_PATH
16
17
 
17
18
  STDLib.compose_macro :sysctl_conf, :file_write_once, SYSCTL_CONF_PATH
18
19
 
19
- STDLib.compose_macro :periodic_conf, :file_write_once, PERIODIC_CONF_PATH
20
+ STDLib.compose_macro :periodic_conf,
21
+ :file_write_once, PERIODIC_CONF_PATH
22
+ STDLib.compose_macro :periodic_conf_append,
23
+ :file_append_once, PERIODIC_CONF_PATH
20
24
 
21
25
  STDLib.compose_macro :make_conf, :file_write_once, MAKE_CONF_PATH
22
26
 
@@ -60,6 +64,16 @@ module Producer
60
64
  rc_conf_update "#{service}_enable", '"NO"'
61
65
  end
62
66
 
67
+ STDLib.define_macro :rc_send do |command, service|
68
+ sh "service #{service} #{command}"
69
+ end
70
+
71
+ STDLib.compose_macro :rc_status, :rc_send, 'status'
72
+ STDLib.compose_macro :rc_reload, :rc_send, 'reload'
73
+ STDLib.compose_macro :rc_restart, :rc_send, 'restart'
74
+ STDLib.compose_macro :rc_start, :rc_send, 'start'
75
+ STDLib.compose_macro :rc_stop, :rc_send, 'stop'
76
+
63
77
  STDLib.compose_macro :hostname, :rc_conf_update, 'hostname'
64
78
 
65
79
  STDLib.define_macro :chsh do |shell|
@@ -124,7 +138,7 @@ module Producer
124
138
  STDLib.define_macro :pkg_install do |pkg|
125
139
  condition { no_pkg? pkg }
126
140
 
127
- sh 'env ASSUME_ALWAYS_YES=YES pkg install %s' % pkg
141
+ sh 'pkg install -y %s' % pkg
128
142
  end
129
143
  end
130
144
  end
@@ -1,24 +1,24 @@
1
1
  module Producer
2
2
  module STDLib
3
3
  module FS
4
- STDLib.define_macro :ensure_dir do |path, mode|
5
- mode ||= 0700
4
+ STDLib.define_macro :ensure_dir do |path, options = {}|
5
+ options[:mode] ||= 0700
6
6
 
7
7
  condition { no_dir? path }
8
8
 
9
- mkdir path, mode
9
+ mkdir path, options
10
10
  end
11
11
 
12
- STDLib.define_macro :file_append_once do |path, content|
13
- condition { no_file_contains path, content }
12
+ STDLib.define_macro :file_write_once do |path, content, options|
13
+ condition { no_file_eq path, content }
14
14
 
15
- file_append path, content
15
+ file_write path, content, options
16
16
  end
17
17
 
18
- STDLib.define_macro :file_write_once do |path, content|
19
- condition { no_file_eq path, content }
18
+ STDLib.define_macro :file_append_once do |path, content|
19
+ condition { no_file_contains path, content }
20
20
 
21
- file_write path, content
21
+ file_append path, content
22
22
  end
23
23
  end
24
24
  end
@@ -5,10 +5,12 @@ module Producer
5
5
  dir? "#{path}/.git"
6
6
  end
7
7
 
8
- STDLib.define_macro :git_clone do |repository, destination|
8
+ STDLib.define_macro :git_clone do |repository, destination, branch: nil|
9
+ branch = branch ? '--branch %s' % branch : ''
10
+
9
11
  condition { no_git? destination }
10
12
 
11
- sh "git clone --depth 1 #{repository} #{destination}"
13
+ sh "git clone #{branch} --depth 1 #{repository} #{destination}"
12
14
  end
13
15
 
14
16
  STDLib.define_macro :git_update do |path|
@@ -3,13 +3,37 @@ module Producer
3
3
  module SSH
4
4
  require 'base64'
5
5
 
6
- SSH_AUTHORIZED_KEYS_PATH = '.ssh/authorized_keys'.freeze
6
+ SSH_AUTHORIZED_KEYS_PATH = '.ssh/authorized_keys'.freeze
7
+ SSH_AUTHORIZED_NO_KEY_FMT =
8
+ '"ssh_authorize macro cannot find key matching `%s\''
7
9
 
8
10
 
9
11
  STDLib.define_macro :ssh_dir do
10
- condition { no_dir? '.ssh' }
12
+ ensure_dir '.ssh', mode: 0700
13
+ end
14
+
15
+ STDLib.define_macro :ssh_authorize do |key_pattern, user: nil|
16
+ path_base = user ? '/home/%s' % user : nil
17
+ path = Pathname.new(path_base) + SSH_AUTHORIZED_KEYS_PATH
18
+
19
+ condition { no_file? path }
20
+
21
+ if condition_met?
22
+ key = Net::SSH::Authentication::Agent.connect.identities.find do |e|
23
+ e.fingerprint =~ /\A#{key_pattern}/
24
+ end
25
+
26
+ fail Core::RuntimeError, SSH_AUTHORIZED_NO_KEY_FMT % key_pattern unless key
11
27
 
12
- mkdir '.ssh', 0700
28
+ line = [
29
+ key.ssh_type,
30
+ ::Base64.encode64(key.to_blob).gsub("\n", '')
31
+ ].join ' '
32
+
33
+ ensure_dir path.dirname, mode: 0700
34
+ file_write_once path, "#{line}\n", mode: 0600
35
+ sh 'chown -R %s %s' % [user, path.dirname] if user
36
+ end
13
37
  end
14
38
 
15
39
  STDLib.define_macro :ssh_copy_id do |path = SSH_AUTHORIZED_KEYS_PATH|
@@ -25,7 +49,7 @@ module Producer
25
49
  ::Base64.encode64(key.to_blob).gsub("\n", '')
26
50
  ].join ' '
27
51
 
28
- file_write path, "#{line}\n", 0600
52
+ file_write path, "#{line}\n", mode: 0600
29
53
  end
30
54
  end
31
55
  end
@@ -1,5 +1,5 @@
1
1
  module Producer
2
2
  module STDLib
3
- VERSION = '0.0.7'.freeze
3
+ VERSION = '0.0.8'.freeze
4
4
  end
5
5
  end
@@ -0,0 +1,11 @@
1
+ module Producer
2
+ module STDLib
3
+ module YAML
4
+ STDLib.define_macro :yaml_write_once do |path, data, options = {}|
5
+ condition { no_yaml_eq path, data }
6
+
7
+ yaml_write path, options.merge(data: data)
8
+ end
9
+ end
10
+ end
11
+ end
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: producer-stdlib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Thibault Jouan
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-09-28 00:00:00.000000000 Z
12
+ date: 2015-02-21 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: producer-core
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - "~>"
18
20
  - !ruby/object:Gem::Version
@@ -23,6 +25,7 @@ dependencies:
23
25
  type: :runtime
24
26
  prerelease: false
25
27
  version_requirements: !ruby/object:Gem::Requirement
28
+ none: false
26
29
  requirements:
27
30
  - - "~>"
28
31
  - !ruby/object:Gem::Version
@@ -38,35 +41,37 @@ extensions: []
38
41
  extra_rdoc_files: []
39
42
  files:
40
43
  - lib/producer/stdlib.rb
44
+ - lib/producer/stdlib/debian.rb
41
45
  - lib/producer/stdlib/freebsd.rb
42
46
  - lib/producer/stdlib/freebsd/ports.rb
43
47
  - lib/producer/stdlib/fs.rb
44
48
  - lib/producer/stdlib/git.rb
45
49
  - lib/producer/stdlib/ssh.rb
46
50
  - lib/producer/stdlib/version.rb
51
+ - lib/producer/stdlib/yaml.rb
47
52
  - producer-stdlib.gemspec
48
53
  homepage: https://rubygems.org/gems/producer-stdlib
49
54
  licenses: []
50
- metadata: {}
51
55
  post_install_message:
52
56
  rdoc_options: []
53
57
  require_paths:
54
58
  - lib
55
59
  required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
56
61
  requirements:
57
62
  - - ">="
58
63
  - !ruby/object:Gem::Version
59
64
  version: '0'
60
65
  required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
61
67
  requirements:
62
68
  - - ">="
63
69
  - !ruby/object:Gem::Version
64
70
  version: '0'
65
71
  requirements: []
66
72
  rubyforge_project:
67
- rubygems_version: 2.2.2
73
+ rubygems_version: 1.8.30
68
74
  signing_key:
69
- specification_version: 4
75
+ specification_version: 3
70
76
  summary: Standard library for producer
71
77
  test_files: []
72
- has_rdoc:
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 61167336d12da40074cc617c7f73c4068455ea43
4
- data.tar.gz: 5124f9aa5afdf16372f77f03e9940c2f084bfdd6
5
- SHA512:
6
- metadata.gz: 4600f297b06e66c9d46c6a1f9c1b94d9b55b195896d280fdc4717279b39926cc96dda7ff98787335d860e6987d3d5ae1754ef11c38fb282367848d207f888bf1
7
- data.tar.gz: b6fbe67d4ed9e63108e035231f87f544ea6f97cb3fc526ad09a895c6427567a6dd92848a5f55b46a31469509b00893899225e2b6aa31bd30b889872734364185