2013-01-13 23:48:52 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module Shell
|
|
|
|
class Config < Vagrant.plugin("2", :config)
|
|
|
|
attr_accessor :inline
|
|
|
|
attr_accessor :path
|
|
|
|
attr_accessor :upload_path
|
|
|
|
attr_accessor :args
|
|
|
|
|
|
|
|
def initialize
|
2013-03-18 11:44:26 +00:00
|
|
|
@args = UNSET_VALUE
|
2013-03-17 23:18:49 +00:00
|
|
|
@inline = UNSET_VALUE
|
|
|
|
@path = UNSET_VALUE
|
|
|
|
@upload_path = UNSET_VALUE
|
|
|
|
end
|
|
|
|
|
|
|
|
def finalize!
|
2013-03-18 11:44:26 +00:00
|
|
|
@args = nil if @args == UNSET_VALUE
|
2013-03-17 23:18:49 +00:00
|
|
|
@inline = nil if @inline == UNSET_VALUE
|
|
|
|
@path = nil if @path == UNSET_VALUE
|
|
|
|
@upload_path = "/tmp/vagrant-shell" if @upload_path == UNSET_VALUE
|
2013-01-13 23:48:52 +00:00
|
|
|
end
|
|
|
|
|
2013-01-18 21:06:29 +00:00
|
|
|
def validate(machine)
|
|
|
|
errors = []
|
|
|
|
|
2013-01-13 23:48:52 +00:00
|
|
|
# Validate that the parameters are properly set
|
|
|
|
if path && inline
|
2013-01-18 21:06:29 +00:00
|
|
|
errors << I18n.t("vagrant.provisioners.shell.path_and_inline_set")
|
2013-01-13 23:48:52 +00:00
|
|
|
elsif !path && !inline
|
2013-01-18 21:06:29 +00:00
|
|
|
errors << I18n.t("vagrant.provisioners.shell.no_path_or_inline")
|
2013-01-13 23:48:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Validate the existence of a script to upload
|
|
|
|
if path
|
2013-01-18 21:06:29 +00:00
|
|
|
expanded_path = Pathname.new(path).expand_path(machine.env.root_path)
|
2013-01-13 23:48:52 +00:00
|
|
|
if !expanded_path.file?
|
2013-01-18 21:06:29 +00:00
|
|
|
errors << I18n.t("vagrant.provisioners.shell.path_invalid",
|
|
|
|
:path => expanded_path)
|
2013-01-13 23:48:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# There needs to be a path to upload the script to
|
|
|
|
if !upload_path
|
2013-01-18 21:06:29 +00:00
|
|
|
errors << I18n.t("vagrant.provisioners.shell.upload_path_not_set")
|
2013-01-13 23:48:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# If there are args and its not a string, that is a problem
|
|
|
|
if args && !args.is_a?(String)
|
2013-01-18 21:06:29 +00:00
|
|
|
errors << I18n.t("vagrant.provisioners.shell.args_not_string")
|
2013-01-13 23:48:52 +00:00
|
|
|
end
|
2013-01-18 21:06:29 +00:00
|
|
|
|
|
|
|
{ "shell provisioner" => errors }
|
2013-01-13 23:48:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|