Skip to content

Commit

Permalink
Implemented repeat mode
Browse files Browse the repository at this point in the history
  • Loading branch information
dmatora committed Jan 8, 2015
1 parent a2cf52a commit 90e254a
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ Vagrantfile

# IDEs
.project
.idea
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ Run `vagrant sync` to start watching the local_folder for changes, and syncing t
Under the covers this uses your system installation of [Unison](http://www.cis.upenn.edu/~bcpierce/unison/),
which must be installed in your path.

## Start syncing Folders in repeat mode

Run `vagrant sync-repeat` to start in bidirect monitor (repeat) mode.

## Development

To work on the `vagrant-unison` plugin, clone this repository out, and use
Expand Down
57 changes: 57 additions & 0 deletions lib/vagrant-unison/command.rb
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,62 @@ def trigger_unison_sync(machine)
end

end
class CommandRepeat < Vagrant.plugin("2", :command)

def execute

with_target_vms do |machine|
hostpath, guestpath = init_paths machine

trigger_unison_sync machine

end

0 #all is well
end

def init_paths(machine)
hostpath = File.expand_path(machine.config.sync.host_folder, @env.root_path)
guestpath = machine.config.sync.guest_folder

# Make sure there is a trailing slash on the host path to
# avoid creating an additional directory with rsync
hostpath = "#{hostpath}/" if hostpath !~ /\/$/

[hostpath, guestpath]
end

def trigger_unison_sync(machine)
hostpath, guestpath = init_paths machine

@env.ui.info "Unisoning changes from {host}::#{hostpath} --> {guest VM}::#{guestpath}"

ssh_info = machine.ssh_info

# Create the guest path
machine.communicate.sudo("mkdir -p '#{guestpath}'")
machine.communicate.sudo("chown #{ssh_info[:username]} '#{guestpath}'")

proxy_command = ""
if ssh_info[:proxy_command]
proxy_command = "-o ProxyCommand='#{ssh_info[:proxy_command]}' "
end

rsh = [
"-p #{ssh_info[:port]} " +
proxy_command +
"-o StrictHostKeyChecking=no " +
"-o UserKnownHostsFile=/dev/null",
ssh_info[:private_key_path].map { |p| "-i #{p}" },
].flatten.join(" ")

# Unison over to the guest path using the SSH info
command = "unison -terse -repeat 1 -sshargs \"#{rsh}\" hosts ssh://#{ssh_info[:username]}@#{ssh_info[:host]}/#{guestpath}"
@env.ui.info "Running #{command}"

system(command)
end

end
end
end
10 changes: 10 additions & 0 deletions lib/vagrant-unison/plugin.rb
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ class Plugin < Vagrant.plugin("2")
Command
end

command "sync-repeat" do
# Setup logging and i18n
setup_logging
setup_i18n

#Return the command
require_relative "command"
CommandRepeat
end

# This initializes the internationalization strings.
def self.setup_i18n
I18n.load_path << File.expand_path("locales/en.yml", Unison.source_root)
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-unison/version.rb
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module VagrantPlugins
module Unison
VERSION = "0.0.11"
VERSION = "0.0.12"
end
end

0 comments on commit 90e254a

Please sign in to comment.