Convert DOS line endings to Unix in shell provisioner [GH-1495]

This commit is contained in:
Mitchell Hashimoto 2013-04-22 23:32:13 -07:00
parent 7524e7a3c0
commit 40e9ce6252
2 changed files with 12 additions and 3 deletions

View File

@ -24,6 +24,8 @@ BUG FIXES:
multiple times. [GH-1467] multiple times. [GH-1467]
- `vagrant box add` with a file path now works correctly on Windows - `vagrant box add` with a file path now works correctly on Windows
when a drive letter is specified. when a drive letter is specified.
- DOS line endings are converted to Unix line endings for the
shell provisioner automatically. [GH-1495]
## 1.2.1 (April 17, 2013) ## 1.2.1 (April 17, 2013)

View File

@ -48,13 +48,20 @@ module VagrantPlugins
# on the remote server. This method will properly clean up the # on the remote server. This method will properly clean up the
# script file if needed. # script file if needed.
def with_script_file def with_script_file
script = nil
if config.path if config.path
# Just yield the path to that file... # Just yield the path to that file...
root_path = @machine.env.root_path root_path = @machine.env.root_path
yield Pathname.new(config.path).expand_path(root_path) script = Pathname.new(config.path).expand_path(root_path).read
return else
# The script is just the inline code...
script = config.inline
end end
# Replace Windows line endings with Unix ones
script.gsub!(/\r\n?$/, "\n")
# Otherwise we have an inline script, we need to Tempfile it, # Otherwise we have an inline script, we need to Tempfile it,
# and handle it specially... # and handle it specially...
file = Tempfile.new('vagrant-shell') file = Tempfile.new('vagrant-shell')
@ -65,7 +72,7 @@ module VagrantPlugins
file.binmode file.binmode
begin begin
file.write(config.inline) file.write(script)
file.fsync file.fsync
file.close file.close
yield file.path yield file.path