Sha256: 96afbaa744c77421a13b08796f7905fa4d091d61aa5fa67c2c57ae12438cf26a

Contents?: true

Size: 1.24 KB

Versions: 2

Compression:

Stored size: 1.24 KB

Contents

require_relative '../errors'

module VagrantPlugins
  module Rsync
    module Cap
      class EnsureRsync

        def self.ensure_rsync(machine, env)
          return unless machine.communicate.ready?

          if rsync_installed?(machine)
            env.ui.info I18n.t('vagrant_rsync.rsync_installed')
          else
            env.ui.info I18n.t('vagrant_rsync.installing_rsync')
            install_rsync!(machine)
          end
        end

        def self.rsync_installed?(machine)
          machine.communicate.execute("rsync --version") rescue false
        end

        def self.install_rsync!(machine)
          machine.communicate.tap do |comm|
            case machine.guest.name
            when :debian, :ubuntu
              comm.sudo "apt-get update"
              comm.sudo "apt-get install rsync -y"
            when :fedora, :centos, :redhat
              comm.sudo "yum install rsync -y"
            when :suse
              comm.sudo "yast2 -i rsync"
            when :gentoo
              comm.sudo "emerge rsync"
            when :arch
              comm.sudo "pacman -s rsync"
            else
              raise Errors::RsyncNotAvailableError, guest: machine.guest.name
            end
          end
        end

      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vagrant-rsync-0.2.5 lib/vagrant-rsync/cap/ensure_rsync.rb
vagrant-rsync-0.2.4 lib/vagrant-rsync/cap/ensure_rsync.rb