Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vagrant_root = File.dirname(__FILE__) # Vagrantfile location
- $vconfig['synced_folders']['smb_username'] = "vagrant"
- $vconfig['synced_folders']['smb_password'] = "vagrant"
- if is_windows
- vagrant_mount_point = `cygpath #{vagrant_root}`.strip! # Remove trailing \n
- vagrant_mount_point = vagrant_mount_point.gsub(/\/cygdrive/, '') # Remove '/cygdrive' prefix
- end
- vagrant_folder_name = File.basename(vagrant_root) # Folder name only. Used as the SMB share name.
- # Run command in an elevated shell.
- def windows_elevated_shell(args)
- command = 'cmd.exe'
- args = "/C #{args} || timeout 10"
- shell = WIN32OLE.new('Shell.Application')
- shell.ShellExecute(command, args, nil, 'runas')
- end
- # Method to create the user and SMB network share on Windows.
- def windows_net_share(share_name, path)
- # Add the vagrant user if it does not exist.
- smb_username = $vconfig['synced_folders']['smb_username']
- smb_password = $vconfig['synced_folders']['smb_password']
- command_user = "net user #{smb_username} || ( net user #{smb_username} #{smb_password} /add && WMIC USERACCOUNT WHERE \"Name='vagrant'\" SET PasswordExpires=FALSE )"
- @ui.info "Adding vagrant user"
- windows_elevated_shell command_user
- # Add the SMB share if it does not exist.
- command_share = "net share #{share_name} || net share #{share_name}=#{path} /grant:#{smb_username},FULL"
- @ui.info "Adding vagrant SMB share"
- windows_elevated_shell command_share
- # Set folder permissions.
- command_permissions = "icacls #{path} /grant #{smb_username}:(OI)(CI)M"
- @ui.info "Setting folder permissions"
- windows_elevated_shell command_permissions
- end
- # Method to remove the user and SMB network share on Windows.
- def windows_net_share_remove(share_name)
- smb_username = $vconfig['synced_folders']['smb_username']
- command_user = "net user #{smb_username} /delete || echo 'User #{smb_username} does not exist' && timeout 10"
- windows_elevated_shell command_user
- command_share = "net share #{share_name} /delete || echo 'Share #{share_name} does not exist' && timeout 10"
- windows_elevated_shell command_share
- end
- config.vm.synced_folder vagrant_root, vagrant_mount_point,
- type: "smb",
- smb_username: synced_folders['smb_username'],
- smb_password: synced_folders['smb_password']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement