vagrant-impressbox 0.1.0

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 (37) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +4 -0
  5. data/Gemfile +21 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +31 -0
  8. data/Rakefile +9 -0
  9. data/bin/console +14 -0
  10. data/bin/setup +8 -0
  11. data/lib/vagrant-impressbox.rb +21 -0
  12. data/lib/vagrant-impressbox/action_builder.rb +20 -0
  13. data/lib/vagrant-impressbox/actions/copy_git_settings.rb +38 -0
  14. data/lib/vagrant-impressbox/actions/insert_key.rb +56 -0
  15. data/lib/vagrant-impressbox/command.rb +165 -0
  16. data/lib/vagrant-impressbox/config.rb +38 -0
  17. data/lib/vagrant-impressbox/configs/command.yml +30 -0
  18. data/lib/vagrant-impressbox/configs/default.yml +13 -0
  19. data/lib/vagrant-impressbox/configs/for/impresscms.yml +8 -0
  20. data/lib/vagrant-impressbox/configurators/base.rb +21 -0
  21. data/lib/vagrant-impressbox/configurators/hyperv.rb +36 -0
  22. data/lib/vagrant-impressbox/configurators/virtualbox.rb +23 -0
  23. data/lib/vagrant-impressbox/objects/config_data.rb +62 -0
  24. data/lib/vagrant-impressbox/objects/config_file.rb +128 -0
  25. data/lib/vagrant-impressbox/objects/configurator.rb +135 -0
  26. data/lib/vagrant-impressbox/objects/ssh_key_detect.rb +116 -0
  27. data/lib/vagrant-impressbox/objects/template.rb +99 -0
  28. data/lib/vagrant-impressbox/plugin.rb +46 -0
  29. data/lib/vagrant-impressbox/provisioner.rb +103 -0
  30. data/lib/vagrant-impressbox/templates/Vagrantfile +37 -0
  31. data/lib/vagrant-impressbox/templates/config.yaml +76 -0
  32. data/lib/vagrant-impressbox/version.rb +4 -0
  33. data/locales/en.yml +28 -0
  34. data/spec/impressbox_spec.rb +11 -0
  35. data/spec/spec_helper.rb +2 -0
  36. data/vagrant-impressbox.gemspec +31 -0
  37. metadata +157 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7058d0e553b2b94d55a1a23dc84bef2256d969f4
4
+ data.tar.gz: 7ad515e10500a70ede69ce1dc2796cd6e29cffd0
5
+ SHA512:
6
+ metadata.gz: 68778fb8535b5b7826cea599470263320c4deba03513435883dda6a37d507a8b819420c379871ea3580eb7a1dab86907f650bdd7176dcefbd9cb7b06a98640ba
7
+ data.tar.gz: 11bdfab2e693518a67a35409b610d88d3ac5c71d660acb7b4c11fd4da4780667353e3893dad11b2f47de98238dea16e81a1d94dd0ce612d42832a5e24c4d1f0f
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.vagrant
11
+ nbproject/
12
+
13
+ /config.yaml
14
+ /Vagrantfile
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,21 @@
1
+ source 'https://rubygems.org'
2
+
3
+ ENV['TEST_VAGRANT_VERSION'] ||= 'v1.8.1'
4
+
5
+ group :plugins do
6
+ gem 'vagrant-impressbox', path: '.'
7
+ gem 'vagrant-hostmanager', '~> 1.8', '>= 1.8.1'
8
+ end
9
+
10
+ group :test do
11
+ if ENV['TEST_VAGRANT_VERSION'] == 'HEAD'
12
+ gem 'vagrant', github: 'mitchellh/vagrant', branch: 'master'
13
+ else
14
+ gem 'vagrant', github: 'mitchellh/vagrant', tag: ENV['TEST_VAGRANT_VERSION']
15
+ end
16
+
17
+ # Pinned on 12/10/2014. Compatible with Vagrant 1.5.x, 1.6.x and 1.7.x.
18
+ # gem 'vagrant-spec', github: 'mitchellh/vagrant-spec', ref: '1df5a3a'
19
+ end
20
+
21
+ eval_gemfile "#{__FILE__}.local" if File.exist? "#{__FILE__}.local"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Raimondas Rimkevičius
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # **!!! DOESN'T WORK YET. Please wait !!!**
2
+
3
+ ------
4
+
5
+ # ImpressBox
6
+
7
+ ImpressBox is plugin to make easier to configure virtual enviroment for Vagrant.
8
+
9
+ ## Installation
10
+
11
+ `vagrant plugin install impressbox`
12
+
13
+ ## Usage
14
+
15
+ `vagrant impressbox`
16
+
17
+ ## Development
18
+
19
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
20
+
21
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
22
+
23
+ ## Contributing
24
+
25
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ImpressCMS/impressbox.
26
+
27
+
28
+ ## License
29
+
30
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
31
+
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ # require 'bundler/gem_tasks'
2
+ # require 'rspec/core/rake_task'
3
+
4
+ # RSpec::Core::RakeTask.new(:spec)
5
+
6
+ # task default: :spec
7
+ require 'rubygems'
8
+ require 'bundler/setup'
9
+ Bundler::GemHelper.install_tasks
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'impressbox'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'vagrant'
3
+ rescue LoadError
4
+ raise 'vagrant-impressbox plugin must be run within Vagrant'
5
+ end
6
+
7
+ # Loads all module data
8
+ module Impressbox
9
+ require 'vagrant-impressbox/version'
10
+ require 'vagrant-impressbox/plugin'
11
+
12
+ # This returns the path to the source of this plugin.
13
+ #
14
+ # @return [Pathname]
15
+ def self.source_root
16
+ @source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
17
+ end
18
+
19
+ I18n.load_path << File.expand_path('locales/en.yml', source_root)
20
+ I18n.reload!
21
+ end
@@ -0,0 +1,20 @@
1
+ module Impressbox
2
+ # Defines builder for actions
3
+ module ActionBuilder
4
+ include Vagrant::Action::Builtin
5
+
6
+ def self.insert_key
7
+ require_relative File.join('actions', 'insert_key')
8
+ Vagrant::Action::Builder.new.tap do |builder|
9
+ builder.use Impressbox::Actions::InsertKey
10
+ end
11
+ end
12
+
13
+ def self.copy_git_settings
14
+ require_relative File.join('actions', 'copy_git_settings')
15
+ Vagrant::Action::Builder.new.tap do |builder|
16
+ builder.use Impressbox::Actions::CopyGitSettings
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,38 @@
1
+ module Impressbox
2
+ module Actions
3
+ # Copies global git settings from host to guest
4
+ class CopyGitSettings
5
+ def initialize(app, _env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ @app.call env
11
+ @machine = env[:machine]
12
+ env[:ui].info I18n.t('copying.git_settings')
13
+ update_remote_cfg local_cfg
14
+ end
15
+
16
+ private
17
+
18
+ def local_cfg
19
+ ret = {}
20
+ output = `git config --list --global`
21
+ output.lines.each do |line|
22
+ line.split(' ', 2) do |name, value|
23
+ ret[name] = value
24
+ end
25
+ end
26
+ ret
27
+ end
28
+
29
+ def update_remote_cfg(cfg)
30
+ @machine.communicate.wait_for_ready 300
31
+
32
+ cfg.each do |key, name|
33
+ @machine.communicate "git config --global #{key} '#{name}'"
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,56 @@
1
+ module Impressbox
2
+ module Actions
3
+ # This is action to insert keys to remote machine when booting
4
+ class InsertKey
5
+ def initialize(app, env)
6
+ @app = app
7
+ @ui = env[:ui]
8
+ end
9
+
10
+ def call(env)
11
+ @app.call env
12
+ @machine = env[:machine]
13
+ insert_ssh_key_if_needed(
14
+ Impressbox::Plugin.get_item(:public_key),
15
+ Impressbox::Plugin.get_item(:private_key)
16
+ )
17
+ end
18
+
19
+ private
20
+
21
+ def insert_ssh_key_if_needed(public_key, private_key)
22
+ @machine.communicate.wait_for_ready 300
23
+
24
+ machine_private_key @machine.communicate, private_key
25
+ machine_public_key @machine.communicate, public_key
26
+ end
27
+
28
+ def machine_public_key(communicator, public_key)
29
+ @ui.info I18n.t('ssh_key.updating.public')
30
+ machine_upload_file communicator, public_key, '~/.ssh/id_rsa.pub'
31
+ communicator.execute 'touch ~/.ssh/authorized_keys'
32
+ communicator.execute 'cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys'
33
+ communicator.execute "echo `awk '!a[$0]++' ~/.ssh/authorized_keys` > ~/.ssh/authorized_keys"
34
+
35
+ communicator.execute 'chmod 600 ~/.ssh/id_rsa.pub'
36
+ end
37
+
38
+ def machine_private_key(communicator, private_key)
39
+ @ui.info I18n.t('ssh_key.updating.private')
40
+ machine_upload_file communicator, private_key, '~/.ssh/id_rsa'
41
+ communicator.execute 'chmod 400 ~/.ssh/id_rsa'
42
+ end
43
+
44
+ def machine_upload_file(communicator, src_file, dst_file)
45
+ communicator.execute 'chmod 777 ' + dst_file + ' || :'
46
+ communicator.execute 'touch ' + dst_file
47
+ communicator.execute 'truncate -s 0 ' + dst_file
48
+ text = File.open(src_file).read
49
+ text.gsub!(/\r\n?/, "\n")
50
+ text.each_line do |line|
51
+ communicator.execute "echo \"#{line.rstrip}\" >> #{dst_file}"
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,165 @@
1
+ require 'vagrant'
2
+ require_relative File.join('objects', 'template')
3
+ require_relative File.join('objects', 'config_data')
4
+
5
+ # Impressbox
6
+ module Impressbox
7
+ # Command class
8
+ class Command < Vagrant.plugin('2', :command)
9
+ ConfigData = Impressbox::Objects::ConfigData
10
+
11
+ def self.synopsis
12
+ I18n.t 'command.impressbox.synopsis'
13
+ end
14
+
15
+ def execute
16
+ prepare_options
17
+ @template = Impressbox::Objects::Template.new
18
+ write_result_msg do_prepare unless argv.nil?
19
+ 0
20
+ end
21
+
22
+ private
23
+
24
+ def default_values
25
+ data = ConfigData.new('default.yml').all
26
+ data[:templates] = ConfigData.list_of_type('for').join(', ')
27
+ data
28
+ end
29
+
30
+ def options_cfg
31
+ Impressbox::Objects::ConfigData.new('command.yml').all
32
+ end
33
+
34
+ def prepare_options
35
+ @options = {}
36
+ # default_values
37
+ @options[:name] = make_name
38
+ @options[:info] = {
39
+ last_update: Time.now.to_s,
40
+ website_url: 'http://impresscms.org'
41
+ }
42
+ end
43
+
44
+ def argv
45
+ parse_options create_option_parser
46
+ end
47
+
48
+ def write_result_msg(result)
49
+ if result
50
+ puts I18n.t('config.recreated')
51
+ else
52
+ puts I18n.t('config.updated')
53
+ end
54
+ end
55
+
56
+ def do_prepare
57
+ do_prepare_vagrantfile
58
+ do_prepare_congig_yaml
59
+ end
60
+
61
+ def do_prepare_congig_yaml
62
+ @template.quick_prepare(
63
+ config_yaml_filename,
64
+ @options,
65
+ must_recreate,
66
+ default_values,
67
+ use_template_filename
68
+ )
69
+ end
70
+
71
+ def do_prepare_vagrantfile
72
+ @template.quick_prepare(
73
+ vagrantfile_filename,
74
+ @options,
75
+ must_recreate,
76
+ default_values,
77
+ use_template_filename
78
+ )
79
+ end
80
+
81
+ def use_template_filename
82
+ return nil unless @options[:___use_template___]
83
+ ConfigData.real_type_filename('for', @options[:___use_template___])
84
+ end
85
+
86
+ def must_recreate
87
+ @options[:___recreate___]
88
+ end
89
+
90
+ def make_name
91
+ if @options[:hostname]
92
+ return @options[:hostname].gsub(/[^A-Za-z0-9_-]/, '-')
93
+ else
94
+ return default_values[:hostname].gsub(/[^A-Za-z0-9_-]/, '-')
95
+ end
96
+ end
97
+
98
+ def make_config
99
+ @template.prepare_file read_config_yaml, 'config.yaml', @options
100
+ end
101
+
102
+ def config_yaml_filename
103
+ @template.real_path 'config.yaml'
104
+ end
105
+
106
+ def vagrantfile_filename
107
+ @template.real_path 'Vagrantfile'
108
+ end
109
+
110
+ def option_full(option, data)
111
+ return data[:full] if data.key?(:full)
112
+ d = option.downcase
113
+ u = option.upcase
114
+ "--#{d} #{u}"
115
+ end
116
+
117
+ def option_short(data)
118
+ data[:short]
119
+ end
120
+
121
+ def option_description(data)
122
+ I18n.t data[:description], default_values
123
+ end
124
+
125
+ def option_data_parse(data, option)
126
+ [
127
+ option_short(data),
128
+ option_full(option, data),
129
+ option_description(data)
130
+ ]
131
+ end
132
+
133
+ def banner
134
+ I18n.t 'command.impressbox.usage', cmd: 'vagrant impressbox'
135
+ end
136
+
137
+ def add_action_on(o, short, full, desc, option)
138
+ if short
139
+ o.on(short, full, desc) do |f|
140
+ @options[option.to_sym] = f
141
+ end
142
+ else
143
+ o.on(full, desc) do |f|
144
+ @options[option.to_sym] = f
145
+ end
146
+ end
147
+ end
148
+
149
+ def bind_options(o)
150
+ options_cfg.each do |option, data|
151
+ short, full, desc = option_data_parse(data, option)
152
+ add_action_on o, short, full, desc, option
153
+ end
154
+ end
155
+
156
+ def create_option_parser
157
+ OptionParser.new do |o|
158
+ o.banner = banner
159
+ o.separator ''
160
+
161
+ bind_options o
162
+ end
163
+ end
164
+ end
165
+ end