synced_folders/rsync: Install `rsync` on guest if needed
Add new `rsync_installed` and `rsync_install` guest capabilities to detect and install `rsync`. Also copy `rsync_pre` capability to all Unix guests.
This commit is contained in:
parent
8cc7d00314
commit
ee2ae94c25
|
@ -432,6 +432,10 @@ module Vagrant
|
|||
error_key(:rsync_not_found)
|
||||
end
|
||||
|
||||
class RSyncNotInstalledInGuest < VagrantError
|
||||
error_key(:rsync_not_installed_in_guest)
|
||||
end
|
||||
|
||||
class SCPPermissionDenied < VagrantError
|
||||
error_key(:scp_permission_denied)
|
||||
end
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
module VagrantPlugins
|
||||
module GuestDarwin
|
||||
module Cap
|
||||
class RSync
|
||||
def self.rsync_installed(machine)
|
||||
machine.communicate.test("which rsync")
|
||||
end
|
||||
|
||||
def self.rsync_pre(machine, folder_opts)
|
||||
username = machine.ssh_info[:username]
|
||||
|
||||
machine.communicate.tap do |comm|
|
||||
comm.sudo("mkdir -p '#{folder_opts[:guestpath]}'")
|
||||
comm.sudo("chown -R #{username} '#{folder_opts[:guestpath]}'")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -36,6 +36,16 @@ module VagrantPlugins
|
|||
Cap::MountVmwareSharedFolder
|
||||
end
|
||||
|
||||
guest_capability("darwin", "rsync_installed") do
|
||||
require_relative "cap/rsync"
|
||||
Cap::RSync
|
||||
end
|
||||
|
||||
guest_capability("darwin", "rsync_pre") do
|
||||
require_relative "cap/rsync"
|
||||
Cap::RSync
|
||||
end
|
||||
|
||||
guest_capability("darwin", "shell_expand_guest_path") do
|
||||
require_relative "cap/shell_expand_guest_path"
|
||||
Cap::ShellExpandGuestPath
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
module VagrantPlugins
|
||||
module GuestDebian
|
||||
module Cap
|
||||
class RSync
|
||||
def self.rsync_install(machine)
|
||||
machine.communicate.tap do |comm|
|
||||
comm.sudo("apt-get -y update")
|
||||
comm.sudo("apt-get -y install rsync")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -25,6 +25,11 @@ module VagrantPlugins
|
|||
require_relative "cap/nfs_client"
|
||||
Cap::NFSClient
|
||||
end
|
||||
|
||||
guest_capability("debian", "rsync_install") do
|
||||
require_relative "cap/rsync"
|
||||
Cap::RSync
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
module VagrantPlugins
|
||||
module GuestFreeBSD
|
||||
module Cap
|
||||
class RSync
|
||||
def self.rsync_install(machine)
|
||||
machine.communicate.tap do |comm|
|
||||
comm.sudo("pkg_add -r rsync")
|
||||
end
|
||||
end
|
||||
|
||||
def self.rsync_installed(machine)
|
||||
machine.communicate.test("which rsync")
|
||||
end
|
||||
|
||||
def self.rsync_pre(machine, folder_opts)
|
||||
username = machine.ssh_info[:username]
|
||||
|
||||
machine.communicate.tap do |comm|
|
||||
comm.sudo("mkdir -p '#{folder_opts[:guestpath]}'", shell: "sh")
|
||||
comm.sudo("chown -R #{username} '#{folder_opts[:guestpath]}'", shell: "sh")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -30,6 +30,21 @@ module VagrantPlugins
|
|||
require_relative "cap/mount_nfs_folder"
|
||||
Cap::MountNFSFolder
|
||||
end
|
||||
|
||||
guest_capability("freebsd", "rsync_install") do
|
||||
require_relative "cap/rsync"
|
||||
Cap::RSync
|
||||
end
|
||||
|
||||
guest_capability("freebsd", "rsync_installed") do
|
||||
require_relative "cap/rsync"
|
||||
Cap::RSync
|
||||
end
|
||||
|
||||
guest_capability("freebsd", "rsync_pre") do
|
||||
require_relative "cap/rsync"
|
||||
Cap::RSync
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,6 +2,10 @@ module VagrantPlugins
|
|||
module GuestLinux
|
||||
module Cap
|
||||
class RSync
|
||||
def self.rsync_installed(machine)
|
||||
machine.communicate.test("which rsync")
|
||||
end
|
||||
|
||||
def self.rsync_pre(machine, folder_opts)
|
||||
username = machine.ssh_info[:username]
|
||||
|
||||
|
|
|
@ -46,7 +46,11 @@ module VagrantPlugins
|
|||
Cap::ReadIPAddress
|
||||
end
|
||||
|
||||
# RSync synced folders
|
||||
guest_capability("linux", "rsync_installed") do
|
||||
require_relative "cap/rsync"
|
||||
Cap::RSync
|
||||
end
|
||||
|
||||
guest_capability("linux", "rsync_pre") do
|
||||
require_relative "cap/rsync"
|
||||
Cap::RSync
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
module VagrantPlugins
|
||||
module GuestNetBSD
|
||||
module Cap
|
||||
class RSync
|
||||
def self.rsync_installed(machine)
|
||||
machine.communicate.test("which rsync")
|
||||
end
|
||||
|
||||
def self.rsync_install(machine)
|
||||
machine.communicate.sudo(
|
||||
'export PKG_PATH="http://ftp.NetBSD.org/pub/pkgsrc/packages/NetBSD/' \
|
||||
'`uname -m`/`uname -r | cut -d. -f1-2`/All"; ' \
|
||||
'pkg_add rsync')
|
||||
end
|
||||
|
||||
def self.rsync_pre(machine, folder_opts)
|
||||
username = machine.ssh_info[:username]
|
||||
|
||||
machine.communicate.tap do |comm|
|
||||
comm.sudo("mkdir -p '#{folder_opts[:guestpath]}'")
|
||||
comm.sudo("chown -R #{username} '#{folder_opts[:guestpath]}'")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -30,6 +30,21 @@ module VagrantPlugins
|
|||
require_relative "cap/mount_nfs_folder"
|
||||
Cap::MountNFSFolder
|
||||
end
|
||||
|
||||
guest_capability("netbsd", "rsync_install") do
|
||||
require_relative "cap/rsync"
|
||||
Cap::RSync
|
||||
end
|
||||
|
||||
guest_capability("netbsd", "rsync_installed") do
|
||||
require_relative "cap/rsync"
|
||||
Cap::RSync
|
||||
end
|
||||
|
||||
guest_capability("netbsd", "rsync_pre") do
|
||||
require_relative "cap/rsync"
|
||||
Cap::RSync
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
module VagrantPlugins
|
||||
module GuestOpenBSD
|
||||
module Cap
|
||||
class RSync
|
||||
def self.rsync_install(machine)
|
||||
machine.communicate.tap do |comm|
|
||||
comm.sudo("pkg_add -I rsync--")
|
||||
end
|
||||
end
|
||||
|
||||
def self.rsync_installed(machine)
|
||||
machine.communicate.test("which rsync")
|
||||
end
|
||||
|
||||
def self.rsync_pre(machine, folder_opts)
|
||||
username = machine.ssh_info[:username]
|
||||
|
||||
machine.communicate.tap do |comm|
|
||||
comm.sudo("mkdir -p '#{folder_opts[:guestpath]}'")
|
||||
comm.sudo("chown -R #{username} '#{folder_opts[:guestpath]}'")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -30,6 +30,21 @@ module VagrantPlugins
|
|||
require_relative "cap/mount_nfs_folder"
|
||||
Cap::MountNFSFolder
|
||||
end
|
||||
|
||||
guest_capability("openbsd", "rsync_install") do
|
||||
require_relative "cap/rsync"
|
||||
Cap::RSync
|
||||
end
|
||||
|
||||
guest_capability("openbsd", "rsync_installed") do
|
||||
require_relative "cap/rsync"
|
||||
Cap::RSync
|
||||
end
|
||||
|
||||
guest_capability("openbsd", "rsync_pre") do
|
||||
require_relative "cap/rsync"
|
||||
Cap::RSync
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
module VagrantPlugins
|
||||
module GuestRedHat
|
||||
module Cap
|
||||
class RSync
|
||||
def self.rsync_install(machine)
|
||||
machine.communicate.tap do |comm|
|
||||
comm.sudo("yum -y install rsync")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -30,6 +30,11 @@ module VagrantPlugins
|
|||
require_relative "cap/nfs_client"
|
||||
Cap::NFSClient
|
||||
end
|
||||
|
||||
guest_capability("redhat", "rsync_install") do
|
||||
require_relative "cap/rsync"
|
||||
Cap::RSync
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
module VagrantPlugins
|
||||
module GuestSolaris
|
||||
module Cap
|
||||
class RSync
|
||||
def self.rsync_installed(machine)
|
||||
machine.communicate.test("which rsync")
|
||||
end
|
||||
|
||||
def self.rsync_pre(machine, folder_opts)
|
||||
username = machine.ssh_info[:username]
|
||||
|
||||
machine.communicate.tap do |comm|
|
||||
comm.sudo("mkdir -p '#{folder_opts[:guestpath]}'")
|
||||
comm.sudo("chown -R #{username} '#{folder_opts[:guestpath]}'")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -35,6 +35,16 @@ module VagrantPlugins
|
|||
require_relative "cap/mount_virtualbox_shared_folder"
|
||||
Cap::MountVirtualBoxSharedFolder
|
||||
end
|
||||
|
||||
guest_capability("solaris", "rsync_installed") do
|
||||
require_relative "cap/rsync"
|
||||
Cap::RSync
|
||||
end
|
||||
|
||||
guest_capability("solaris", "rsync_pre") do
|
||||
require_relative "cap/rsync"
|
||||
Cap::RSync
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
module VagrantPlugins
|
||||
module GuestSolaris11
|
||||
module Cap
|
||||
class RSync
|
||||
def self.rsync_installed(machine)
|
||||
machine.communicate.test("which rsync")
|
||||
end
|
||||
|
||||
def self.rsync_pre(machine, folder_opts)
|
||||
username = machine.ssh_info[:username]
|
||||
|
||||
machine.communicate.tap do |comm|
|
||||
comm.sudo("mkdir -p '#{folder_opts[:guestpath]}'")
|
||||
comm.sudo("chown -R #{username} '#{folder_opts[:guestpath]}'")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -39,6 +39,16 @@ module VagrantPlugins
|
|||
require_relative "cap/mount_virtualbox_shared_folder"
|
||||
Cap::MountVirtualBoxSharedFolder
|
||||
end
|
||||
|
||||
guest_capability("solaris11", "rsync_installed") do
|
||||
require_relative "cap/rsync"
|
||||
Cap::RSync
|
||||
end
|
||||
|
||||
guest_capability("solaris11", "rsync_pre") do
|
||||
require_relative "cap/rsync"
|
||||
Cap::RSync
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -28,6 +28,16 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
def enable(machine, folders, opts)
|
||||
if machine.guest.capability?(:rsync_installed)
|
||||
installed = machine.guest.capability(:rsync_installed)
|
||||
if !installed
|
||||
can_install = machine.guest.capability?(:rsync_install)
|
||||
raise Vagrant::Errors::RSyncNotInstalledInGuest if !can_install
|
||||
machine.ui.info I18n.t("vagrant.rsync_installing")
|
||||
machine.guest.capability(:rsync_install)
|
||||
end
|
||||
end
|
||||
|
||||
ssh_info = machine.ssh_info
|
||||
|
||||
if ssh_info[:private_key_path].empty? && ssh_info[:password]
|
||||
|
|
|
@ -99,6 +99,7 @@ en:
|
|||
rsync_folder: |-
|
||||
Rsyncing folder: %{hostpath} => %{guestpath}
|
||||
rsync_folder_excludes: " - Exclude: %{excludes}"
|
||||
rsync_installing: "Installing rsync to the VM..."
|
||||
rsync_ssh_password: |-
|
||||
The machine you're rsyncing folders to is configured to use
|
||||
password-based authentication. Vagrant can't script rsync to automatically
|
||||
|
@ -574,6 +575,11 @@ en:
|
|||
rsync_not_found: |-
|
||||
"rsync" could not be found on your PATH. Make sure that rsync
|
||||
is properly installed on your system and available on the PATH.
|
||||
rsync_not_installed_in_guest: |-
|
||||
"rsync" was not detected as installed in your guest machine. This
|
||||
is required for rsync synced folders to work. In addition to this,
|
||||
Vagrant doesn't know how to automatically install rsync for your
|
||||
machine, so you must do this manually.
|
||||
scp_permission_denied: |-
|
||||
Failed to upload a file to the guest VM via SCP due to a permissions
|
||||
error. This is normally because the user running Vagrant doesn't have
|
||||
|
|
|
@ -48,6 +48,7 @@ describe VagrantPlugins::SyncedFolderRSync::SyncedFolder do
|
|||
|
||||
before do
|
||||
machine.stub(ssh_info: ssh_info)
|
||||
guest.stub(:capability?).with(:rsync_installed)
|
||||
end
|
||||
|
||||
it "rsyncs each folder" do
|
||||
|
@ -64,5 +65,33 @@ describe VagrantPlugins::SyncedFolderRSync::SyncedFolder do
|
|||
|
||||
subject.enable(machine, folders, {})
|
||||
end
|
||||
|
||||
it "installs rsync if capable" do
|
||||
folders = [ [:foo, {}] ]
|
||||
|
||||
helper_class.stub(:rsync_single)
|
||||
|
||||
guest.stub(:capability?).with(:rsync_installed).and_return(true)
|
||||
guest.stub(:capability?).with(:rsync_install).and_return(true)
|
||||
|
||||
expect(guest).to receive(:capability).with(:rsync_installed).and_return(false)
|
||||
expect(guest).to receive(:capability).with(:rsync_install)
|
||||
|
||||
subject.enable(machine, folders, {})
|
||||
end
|
||||
|
||||
it "errors if rsync not installable" do
|
||||
folders = [ [:foo, {}] ]
|
||||
|
||||
helper_class.stub(:rsync_single)
|
||||
|
||||
guest.stub(:capability?).with(:rsync_installed).and_return(true)
|
||||
guest.stub(:capability?).with(:rsync_install).and_return(false)
|
||||
|
||||
expect(guest).to receive(:capability).with(:rsync_installed).and_return(false)
|
||||
|
||||
expect { subject.enable(machine, folders, {}) }.
|
||||
to raise_error(Vagrant::Errors::RSyncNotInstalledInGuest)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue