vagrant-rsync-pull 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ # OS-specific
2
+ .DS_Store
3
+
4
+ # Bundler/Rubygems
5
+ *.gem
6
+ .bundle
7
+ pkg/*
8
+ tags
9
+ Gemfile.lock
10
+
11
+ # Vagrant
12
+ .vagrant
13
+ Vagrantfile
14
+ !example_box/Vagrantfile
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # 0.0.1 (1 July 2014)
2
+
3
+ * Initial release.
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ group :development do
4
+ gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git"
5
+ end
6
+
7
+ group :plugins do
8
+ gemspec
9
+ end
data/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2013 Mitchell Hashimoto
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # Vagrant RSync-Pull Plugin
2
+
3
+ This is a [Vagrant](http://www.vagrantup.com) 1.5+ plugin that works the same as the built-in RSync plugin,
4
+ except files are sync'd from the guest to the host.
5
+
6
+ **NOTE:** This plugin requires Vagrant 1.5+
7
+
8
+ ## Usage
9
+
10
+ 1. Install using standard Vagrant 1.1+ plugin installation methods.
11
+ ```
12
+ $ vagrant plugin install vagrant-rsync-pull
13
+ ```
14
+ 2. After installing, edit your Vagrantfile and add a configuration directive similar to the below:
15
+ ```
16
+ Vagrant.configure("2") do |config|
17
+ config.vm.box = "dummy"
18
+ config.vm.synced_folder "/home/myuser/myproject", "/opt/myproject", type: "rsync_pull"
19
+ end
20
+ ```
21
+ 3. Start up your starting your vagrant box as normal (eg: `vagrant up`)
22
+
23
+ ## Start syncing folders
24
+
25
+ Folders will be pulled from the guest on `vagrant up`.
26
+
27
+ Run `vagrant rsync-pull` to manually sync files from the guest to your local host.
@@ -0,0 +1,12 @@
1
+ require "pathname"
2
+
3
+ require "vagrant-rsync-pull/plugin"
4
+ require "vagrant-rsync-pull/errors"
5
+
6
+ module VagrantPlugins
7
+ module SyncedFolderRSyncPull
8
+ def self.source_root
9
+ @source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,46 @@
1
+ require "optparse"
2
+ require "log4r"
3
+ require "vagrant"
4
+ require "vagrant/action/builtin/mixin_synced_folders"
5
+
6
+ require_relative "helper"
7
+
8
+ module VagrantPlugins
9
+ module SyncedFolderRSyncPull
10
+ class Command < Vagrant.plugin("2", :command)
11
+ include Vagrant::Action::Builtin::MixinSyncedFolders
12
+
13
+ def self.synopsis
14
+ "rsyncs guest files to host"
15
+ end
16
+
17
+ def execute
18
+ opts = OptionParser.new do |o|
19
+ o.banner = "Usage: vagrant rsync-pull [vm-name]"
20
+ o.separator ""
21
+ end
22
+
23
+ argv = parse_options(opts)
24
+ return if !argv
25
+
26
+ error = false
27
+ with_target_vms do |machine|
28
+ if !machine.communicate.ready?
29
+ machine.ui.error(I18n.t("vagrant.rsync_communicator_not_ready"))
30
+ error = true
31
+ next
32
+ end
33
+
34
+ folders = synced_folders(machine)[:rsync_pull]
35
+ next if !folders || folders.empty?
36
+
37
+ folders.each do |id, folder_opts|
38
+ RsyncPullHelper.rsync_single(machine, folder_opts)
39
+ end
40
+ end
41
+
42
+ return error ? 1 : 0
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,9 @@
1
+ require "vagrant"
2
+
3
+ module Vagrant
4
+ module Errors
5
+ class SyncedFolderRSyncPullError < VagrantError
6
+ error_key(:rsync_pull_error, "vagrant_rsync_pull.errors")
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,105 @@
1
+ require "vagrant/util/platform"
2
+ require "vagrant/util/subprocess"
3
+
4
+ module VagrantPlugins
5
+ module SyncedFolderRSyncPull
6
+ class RsyncPullHelper
7
+ def self.rsync_single(machine, opts)
8
+ ssh_info = machine.ssh_info
9
+ guestpath = opts[:guestpath]
10
+ hostpath = opts[:hostpath]
11
+ hostpath = File.expand_path(hostpath, machine.env.root_path)
12
+ hostpath = Vagrant::Util::Platform.fs_real_path(hostpath).to_s
13
+
14
+ if Vagrant::Util::Platform.windows?
15
+ hostpath = Vagrant::Util::Platform.cygwin_path(hostpath)
16
+ end
17
+
18
+ if !guestpath.end_with?("/")
19
+ guestpath += "/"
20
+ end
21
+
22
+ if !hostpath.end_with?("/")
23
+ hostpath += "/"
24
+ end
25
+
26
+ opts[:owner] ||= ssh_info[:username]
27
+ opts[:group] ||= ssh_info[:username]
28
+
29
+ username = ssh_info[:username]
30
+ host = ssh_info[:host]
31
+ proxy_command = ""
32
+ if ssh_info[:proxy_command]
33
+ proxy_command = "-o ProxyCommand='#{ssh_info[:proxy_command]}' "
34
+ end
35
+
36
+ rsh = [
37
+ "ssh -p #{ssh_info[:port]} " +
38
+ proxy_command +
39
+ "-o StrictHostKeyChecking=no " +
40
+ "-o UserKnownHostsFile=/dev/null",
41
+ ssh_info[:private_key_path].map { |p| "-i '#{p}'" },
42
+ ].flatten.join(" ")
43
+
44
+ excludes = ['.vagrant/', 'Vagrantfile']
45
+ excludes += Array(opts[:exclude]).map(&:to_s) if opts[:exclude]
46
+ excludes.uniq!
47
+
48
+ args = nil
49
+ args = Array(opts[:args]).dup if opts[:args]
50
+ args ||= ["--verbose", "--archive", "--delete", "-z", "--copy-links"]
51
+
52
+ if Vagrant::Util::Platform.windows? && !args.any? { |arg| arg.start_with?("--chmod=") }
53
+ args << "--chmod=ugo=rwX"
54
+
55
+ args << "--no-perms" if args.include?("--archive") || args.include?("-a")
56
+ end
57
+
58
+ args << "--no-owner" unless args.include?("--owner") || args.include?("-o")
59
+ args << "--no-group" unless args.include?("--group") || args.include?("-g")
60
+
61
+ if machine.guest.capability?(:rsync_command)
62
+ args << "--rsync-path"<< machine.guest.capability(:rsync_command)
63
+ end
64
+
65
+ command = [
66
+ "rsync",
67
+ args,
68
+ "-e", rsh,
69
+ excludes.map { |e| ["--exclude", e] },
70
+ "#{username}@#{host}:#{guestpath}",
71
+ hostpath,
72
+ ].flatten
73
+
74
+ command_opts = {}
75
+ command_opts[:workdir] = machine.env.root_path.to_s
76
+
77
+ machine.ui.info(I18n.t(
78
+ "vagrant.rsync_folder", guestpath: guestpath, hostpath: hostpath))
79
+ if excludes.length > 1
80
+ machine.ui.info(I18n.t(
81
+ "vagrant.rsync_folder_excludes", excludes: excludes.inspect))
82
+ end
83
+
84
+ if machine.guest.capability?(:rsync_pre)
85
+ machine.guest.capability(:rsync_pre, opts)
86
+ end
87
+
88
+ command = command + [command_opts]
89
+
90
+ r = Vagrant::Util::Subprocess.execute(*command)
91
+ if r.exit_code != 0
92
+ raise Vagrant::Errors::SyncedFolderRSyncPullError,
93
+ command: command.inspect,
94
+ guestpath: guestpath,
95
+ hostpath: hostpath,
96
+ stderr: r.stderr
97
+ end
98
+
99
+ if machine.guest.capability?(:rsync_post)
100
+ machine.guest.capability(:rsync_post, opts)
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,55 @@
1
+ begin
2
+ require "vagrant"
3
+ rescue LoadError
4
+ raise "The vagrant-rsync-pull plugin must be run within Vagrant."
5
+ end
6
+
7
+ if Vagrant::VERSION < "1.5"
8
+ raise "The vagrant-rsync-pull plugin is only compatible with Vagrant 1.5+"
9
+ end
10
+
11
+ module VagrantPlugins
12
+ module SyncedFolderRSyncPull
13
+ class Plugin < Vagrant.plugin("2")
14
+ name "SyncedFolderRSyncPull"
15
+ description "Vagrant plugin to rsync guest files to host"
16
+
17
+ command "rsync-pull" do
18
+ setup_logging
19
+ setup_i18n
20
+ require_relative "command"
21
+ Command
22
+ end
23
+
24
+ synced_folder("rsync_pull", 5) do
25
+ require_relative "synced_folder"
26
+ SyncedFolder
27
+ end
28
+
29
+ def self.setup_i18n
30
+ I18n.load_path << File.expand_path("locales/en.yml", SyncedFolderRSyncPull.source_root)
31
+ I18n.reload!
32
+ end
33
+
34
+ def self.setup_logging
35
+ require "log4r"
36
+
37
+ level = nil
38
+ begin
39
+ level = Log4r.const_get(ENV["VAGRANT_LOG"].upcase)
40
+ rescue NameError
41
+ level = nil
42
+ end
43
+
44
+ level = nil if !level.is_a?(Integer)
45
+
46
+ if level
47
+ logger = Log4r::Logger.new("vagrant_rsync_pull")
48
+ logger.outputters = Log4r::Outputter.stderr
49
+ logger.level = level
50
+ logger = nil
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,52 @@
1
+ require "log4r"
2
+
3
+ require "vagrant/util/subprocess"
4
+ require "vagrant/util/which"
5
+
6
+ require_relative "helper"
7
+
8
+ module VagrantPlugins
9
+ module SyncedFolderRSyncPull
10
+ class SyncedFolder < Vagrant.plugin("2", :synced_folder)
11
+ include Vagrant::Util
12
+
13
+ def initialize(*args)
14
+ super
15
+
16
+ @logger = Log4r::Logger.new("vagrant_rsync_pull")
17
+ end
18
+
19
+ def usable?(machine, raise_error=false)
20
+ rsync_path = Which.which("rsync")
21
+ return true if rsync_path
22
+ return false if !raise_error
23
+ raise Vagrant::Errors::RSyncNotFound
24
+ end
25
+
26
+ def prepare(machine, folders, opts)
27
+ end
28
+
29
+ def enable(machine, folders, opts)
30
+ if machine.guest.capability?(:rsync_installed)
31
+ installed = machine.guest.capability(:rsync_installed)
32
+ if !installed
33
+ can_install = machine.guest.capability?(:rsync_install)
34
+ raise Vagrant::Errors::RSyncNotInstalledInGuest if !can_install
35
+ machine.ui.info I18n.t("vagrant.rsync_installing")
36
+ machine.guest.capability(:rsync_install)
37
+ end
38
+ end
39
+
40
+ ssh_info = machine.ssh_info
41
+
42
+ if ssh_info[:private_key_path].empty? && ssh_info[:password]
43
+ machine.ui.warn(I18n.t("vagrant.rsync_ssh_password"))
44
+ end
45
+
46
+ folders.each do |id, folder_opts|
47
+ RsyncPullHelper.rsync_single(machine, folder_opts)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module SyncedFolderRSyncPull
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,12 @@
1
+ en:
2
+ vagrant_rsync_pull:
3
+ errors:
4
+ rsync_pull_error: |-
5
+ There was an error when attemping to sync folders using rsync.
6
+ Please inspect the error message below for more info.
7
+
8
+ Host path: %{hostpath}
9
+ Guest path: %{guestpath}
10
+ Error: %{stderr}
11
+ Full command causing error:
12
+ %{command}
@@ -0,0 +1,50 @@
1
+ $:.unshift File.expand_path("../lib", __FILE__)
2
+ require "vagrant-rsync-pull/version"
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "vagrant-rsync-pull"
6
+ s.version = VagrantPlugins::SyncedFolderRSyncPull::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = "Ed Toon"
9
+ s.email = "edtoon@edtoon"
10
+ s.homepage = "https://github.com/edtoon/vagrant-rsync-pull"
11
+ s.summary = "Vagrant plugin to rsync guest files to host"
12
+ s.description = "Vagrant plugin to rsync guest files to host"
13
+
14
+ s.required_rubygems_version = ">= 1.3.6"
15
+
16
+ # The following block of code determines the files that should be included
17
+ # in the gem. It does this by reading all the files in the directory where
18
+ # this gemspec is, and parsing out the ignored files from the gitignore.
19
+ # Note that the entire gitignore(5) syntax is not supported, specifically
20
+ # the "!" syntax, but it should mostly work correctly.
21
+ root_path = File.dirname(__FILE__)
22
+ all_files = Dir.chdir(root_path) { Dir.glob("**/{*,.*}") }
23
+ all_files.reject! { |file| [".", ".."].include?(File.basename(file)) }
24
+ gitignore_path = File.join(root_path, ".gitignore")
25
+ gitignore = File.readlines(gitignore_path)
26
+ gitignore.map! { |line| line.chomp.strip }
27
+ gitignore.reject! { |line| line.empty? || line =~ /^(#|!)/ }
28
+
29
+ unignored_files = all_files.reject do |file|
30
+ # Ignore any directories, the gemspec only cares about files
31
+ next true if File.directory?(file)
32
+
33
+ # Ignore any paths that match anything in the gitignore. We do
34
+ # two tests here:
35
+ #
36
+ # - First, test to see if the entire path matches the gitignore.
37
+ # - Second, match if the basename does, this makes it so that things
38
+ # like '.DS_Store' will match sub-directories too (same behavior
39
+ # as git).
40
+ #
41
+ gitignore.any? do |ignore|
42
+ File.fnmatch(ignore, file, File::FNM_PATHNAME) ||
43
+ File.fnmatch(ignore, File.basename(file), File::FNM_PATHNAME)
44
+ end
45
+ end
46
+
47
+ s.files = unignored_files
48
+ s.executables = unignored_files.map { |f| f[/^bin\/(.*)/, 1] }.compact
49
+ s.require_path = 'lib'
50
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-rsync-pull
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ed Toon
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-07-03 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Vagrant plugin to rsync guest files to host
15
+ email: edtoon@edtoon
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/vagrant-rsync-pull/command.rb
21
+ - lib/vagrant-rsync-pull/synced_folder.rb
22
+ - lib/vagrant-rsync-pull/helper.rb
23
+ - lib/vagrant-rsync-pull/errors.rb
24
+ - lib/vagrant-rsync-pull/plugin.rb
25
+ - lib/vagrant-rsync-pull/version.rb
26
+ - lib/vagrant-rsync-pull.rb
27
+ - Gemfile
28
+ - vagrant-rsync-pull.gemspec
29
+ - LICENSE
30
+ - README.md
31
+ - locales/en.yml
32
+ - CHANGELOG.md
33
+ - .gitignore
34
+ homepage: https://github.com/edtoon/vagrant-rsync-pull
35
+ licenses: []
36
+ post_install_message:
37
+ rdoc_options: []
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: 1.3.6
52
+ requirements: []
53
+ rubyforge_project:
54
+ rubygems_version: 1.8.11
55
+ signing_key:
56
+ specification_version: 3
57
+ summary: Vagrant plugin to rsync guest files to host
58
+ test_files: []