Class: Vagrant::Solaris10::Cap::MountVmwareSharedFolder

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-solaris10/cap/mount_vmware_shared_folder.rb

Class Method Summary collapse

Class Method Details

.mount_vmware_shared_folder(machine, name, guestpath, options) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/vagrant-solaris10/cap/mount_vmware_shared_folder.rb', line 8

def self.mount_vmware_shared_folder(machine, name, guestpath, options)
  owner = options[:owner]
  group = options[:group]
  machine.communicate.tap do |comm|
    if owner.is_a? Integer
      mount_uid = owner
    else
      mount_uid = "$(/usr/xpg4/bin/id -u #{owner})"
    end

    if group.is_a? Integer
      mount_gid = group
    else
      mount_gid = "$(/bin/getent group #{group}  | cut -d: -f3)"
    end

    # clear prior symlink
    if comm.test("test -L \"#{guestpath}\"", sudo: true)
      comm.sudo("rm -f \"#{guestpath}\"")
    end
  
    # clear prior directory if exists
    if comm.test("test -d \"#{guestpath}\"", sudo: true)
      comm.sudo("rm -Rf \"#{guestpath}\"")
    end
  
    # create guest parent folder if doesn't exist
    parent_guest_path = File.dirname(guestpath)
    if !comm.test("test -d \"#{parent_guest_path}\"", sudo: true)
      comm.sudo("mkdir -p \"#{parent_guest_path}\"")
    end

    # finally make the symlink
    comm.sudo("ln -s \"/hgfs/#{name}\" \"#{guestpath}\"")

    # Set permissions correctly on the link
    comm.sudo("chown -h #{mount_uid}:#{mount_gid} \"#{guestpath}\"")
  end
end