Method: Vagrant::Provisioners::Shell#with_script_file

Defined in:
lib/vagrant/provisioners/shell.rb

#with_script_fileObject

This method yields the path to a script to upload and execute on the remote server. This method will properly clean up the script file if needed.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/vagrant/provisioners/shell.rb', line 52

def with_script_file
  if config.path
    # Just yield the path to that file...
    yield Pathname.new(config.path).expand_path(env[:root_path])
    return
  end

  # Otherwise we have an inline script, we need to Tempfile it,
  # and handle it specially...
  file = Tempfile.new('vagrant-shell')

  # Unless you set binmode, on a Windows host the shell script will
  # have CRLF line endings instead of LF line endings, causing havoc
  # when the guest executes it
  file.binmode

  begin
    file.write(config.inline)
    file.fsync
    file.close
    yield file.path
  ensure
    file.close
    file.unlink
  end
end