Can now specify the UID/GID of the shared folders from the Vagrantfile
This commit is contained in:
parent
51116438a7
commit
5bdabbc8c8
|
@ -18,6 +18,8 @@ Vagrant::Config.run do |config|
|
||||||
config.vm.forward_port("ssh", 22, 2222)
|
config.vm.forward_port("ssh", 22, 2222)
|
||||||
config.vm.disk_image_format = 'VMDK'
|
config.vm.disk_image_format = 'VMDK'
|
||||||
config.vm.provisioner = nil
|
config.vm.provisioner = nil
|
||||||
|
config.vm.shared_folder_uid = nil
|
||||||
|
config.vm.shared_folder_gid = nil
|
||||||
|
|
||||||
config.package.name = 'vagrant'
|
config.package.name = 'vagrant'
|
||||||
config.package.extension = '.box'
|
config.package.extension = '.box'
|
||||||
|
|
|
@ -54,10 +54,16 @@ module Vagrant
|
||||||
# Note: This method seems pretty OS-specific and could also use
|
# Note: This method seems pretty OS-specific and could also use
|
||||||
# some configuration options. For now its duct tape and "works"
|
# some configuration options. For now its duct tape and "works"
|
||||||
# but should be looked at in the future.
|
# but should be looked at in the future.
|
||||||
attempts = 0
|
|
||||||
|
|
||||||
|
# Determine the permission string to attach to the mount command
|
||||||
|
perms = []
|
||||||
|
perms << "uid=#{Vagrant.config.vm.shared_folder_uid}" if Vagrant.config.vm.shared_folder_uid
|
||||||
|
perms << "gid=#{Vagrant.config.vm.shared_folder_gid}" if Vagrant.config.vm.shared_folder_gid
|
||||||
|
perms = " -o #{perms.join(",")}" if !perms.empty?
|
||||||
|
|
||||||
|
attempts = 0
|
||||||
while true
|
while true
|
||||||
result = ssh.exec!("sudo mount -t vboxsf #{name} #{guestpath}") do |ch, type, data|
|
result = ssh.exec!("sudo mount -t vboxsf#{perms} #{name} #{guestpath}") do |ch, type, data|
|
||||||
# net/ssh returns the value in ch[:result] (based on looking at source)
|
# net/ssh returns the value in ch[:result] (based on looking at source)
|
||||||
ch[:result] = !!(type == :stderr && data =~ /No such device/i)
|
ch[:result] = !!(type == :stderr && data =~ /No such device/i)
|
||||||
end
|
end
|
||||||
|
|
|
@ -81,6 +81,8 @@ module Vagrant
|
||||||
attr_accessor :hd_location
|
attr_accessor :hd_location
|
||||||
attr_accessor :disk_image_format
|
attr_accessor :disk_image_format
|
||||||
attr_accessor :provisioner
|
attr_accessor :provisioner
|
||||||
|
attr_accessor :shared_folder_uid
|
||||||
|
attr_accessor :shared_folder_gid
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@forwarded_ports = {}
|
@forwarded_ports = {}
|
||||||
|
|
|
@ -23,7 +23,7 @@ class Test::Unit::TestCase
|
||||||
Vagrant::Config.reset!
|
Vagrant::Config.reset!
|
||||||
|
|
||||||
Vagrant::Config.run do |config|
|
Vagrant::Config.run do |config|
|
||||||
config.vagrant.dotfile_name = ".hobo"
|
config.vagrant.dotfile_name = ".vagrant"
|
||||||
|
|
||||||
config.ssh.username = "foo"
|
config.ssh.username = "foo"
|
||||||
config.ssh.password = "bar"
|
config.ssh.password = "bar"
|
||||||
|
@ -36,9 +36,11 @@ class Test::Unit::TestCase
|
||||||
config.vm.box = "foo"
|
config.vm.box = "foo"
|
||||||
config.vm.box_ovf = "box.ovf"
|
config.vm.box_ovf = "box.ovf"
|
||||||
config.vm.base_mac = "42"
|
config.vm.base_mac = "42"
|
||||||
config.vm.project_directory = "/hobo"
|
config.vm.project_directory = "/vagrant"
|
||||||
config.vm.disk_image_format = 'VMDK'
|
config.vm.disk_image_format = 'VMDK'
|
||||||
config.vm.forward_port("ssh", 22, 2222)
|
config.vm.forward_port("ssh", 22, 2222)
|
||||||
|
config.vm.shared_folder_uid = nil
|
||||||
|
config.vm.shared_folder_gid = nil
|
||||||
|
|
||||||
config.package.name = 'vagrant'
|
config.package.name = 'vagrant'
|
||||||
config.package.extension = '.box'
|
config.package.extension = '.box'
|
||||||
|
@ -48,9 +50,9 @@ class Test::Unit::TestCase
|
||||||
config.chef.validation_key_path = "validation.pem"
|
config.chef.validation_key_path = "validation.pem"
|
||||||
config.chef.client_key_path = "/zoo/foo/bar.pem"
|
config.chef.client_key_path = "/zoo/foo/bar.pem"
|
||||||
config.chef.cookbooks_path = "cookbooks"
|
config.chef.cookbooks_path = "cookbooks"
|
||||||
config.chef.provisioning_path = "/tmp/hobo-chef"
|
config.chef.provisioning_path = "/tmp/vagrant-chef"
|
||||||
config.chef.json = {
|
config.chef.json = {
|
||||||
:recipes => ["hobo_main"]
|
:recipes => ["vagrant_main"]
|
||||||
}
|
}
|
||||||
|
|
||||||
config.vagrant.home = '~/.home'
|
config.vagrant.home = '~/.home'
|
||||||
|
|
|
@ -154,5 +154,37 @@ class SharedFoldersActionTest < Test::Unit::TestCase
|
||||||
mount_folder
|
mount_folder
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "add uid to mount if set" do
|
||||||
|
uid = "foo"
|
||||||
|
mock_config do |config|
|
||||||
|
config.vm.shared_folder_uid = uid
|
||||||
|
end
|
||||||
|
|
||||||
|
@ssh.expects(:exec!).with("sudo mount -t vboxsf -o uid=#{uid} #{@name} #{@guestpath}").returns(@success_return)
|
||||||
|
mount_folder
|
||||||
|
end
|
||||||
|
|
||||||
|
should "add gid to mount if set" do
|
||||||
|
gid = "foo"
|
||||||
|
mock_config do |config|
|
||||||
|
config.vm.shared_folder_gid = gid
|
||||||
|
end
|
||||||
|
|
||||||
|
@ssh.expects(:exec!).with("sudo mount -t vboxsf -o gid=#{gid} #{@name} #{@guestpath}").returns(@success_return)
|
||||||
|
mount_folder
|
||||||
|
end
|
||||||
|
|
||||||
|
should "add uid AND gid to mount if set" do
|
||||||
|
uid = "foo"
|
||||||
|
gid = "bar"
|
||||||
|
mock_config do |config|
|
||||||
|
config.vm.shared_folder_uid = uid
|
||||||
|
config.vm.shared_folder_gid = gid
|
||||||
|
end
|
||||||
|
|
||||||
|
@ssh.expects(:exec!).with("sudo mount -t vboxsf -o uid=#{uid},gid=#{gid} #{@name} #{@guestpath}").returns(@success_return)
|
||||||
|
mount_folder
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue