vagrant-vaimo-unison 1.1.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +18 -13
- data/lib/vagrant-vaimo-unison.rb +1 -0
- data/lib/vagrant-vaimo-unison/command.rb +11 -33
- data/lib/vagrant-vaimo-unison/config.rb +6 -3
- data/lib/vagrant-vaimo-unison/errors.rb +1 -0
- data/lib/vagrant-vaimo-unison/plugin.rb +7 -25
- data/lib/vagrant-vaimo-unison/shell_command.rb +22 -30
- data/lib/vagrant-vaimo-unison/ssh_command.rb +30 -18
- data/lib/vagrant-vaimo-unison/unison_paths.rb +2 -1
- data/lib/vagrant-vaimo-unison/unison_sync.rb +68 -53
- data/lib/vagrant-vaimo-unison/version.rb +1 -1
- data/vagrant-vaimo-unison.gemspec +4 -4
- metadata +2 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7f7c7b8e8b09e06d91b2ac37bebd6f985024935
|
4
|
+
data.tar.gz: 3e363ea9c5cce5dc7fc601262682a14e407b6646
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5809cee217026ff63da55ecc006b226e50318a359ba6958a69bc647aff04fa36172be50874c936f7fe7016cc4d40ad706817d5b7b086b25fefa31611ade13256
|
7
|
+
data.tar.gz: 0038097598f920b3b513f9d3ea5133d4e2f35d295efb90e7d3d38e6de1412f4b08fc53bf8c75f37318546f126c3f8eefb6604aa186e8e72d1b4243425c106e9a
|
data/README.md
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
# Vagrant Unison 2 Plugin
|
2
2
|
|
3
|
-
This is a [Vagrant](http://www.vagrantup.com)
|
3
|
+
This is a [Vagrant](http://www.vagrantup.com) 2.0+ plugin that syncs files over SSH from a local folder
|
4
4
|
to your Vagrant VM (local or on AWS). Under the covers it uses [Unison](http://www.cis.upenn.edu/~bcpierce/unison/)
|
5
5
|
|
6
|
-
**NOTE:** This plugin requires Vagrant
|
6
|
+
**NOTE:** This plugin requires Vagrant 2.0+
|
7
|
+
|
8
|
+
**INFO:** This plugin is based on [vagrant-unison by Danny Cosson](https://github.com/dcosson/vagrant-unison2)
|
7
9
|
|
8
10
|
## Features
|
9
11
|
|
@@ -12,8 +14,10 @@ to your Vagrant VM (local or on AWS). Under the covers it uses [Unison](http://
|
|
12
14
|
## Usage
|
13
15
|
|
14
16
|
1. You must already have [Unison](http://www.cis.upenn.edu/~bcpierce/unison/) installed on your path on your host and guest machines, and it must be the same version of Unison on both.
|
15
|
-
* On Mac you can install this with Homebrew:
|
16
|
-
*
|
17
|
+
* On Mac you can install this with Homebrew:
|
18
|
+
* `brew tap eugenmayer/dockersync`
|
19
|
+
* `brew install unison eugenmayer/dockersync/unox`
|
20
|
+
* This will install unison 2.48.3
|
17
21
|
* On Ubuntu:
|
18
22
|
* [Xenial (16.04)](https://launchpad.net/ubuntu/xenial/+source/unison): `sudo apt-get install unison`
|
19
23
|
* Ubuntu Trusty (14.04):
|
@@ -24,7 +28,7 @@ to your Vagrant VM (local or on AWS). Under the covers it uses [Unison](http://
|
|
24
28
|
* Install package from `http://ftp5.gwdg.de/pub/linux/archlinux/extra/os/x86_64/unison-2.48.3-2-x86_64.pkg.tar.xz`. (Install at your own risk, this is a plain http link. If someone knows of a signed version, checksum, or https host let me know so I can update it).
|
25
29
|
* On Windows, download [2.48.3](http://www.pps.univ-paris-diderot.fr/~vouillon/unison/unison 2.48.3.zip), unzip, rename `unison-2.48.3 text.exe` to `unison.exe` and copy to somewhere in your path. Alternatively, install [using Chocolatey](https://chocolatey.org/packages/unison).
|
26
30
|
|
27
|
-
2. Install using standard Vagrant
|
31
|
+
2. Install using standard Vagrant 2.0+ plugin installation methods.
|
28
32
|
* `vagrant plugin install vagrant-vaimo-unison`
|
29
33
|
|
30
34
|
3. Configure unison in your Vagrantfile, as shown below.
|
@@ -56,7 +60,7 @@ to your Vagrant VM (local or on AWS). Under the covers it uses [Unison](http://
|
|
56
60
|
|
57
61
|
# `vagrant unison-sync-polling` command will restart unison in VM if memory
|
58
62
|
# usage gets above this threshold (in MB).
|
59
|
-
config.unison.mem_cap_mb =
|
63
|
+
config.unison.mem_cap_mb = 400 # Default: 500
|
60
64
|
|
61
65
|
# Change polling interval (in seconds) at which to sync changes
|
62
66
|
config.unison.repeat = 5 # Default: 1
|
@@ -65,7 +69,7 @@ to your Vagrant VM (local or on AWS). Under the covers it uses [Unison](http://
|
|
65
69
|
|
66
70
|
## Start syncing/watching Folders
|
67
71
|
|
68
|
-
Run `vagrant unison-sync` to
|
72
|
+
Run `vagrant unison-sync` to start the unison process, on the first step it will start the main sync to get your sync folder to host and guest and then the polling process will start
|
69
73
|
|
70
74
|
## Sync in interactive mode
|
71
75
|
|
@@ -138,17 +142,18 @@ See [perms documentation](http://www.cis.upenn.edu/~bcpierce/unison/download/rel
|
|
138
142
|
|
139
143
|
## Development
|
140
144
|
|
141
|
-
|
142
|
-
[Bundler](http://gembundler.com) to get the dependencies:
|
145
|
+
When using ubuntu for development and testing then be sure to install ruby-dev
|
143
146
|
|
144
147
|
```
|
145
|
-
$
|
148
|
+
$ sudo apt-get install ruby-dev
|
149
|
+
$ sudo gem install bundle
|
146
150
|
```
|
147
151
|
|
148
|
-
|
152
|
+
To work on the `vagrant-vaimo-unison` plugin, clone this repository out, and use
|
153
|
+
[Bundler](http://gembundler.com) to get the dependencies:
|
149
154
|
|
150
155
|
```
|
151
|
-
$
|
156
|
+
$ bundle
|
152
157
|
```
|
153
158
|
|
154
159
|
Once you have the dependencies, verify the unit tests pass with `rake`:
|
@@ -179,5 +184,5 @@ rake build
|
|
179
184
|
Now you'll see the built gem in a pkg directory. Install it with
|
180
185
|
|
181
186
|
```
|
182
|
-
vagrant plugin install pkg/vagrant-unison-VERSION.gem
|
187
|
+
vagrant plugin install pkg/vagrant-vaimo-unison-VERSION.gem
|
183
188
|
```
|
data/lib/vagrant-vaimo-unison.rb
CHANGED
@@ -9,6 +9,7 @@ require_relative 'unison_sync'
|
|
9
9
|
|
10
10
|
module VagrantPlugins
|
11
11
|
module Unison
|
12
|
+
# Command Sync
|
12
13
|
class CommandSync < Vagrant.plugin('2', :command)
|
13
14
|
include UnisonSync
|
14
15
|
attr_accessor :bg_thread
|
@@ -19,7 +20,7 @@ module VagrantPlugins
|
|
19
20
|
|
20
21
|
def execute
|
21
22
|
sync_once
|
22
|
-
sync_polling
|
23
|
+
sync_polling unless options[:no_polling]
|
23
24
|
end
|
24
25
|
|
25
26
|
def sync_once
|
@@ -67,7 +68,7 @@ module VagrantPlugins
|
|
67
68
|
# If INT comes in after we've respanwned,
|
68
69
|
# will bring us back to this trap handler.
|
69
70
|
exit_on_next_sigint = false
|
70
|
-
|
71
|
+
loop do
|
71
72
|
begin
|
72
73
|
sleep 2 if exit_on_next_sigint
|
73
74
|
exit_on_next_sigint = false
|
@@ -80,8 +81,8 @@ module VagrantPlugins
|
|
80
81
|
end
|
81
82
|
@env.ui.info '** Hit Ctrl + C again to kill. **'
|
82
83
|
exit_on_next_sigint = true
|
83
|
-
rescue
|
84
|
-
@env.ui.info '** Sync crashed.
|
84
|
+
rescue StandardError
|
85
|
+
@env.ui.info '** Sync crashed. Restarting. Hit Ctrl + C twice to kill. **'
|
85
86
|
end
|
86
87
|
end
|
87
88
|
end
|
@@ -94,7 +95,7 @@ module VagrantPlugins
|
|
94
95
|
def watch_vm_for_memory_leak(machine)
|
95
96
|
ssh_command = SshCommand.new(machine, options)
|
96
97
|
Thread.new(ssh_command.ssh, machine.config.unison.mem_cap_mb) do |ssh_command_text, mem_cap_mb|
|
97
|
-
|
98
|
+
loop do
|
98
99
|
sleep 15
|
99
100
|
total_mem = `#{ssh_command_text} 'free -m | egrep "^Mem:" | awk "{print \\$2}"' 2>/dev/null`
|
100
101
|
unison_proc_returnval = `#{ssh_command_text} 'ps aux | grep "[u]nison -server" | awk "{print \\$2, \\$4}"' 2>/dev/null`
|
@@ -117,31 +118,7 @@ module VagrantPlugins
|
|
117
118
|
end
|
118
119
|
end
|
119
120
|
|
120
|
-
|
121
|
-
include UnisonSync
|
122
|
-
|
123
|
-
def self.synopsis
|
124
|
-
'sync the unison shared folder once (deprecated)'
|
125
|
-
end
|
126
|
-
|
127
|
-
def execute
|
128
|
-
@env.ui.info 'The command is deprecated, use vagrant unison-sync --no-polling'
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
class CommandPolling < Vagrant.plugin('2', :command)
|
133
|
-
include UnisonSync
|
134
|
-
attr_accessor :bg_thread
|
135
|
-
|
136
|
-
def self.synopsis
|
137
|
-
'sync the unison shared folder forever, by polling for changes (deprecated)'
|
138
|
-
end
|
139
|
-
|
140
|
-
def execute
|
141
|
-
@env.ui.info 'The command is deprecated, use vagrant unison-sync'
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
121
|
+
# Command Cleanup
|
145
122
|
class CommandCleanup < Vagrant.plugin('2', :command)
|
146
123
|
def self.synopsis
|
147
124
|
'Remove archives and configuration from host and guest. Keeps files in guest (need to remove manually if needed)'
|
@@ -150,11 +127,11 @@ module VagrantPlugins
|
|
150
127
|
def execute
|
151
128
|
with_target_vms do |machine|
|
152
129
|
command = "rm -rf ~/Library/'Application Support'/Unison/*"
|
153
|
-
@env.ui.info "Running #{command} on host"
|
130
|
+
@env.ui.info "Running #{command} on host" if options[:verbose]
|
154
131
|
system(command)
|
155
132
|
|
156
133
|
command = 'rm -rf ~/.unison'
|
157
|
-
@env.ui.info "Running #{command} on guest VM"
|
134
|
+
@env.ui.info "Running #{command} on guest VM" if options[:verbose]
|
158
135
|
machine.communicate.execute(command)
|
159
136
|
end
|
160
137
|
|
@@ -162,6 +139,7 @@ module VagrantPlugins
|
|
162
139
|
end
|
163
140
|
end
|
164
141
|
|
142
|
+
# Command Interact
|
165
143
|
class CommandInteract < Vagrant.plugin('2', :command)
|
166
144
|
include UnisonSync
|
167
145
|
|
@@ -175,7 +153,7 @@ module VagrantPlugins
|
|
175
153
|
command.terse = true
|
176
154
|
command = command.to_s
|
177
155
|
|
178
|
-
@env.ui.info "Running #{command}"
|
156
|
+
@env.ui.info "Running #{command}" if options[:verbose]
|
179
157
|
|
180
158
|
system(command)
|
181
159
|
end
|
@@ -1,7 +1,10 @@
|
|
1
1
|
require 'vagrant'
|
2
2
|
|
3
|
+
UNSET_VALUE = nil
|
4
|
+
|
3
5
|
module VagrantPlugins
|
4
6
|
module Unison
|
7
|
+
# Config
|
5
8
|
class Config < Vagrant.plugin('2', :config)
|
6
9
|
# Host Folder to Sync
|
7
10
|
#
|
@@ -60,7 +63,7 @@ module VagrantPlugins
|
|
60
63
|
# @return [Boolean]
|
61
64
|
attr_accessor :ssh_use_agent
|
62
65
|
|
63
|
-
def initialize
|
66
|
+
def initialize
|
64
67
|
@host_folder = UNSET_VALUE
|
65
68
|
@guest_folder = UNSET_VALUE
|
66
69
|
@ignore = UNSET_VALUE
|
@@ -92,7 +95,7 @@ module VagrantPlugins
|
|
92
95
|
@__finalized = true
|
93
96
|
end
|
94
97
|
|
95
|
-
def validate
|
98
|
+
def validate
|
96
99
|
errors = []
|
97
100
|
|
98
101
|
unless @host_folder.nil? && @guest_folder.nil?
|
@@ -100,7 +103,7 @@ module VagrantPlugins
|
|
100
103
|
errors << I18n.t('vagrant_unison.config.unison_guest_folder_required') if @guest_folder.nil?
|
101
104
|
end
|
102
105
|
|
103
|
-
{
|
106
|
+
{'Unison' => errors}
|
104
107
|
end
|
105
108
|
end
|
106
109
|
end
|
@@ -6,12 +6,13 @@ end
|
|
6
6
|
|
7
7
|
# This is a sanity check to make sure no one is attempting to install
|
8
8
|
# this into an early Vagrant version.
|
9
|
-
if Vagrant::VERSION < '
|
10
|
-
raise 'The vagrant-unison plugin is only compatible with Vagrant
|
9
|
+
if Vagrant::VERSION < '2.0.0'
|
10
|
+
raise 'The vagrant-unison plugin is only compatible with Vagrant 2.0+'
|
11
11
|
end
|
12
12
|
|
13
13
|
module VagrantPlugins
|
14
14
|
module Unison
|
15
|
+
# Unison Plugin
|
15
16
|
class Plugin < Vagrant.plugin('2')
|
16
17
|
name 'Unison'
|
17
18
|
description <<-DESC
|
@@ -25,50 +26,31 @@ module VagrantPlugins
|
|
25
26
|
end
|
26
27
|
|
27
28
|
command 'unison-sync' do
|
29
|
+
# Setup logging and i18n
|
28
30
|
setup_logging
|
29
31
|
setup_i18n
|
30
32
|
|
31
|
-
#Return the command
|
33
|
+
# Return the command
|
32
34
|
require_relative 'command'
|
33
35
|
CommandSync
|
34
36
|
end
|
35
37
|
|
36
|
-
command 'unison-sync-once' do
|
37
|
-
setup_logging
|
38
|
-
setup_i18n
|
39
|
-
|
40
|
-
#Return the command
|
41
|
-
require_relative 'command'
|
42
|
-
CommandOnce
|
43
|
-
end
|
44
|
-
|
45
38
|
command 'unison-sync-interact' do
|
46
39
|
# Setup logging and i18n
|
47
40
|
setup_logging
|
48
41
|
setup_i18n
|
49
42
|
|
50
|
-
#Return the command
|
43
|
+
# Return the command
|
51
44
|
require_relative 'command'
|
52
45
|
CommandInteract
|
53
46
|
end
|
54
47
|
|
55
|
-
|
56
|
-
command 'unison-sync-polling' do
|
57
|
-
# Setup logging and i18n
|
58
|
-
setup_logging
|
59
|
-
setup_i18n
|
60
|
-
|
61
|
-
#Return the command
|
62
|
-
require_relative 'command'
|
63
|
-
CommandPolling
|
64
|
-
end
|
65
|
-
|
66
48
|
command 'unison-cleanup' do
|
67
49
|
# Setup logging and i18n
|
68
50
|
setup_logging
|
69
51
|
setup_i18n
|
70
52
|
|
71
|
-
#Return the command
|
53
|
+
# Return the command
|
72
54
|
require_relative 'command'
|
73
55
|
CommandCleanup
|
74
56
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module VagrantPlugins
|
2
2
|
module Unison
|
3
|
+
# ShellCommand
|
3
4
|
class ShellCommand
|
4
5
|
def initialize(machine, unison_paths, ssh_command)
|
5
6
|
@machine = machine
|
@@ -26,20 +27,12 @@ module VagrantPlugins
|
|
26
27
|
private
|
27
28
|
|
28
29
|
def args
|
29
|
-
_args = [
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
repeat_arg,
|
36
|
-
ignore_arg,
|
37
|
-
ignorenot_arg,
|
38
|
-
perms_arg,
|
39
|
-
force_arg,
|
40
|
-
prefer_arg,
|
41
|
-
ssh_args,
|
42
|
-
].flatten.compact
|
30
|
+
_args = ['unison',
|
31
|
+
local_root_arg, remote_root_arg,
|
32
|
+
batch_arg, terse_arg, repeat_arg, perms_arg,
|
33
|
+
ignore_arg, ignorenot_arg,
|
34
|
+
force_arg, prefer_arg,
|
35
|
+
ssh_args].flatten.compact
|
43
36
|
end
|
44
37
|
|
45
38
|
def local_root_arg
|
@@ -59,27 +52,15 @@ module VagrantPlugins
|
|
59
52
|
end
|
60
53
|
|
61
54
|
def ignore_arg
|
62
|
-
|
63
|
-
|
64
|
-
patterns += @machine.config.unison.ignore
|
65
|
-
elsif @machine.config.unison.ignore
|
66
|
-
patterns << @machine.config.unison.ignore
|
67
|
-
end
|
68
|
-
|
69
|
-
patterns.map do |pattern|
|
55
|
+
ignore = @machine.config.unison.ignore
|
56
|
+
patterns_from_config(ignore).map do |pattern|
|
70
57
|
['-ignore', %("#{pattern}")]
|
71
58
|
end
|
72
59
|
end
|
73
60
|
|
74
61
|
def ignorenot_arg
|
75
|
-
|
76
|
-
|
77
|
-
patterns += @machine.config.unison.ignorenot
|
78
|
-
elsif @machine.config.unison.ignorenot
|
79
|
-
patterns << @machine.config.unison.ignorenot
|
80
|
-
end
|
81
|
-
|
82
|
-
patterns.map do |pattern|
|
62
|
+
ignorenot = @machine.config.unison.ignorenot
|
63
|
+
patterns_from_config(ignorenot).map do |pattern|
|
83
64
|
['-ignorenot', %("#{pattern}")]
|
84
65
|
end
|
85
66
|
end
|
@@ -126,6 +107,17 @@ module VagrantPlugins
|
|
126
107
|
return ['-prefer', local_root_arg] if prefer_local
|
127
108
|
['-prefer', remote_root_arg] if prefer_remote
|
128
109
|
end
|
110
|
+
|
111
|
+
def patterns_from_config(data)
|
112
|
+
patterns = []
|
113
|
+
if data.is_a? ::Array
|
114
|
+
patterns += data
|
115
|
+
elsif data
|
116
|
+
patterns << data
|
117
|
+
end
|
118
|
+
|
119
|
+
patterns
|
120
|
+
end
|
129
121
|
end
|
130
122
|
end
|
131
123
|
end
|
@@ -7,25 +7,17 @@ module VagrantPlugins
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def ssh
|
10
|
-
%W(
|
11
|
-
ssh
|
12
|
-
#{@machine.config.unison.ssh_user}@#{@machine.config.unison.ssh_host}
|
13
|
-
#{ssh_args}
|
14
|
-
).compact.join(' ')
|
10
|
+
%W[ssh #{ssh_auth} #{ssh_args}].compact.join(' ')
|
15
11
|
end
|
16
12
|
|
17
13
|
def ssh_args
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
-o StrictHostKeyChecking=no
|
26
|
-
-o UserKnownHostsFile=/dev/null
|
27
|
-
#{identity}
|
28
|
-
).compact.join(' ')
|
14
|
+
%W[
|
15
|
+
#{ssh_port}
|
16
|
+
#{proxy_command}
|
17
|
+
#{ssh_log_options}
|
18
|
+
#{ssh_options}
|
19
|
+
#{identity}
|
20
|
+
].compact.join(' ')
|
29
21
|
end
|
30
22
|
|
31
23
|
def uri(unison_paths)
|
@@ -37,6 +29,24 @@ module VagrantPlugins
|
|
37
29
|
|
38
30
|
private
|
39
31
|
|
32
|
+
def ssh_auth
|
33
|
+
"#{@machine.config.unison.ssh_user}@#{@machine.config.unison.ssh_host}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def ssh_port
|
37
|
+
"-p #{@machine.config.unison.ssh_port}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def ssh_log_options
|
41
|
+
log_line = ''
|
42
|
+
log_line = '-o LogLevel=quiet' unless @options[:verbose]
|
43
|
+
log_line
|
44
|
+
end
|
45
|
+
|
46
|
+
def ssh_options
|
47
|
+
' -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'
|
48
|
+
end
|
49
|
+
|
40
50
|
def proxy_command
|
41
51
|
command = @machine.ssh_info[:proxy_command]
|
42
52
|
return nil unless command
|
@@ -47,12 +57,14 @@ module VagrantPlugins
|
|
47
57
|
if @machine.config.unison.ssh_use_agent
|
48
58
|
''
|
49
59
|
else
|
50
|
-
(%w
|
60
|
+
(%w[-o IdentitiesOnly=yes] << key_paths).join(' ')
|
51
61
|
end
|
52
62
|
end
|
53
63
|
|
54
64
|
def key_paths
|
55
|
-
@machine.ssh_info[:private_key_path].map { |p|
|
65
|
+
@machine.ssh_info[:private_key_path].map { |p|
|
66
|
+
"-i #{p.shellescape}"
|
67
|
+
}.join(' ')
|
56
68
|
end
|
57
69
|
end
|
58
70
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module VagrantPlugins
|
2
2
|
module Unison
|
3
|
+
# UnisonPaths
|
3
4
|
class UnisonPaths
|
4
5
|
def initialize(env, machine, project = '')
|
5
6
|
@env = env
|
@@ -17,7 +18,7 @@ module VagrantPlugins
|
|
17
18
|
|
18
19
|
# Make sure there is a trailing slash on the host path to
|
19
20
|
# avoid creating an additional directory with rsync
|
20
|
-
|
21
|
+
"#{path}/#{@project}" if path !~ /\/$/
|
21
22
|
end
|
22
23
|
end
|
23
24
|
end
|
@@ -7,22 +7,30 @@ module VagrantPlugins
|
|
7
7
|
def execute_sync_command(machine)
|
8
8
|
parse_options!
|
9
9
|
|
10
|
-
return
|
10
|
+
return 0 if machine.config.unison.host_folder.nil?
|
11
11
|
|
12
12
|
unison_paths = UnisonPaths.new(@env, machine, options[:project])
|
13
13
|
|
14
|
+
startup_command(machine, unison_paths)
|
15
|
+
|
16
|
+
yield set_shell_command(machine, options, unison_paths)
|
17
|
+
end
|
18
|
+
|
19
|
+
def startup_command(machine, unison_paths)
|
14
20
|
guest_path = unison_paths.guest
|
15
21
|
host_path = unison_paths.host
|
16
|
-
|
17
|
-
ssh_user = machine.config.unison.ssh_user
|
22
|
+
ssh_user = machine.config.unison.ssh_user
|
18
23
|
|
19
24
|
@env.ui.info "Sync changes from {host}::#{host_path}"
|
20
25
|
@env.ui.info " --> {guest VM}::#{guest_path}"
|
21
26
|
|
22
|
-
# Create the guest path
|
27
|
+
# Create the guest and host path if they don't exists path
|
23
28
|
machine.communicate.sudo("mkdir -p '#{guest_path}'")
|
24
29
|
machine.communicate.sudo("chown #{ssh_user} '#{guest_path}'")
|
30
|
+
system("mkdir -p '#{host_path}'")
|
31
|
+
end
|
25
32
|
|
33
|
+
def set_shell_command(machine, options, unison_paths)
|
26
34
|
ssh_command = SshCommand.new(machine, options)
|
27
35
|
shell_command = ShellCommand.new(machine, unison_paths, ssh_command)
|
28
36
|
|
@@ -32,7 +40,7 @@ module VagrantPlugins
|
|
32
40
|
shell_command.force_remote = options[:force_remote]
|
33
41
|
shell_command.project = options[:project]
|
34
42
|
|
35
|
-
|
43
|
+
shell_command
|
36
44
|
end
|
37
45
|
|
38
46
|
def parse_options!
|
@@ -41,74 +49,81 @@ module VagrantPlugins
|
|
41
49
|
# a binding.pry in here and then type `? parse_options`
|
42
50
|
@parsed_argv ||= parse_options(options_parser)
|
43
51
|
|
44
|
-
if options[:verbose]
|
45
|
-
@env.ui.info "Options: #{options}"
|
46
|
-
end
|
52
|
+
@env.ui.info "Options: #{options}" if options[:verbose]
|
47
53
|
|
48
54
|
# According to the docs:
|
49
55
|
# > If parse_options returns `nil`, then you should assume that
|
50
56
|
# > help was printed and parsing failed.
|
51
|
-
if @parsed_argv
|
52
|
-
exit 1
|
53
|
-
end
|
57
|
+
exit 1 if @parsed_argv.nil?
|
54
58
|
end
|
55
59
|
|
56
60
|
def options
|
57
|
-
@options ||= {
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
:no_polling => false
|
65
|
-
}
|
61
|
+
@options ||= { prefer_local: false,
|
62
|
+
prefer_remote: false,
|
63
|
+
force_local: false,
|
64
|
+
force_remote: false,
|
65
|
+
verbose: false,
|
66
|
+
project: nil,
|
67
|
+
no_polling: false }
|
66
68
|
end
|
67
69
|
|
68
70
|
def options_parser
|
69
71
|
@option_parser ||= OptionParser.new do |o|
|
70
72
|
o.banner = "Usage: vagrant #{ARGV[0]} [options]"
|
73
|
+
options_pull_flags(o)
|
74
|
+
options_push_flags(o)
|
75
|
+
options_optional_flags(o)
|
76
|
+
options_optional_values(o)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def options_optional_flags(o)
|
81
|
+
# Coming soon
|
82
|
+
# o.on('--no-polling', 'trigger sync without starting the polling process') do |flag|
|
83
|
+
# options[:no_polling] = flag
|
84
|
+
# end
|
85
|
+
|
86
|
+
o.on('--verbose', 'print additional debug information') do |flag|
|
87
|
+
options[:verbose] = flag
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def options_optional_values(o)
|
92
|
+
o.on('-p', '--project=project', 'project folder to sync') do |project|
|
93
|
+
options[:project] = project
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def options_pull_flags(o)
|
98
|
+
o.on('--pull', 'prefer changes on the remote machine.') do |flag|
|
99
|
+
options[:prefer_remote] = flag
|
100
|
+
check_conflicting_options!
|
101
|
+
end
|
102
|
+
|
103
|
+
o.on('--force-pull', 'force-pull changes from the remote machine. Super dangerous!') do |flag|
|
104
|
+
options[:force_remote] = flag
|
105
|
+
check_conflicting_options!
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def options_push_flags(o)
|
110
|
+
o.on('--push', 'prefer changes on the local machine.') do |flag|
|
111
|
+
options[:prefer_local] = flag
|
112
|
+
check_conflicting_options!
|
113
|
+
end
|
71
114
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
o.on('--push', 'prefer changes on the local machine.') do |flag|
|
77
|
-
options[:prefer_local] = flag
|
78
|
-
check_conflicting_options!
|
79
|
-
end
|
80
|
-
|
81
|
-
o.on('--pull', 'prefer changes on the remote machine.') do |flag|
|
82
|
-
options[:prefer_remote] = flag
|
83
|
-
check_conflicting_options!
|
84
|
-
end
|
85
|
-
|
86
|
-
o.on('--force-push', 'force-push changes to the remote machine. Dangerous!') do |flag|
|
87
|
-
options[:force_local] = flag
|
88
|
-
check_conflicting_options!
|
89
|
-
end
|
90
|
-
|
91
|
-
o.on('--force-pull', 'force-pull changes from the remote machine. Super dangerous!') do |flag|
|
92
|
-
options[:force_remote] = flag
|
93
|
-
check_conflicting_options!
|
94
|
-
end
|
95
|
-
|
96
|
-
o.on('--verbose', 'print additional debug information') do |flag|
|
97
|
-
options[:verbose] = flag
|
98
|
-
end
|
99
|
-
|
100
|
-
o.on('-p', '--project=project', 'project folder to sync') do |project|
|
101
|
-
options[:project] = project
|
102
|
-
end
|
115
|
+
o.on('--force-push', 'force-push changes to the remote machine. Dangerous!') do |flag|
|
116
|
+
options[:force_local] = flag
|
117
|
+
check_conflicting_options!
|
103
118
|
end
|
104
119
|
end
|
105
120
|
|
106
121
|
def check_conflicting_options!
|
107
|
-
enabled = [
|
122
|
+
enabled = %i[prefer_local prefer_remote force_local force_remote].select do |opt|
|
108
123
|
options[opt]
|
109
124
|
end
|
110
125
|
|
111
|
-
raise ArgumentError
|
126
|
+
raise ArgumentError, "Conflicting options: #{enabled.inspect}" if enabled.length > 1
|
112
127
|
end
|
113
128
|
end
|
114
129
|
end
|
@@ -6,11 +6,11 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.name = 'vagrant-vaimo-unison'
|
7
7
|
s.version = VagrantPlugins::Unison::VERSION
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
|
-
s.authors = ['
|
9
|
+
s.authors = ['Platform Team @ Vaimo']
|
10
10
|
s.email = 'platform@vaimo.com'
|
11
11
|
s.homepage = 'https://bitbucket.org/vaimo/vagrant-vaimo-unison'
|
12
12
|
s.summary = 'Vagrant plugin to sync local files to VM over SSH using Unison'
|
13
|
-
s.description = 'Vagrant
|
13
|
+
s.description = 'Vagrant 2.0+ plugin to sync local files to VM over SSH using Unison'
|
14
14
|
|
15
15
|
s.required_rubygems_version = '>= 1.3.6'
|
16
16
|
|
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
# the "!" syntax, but it should mostly work correctly.
|
27
27
|
root_path = File.dirname(__FILE__)
|
28
28
|
all_files = Dir.chdir(root_path) { Dir.glob('**/{*,.*}') }
|
29
|
-
all_files.reject! { |file| %w
|
29
|
+
all_files.reject! { |file| %w[. ..].include?(File.basename(file)) }
|
30
30
|
gitignore_path = File.join(root_path, '.gitignore')
|
31
31
|
gitignore = File.readlines(gitignore_path)
|
32
32
|
gitignore.map! { |line| line.chomp.strip }
|
@@ -46,7 +46,7 @@ Gem::Specification.new do |s|
|
|
46
46
|
#
|
47
47
|
gitignore.any? do |ignore|
|
48
48
|
File.fnmatch(ignore, file, File::FNM_PATHNAME) ||
|
49
|
-
|
49
|
+
File.fnmatch(ignore, File.basename(file), File::FNM_PATHNAME)
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
metadata
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-vaimo-unison
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- David Laing
|
8
|
-
- dmatora
|
9
|
-
- Danny Cosson
|
10
7
|
- Platform Team @ Vaimo
|
11
8
|
autorequire:
|
12
9
|
bindir: bin
|
@@ -69,7 +66,7 @@ dependencies:
|
|
69
66
|
- - "~>"
|
70
67
|
- !ruby/object:Gem::Version
|
71
68
|
version: 2.12.1
|
72
|
-
description: Vagrant
|
69
|
+
description: Vagrant 2.0+ plugin to sync local files to VM over SSH using Unison
|
73
70
|
email: platform@vaimo.com
|
74
71
|
executables: []
|
75
72
|
extensions: []
|