From 90e254a6a7a1be51e94ba341c62ed32a86d24a79 Mon Sep 17 00:00:00 2001 From: dmatora Date: Fri, 9 Jan 2015 00:16:26 +0300 Subject: [PATCH] Implemented repeat mode --- .gitignore | 1 + README.md | 4 +++ lib/vagrant-unison/command.rb | 57 +++++++++++++++++++++++++++++++++++ lib/vagrant-unison/plugin.rb | 10 ++++++ lib/vagrant-unison/version.rb | 2 +- 5 files changed, 73 insertions(+), 1 deletion(-) mode change 100755 => 100644 lib/vagrant-unison/command.rb mode change 100755 => 100644 lib/vagrant-unison/plugin.rb mode change 100755 => 100644 lib/vagrant-unison/version.rb diff --git a/.gitignore b/.gitignore index cdb1aa8..78045c7 100755 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ Vagrantfile # IDEs .project +.idea diff --git a/README.md b/README.md index e7aa498..883ec23 100755 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/vagrant-unison/command.rb b/lib/vagrant-unison/command.rb old mode 100755 new mode 100644 index 56f1573..33f832a --- a/lib/vagrant-unison/command.rb +++ b/lib/vagrant-unison/command.rb @@ -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 \ No newline at end of file diff --git a/lib/vagrant-unison/plugin.rb b/lib/vagrant-unison/plugin.rb old mode 100755 new mode 100644 index 42f55f5..f8b7ea8 --- a/lib/vagrant-unison/plugin.rb +++ b/lib/vagrant-unison/plugin.rb @@ -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) diff --git a/lib/vagrant-unison/version.rb b/lib/vagrant-unison/version.rb old mode 100755 new mode 100644 index 43da8f7..963644e --- a/lib/vagrant-unison/version.rb +++ b/lib/vagrant-unison/version.rb @@ -1,5 +1,5 @@ module VagrantPlugins module Unison - VERSION = "0.0.11" + VERSION = "0.0.12" end end