This repository has been archived by the owner on Dec 26, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 100
/
install.rb
71 lines (58 loc) · 2.64 KB
/
install.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
module Berkshelf
module Vagrant
module Action
# @author Jamie Winsor <jamie@vialstudios.com>
class Install
include Berkshelf::Vagrant::EnvHelpers
def initialize(app, env)
@app = app
end
def call(env)
if provision_disabled?(env)
env[:berkshelf].ui.info "Skipping Berkshelf with --no-provision"
return @app.call(env)
end
unless berkshelf_enabled?(env)
if File.exist?(env[:global_config].berkshelf.berksfile_path)
warn_disabled_but_berksfile_exists(env)
end
return @app.call(env)
end
env[:berkshelf].berksfile = Berkshelf::Berksfile.from_file(env[:global_config].berkshelf.berksfile_path)
if chef_solo?(env)
install(env)
end
@app.call(env)
rescue Berkshelf::BerkshelfError => e
raise Berkshelf::VagrantWrapperError.new(e)
end
private
def install(env)
check_vagrant_version(env)
env[:berkshelf].ui.info "Updating Vagrant's berkshelf: '#{env[:berkshelf].shelf}'"
opts = {
path: env[:berkshelf].shelf
}.merge(env[:global_config].berkshelf.to_hash).symbolize_keys!
env[:berkshelf].berksfile.install(opts)
end
def warn_disabled_but_berksfile_exists(env)
env[:berkshelf].ui.warn "Berkshelf plugin is disabled but a Berksfile was found at" +
" your configured path: #{env[:global_config].berkshelf.berksfile_path}"
env[:berkshelf].ui.warn "Enable the Berkshelf plugin by setting 'config.berkshelf.enabled = true'" +
" in your vagrant config"
end
def check_vagrant_version(env)
unless Solve::Constraint.new(">= 1.1").satisfies?(::Vagrant::VERSION)
raise Berkshelf::VagrantWrapperError.new(RuntimeError.new("vagrant-berkshelf requires Vagrant 1.1 or later."))
end
unless Solve::Constraint.new(::Berkshelf::Vagrant::TESTED_CONSTRAINT).satisfies?(::Vagrant::VERSION)
env[:berkshelf].ui.warn "This version of the Berkshelf plugin has not been fully tested on this version of Vagrant."
env[:berkshelf].ui.warn "You should check for a newer version of vagrant-berkshelf."
env[:berkshelf].ui.warn "If you encounter any errors with this version, please report them at https://github.com/RiotGames/vagrant-berkshelf/issues"
env[:berkshelf].ui.warn "You can also join the discussion in #berkshelf on Freenode."
end
end
end
end
end
end