vagrant-rsync-back 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7ebb0b6a7417809cc6743de98dec4333de70c7ee
4
+ data.tar.gz: e942aed14a268627f741a9793f83290f2e21c517
5
+ SHA512:
6
+ metadata.gz: 0fd0c2c43a9ab1231303f6e192542b10ce60209a43c9909da887bf12df00bff1aab50633c7b1f235522a416628f50a9c80e7631e15f0a9dee53702dcc60a040f
7
+ data.tar.gz: 19874ba46f8f6aaad08f6cfbdc693f3b2be8e3568e39eeda7f1e7f89ba833415960de6ee2599d5c5b743e64e564abe368239ba884bdfc161f073f3c7ba96dde8
@@ -0,0 +1,21 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.swp
19
+ *.swo
20
+ example/files/*
21
+ example/vagrant/.vagrant
@@ -0,0 +1 @@
1
+ 2.0.0-p353
@@ -0,0 +1,12 @@
1
+ ## 0.0.1 (April 4, 2014)
2
+
3
+ Initial release.
4
+
5
+ FEATURES:
6
+
7
+ - Implement rsync back from guest to host.
8
+
9
+ ## Backlog
10
+
11
+ - Test more.
12
+ - Test on Windows.
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vagrant-rsync-back.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem "vagrant", :git => "https://github.com/mitchellh/vagrant.git", :tag => 'v1.5.1'
8
+ gem "pry"
9
+ end
10
+
11
+ group :plugins do
12
+ gem "vagrant-rsync-back", path: "."
13
+ end
14
+
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Steven Merrill
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,34 @@
1
+ # vagrant-rsync-back
2
+
3
+ A plugin for Vagrant 1.5.1+ that lets you rsync from guest to host.
4
+
5
+ ## Getting started
6
+
7
+ This plugin has only been lightly tested. It might eat all your data! (Use at
8
+ your own risk.)
9
+
10
+ To get started, you need to have Vagrant 1.5.1 installed on your host machine.
11
+ To install the plugin, use the following command.
12
+
13
+ ```bash
14
+ vagrant plugin install vagrant-rsync-back
15
+ ```
16
+
17
+ Then once you have generated some content on the guest that you want to bring
18
+ back to the host, run the rsync-back command.
19
+
20
+ ```bash
21
+ vagrant rsync-back
22
+ ```
23
+
24
+ ## Why rsync back?
25
+
26
+ Sometimes, the application on your host will write things to the source code
27
+ directory that you want to sync back to the host. A Drupal-specific example
28
+ is generating new Features to disk and then wanting to commit them to git
29
+ from the host machine.
30
+
31
+ ## Author
32
+
33
+ Steven Merrill (@stevenmerrill) built this based on vagrant-gatling-rsync.
34
+
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,16 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ # Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
5
+ VAGRANTFILE_API_VERSION = "2"
6
+
7
+ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
8
+ config.vm.box = "hashicorp/precise64"
9
+
10
+ # Share an additional folder to the guest VM. The first argument is
11
+ # the path on the host to the actual folder. The second argument is
12
+ # the path on the guest to mount the folder. And the optional third
13
+ # argument is a set of non-required options.
14
+ config.vm.synced_folder "../files", "/opt/vagrant/rsynced_folder", type: "rsync",
15
+ rsync__exclude: [".git/", ".idea/"]
16
+ end
@@ -0,0 +1,23 @@
1
+ # This file is required because Vagrant's plugin system expects
2
+ # a eponymous ruby file matching the rubygem.
3
+ #
4
+ # So this gem is called 'vagrant-rsync-auto' and thus vagrant tries
5
+ # to require "vagrant-rsync-auto"
6
+
7
+ require "vagrant-rsync-back/plugin"
8
+
9
+ require "pathname"
10
+
11
+ module VagrantPlugins
12
+ module RsyncBack
13
+ lib_path = Pathname.new(File.expand_path("../vagrant-rsync-back", __FILE__))
14
+ autoload :Errors, lib_path.join("errors")
15
+
16
+ # This returns the path to the source of this plugin.
17
+ #
18
+ # @return [Pathname]
19
+ def self.source_root
20
+ @source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,157 @@
1
+ require "log4r"
2
+ require "optparse"
3
+
4
+ require "vagrant"
5
+
6
+ # Monkeypatch RsyncHelper for now. Maybe merge this into Vagrant proper?
7
+ require Vagrant.source_root.join("plugins/synced_folders/rsync/helper")
8
+ VagrantPlugins::SyncedFolderRSync::RsyncHelper.class_eval do
9
+ def self.rsync_single(machine, ssh_info, opts, rsync_back=false)
10
+ # Folder info
11
+ guestpath = opts[:guestpath]
12
+ hostpath = opts[:hostpath]
13
+ hostpath = File.expand_path(hostpath, machine.env.root_path)
14
+ hostpath = Vagrant::Util::Platform.fs_real_path(hostpath).to_s
15
+
16
+ if Vagrant::Util::Platform.windows?
17
+ # rsync for Windows expects cygwin style paths, always.
18
+ hostpath = Vagrant::Util::Platform.cygwin_path(hostpath)
19
+ end
20
+
21
+ # Make sure the host path ends with a "/" to avoid creating
22
+ # a nested directory...
23
+ if rsync_back
24
+ if !guestpath.end_with?("/")
25
+ guestpath += "/"
26
+ end
27
+ else
28
+ if !hostpath.end_with?("/")
29
+ hostpath += "/"
30
+ end
31
+ end
32
+
33
+ # Folder options
34
+ opts[:owner] ||= ssh_info[:username]
35
+ opts[:group] ||= ssh_info[:username]
36
+
37
+ # Connection information
38
+ username = ssh_info[:username]
39
+ host = ssh_info[:host]
40
+ rsh = [
41
+ "ssh -p #{ssh_info[:port]} -o StrictHostKeyChecking=no",
42
+ ssh_info[:private_key_path].map { |p| "-i '#{p}'" },
43
+ ].flatten.join(" ")
44
+
45
+ # Exclude some files by default, and any that might be configured
46
+ # by the user.
47
+ excludes = ['.vagrant/']
48
+ excludes += Array(opts[:exclude]).map(&:to_s) if opts[:exclude]
49
+ excludes.uniq!
50
+
51
+ # Get the command-line arguments
52
+ args = nil
53
+ args = Array(opts[:args]) if opts[:args]
54
+ args ||= ["--verbose", "--archive", "--delete", "-z"]
55
+
56
+ # On Windows, we have to set the chmod flag to avoid permission issues
57
+ if Vagrant::Util::Platform.windows?
58
+ args << "--chmod=ugo=rwX"
59
+ end
60
+
61
+ # Build up the actual command to execute
62
+ command_parts = [
63
+ "rsync",
64
+ args,
65
+ "-e", rsh,
66
+ excludes.map { |e| ["--exclude", e] },
67
+ hostpath,
68
+ "#{username}@#{host}:#{guestpath}",
69
+ ]
70
+
71
+ command_parts = command_parts.concat(command_parts.slice!(-2, 2).reverse) if rsync_back
72
+ command = command_parts.flatten
73
+
74
+ # The working directory should be the root path
75
+ command_opts = {}
76
+ command_opts[:workdir] = machine.env.root_path.to_s
77
+
78
+ if rsync_back
79
+ machine.ui.info(I18n.t(
80
+ "vagrant.rsync_folder", guestpath: hostpath, hostpath: guestpath))
81
+ else
82
+ machine.ui.info(I18n.t(
83
+ "vagrant.rsync_folder", guestpath: guestpath, hostpath: hostpath))
84
+ end
85
+
86
+ if excludes.length > 1
87
+ machine.ui.info(I18n.t(
88
+ "vagrant.rsync_folder_excludes", excludes: excludes.inspect))
89
+ end
90
+
91
+ # If we have tasks to do before rsyncing, do those.
92
+ if machine.guest.capability?(:rsync_pre)
93
+ machine.guest.capability(:rsync_pre, opts) unless rsync_back
94
+ end
95
+
96
+ r = Vagrant::Util::Subprocess.execute(*(command + [command_opts]))
97
+ if r.exit_code != 0
98
+ raise Vagrant::Errors::RSyncError,
99
+ command: command.join(" "),
100
+ guestpath: guestpath,
101
+ hostpath: hostpath,
102
+ stderr: r.stderr
103
+ end
104
+
105
+ # If we have tasks to do after rsyncing, do those.
106
+ if machine.guest.capability?(:rsync_post)
107
+ machine.guest.capability(:rsync_post, opts) unless rsync_back
108
+ end
109
+ end
110
+ end
111
+
112
+ module VagrantPlugins
113
+ module RsyncBack
114
+ class RsyncBackCommand < Vagrant.plugin(2, :command)
115
+ include Vagrant::Action::Builtin::MixinSyncedFolders
116
+
117
+ def self.synopsis
118
+ "syncs rsync synced folders from remote machine"
119
+ end
120
+
121
+ def execute
122
+ opts = OptionParser.new do |o|
123
+ o.banner = "Usage: vagrant rsync-back [vm-name]"
124
+ o.separator ""
125
+ end
126
+
127
+ # Parse the options and return if we don't have any target.
128
+ argv = parse_options(opts)
129
+ return if !argv
130
+
131
+ # Go through each machine and perform the rsync
132
+ error = false
133
+ with_target_vms(argv) do |machine|
134
+ if !machine.communicate.ready?
135
+ machine.ui.error(I18n.t("vagrant.rsync_communicator_not_ready"))
136
+ error = true
137
+ next
138
+ end
139
+
140
+ # Determine the rsync synced folders for this machine
141
+ folders = synced_folders(machine)[:rsync]
142
+ next if !folders || folders.empty?
143
+
144
+ # Get the SSH info for this machine so we can access it
145
+ ssh_info = machine.ssh_info
146
+
147
+ # Sync them!
148
+ folders.each do |id, folder_opts|
149
+ VagrantPlugins::SyncedFolderRSync::RsyncHelper.rsync_single(machine, ssh_info, folder_opts, true)
150
+ end
151
+ end
152
+
153
+ return error ? 1 : 0
154
+ end
155
+ end
156
+ end
157
+ end
@@ -0,0 +1,19 @@
1
+ require "vagrant"
2
+
3
+ module VagrantPlugins
4
+ module RsyncBack
5
+ module Errors
6
+ class VagrantRsyncBackError < Vagrant::Errors::VagrantError
7
+ error_namespace("vagrant_rsync_back.errors")
8
+ end
9
+
10
+ class OnlyOSXLinuxSupportError < VagrantRsyncBackError
11
+ error_key(:only_osx_linux_support)
12
+ end
13
+
14
+ class Vagrant15RequiredError < VagrantRsyncBackError
15
+ error_key(:vagrant_15_required)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,35 @@
1
+ begin
2
+ require "vagrant"
3
+ rescue LoadError
4
+ raise "The Vagrant gatling rsync plugin must be run within Vagrant."
5
+ end
6
+
7
+ # This is a sanity check to make sure no one is attempting to install
8
+ # this into an early Vagrant version.
9
+ if Vagrant::VERSION < "1.5.1"
10
+ raise Errors::Vagrant15RequiredError
11
+ end
12
+
13
+ module VagrantPlugins
14
+ module RsyncBack
15
+ class Plugin < Vagrant.plugin("2")
16
+ name "Rsync Back"
17
+ description <<-DESC
18
+ Rsync back from the guest to the host.
19
+ DESC
20
+
21
+ # This initializes the internationalization strings.
22
+ def self.setup_i18n
23
+ I18n.load_path << File.expand_path("locales/en.yml", RsyncBack.source_root)
24
+ I18n.reload!
25
+ end
26
+
27
+ command("rsync-back", primary: false) do
28
+ setup_i18n
29
+
30
+ require_relative "command/rsync_back"
31
+ RsyncBackCommand
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module RsyncBack
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ en:
2
+ vagrant_gatling_rsync:
3
+ errors:
4
+ only_osx_linux_support: |-
5
+ This plugin currently only supports Max OS X and Linux hosts.
6
+ vagrant_15_required: |-
7
+ This plugin requires Vagrant 1.5.1 or newer to function.
8
+
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vagrant-rsync-back/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vagrant-rsync-back"
8
+ spec.version = VagrantPlugins::RsyncBack::VERSION
9
+ spec.authors = ["Steven Merrill"]
10
+ spec.email = ["steven.merrill@gmail.com"]
11
+ spec.summary = %q{Rsync in reverse to pull files from your Vagrant rsynced folders.}
12
+ spec.description = %q{Rsync in reverse to pull files from your Vagrant rsynced folders.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ # @TODO: Remove example files from the built gem.
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.5"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "pry"
25
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-rsync-back
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Steven Merrill
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Rsync in reverse to pull files from your Vagrant rsynced folders.
56
+ email:
57
+ - steven.merrill@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .ruby-version
64
+ - CHANGELOG.md
65
+ - Gemfile
66
+ - LICENSE
67
+ - README.md
68
+ - Rakefile
69
+ - example/vagrant/Vagrantfile
70
+ - lib/vagrant-rsync-back.rb
71
+ - lib/vagrant-rsync-back/command/rsync_back.rb
72
+ - lib/vagrant-rsync-back/errors.rb
73
+ - lib/vagrant-rsync-back/plugin.rb
74
+ - lib/vagrant-rsync-back/version.rb
75
+ - locales/en.yml
76
+ - vagrant-rsync-back.gemspec
77
+ homepage: ''
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.0.14
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Rsync in reverse to pull files from your Vagrant rsynced folders.
101
+ test_files: []