vagrant-sync 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vagrant-sync.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ == vagrant-sync
2
+
3
+ Copyright (c) 2012 David Calavera
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # Vagrant sync
2
+
3
+ Vagrant command to copy files in your box using rsync.
4
+
5
+ You don't need to add anything to your ssh-config to use this command.
6
+
7
+ ## Usage
8
+
9
+ ```
10
+ $ vagrant sync [vm_name] --from /bar/foo --to /foo/bar
11
+ ```
12
+
13
+ ## Options
14
+
15
+ * --from: source file or directory, if this options is not provided the current directory is copied.
16
+ * --to: destination directory, mandatory.
17
+ * --verbose very verbose.
18
+
19
+ ## Copyright
20
+
21
+ Copyright (c) 2012 David Calavera. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1 @@
1
+ require 'vagrant_sync'
@@ -0,0 +1,50 @@
1
+ class Sync < Vagrant::Command::Base
2
+ def execute
3
+ options = {}
4
+
5
+ opts = OptionParser.new do |opts|
6
+ opts.banner = "Usage: vagrant rsync [vm-name] [-f from] [-t to]"
7
+
8
+ opts.separator ""
9
+
10
+ opts.on("-f", "--from SOURCE", "Source directory or file, current directory by default") do |from|
11
+ options[:from] = from
12
+ end
13
+
14
+ opts.on('-t', '--to DESTINATION', 'Destination directory or file') do |to|
15
+ options[:to] = to
16
+ end
17
+
18
+ opts.on('--verbose') do |v|
19
+ options[:verbose] = true
20
+ end
21
+ end
22
+
23
+ argv = parse_options(opts)
24
+ return unless argv
25
+
26
+ raise ArgumentError, "destination path not found, use -t flag" unless options[:to]
27
+ options[:from] ||= Dir.pwd
28
+
29
+ with_target_vms(argv[0], :single_target => true) do |vm|
30
+ raise Errors::VMNotCreatedError if !vm.created?
31
+ raise Errors::VMInaccessible if !vm.state == :inaccessible
32
+
33
+ with_target_vms(argv[0], :single_target => true) do |vm|
34
+ ssh_info = vm.ssh.info
35
+
36
+ ssh_options = "-p#{ssh_info[:port]} -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no -oPasswordAuthentication=no -oIdentitiesOnly=yes -i#{ssh_info[:private_key_path]}"
37
+ ssh_host = "#{ssh_info[:username]}@#{ssh_info[:host]}:#{options[:to]}"
38
+
39
+ rsync_options = '-az'
40
+ rsync_options << 'vvv' if options[:verbose]
41
+
42
+ command = 'rsync %s --delete %s -e "ssh %s" %s' % [rsync_options, options[:from], ssh_options, ssh_host]
43
+ puts command if options[:verbose]
44
+ system(command)
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ Vagrant.commands.register(:sync) { Sync }
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ Gem::Specification.new do |gem|
3
+ gem.authors = ["David Calavera"]
4
+ gem.email = ["david.calavera@gmail.com"]
5
+ gem.description = %q{rsync for Vagrant}
6
+ gem.summary = %q{rsync for Vagrant}
7
+ gem.homepage = ""
8
+
9
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
10
+ gem.files = `git ls-files`.split("\n")
11
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
12
+ gem.name = "vagrant-sync"
13
+ gem.require_paths = ["lib"]
14
+ gem.version = '0.1.0'
15
+
16
+ gem.add_runtime_dependency 'vagrant'
17
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-sync
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - David Calavera
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: vagrant
16
+ requirement: &2158066720 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2158066720
25
+ description: rsync for Vagrant
26
+ email:
27
+ - david.calavera@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - lib/vagrant_init.rb
38
+ - lib/vagrant_sync.rb
39
+ - vagrant-sync.gemspec
40
+ homepage: ''
41
+ licenses: []
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 1.8.10
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: rsync for Vagrant
64
+ test_files: []
65
+ has_rdoc: