producer-stdlib 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ea82d4f4915bf9bd656fa07766375552ccf585e7
4
+ data.tar.gz: eb3788bc0b1424ffa775a23d03707b8ac7509290
5
+ SHA512:
6
+ metadata.gz: 4b7e43a56e4e614bc3989d39fb1a32c785b9b5ca5b8bceb6956d3c16eeb8348e95df5518097966f1e37f4585be520065cf2db3cbb08a1b4be9782b24ddbee782
7
+ data.tar.gz: c7b0c32596fdee2224d97057793bf9e37ed759a362d5d3a0667b66542f46e8ef524e44f5e73bbe57d8e310ba5900dd9d59d7c01d0e4f8e8605cdbfe1db6bbf52
@@ -0,0 +1,6 @@
1
+ module Producer
2
+ module STDLib
3
+ module Base
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,29 @@
1
+ module Producer
2
+ module STDLib
3
+ module FreeBSD
4
+ module Ports
5
+ STDLib.define_macro :port_install do |port, options = {}|
6
+ make_args = []
7
+
8
+ condition { no_pkg? port }
9
+
10
+ make_args << '-DBATCH'
11
+
12
+ %w[with without].each do |e|
13
+ if options[e.to_sym]
14
+ make_args << "#{e.upcase}='%s'" % options[e.to_sym].map(&:upcase).join(' ')
15
+ end
16
+ end
17
+
18
+ sh "cd /usr/ports/#{port} && make #{make_args.join ' '} install clean"
19
+ end
20
+
21
+ STDLib.define_macro :portmaster do |port|
22
+ condition { no_pkg? port }
23
+
24
+ sh "portmaster -bDG --no-confirm #{port}"
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,133 @@
1
+ module Producer
2
+ module STDLib
3
+ module FreeBSD
4
+ require 'shellwords'
5
+
6
+ LOADER_CONF_PATH = '/boot/loader.conf'.freeze
7
+ RC_CONF_PATH = '/etc/rc.conf'.freeze
8
+ SYSCTL_CONF_PATH = '/etc/sysctl.conf'.freeze
9
+ PERIODIC_CONF_PATH = '/etc/periodic.conf'.freeze
10
+ MAKE_CONF_PATH = '/etc/make.conf'.freeze
11
+
12
+
13
+ STDLib.define_test(:rc_enabled?) do |service|
14
+ sh "service #{service} enabled > /dev/null"
15
+ end
16
+
17
+ STDLib.define_macro :rc_enable do |service|
18
+ condition { no_rc_enabled? service }
19
+
20
+ file_append RC_CONF_PATH, %{\n#{service}_enable=\"YES\"\n}
21
+ sh "service #{service} start"
22
+ end
23
+
24
+ STDLib.define_macro :hostname do |hostname|
25
+ rc_conf_value = "hostname=#{hostname}"
26
+
27
+ condition { no_file_contains RC_CONF_PATH, rc_conf_value }
28
+
29
+ file_replace_content RC_CONF_PATH, /^hostname=.+$/, rc_conf_value
30
+ end
31
+
32
+ # FIXME: refactor with file_add macro?
33
+ STDLib.define_macro :loader_conf do |conf|
34
+ condition { no_file_contains LOADER_CONF_PATH, conf }
35
+
36
+ file_append LOADER_CONF_PATH, "\n%s" % conf
37
+ end
38
+
39
+ # FIXME: refactor with file_add macro?
40
+ STDLib.define_macro :rc_conf do |conf|
41
+ condition { no_file_contains RC_CONF_PATH, conf }
42
+
43
+ file_append RC_CONF_PATH, "\n%s" % conf
44
+ end
45
+
46
+ # FIXME: refactor with file_add macro?
47
+ STDLib.define_macro :sysctl_conf do |conf|
48
+ condition { no_file_contains SYSCTL_CONF_PATH, conf }
49
+
50
+ file_append SYSCTL_CONF_PATH, "\n%s" % conf
51
+ end
52
+
53
+ # FIXME: refactor with file_add macro?
54
+ STDLib.define_macro :periodic_conf do |conf|
55
+ condition { no_file_contains PERIODIC_CONF_PATH, conf }
56
+
57
+ file_append PERIODIC_CONF_PATH, "\n%s" % conf
58
+ end
59
+
60
+ # FIXME: refactor with file_add macro?
61
+ STDLib.define_macro :ports_config do |config|
62
+ condition { no_file_contains MAKE_CONF_PATH, config }
63
+
64
+ file_write MAKE_CONF_PATH, config
65
+ end
66
+
67
+ STDLib.define_macro :chsh do |shell|
68
+ condition { no_env? :shell, shell }
69
+
70
+ sh "chsh -s #{shell}"
71
+ end
72
+
73
+ STDLib.define_macro :group_add do |group, gid = nil|
74
+ condition do
75
+ no_sh "getent group #{group}"
76
+ no_sh "getent group #{gid}" if gid
77
+ end
78
+
79
+ cmd = "pw group add #{group}"
80
+ cmd << " -g #{gid}" if gid
81
+
82
+ sh cmd
83
+ end
84
+
85
+ STDLib.define_macro :user_add do |user, opts = {}|
86
+ options = {
87
+ mask: '0700',
88
+ skel: '/var/empty',
89
+ shell: '/bin/sh',
90
+ pass: 'random'
91
+ }.merge opts
92
+ switches = {
93
+ uid: ?u,
94
+ name: ?c,
95
+ group: ?g,
96
+ groups: ?G,
97
+ mask: ?M,
98
+ skel: ?k,
99
+ shell: ?s,
100
+ pass: ?w
101
+ }
102
+
103
+ condition do
104
+ no_sh "getent passwd #{user}"
105
+ no_sh "getent passwd #{options[:uid]}" if options[:uid]
106
+ end
107
+
108
+ cmd = switches.inject("pw user add #{user} -m") do |m, (k, v)|
109
+ m << " -#{v} #{::Shellwords.escape(options[k])}" if options[k]
110
+ m
111
+ end
112
+
113
+ sh cmd
114
+ end
115
+
116
+ STDLib.define_test(:pkg?) { |pkg| sh "pkg info -eO #{pkg}" }
117
+
118
+ STDLib.define_macro :pkg_bootstrap do |repo_uri|
119
+ condition { no_sh 'pkg -N' }
120
+
121
+ # FIXME: must not disable signature
122
+ sh "PACKAGESITE=#{repo_uri} SIGNATURE_TYPE=NONE ASSUME_ALWAYS_YES=YES pkg bootstrap"
123
+ sh "PACKAGESITE=#{repo_uri} pkg update"
124
+ end
125
+
126
+ STDLib.define_macro :pkg_install do |pkg|
127
+ condition { no_pkg? pkg }
128
+
129
+ sh 'ASSUME_ALWAYS_YES=YES pkg install %s' % pkg
130
+ end
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,29 @@
1
+ module Producer
2
+ module STDLib
3
+ module FS
4
+ STDLib.define_macro :ensure_dir do |path, mode|
5
+ mode ||= 0700
6
+
7
+ condition { no_dir? path }
8
+
9
+ mkdir path, mode
10
+ end
11
+
12
+ STDLib.define_macro :file_append_once do |path, content|
13
+ condition { no_file_contains path, content }
14
+
15
+ file_append path, content
16
+ end
17
+
18
+ STDLib.define_macro :file_write do |path, content|
19
+ file_write path, content
20
+ end
21
+
22
+ STDLib.define_macro :file_write_once do |path, content|
23
+ condition { no_file_eq path, content }
24
+
25
+ file_write path, content
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,22 @@
1
+ module Producer
2
+ module STDLib
3
+ module Git
4
+ STDLib.define_test :git? do |path|
5
+ dir? "#{path}/.git"
6
+ end
7
+
8
+ STDLib.define_macro :git_clone do |repository, destination|
9
+ condition { no_git? destination }
10
+
11
+ sh "git clone --depth 1 #{repository} #{destination}"
12
+ end
13
+
14
+ STDLib.define_macro :git_update do |path|
15
+ git = "git -C #{path}"
16
+
17
+ sh "#{git} fetch origin"
18
+ sh "#{git} reset --hard origin"
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,34 @@
1
+ module Producer
2
+ module STDLib
3
+ module SSH
4
+ require 'base64'
5
+
6
+ SSH_AUTHORIZED_KEYS_PATH = '.ssh/authorized_keys'.freeze
7
+
8
+
9
+ STDLib.define_macro :ssh_dir do
10
+ condition { no_dir? '.ssh' }
11
+
12
+ mkdir '.ssh', 0700
13
+ end
14
+
15
+ STDLib.define_macro :ssh_copy_id do |path = SSH_AUTHORIZED_KEYS_PATH|
16
+ condition { no_file? path }
17
+
18
+ # FIXME: remove this hack, should have proper keyword or another way
19
+ if !!condition
20
+ agent = Net::SSH::Authentication::Agent.connect
21
+ choices = agent.identities.map { |e| [e, e.comment] }
22
+ key = ask 'Which key do you want to copy?', choices
23
+
24
+ line = [
25
+ key.ssh_type,
26
+ ::Base64.encode64(key.to_blob).gsub("\n", '')
27
+ ].join ' '
28
+
29
+ file_write path, "#{line}\n", 0600
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,5 @@
1
+ module Producer
2
+ module STDLib
3
+ VERSION = '0.0.2'.freeze
4
+ end
5
+ end
@@ -0,0 +1,20 @@
1
+ module Producer
2
+ module STDLib
3
+ class << self
4
+ def define_macro(name, &block)
5
+ ::Producer::Core::Recipe::DSL.define_macro(name, block)
6
+ end
7
+
8
+ def define_test(name, &block)
9
+ ::Producer::Core::Condition::DSL.define_test(name, block)
10
+ end
11
+ end
12
+
13
+ require 'producer/stdlib/fs'
14
+ require 'producer/stdlib/freebsd'
15
+ require 'producer/stdlib/freebsd/ports'
16
+ require 'producer/stdlib/git'
17
+ require 'producer/stdlib/ssh'
18
+ require 'producer/stdlib/version'
19
+ end
20
+ end
@@ -0,0 +1,18 @@
1
+ require File.expand_path('../lib/producer/stdlib/version', __FILE__)
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'producer-stdlib'
5
+ s.version = Producer::STDLib::VERSION.dup
6
+ s.summary = 'Provisioning tool'
7
+ s.description = <<-eoh.gsub(/^ +/, '')
8
+ Standard library for producer (gem: producer-core).
9
+ eoh
10
+ s.homepage = 'https://rubygems.org/gems/producer-stdlib'
11
+
12
+ s.authors = 'Thibault Jouan'
13
+ s.email = 'tj@a13.fr'
14
+
15
+ s.files = `git ls-files`.split $/
16
+
17
+ s.add_dependency 'producer-core', '~> 0.2', '>= 0.2.13'
18
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: producer-stdlib
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Thibault Jouan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: producer-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.2'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.2.13
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.2'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.2.13
33
+ description: |
34
+ Standard library for producer (gem: producer-core).
35
+ email: tj@a13.fr
36
+ executables: []
37
+ extensions: []
38
+ extra_rdoc_files: []
39
+ files:
40
+ - lib/producer/stdlib.rb
41
+ - lib/producer/stdlib/base.rb
42
+ - lib/producer/stdlib/freebsd.rb
43
+ - lib/producer/stdlib/freebsd/ports.rb
44
+ - lib/producer/stdlib/fs.rb
45
+ - lib/producer/stdlib/git.rb
46
+ - lib/producer/stdlib/ssh.rb
47
+ - lib/producer/stdlib/version.rb
48
+ - producer-stdlib.gemspec
49
+ homepage: https://rubygems.org/gems/producer-stdlib
50
+ licenses: []
51
+ metadata: {}
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 2.2.2
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: Provisioning tool
72
+ test_files: []
73
+ has_rdoc: