Use current user's uid for NFS exports

This commit is contained in:
Dave Marshall 2013-03-27 15:15:39 +00:00
parent 87613ec939
commit b8a8286fac
6 changed files with 21 additions and 13 deletions

View File

@ -27,7 +27,8 @@ module VagrantPlugins
output = TemplateRenderer.render('nfs/exports_linux', output = TemplateRenderer.render('nfs/exports_linux',
:uuid => id, :uuid => id,
:ip => ip, :ip => ip,
:folders => folders) :folders => folders,
:user => Process.uid)
@ui.info I18n.t("vagrant.hosts.arch.nfs_export.prepare") @ui.info I18n.t("vagrant.hosts.arch.nfs_export.prepare")
sleep 0.5 sleep 0.5

View File

@ -38,7 +38,8 @@ module VagrantPlugins
output = TemplateRenderer.render(@nfs_exports_template, output = TemplateRenderer.render(@nfs_exports_template,
:uuid => id, :uuid => id,
:ip => ip, :ip => ip,
:folders => folders) :folders => folders,
:user => Process.uid)
# The sleep ensures that the output is truly flushed before any `sudo` # The sleep ensures that the output is truly flushed before any `sudo`
# commands are issued. # commands are issued.
@ -65,9 +66,10 @@ module VagrantPlugins
@logger.info("Pruning invalid NFS entries...") @logger.info("Pruning invalid NFS entries...")
output = false output = false
user = Process.uid
File.read("/etc/exports").lines.each do |line| File.read("/etc/exports").lines.each do |line|
if id = line[/^# VAGRANT-BEGIN: (.+?)$/, 1] if id = line[/^# VAGRANT-BEGIN:( #{user})? ([A-Za-z0-9-]+?)$/, 2]
if valid_ids.include?(id) if valid_ids.include?(id)
@logger.debug("Valid ID: #{id}") @logger.debug("Valid ID: #{id}")
else else
@ -93,9 +95,11 @@ module VagrantPlugins
id = id.gsub("/", "\\/") id = id.gsub("/", "\\/")
id = id.gsub(".", "\\.") id = id.gsub(".", "\\.")
user = Process.uid
# Use sed to just strip out the block of code which was inserted # Use sed to just strip out the block of code which was inserted
# by Vagrant, and restart NFS. # by Vagrant, and restart NFS.
system("sudo sed -e '/^# VAGRANT-BEGIN: #{id}/,/^# VAGRANT-END: #{id}/ d' -ibak /etc/exports") system("sudo sed -e '/^# VAGRANT-BEGIN:\\( #{user}\\)\\? #{id}/,/^# VAGRANT-END:\\( #{user}\\)\\? #{id}/ d' -ibak /etc/exports")
end end
end end
end end

View File

@ -38,7 +38,8 @@ module VagrantPlugins
output = TemplateRenderer.render('nfs/exports_linux', output = TemplateRenderer.render('nfs/exports_linux',
:uuid => id, :uuid => id,
:ip => ip, :ip => ip,
:folders => folders) :folders => folders,
:user => Process.uid)
@ui.info I18n.t("vagrant.hosts.linux.nfs_export") @ui.info I18n.t("vagrant.hosts.linux.nfs_export")
sleep 0.5 sleep 0.5
@ -62,9 +63,10 @@ module VagrantPlugins
@logger.info("Pruning invalid NFS entries...") @logger.info("Pruning invalid NFS entries...")
output = false output = false
user = Process.uid
File.read("/etc/exports").lines.each do |line| File.read("/etc/exports").lines.each do |line|
if id = line[/^# VAGRANT-BEGIN: (.+?)$/, 1] if id = line[/^# VAGRANT-BEGIN:( #{user})? ([A-Za-z0-9-]+?)$/, 2]
if valid_ids.include?(id) if valid_ids.include?(id)
@logger.debug("Valid ID: #{id}") @logger.debug("Valid ID: #{id}")
else else
@ -86,9 +88,10 @@ module VagrantPlugins
def nfs_cleanup(id) def nfs_cleanup(id)
return if !File.exist?("/etc/exports") return if !File.exist?("/etc/exports")
user = Process.uid
# Use sed to just strip out the block of code which was inserted # Use sed to just strip out the block of code which was inserted
# by Vagrant # by Vagrant
system("sudo sed -e '/^# VAGRANT-BEGIN: #{id}/,/^# VAGRANT-END: #{id}/ d' -ibak /etc/exports") system("sudo sed -e '/^# VAGRANT-BEGIN:\\( #{user}\\)\\? #{id}/,/^# VAGRANT-END:\\( #{user}\\)\\? #{id}/ d' -ibak /etc/exports")
end end
end end
end end

View File

@ -1,5 +1,5 @@
# VAGRANT-BEGIN: <%= uuid %> # VAGRANT-BEGIN: <%= user %> <%= uuid %>
<% folders.each do |name, opts| %> <% folders.each do |name, opts| %>
"<%= opts[:hostpath] %>" <%= ip %><% if opts[:map_uid] -%> -mapall=<%= [opts[:map_uid],opts[:map_gid]].compact.join(":") %><% end -%> "<%= opts[:hostpath] %>" <%= ip %><% if opts[:map_uid] -%> -mapall=<%= [opts[:map_uid],opts[:map_gid]].compact.join(":") %><% end -%>
<% end %> <% end %>
# VAGRANT-END: <%= uuid %> # VAGRANT-END: <%= user %> <%= uuid %>

View File

@ -1,5 +1,5 @@
# VAGRANT-BEGIN: <%= uuid %> # VAGRANT-BEGIN: <%= user %> <%= uuid %>
<% folders.each do |name, opts| %> <% folders.each do |name, opts| %>
<%= opts[:hostpath] %> <%= ip %><% if opts[:map_uid] -%> -alldirs -mapall=<%= [opts[:map_uid],opts[:map_gid]].compact.join(":") %><% end -%> <%= opts[:hostpath] %> <%= ip %><% if opts[:map_uid] -%> -alldirs -mapall=<%= [opts[:map_uid],opts[:map_gid]].compact.join(":") %><% end -%>
<% end %> <% end %>
# VAGRANT-END: <%= uuid %> # VAGRANT-END: <%= user %> <%= uuid %>

View File

@ -1,5 +1,5 @@
# VAGRANT-BEGIN: <%= uuid %> # VAGRANT-BEGIN: <%= user %> <%= uuid %>
<% folders.each do |name, opts| %> <% folders.each do |name, opts| %>
"<%= opts[:hostpath] %>" <%= ip %>(rw,no_subtree_check,all_squash<% if opts[:map_uid] %>,anonuid=<%= opts[:map_uid] %><% end %><% if opts[:map_gid] %>,anongid=<%= opts[:map_gid] %><% end %>,fsid=<%= opts[:uuid] %>) "<%= opts[:hostpath] %>" <%= ip %>(rw,no_subtree_check,all_squash<% if opts[:map_uid] %>,anonuid=<%= opts[:map_uid] %><% end %><% if opts[:map_gid] %>,anongid=<%= opts[:map_gid] %><% end %>,fsid=<%= opts[:uuid] %>)
<% end %> <% end %>
# VAGRANT-END: <%= uuid %> # VAGRANT-END: <%= user %> <%= uuid %>