2013-07-12 13:40:41 +00:00
|
|
|
require 'uri'
|
|
|
|
|
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
|
2013-02-11 18:42:36 +00:00
|
|
|
attr_accessor :privileged
|
2013-09-19 11:33:58 +00:00
|
|
|
attr_accessor :binary
|
2013-11-16 12:30:58 +00:00
|
|
|
attr_accessor :keep_color
|
2013-01-13 23:48:52 +00:00
|
|
|
|
|
|
|
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
|
2013-08-29 05:29:49 +00:00
|
|
|
@privileged = UNSET_VALUE
|
2013-09-19 11:33:58 +00:00
|
|
|
@binary = UNSET_VALUE
|
2013-11-16 12:30:58 +00:00
|
|
|
@keep_color = UNSET_VALUE
|
2013-03-17 23:18:49 +00:00
|
|
|
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-08-29 05:29:49 +00:00
|
|
|
@privileged = true if @privileged == UNSET_VALUE
|
2013-09-19 11:33:58 +00:00
|
|
|
@binary = false if @binary == UNSET_VALUE
|
2013-11-16 12:30:58 +00:00
|
|
|
@keep_color = false if @keep_color == UNSET_VALUE
|
2013-01-13 23:48:52 +00:00
|
|
|
end
|
|
|
|
|
2013-01-18 21:06:29 +00:00
|
|
|
def validate(machine)
|
2013-04-03 23:18:37 +00:00
|
|
|
errors = _detected_errors
|
2013-01-18 21:06:29 +00:00
|
|
|
|
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
|
|
|
|
|
2013-07-12 13:40:41 +00:00
|
|
|
# If it is not an URL, we validate the existence of a script to upload
|
|
|
|
if path && ! remote?
|
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
|
|
|
|
|
2013-11-29 08:02:20 +00:00
|
|
|
if !args_valid?
|
2013-11-25 21:36:51 +00:00
|
|
|
errors << I18n.t("vagrant.provisioners.shell.args_bad_type")
|
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
|
2013-07-12 13:40:41 +00:00
|
|
|
|
2013-11-29 01:54:10 +00:00
|
|
|
# Args are optional, but if they're provided we only support them as a
|
|
|
|
# string or as an array.
|
|
|
|
def args_valid?
|
2013-11-29 08:02:20 +00:00
|
|
|
return true if !args
|
2013-11-29 01:54:10 +00:00
|
|
|
args.is_a?(String) || args.is_a?(Array)
|
|
|
|
end
|
|
|
|
|
2013-07-12 13:40:41 +00:00
|
|
|
def remote?
|
2013-09-03 17:44:16 +00:00
|
|
|
path =~ URI.regexp(["ftp", "http", "https"])
|
2013-07-12 13:40:41 +00:00
|
|
|
end
|
2013-01-13 23:48:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|