Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@ #484 | should make vagrant plugin can install by command #485

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 62 additions & 6 deletions lib/teracy-dev/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,19 @@ def self.sync(plugins)
if !installed_plugins.has_key?(plugin['name']) and plugin['state'] == 'installed'
logger.info("installing plugin: #{plugin}")

if plugin['sources'].nil? or plugin['sources'].empty?
plugin['sources'] = [
"https://rubygems.org/",
"https://gems.hashicorp.com/"
]
unless plugin['plugin_vars'].nil?
install_plugin_by_cmd(plugin, logger)
else
if plugin['sources'].nil? or plugin['sources'].empty?
plugin['sources'] = [
"https://rubygems.org/",
"https://gems.hashicorp.com/"
]
end

plugin_manager.install_plugin(plugin['name'], Util.symbolize(plugin))
end

plugin_manager.install_plugin(plugin['name'], Util.symbolize(plugin))
reload_required = true
end

Expand All @@ -45,5 +50,56 @@ def self.sync(plugins)
def self.installed?(plugin_name)
return Vagrant.has_plugin?(plugin_name)
end

private

def self.cmd_install_plugin(plugin_vars, plugin_to_install, command_opts)
cmd = ''

plugin_vars.each do |key, val|
key = key.to_s.upcase
val = val.to_s

cmd << "#{key}='#{val}' "
end

cmd << "vagrant plugin install #{plugin_to_install}"

unless command_opts.empty?
command_opts.each do |key, val|
key = key.to_s
val = val.to_s

if val.empty?
cmd << " --#{key}"
else
cmd << " --#{key}='#{val}'"
end
end
end

cmd
end

def self.install_plugin_by_cmd(plugin, logger)
logger.info("installing vagrant plugin by command...")
plugin_to_install = plugin['name']

unless plugin_to_install.empty?
command_opts = ''
command_opts = plugin['command_opts'] if !plugin['command_opts'].nil?

cmd = cmd_install_plugin(plugin['plugin_vars'], plugin_to_install, command_opts)
logger.info("Command install: #{cmd}")

if cmd.empty?
abort "Installation of plugin has failed. Command is empty..."
end

unless system cmd
abort "Installation of plugin has failed. Aborting..."
end
end
end
end
end