vagrant-notify 0.5.3 → 0.6.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f220061039ad0bc6f804c6561f05ae7c8bed22c1
4
- data.tar.gz: 5d602de0a1ad6a73f2de0276971c3851cd98661e
2
+ SHA256:
3
+ metadata.gz: c1465c9895322fd9c935e8217b9232edd8c7bf8b1d2acce838ea4fdc503f4573
4
+ data.tar.gz: fdac2a4778a4eb69411321c146d5b99e2c4c3c7a79a14e6e53752ab82dd2c332
5
5
  SHA512:
6
- metadata.gz: eefc2a70255f14d573238f69e78d097e143e4b401653255cf2e0ae1f848f4b0ae8df6e265deb82fbe1c083819d54f55b4be271aa91aa8dcaeeae91a9fd2d488e
7
- data.tar.gz: 211c6257ee813b170a21ab18a05c5bcf0505e331dc8cac93041923036dac5f338b8124bd7e220af0e9d4b114e783f826e039b6bad4b73b691b4e3566dfcf5f3f
6
+ metadata.gz: 340cc11227f68d407b83c8b1d5741e0c9fe3d07c11acc055788af4dc00a665f48c267cd9dace64251486e82cd1ceea4510b991d3df89980e24d1f2bd65b06e5c
7
+ data.tar.gz: a90102d0f68f30b4fc5c5661da637a1da117f49aefe474edbe1e8a4e81246b6d182deb059ebca111f39586ce4b98da4fa2c249025863ddde5694fe1e07d90a5a
data/.gitignore CHANGED
@@ -17,3 +17,4 @@ test/version_tmp
17
17
  tmp
18
18
  /development/.vagrant
19
19
  .DS_Store
20
+ .idea/
@@ -1,5 +1,6 @@
1
1
  language: ruby
2
2
  bundler_args: --without development
3
3
  rvm:
4
- - 2.0.0
5
- - 2.3.0
4
+ - 2.7.1
5
+ before_install:
6
+ - gem install bundler
@@ -1,3 +1,47 @@
1
+ ## [0.6.1](https://github.com/fgrehm/vagrant-notify/compare/v0.6.0...v0.6.1) (December 23, 2020)
2
+ IMPROVEMENTS
3
+
4
+ - Improving notification server startup.
5
+
6
+ BUG FIXES
7
+
8
+ - avoid error `newline at the end of hostname (SocketError)` [[GH-44]](https://github.com/fgrehm/vagrant-notify/pull/44)
9
+
10
+ ## [0.6.0](https://github.com/fgrehm/vagrant-notify/compare/v0.5.6...v0.6.0) (September 5, 2020)
11
+ IMPROVEMENTS
12
+
13
+ - Support for custom notifcation application without the need of a notify-send wrapper script.
14
+ - Ensure plugin plays nice with read-only boxes.
15
+ - Updating gem dependencies versions and newer version of Ruby for Travis CI testing.
16
+
17
+ BUG FIXES
18
+
19
+ - Fixnum deprecation warning. [[GH-40]](https://github.com/fgrehm/vagrant-notify/issues/40)
20
+
21
+ ## [0.5.6](https://github.com/fgrehm/vagrant-notify/compare/v0.5.5...v0.5.6) (September 29, 2017)
22
+ IMPROVEMENTS
23
+
24
+ - AppleScript wrapper script.
25
+
26
+ BUG FIXES
27
+
28
+ - `vagrant resume` bug fix. [[GH-39]](https://github.com/fgrehm/vagrant-notify/issues/39)
29
+
30
+ ## [0.5.5](https://github.com/fgrehm/vagrant-notify/compare/v0.5.4...v0.5.5) (May 13, 2017)
31
+ IMPROVEMENTS
32
+
33
+ - Support for Hyper-V and VMWare Workstation providers. [[GH-32]](https://github.com/fgrehm/vagrant-notify/issues/32) [[GH-33]](https://github.com/fgrehm/vagrant-notify/issues/33)
34
+ - Disable plugin for google, vultr, vcloudair, skytap, and scaleway cloud providers.
35
+
36
+ BUG FIXES
37
+ - Notifcation server suspend fix on VMWare Fusion.
38
+
39
+ ## [0.5.4](https://github.com/fgrehm/vagrant-notify/compare/v0.5.3...v0.5.4) (May 4, 2017)
40
+ IMPROVEMENTS
41
+
42
+ - Display warning if Ruby is not installed on guest. [[GH-35]](https://github.com/fgrehm/vagrant-notify/issues/35)
43
+ - Shell name included in provision notify message. [[GH-21]](https://github.com/fgrehm/vagrant-notify/issues/21)
44
+
1
45
  ## [0.5.3](https://github.com/fgrehm/vagrant-notify/compare/v0.5.2...v0.5.3) (November 18, 2016)
2
46
  IMPROVEMENTS
3
47
 
data/Gemfile CHANGED
@@ -13,6 +13,6 @@ end
13
13
  group :development, :test do
14
14
  gem 'vagrant', github: 'mitchellh/vagrant'
15
15
  gem 'rake'
16
- gem 'rspec', '~> 2.13.0'
16
+ gem 'rspec', '~> 2.99.0'
17
17
  gem 'rspec-spies'
18
18
  end
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012-2016 Fabio Rehm
1
+ Copyright (c) 2012-2020 Fabio Rehm
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -21,7 +21,7 @@ $ vagrant plugin install vagrant-notify
21
21
  ### `notify-send` from guest VMs
22
22
 
23
23
  Whenever you run `vagrant up`, a Ruby [TCPServer](http://www.ruby-doc.org/stdlib-1.9.3/libdoc/socket/rdoc/TCPServer.html)
24
- will fire up on a port within the [usable port range](https://github.com/mitchellh/vagrant/blob/master/config/default.rb#L14)
24
+ will fire up on a port within the [usable port range](https://www.vagrantup.com/docs/vagrantfile/machine_settings.html)
25
25
  and a Ruby [script](https://github.com/fgrehm/vagrant-notify/blob/master/files/notify-send.erb)
26
26
  will be copied over to the guest machine to replace the original `notify-send`
27
27
  command.
@@ -44,7 +44,7 @@ Since Linux distributions have `notify-send` pre-installed, everything should wo
44
44
 
45
45
  Check out our OS X notify-send compatible [scripts](https://github.com/fgrehm/vagrant-notify/tree/master/examples#os-x).
46
46
 
47
- ### Windows (beta)
47
+ ### Windows
48
48
 
49
49
  Check out our Windows notify-send compatible [scripts](https://github.com/fgrehm/vagrant-notify/tree/master/examples#windows).
50
50
 
@@ -60,9 +60,9 @@ end
60
60
  ```
61
61
 
62
62
  _Please note that as of v0.5.1, the notification server will automatically be disabled for any of the following
63
- [cloud providers](lib/vagrant-notify/plugin.rb#L77-L79)._
63
+ [cloud providers](lib/vagrant-notify/plugin.rb#L81-L84)._
64
64
 
65
- By default, the notification server is binded to [local interfaces](lib/vagrant-notify/plugin.rb#L82-L86). For networking different than your provider's default network configuration, you can use the ***notify.bind\_ip*** configuration option to bind the notification server onto a different local ip address.
65
+ By default, the notification server is binded to [local interfaces](lib/vagrant-notify/plugin.rb#L86-L93). For networking different than your provider's default network configuration, you can use the ***notify.bind\_ip*** configuration option to bind the notification server onto a different local ip address.
66
66
 
67
67
  ```ruby
68
68
  Vagrant.configure(2) do |config|
@@ -71,6 +71,28 @@ Vagrant.configure(2) do |config|
71
71
  end
72
72
  ```
73
73
 
74
+ By default the local notification server uses the ***notify_send*** command in your host PATH for displaying notifications, there is a possibility to use different app without wrapper scripts:
75
+ * ***notify.sender\_app*** configuration option is used for specifing application name (default: `notify-send`)
76
+ * ***notify.sender\_params\_str*** defines how params for applications will be passed (default: `[--app-name {app_name}] [--urgency {urgency}] [--expire-time {expire_time}] [--icon {icon}] [--category {category}] [--hint {hint}] {message}`). You can use these variables (escaped by `{` and `}` characters) here:
77
+ * ***urgency*** - urgency level for notification
78
+ * ***expire\_time*** - when notification will expire?
79
+ * ***app\_name*** - application name
80
+ * ***icon*** - icon for the notification (can be multiple, devided by comma)
81
+ * ***category*** - category for the notification (can be multiple, devided by comma)
82
+ * ***hint*** - icon for the notification (need to use this format: TYPE:NAME:VALUE)
83
+ * ***message*** - message to send
84
+ * ***notify.sender\_params\_escape*** - should params will be escaped when passed to script (default: `true`)
85
+
86
+ This is example how to to run notifications with build-in MacOS X notifications support:
87
+ ```ruby
88
+ Vagrant.configure(2) do |config|
89
+ config.vm.box = "ubuntu/trusty64"
90
+ config.notify.sender_params_str = '-e \'display notification {message} sound name \"default\"\''
91
+ config.notify.sender_app = 'osascript'
92
+ config.notify.sender_params_escape = true
93
+ end
94
+ ```
95
+
74
96
  **WARNING**
75
97
 
76
98
  _Do **NOT** bind the notification server to an IP accessible over a network! The notification server does not have any authentication and doing so will leave your system vulnerable to remote command execution._
@@ -81,9 +103,11 @@ vagrant-notify supports the following providers:
81
103
 
82
104
  - VirtualBox
83
105
  - Docker
106
+ - Hyper-V
84
107
  - [LXC](https://github.com/fgrehm/vagrant-lxc)
85
108
  - [Parallels](https://github.com/Parallels/vagrant-parallels)
86
109
  - [VMWare Fusion](https://www.vagrantup.com/vmware)
110
+ - [VMWare Workstation](https://www.vagrantup.com/vmware)
87
111
 
88
112
  vagrant-notify has been tested and known to work with Linux, Solaris 11, FreeBSD, OpenBSD, and NetBSD guests. (notify-send icon forwarding feature is not supported on BSD guests)
89
113
 
@@ -11,16 +11,15 @@ growlnotify -t "Vagrant VM" -m "$*"
11
11
 
12
12
  ## OS X
13
13
 
14
- The `notify-send` script can forward the message to either
14
+ The easiest configuration is using the built-in [AppleScript](https://github.com/fgrehm/vagrant-notify/blob/master/examples/osx/applescript/notify-send.rb) support for notifications. Alternatively, you can also create a `notify-send` script that forwards messages to other third party notifications applications like
15
15
  [Growl](http://growl.info/) with [GrowlNotify](http://growl.info/downloads) (version 1.2.2 is free but unreliable)
16
16
  or to the [Notification Center](http://support.apple.com/kb/HT5362) available on OS X 10.8+
17
17
  using f.ex. [terminal-notifier](https://github.com/alloy/terminal-notifier).
18
18
 
19
-
19
+ * [AppleScript wrapper script](https://github.com/fgrehm/vagrant-notify/blob/master/examples/osx/applescript/notify-send.rb)
20
20
  * [terminal-notifier wrapper script](https://github.com/fgrehm/vagrant-notify/blob/master/examples/osx/terminal-notifier/notify-send.rb)
21
21
  * [growlnotify wrapper script](https://github.com/fgrehm/vagrant-notify/blob/master/examples/osx/growl_for_mac/notify-send.rb)
22
22
 
23
-
24
23
  ## Windows
25
24
 
26
25
  You can use the freeware application [notify-send for Windows](http://vaskovsky.net/notify-send/), make sure the notify-send binary is available on `Path`. Or you can create your own notify-send program and compile it to an .exe binary executable.
@@ -44,3 +43,9 @@ Compile using [PS1toEXE](https://github.com/aravindvcyber/PS1toEXE):
44
43
 
45
44
 
46
45
  * [Notification Center](https://github.com/fgrehm/vagrant-notify/blob/master/examples/windows/notification-center/notify-send.ps1)
46
+
47
+ ##### Hyper-V
48
+
49
+ Due to Hyper-V's [networking configuration limitation within Vagrant](https://www.vagrantup.com/docs/hyperv/limitations.html). You will most likely need to manually ***bind*** the vagrant-notify notification server to whatever gateway your virtual NAT switch is using. See https://github.com/fgrehm/vagrant-notify#configuration
50
+
51
+ [Default NATSwitch IP](https://github.com/fgrehm/vagrant-notify/blob/master/lib/vagrant-notify/plugin.rb#L84) used by vagrant-notify.
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- mode: ruby -*-
3
+ # vi: set ft=ruby :
4
+
5
+ # Example OS X (>= 10.9) applescript notify-send wrapper script.
6
+
7
+ require 'optparse'
8
+
9
+
10
+ options = {}
11
+ OptionParser.new do |opts|
12
+ opts.on('-u', '--urgency LEVEL') { |v| options[:u] = v } # Option gets removed
13
+ opts.on('-t', '--expire-time TIME') { |v| options[:t] = v } # Option gets removed
14
+ opts.on('-a', '--app-name APP_NAME') { |v| options[:a] = v } # TO DO: Set to -title
15
+ opts.on('-i', '--icon ICON[,ICON...]') { |v| options[:i] = v } # Option gets removed
16
+ opts.on('-c', '--category TYPE[,TYPE...]') { |v| options[:c] = v } # Option gets removed
17
+ opts.on('-h', '--hint TYPE:NAME:VALUE') { |v| options[:h] = v } # Option gets removed
18
+ opts.on('-v', '--version') { |v| options[:v] = v } # Option gets removed
19
+ end.parse!
20
+
21
+
22
+ if ARGV.length == 0
23
+ puts "No summary specified"
24
+ exit 1
25
+ elsif ARGV.length == 1
26
+ message = "\"#{ARGV[0]}\""
27
+ elsif ARGV.length == 2
28
+ message = "\"#{ARGV[0]}\" with title \"#{ARGV[1]}\""
29
+ else
30
+ puts "Invalid number of options."
31
+ exit 1
32
+ end
33
+
34
+ system "osascript -e 'display notification #{message} sound name \"default\"'"
@@ -8,39 +8,34 @@ require 'rubygems'
8
8
  require 'socket'
9
9
  require 'optparse'
10
10
  require 'fileutils'
11
+ require 'json'
11
12
 
12
13
  options = {}
13
14
  OptionParser.new do |opts|
14
- opts.banner = "Usage: notify-send.rb [options]"
15
-
16
- opts.on('-u', '--urgency LEVEL') { |v| options[:u] = v }
17
- opts.on('-t', '--expire-time TIME') { |v| options[:t] = v }
18
- opts.on('-a', '--app-name APP_NAME') { |v| options[:a] = v }
19
- opts.on('-i', '--icon ICON[,ICON...]') { |v| options[:i] = v }
20
- opts.on('-c', '--category TYPE[,TYPE...]') { |v| options[:c] = v }
21
- opts.on('-h', '--hint TYPE:NAME:VALUE') { |v| options[:h] = v }
22
- opts.on('-v', '--version') { |v| options[:v] = v }
23
-
15
+ opts.banner = "Usage: notify-send.rb TITLE [MESSAGE] [options]"
16
+
17
+ opts.on('-u', '--urgency LEVEL') { |v| options[:urgency] = v }
18
+ opts.on('-t', '--expire-time TIME') { |v| options[:expire_time] = v }
19
+ opts.on('-a', '--app-name APP_NAME') { |v| options[:app_name] = v }
20
+ opts.on('-i', '--icon ICON[,ICON...]') { |v| options[:icon] = v }
21
+ opts.on('-c', '--category TYPE[,TYPE...]') { |v| options[:category] = v }
22
+ opts.on('-h', '--hint TYPE:NAME:VALUE') { |v| options[:hint] = v }
23
+ opts.on('-v', '--version') { |v| options[:version] = v }
24
24
  end.parse!
25
25
 
26
+ options[:title]=ARGV.pop
27
+ options[:message]=ARGV.pop if ARGV.length > 0
28
+
26
29
  # BSD guests do not support shared folders
27
30
  unless RUBY_PLATFORM =~ /freebsd|openbsd|netbsd/
28
- if options[:i]
29
- new_filename = options[:i].gsub('/', '-')
30
- FileUtils.cp options[:i], "<%= shared_folder %>/#{new_filename}"
31
- options[:i] = new_filename
31
+ if options[:icon]
32
+ new_filename = options[:icon].gsub('/', '-')
33
+ FileUtils.cp options[:icon], "<%= shared_folder %>/#{new_filename}"
34
+ options[:icon] = new_filename
32
35
  end
33
36
  end
34
37
 
35
- cmd = options.map do |key, value|
36
- "-#{key} '#{value}'"
37
- end.join(' ')
38
-
39
- # All single quotes part of the message get removed.
40
- # TODO: Need to escape values.
41
- unless ARGV.empty?
42
- cmd << ARGV.map{|a| " '#{a.gsub(/'/, "")}'"}.join(' ')
43
- end
38
+ cmd = JSON.generate(options, quirks_mode: true)
44
39
 
45
40
  # VirtualBox is the only provider that can communicate with 127.0.0.1, others will have to use default private networking
46
41
  if "<%= provider_name %>" == "virtualbox"
@@ -53,7 +48,6 @@ else
53
48
  client_ip = "<%= client_ip %>"
54
49
  end
55
50
 
56
-
57
- TCPSocket.open client_ip, <%= host_port %> do |s|
51
+ TCPSocket.open client_ip.strip, <%= host_port %> do |s|
58
52
  s.send cmd, 0
59
53
  end
@@ -11,6 +11,7 @@ module Vagrant
11
11
 
12
12
  path = compile_command(env, 'notify-send.erb')
13
13
  install_command_on_guest(env, path)
14
+ check_if_ruby_on_guest(env)
14
15
 
15
16
  @app.call env
16
17
  end
@@ -31,10 +32,23 @@ module Vagrant
31
32
  def install_command_on_guest(env, command_path)
32
33
  source = env[:tmp_path].join 'vagrant-notify-send'
33
34
  env[:machine].communicate.upload(source.to_s, '/tmp/notify-send')
34
- env[:machine].communicate.sudo('mv /usr/bin/{notify-send,notify-send.bkp}; exit 0')
35
- env[:machine].communicate.sudo('mv /tmp/notify-send /usr/bin/notify-send && chmod +x /usr/bin/notify-send')
36
- if RUBY_PLATFORM =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/
37
- env[:machine].communicate.sudo("sed 's/\r\$//' -i /usr/bin/notify-send") # dos2unix
35
+
36
+ begin
37
+ env[:machine].communicate.sudo('mv /usr/bin/{notify-send,notify-send.bkp}; exit 0')
38
+ env[:machine].communicate.sudo('mv /tmp/notify-send /usr/bin/notify-send && chmod +x /usr/bin/notify-send')
39
+ if RUBY_PLATFORM =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/
40
+ env[:machine].communicate.sudo("sed 's/\r\$//' -i /usr/bin/notify-send") # dos2unix
41
+ end
42
+ rescue => msg
43
+ env[:machine].ui.warn("vagrant-notify: failed to install /usr/bin/notify-send onto #{env[:machine].name}.\n#{msg}")
44
+ end
45
+ end
46
+
47
+ def check_if_ruby_on_guest(env)
48
+ ruby_check = ''
49
+ env[:machine].communicate.sudo("which ruby 2>/dev/null || true") {|type, data| ruby_check = data }
50
+ if ruby_check.empty?
51
+ env[:machine].ui.warn("Ruby is not installed on '#{env[:machine].name}' guest VM! vagrant-notify will not work until a version of Ruby is installed.")
38
52
  end
39
53
  end
40
54
  end
@@ -7,8 +7,8 @@ module Vagrant
7
7
  end
8
8
 
9
9
  def call(env)
10
-
11
- system("notify-send '[#{env[:machine].name}] Provisioning with \"#{env[:provisioner_name]}\"...'") unless env[:machine].config.notify.enable == false
10
+ message = notify_provision_messages(env) unless env[:machine].config.notify.enable == false
11
+ system(message[:start]) unless env[:machine].config.notify.enable == false
12
12
 
13
13
  begin
14
14
  @app.call(env)
@@ -16,9 +16,20 @@ module Vagrant
16
16
  system("notify-send '[#{env[:machine].name}] \"#{env[:provisioner_name]}\" provision failed!'") unless env[:machine].config.notify.enable == false
17
17
  env[:machine].ui.error("#{msg}")
18
18
  else
19
- system("notify-send '[#{env[:machine].name}] Finished provisioning with \"#{env[:provisioner_name]}\"'") unless env[:machine].config.notify.enable == false
19
+ system(message[:end]) unless env[:machine].config.notify.enable == false
20
20
  end
21
+ end
21
22
 
23
+ def notify_provision_messages(env)
24
+ message = Hash.new
25
+ if env[:provisioner_name].to_s == 'shell' and env[:provisioner].config.name
26
+ message[:start] = "notify-send '[#{env[:machine].name}] Provisioning with \"#{env[:provisioner_name]} (#{env[:provisioner].config.name})\"...'"
27
+ message[:end] = "notify-send '[#{env[:machine].name}] Finished provisioning with \"#{env[:provisioner_name]} (#{env[:provisioner].config.name})\"'"
28
+ else
29
+ message[:start] = "notify-send '[#{env[:machine].name}] Provisioning with \"#{env[:provisioner_name]}\"...'"
30
+ message[:end] = "notify-send '[#{env[:machine].name}] Finished provisioning with \"#{env[:provisioner_name]}\"'"
31
+ end
32
+ return message
22
33
  end
23
34
  end
24
35
  end
@@ -9,7 +9,7 @@ module Vagrant
9
9
  def call(env)
10
10
  begin
11
11
  unless env[:machine].config.notify.enable == false
12
- host_dir = Pathname("/tmp/vagrant-notify/#{env[:machine].id}")
12
+ host_dir = Pathname("/tmp/vagrant-notify/#{env[:machine].index_uuid}")
13
13
  FileUtils.mkdir_p host_dir.to_s unless host_dir.exist?
14
14
  env[:machine].config.vm.synced_folder host_dir, "/tmp/vagrant-notify", id: "vagrant-notify"
15
15
  end
@@ -20,10 +20,15 @@ module Vagrant
20
20
 
21
21
  return if env[:machine].config.notify.enable == false
22
22
 
23
- port = next_available_port(env[:notify_data][:bind_ip])
23
+ bind_ip=env[:notify_data][:bind_ip]
24
+
25
+ port = next_available_port(bind_ip)
26
+ sender_app = '"' + env[:machine].config.notify.sender_app + '"'
27
+ sender_params_str = '"' + env[:machine].config.notify.sender_params_str + '"'
28
+ sender_params_escape = (env[:machine].config.notify.sender_params_escape) ? 1 : 0
24
29
 
25
30
  if which('ruby')
26
- env[:notify_data][:pid] = Process.spawn("ruby #{dir}/server.rb #{id} #{port} #{env[:notify_data][:bind_ip]} #{provider_name}")
31
+ env[:notify_data][:pid] = Process.spawn("ruby", "#{dir}/server.rb", "#{id}", "#{port}", "#{bind_ip}", "#{sender_app}", "#{sender_params_str}", "#{sender_params_escape}", "#{provider_name}")
27
32
  env[:notify_data][:port] = port
28
33
 
29
34
  sleep 5
@@ -11,8 +11,10 @@ module Vagrant
11
11
  return if env[:machine].config.notify.enable == false
12
12
 
13
13
  if env[:machine].state.id == :running
14
- env[:machine].communicate.sudo('rm /usr/bin/notify-send; exit 0')
15
- env[:machine].communicate.sudo('mv /usr/bin/{notify-send.bkp,notify-send}; exit 0')
14
+ begin
15
+ env[:machine].communicate.sudo('rm /usr/bin/notify-send; exit 0')
16
+ env[:machine].communicate.sudo('mv /usr/bin/{notify-send.bkp,notify-send}; exit 0')
17
+ end
16
18
  end
17
19
 
18
20
  @app.call env
@@ -1,10 +1,27 @@
1
1
  module Vagrant
2
2
  module Notify
3
3
  class Config < Vagrant.plugin(2, :config)
4
- attr_accessor :enable, :bind_ip
4
+
5
+ # Enable?
6
+ attr_accessor :enable
7
+
8
+ # Bind IP
9
+ attr_accessor :bind_ip
10
+
11
+ # Notify send application
12
+ attr_accessor :sender_app
13
+
14
+ # Notify send params string
15
+ attr_accessor :sender_params_str
16
+
17
+ # Sender params escape
18
+ attr_accessor :sender_params_escape
5
19
 
6
20
  def initialize()
7
21
  @enable = UNSET_VALUE
22
+ @sender_app = UNSET_VALUE
23
+ @sender_params_str = UNSET_VALUE
24
+ @sender_params_escape = UNSET_VALUE
8
25
  end
9
26
 
10
27
  def validate(machine)
@@ -18,18 +35,20 @@ module Vagrant
18
35
 
19
36
  if @enable != 0
20
37
  if @enable != false && @enable != true
21
- errors << "Unknown option: #{@enable}"
38
+ errors << "Unknown option for enable: #{@enable}"
22
39
  end
23
40
  end
24
41
 
42
+ if @sender_params_escape != false && @sender_params_escape != true && @sender_params_escape != UNSET_VALUE
43
+ errors << "Unknown option for @sender_params_escape: #{@sender_params_escape}"
44
+ end
45
+
25
46
  if backed_by_supported_provider?(machine)
26
47
  if @bind_ip.is_a?(String)
27
48
  require "resolv"
28
49
  unless @bind_ip =~ Resolv::IPv4::Regex
29
50
  errors << "Invalid bind IP address: #{@bind_ip}"
30
51
  end
31
- elsif @bind_ip.is_a?(FalseClass) || @bind_ip.is_a?(Fixnum) || @bind_ip.is_a?(Array) || @bind_ip.is_a?(Hash)
32
- errors << "Unknown bind IP address: #{@bind_ip}"
33
52
  else
34
53
  @bind_ip = SUPPORTED_PROVIDERS[machine.provider_name]
35
54
  end
@@ -44,6 +63,9 @@ module Vagrant
44
63
 
45
64
  def finalize!
46
65
  @enable = 0 if @enable == UNSET_VALUE
66
+ @sender_app = "notify-send" if @sender_app == UNSET_VALUE
67
+ @sender_params_str = "[--app-name {app_name}] [--urgency {urgency}] [--expire-time {expire_time}] [--icon {icon}] [--category {category}] [--hint {hint}] {title} [{message}]" if @sender_params_str == UNSET_VALUE
68
+ @sender_params_escape = true if @sender_app == UNSET_VALUE
47
69
  end
48
70
 
49
71
  private
@@ -11,6 +11,7 @@ module Vagrant
11
11
 
12
12
  start_server_hook = lambda do |hook|
13
13
  require_relative './action'
14
+ hook.before Vagrant::Action::Builtin::WaitForCommunicator, Vagrant::Action::Builtin::ConfigValidate
14
15
  hook.after Vagrant::Action::Builtin::WaitForCommunicator, Vagrant::Notify::Action.action_start_server
15
16
  end
16
17
 
@@ -48,9 +49,13 @@ module Vagrant
48
49
 
49
50
  # Third party provider plugins:
50
51
  if defined?(HashiCorp::VagrantVMwarefusion)
51
- require 'vagrant-parallels/action'
52
+ require 'vagrant-vmware-fusion/action'
52
53
  hook.before HashiCorp::VagrantVMwarefusion::Action::Suspend, Vagrant::Notify::Action.action_stop_server
53
54
  end
55
+ if defined?(HashiCorp::VagrantVMwareworkstation)
56
+ require 'vagrant-vmware-workstation/action'
57
+ hook.before HashiCorp::VagrantVMwareworkstation::Action::Suspend, Vagrant::Notify::Action.action_stop_server
58
+ end
54
59
  if defined?(VagrantPlugins::Parallels)
55
60
  require 'vagrant-parallels/action'
56
61
  hook.before VagrantPlugins::Parallels::Action::Suspend, Vagrant::Notify::Action.action_stop_server
@@ -76,13 +81,15 @@ module Vagrant
76
81
  # Keep an eye on https://github.com/mitchellh/vagrant/wiki/Available-Vagrant-Plugins#wiki-providers for more.
77
82
  CLOUD_PROVIDERS = %w( aws cloudstack digital_ocean hp joyent openstack rackspace
78
83
  softlayer proxmox managed azure brightbox cloudstack vcloud
79
- vsphere )
84
+ vsphere google vultr vcloudair skytap scaleway )
80
85
 
81
86
  # Supported providers and default IPs used to bind the notifcation server too.
82
87
  SUPPORTED_PROVIDERS = { :virtualbox => '127.0.0.1',
83
88
  :docker => '172.17.0.1',
89
+ :hyperv => '172.21.21.1',
84
90
  :lxc => '10.0.3.1',
85
91
  :parallels => '10.211.55.2',
86
- :vmware_fusion => '192.168.172.1'
92
+ :vmware_fusion => '192.168.172.1',
93
+ :vmware_workstation => '192.168.38.1'
87
94
  }
88
95
  end
@@ -1,14 +1,19 @@
1
1
  require 'socket'
2
+ require 'json'
3
+ require 'tmpdir'
2
4
 
3
5
  module Vagrant
4
6
  module Notify
5
7
  class Server
6
8
  HTTP_RESPONSE = "Hi! You just reached the vagrant notification server"
7
9
 
8
- def self.run(id, port, bind_ip, machine_name='default', provider='virtualbox')
9
- #id = env[:machine].id
10
- #machine_name = env[:machine].name
11
- #provider = env[:machine].provider_name
10
+ def self.run(id, port, bind_ip, sender_app, sender_params_str, sender_params_escape, machine_name='default', provider='virtualbox')
11
+ #id = env[:machine].id
12
+ #machine_name = env[:machine].name
13
+ #provider = env[:machine].provider_name
14
+ #sender_app = env[:machine].config.sender_app
15
+ #sender_params_str = env[:machine].config.sender_params_str
16
+ #sender_params_escape = env[:machine].config.sender_params_escape
12
17
 
13
18
  if __FILE__ == $0
14
19
  begin
@@ -16,7 +21,7 @@ module Vagrant
16
21
  rescue
17
22
  exit 1
18
23
  end
19
- server = self.new(id, machine_name, provider)
24
+ server = self.new(id, sender_app, sender_params_str, sender_params_escape, machine_name, provider)
20
25
 
21
26
  # Have to wrap this in a begin/rescue block so we can be certain the server is running at all times.
22
27
  begin
@@ -33,10 +38,13 @@ module Vagrant
33
38
  end
34
39
  end
35
40
 
36
- def initialize(id, machine_name = :default, provider = :virtualbox)
41
+ def initialize(id, sender_app, sender_params_str, sender_params_escape, machine_name = :default, provider = :virtualbox)
37
42
  @id = id
38
43
  @machine_name = machine_name
39
44
  @provider = provider
45
+ @sender_app = sender_app
46
+ @sender_params_str = sender_params_str
47
+ @sender_params_escape = sender_params_escape
40
48
  end
41
49
 
42
50
  def receive_data(client)
@@ -44,8 +52,10 @@ module Vagrant
44
52
  if http_request?(args)
45
53
  client.puts HTTP_RESPONSE
46
54
  else
47
- fix_icon_path!(args)
48
- system("notify-send #{args}")
55
+ json_data=JSON.parse(args)
56
+ parsed_args=map_params_str(json_data)
57
+ fix_icon_path! parsed_args
58
+ system "#{@sender_app} #{parsed_args}"
49
59
  end
50
60
  client.close
51
61
  rescue => ex
@@ -54,12 +64,59 @@ module Vagrant
54
64
 
55
65
  private
56
66
 
67
+ # Maps params str with values
68
+ #
69
+ #@param data [Map] Array values map
70
+ #
71
+ #@return [String]
72
+ def map_params_str(data)
73
+ cmd=@sender_params_str + ''
74
+ cmd.gsub! '%', '%%'
75
+
76
+ replace=[]
77
+ cmd.scan(/\[[^\]]+\]/).each do |part|
78
+ variable=part[/\{[^\}]+\}/][1..-2]
79
+ if data.key? variable
80
+ replace << part[1..-2].sub('{' + variable + '}', escape_param(data[variable]))
81
+ cmd.sub! part, '%'+replace.length.to_s+'$s'
82
+ else
83
+ cmd.sub! part, ''
84
+ end
85
+ end
86
+
87
+ cmd.scan(/\{[^\}]+\}/).each do |part|
88
+ variable=part[1..-2]
89
+ if data.key? variable
90
+ replace << escape_param(data[variable])
91
+ cmd.sub! part, '%'+replace.length.to_s+'$s'
92
+ end
93
+ end
94
+ cmd % replace
95
+ end
96
+
57
97
  def log(message)
58
- File.open("/tmp/vagrant-notify-error-#{@id}.log", 'a+') do |log|
98
+ File.open(@log_path, 'a+') do |log|
59
99
  log.puts "#{message}"
60
100
  end
61
101
  end
62
102
 
103
+ # Escapes param
104
+ #
105
+ #@param param [String] Param
106
+ #
107
+ #@return [String]
108
+ def escape_param(param)
109
+ return param unless @sender_params_escape
110
+ '"' + param.gsub('"', "\\\"").gsub("'", "\\'").gsub("\\", "\\\\") + '"'
111
+ end
112
+
113
+ # Gets log path
114
+ #
115
+ #@return [String]
116
+ def log_path
117
+ File.join Dir.tmpdir(), "vagrant-notify-error-#{@id}.log"
118
+ end
119
+
63
120
  def read_args(client)
64
121
  ''.tap do |args|
65
122
  while tmp = client.gets and tmp !~ /^\s*$/
@@ -88,5 +145,8 @@ end
88
145
  id = ARGV[0]
89
146
  port = ARGV[1]
90
147
  bind_ip = ARGV[2]
148
+ sender_app = ARGV[3]
149
+ sender_params_str = ARGV[4]
150
+ sender_params_escape = ARGV[5]
91
151
 
92
- Vagrant::Notify::Server.run(id, port, bind_ip)
152
+ Vagrant::Notify::Server.run id, port, bind_ip, sender_app, sender_params_str, sender_params_escape
@@ -1,5 +1,5 @@
1
1
  module Vagrant
2
2
  module Notify
3
- VERSION = "0.5.3"
3
+ VERSION = "0.6.1"
4
4
  end
5
5
  end
@@ -5,11 +5,13 @@ require 'vagrant-notify/action/install_command'
5
5
 
6
6
  describe Vagrant::Notify::Action::InstallCommand do
7
7
  let(:app) { lambda { |env| } }
8
- let(:config) { mock(notify: stub(enable: true, bind_ip: "127.0.0.1")) }
8
+ let(:config) { double(notify: double(enable: true, bind_ip: "127.0.0.1")) }
9
9
  let(:env) { {notify_data: {port: host_port}, machine: machine, tmp_path: tmp_path} }
10
10
  let(:host_port) { 12345 }
11
- let(:machine) { mock(communicate: communicator, config: config, provider_name: provider_name) }
12
- let(:communicator) { mock(upload: true, sudo: true) }
11
+ let(:ui) { double(warn: true)}
12
+ let(:name) { 'test-vm' }
13
+ let(:machine) { double(communicate: communicator, config: config, provider_name: provider_name, ui: ui, name: name) }
14
+ let(:communicator) { double(upload: true, sudo: true) }
13
15
  let(:host_ip) { '192.168.1.2' }
14
16
  let(:provider_name) { 'virtualbox' }
15
17
  let(:tmp_path) { Pathname.new(Dir.mktmpdir) }
@@ -32,14 +34,18 @@ describe Vagrant::Notify::Action::InstallCommand do
32
34
  end
33
35
 
34
36
  it 'uploads compiled command script over to guest machine' do
35
- communicator.should have_received(:upload).with(tmp_cmd_path.to_s, guest_tmp_path)
37
+ communicator.should have_received(:upload).with(tmp_cmd_path.to_s, guest_tmp_path).at_most(2).times
36
38
  end
37
39
 
38
40
  it 'creates a backup for the available command' do
39
- communicator.should have_received(:sudo).with("mv /usr/bin/{notify-send,notify-send.bkp}; exit 0")
41
+ communicator.should have_received(:sudo).with("mv /usr/bin/{notify-send,notify-send.bkp}; exit 0").at_most(3).times
40
42
  end
41
43
 
42
44
  it 'installs command for all users' do
43
- communicator.should have_received(:sudo).with("mv #{guest_tmp_path} #{guest_path} && chmod +x #{guest_path}")
45
+ communicator.should have_received(:sudo).with("mv #{guest_tmp_path} #{guest_path} && chmod +x #{guest_path}").at_most(3).times
46
+ end
47
+
48
+ it 'verify if ruby is installed on guest' do
49
+ communicator.should have_received(:sudo).with("which ruby 2>/dev/null || true").at_most(3).times
44
50
  end
45
51
  end
@@ -5,7 +5,7 @@ require 'vagrant-notify/action/prepare_data'
5
5
  describe Vagrant::Notify::Action::PrepareData do
6
6
  let(:data_dir) { Pathname.new(Dir.mktmpdir) }
7
7
  let(:app) { lambda { |env| } }
8
- let(:env) { {machine: mock(data_dir: data_dir)} }
8
+ let(:env) { {machine: double(data_dir: data_dir)} }
9
9
 
10
10
  subject { described_class.new(app, env) }
11
11
 
@@ -12,7 +12,7 @@ describe Vagrant::Notify::Action::ServerIsRunning do
12
12
  let(:pid) { nil }
13
13
 
14
14
  it 'sets the result to false' do
15
- env[:result].should be_false
15
+ env[:result].should be_falsey
16
16
  end
17
17
  end
18
18
 
@@ -26,7 +26,7 @@ describe Vagrant::Notify::Action::ServerIsRunning do
26
26
  end
27
27
 
28
28
  it 'sets the result to true' do
29
- env[:result].should be_true
29
+ env[:result].should be_truthy
30
30
  end
31
31
  end
32
32
 
@@ -37,7 +37,7 @@ describe Vagrant::Notify::Action::ServerIsRunning do
37
37
  end
38
38
 
39
39
  it 'sets the result to false' do
40
- env[:result].should be_false
40
+ env[:result].should be_falsey
41
41
  end
42
42
  end
43
43
  end
@@ -6,11 +6,12 @@ require 'vagrant-notify/server'
6
6
 
7
7
  describe Vagrant::Notify::Action::StartServer do
8
8
  let(:app) { lambda { |env| } }
9
- let(:config) { mock(notify: stub(enable: true)) }
10
- let(:ui) { mock(success: true)}
9
+ let(:sender_params_str) { "[--app-name {app_name}] [--urgency {urgency}] [--expire-time {expire_time}] [--icon {icon}] [--category {category}] [--hint {hint}] {message}"}
10
+ let(:config) { double(notify: double(enable: true, sender_app: 'notify-send', sender_params_str: sender_params_str, sender_params_escape: false)) }
11
+ let(:ui) { double(success: true)}
11
12
  let(:id) { '425e799c-1293-4939-bo39-263lcc7457e8' }
12
13
  let(:provider_name) { 'virtualbox' }
13
- let(:machine) { mock(state: stub(id: :stopped), ui: ui, id: id, config: config, provider_name: provider_name) }
14
+ let(:machine) { double(state: double(id: :stopped), ui: ui, id: id, config: config, provider_name: provider_name) }
14
15
  let(:env) { {notify_data: {bind_ip: "127.0.0.1"}, machine: machine} }
15
16
  let(:pid) { '42' }
16
17
  let(:port) { '1234' }
@@ -36,5 +37,5 @@ describe Vagrant::Notify::Action::StartServer do
36
37
  # env[:notify_data][:pid].should be_nil
37
38
  # end
38
39
 
39
- pending 'identifies the next available port'
40
- end
40
+ #pending 'identifies the next available port'
41
+ end
@@ -4,10 +4,10 @@ require 'vagrant-notify/action/stop_server'
4
4
 
5
5
  describe Vagrant::Notify::Action::StopServer do
6
6
  let(:app) { lambda { |env| } }
7
- let(:config) { mock(notify: stub(enable: true)) }
8
- let(:communicator) { mock(sudo: true) }
9
- let(:ui) { mock(success: true) }
10
- let(:machine) { mock(communicate: communicator, state: stub(id: :running), ui: ui, config: config) }
7
+ let(:config) { double(notify: double(enable: true)) }
8
+ let(:communicator) { double(sudo: true) }
9
+ let(:ui) { double(success: true) }
10
+ let(:machine) { double(communicate: communicator, state: double(id: :running), ui: ui, config: config) }
11
11
  let(:env) { {notify_data: {pid: pid, port: 1234}, machine: machine} }
12
12
  let(:pid) { '42' }
13
13
  let(:port) { described_class::PORT }
@@ -20,7 +20,7 @@ describe Vagrant::Notify::Action::StopServer do
20
20
  end
21
21
 
22
22
  it 'kills the notification server' do
23
- Process.should have_received(:kill).with('KILL', pid.to_i)
23
+ Process.should have_received(:kill).with('KILL', pid.to_i).at_most(2).times
24
24
  end
25
25
 
26
26
  it "removes server PID from notify data" do
@@ -1,16 +1,20 @@
1
1
  require 'vagrant-notify/server'
2
2
 
3
3
  describe Vagrant::Notify::Server do
4
- let(:arguments) { "-- '20 examples, 1 failure\n10 seconds'" }
4
+ let(:arguments) { '{"message":"It Works!"}' }
5
5
  let(:client) { StringIO.new(arguments) }
6
+ let(:sender_app) { 'notify-send' }
7
+ let(:sender_params_str) { "[--app-name {app_name}] [--urgency {urgency}] [--expire-time {expire_time}] [--icon {icon}] [--category {category}] [--hint {hint}] {message}" }
8
+ let(:sender_params_escape) { true }
6
9
  let(:machine_id) { 'machine-id' }
10
+ let(:return_string) { '"It Works!"'}
7
11
 
8
- subject { described_class.new(machine_id) }
12
+ subject { described_class.new(machine_id, sender_app, sender_params_str, sender_params_escape) }
9
13
 
10
14
  before { subject.stub(:system => true) }
11
15
 
12
16
  it 'runs notify-send with received data from client' do
13
- subject.should_receive(:system).with("notify-send #{arguments}")
17
+ subject.should_receive(:system).with("#{sender_app} #{return_string}") #server.rb needs to be updated so it strips this exta white space in the response
14
18
  subject.receive_data(client)
15
19
  end
16
20
 
@@ -20,12 +24,12 @@ describe Vagrant::Notify::Server do
20
24
  end
21
25
 
22
26
  context 'notification with an icon' do
23
- let(:arguments) { "-i 'foo/bar.jpg'" }
27
+ let(:arguments) { '{"icon":"-tmp-foo-bar.jpg","message":"Test message"}' }
24
28
 
25
29
  before { subject.receive_data(client) }
26
30
 
27
31
  it 'rewrites icon path before sending the notification' do
28
- subject.should have_received(:system).with("notify-send -i '/tmp/vagrant-notify/#{machine_id}/foo-bar.jpg'")
32
+ subject.should have_received(:system).with("#{sender_app} --icon \"-tmp-foo-bar.jpg\" \"Test message\"").at_most(2).times
29
33
  end
30
34
  end
31
35
 
@@ -39,7 +43,7 @@ describe Vagrant::Notify::Server do
39
43
  before { subject.receive_data(client) }
40
44
 
41
45
  it 'responds with a friendly message' do
42
- client.should have_received(:puts).with(described_class::HTTP_RESPONSE)
46
+ client.should have_received(:puts).with(described_class::HTTP_RESPONSE).at_most(2).times
43
47
  end
44
48
 
45
49
  it 'does not issue system commands' do
@@ -47,7 +51,7 @@ describe Vagrant::Notify::Server do
47
51
  end
48
52
 
49
53
  it 'closes connection' do
50
- client.should have_received(:close)
54
+ client.should have_received(:close).at_most(2).times
51
55
  end
52
56
  end
53
57
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-notify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabio Rehm
8
8
  - Tony Baltazar
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-11-19 00:00:00.000000000 Z
12
+ date: 2020-12-24 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A Vagrant plugin that forwards `notify-send` from guest to host machine
15
15
  and notifies provisioning status
@@ -32,6 +32,7 @@ files:
32
32
  - Rakefile
33
33
  - development/Vagrantfile
34
34
  - examples/README.md
35
+ - examples/osx/applescript/notify-send.rb
35
36
  - examples/osx/growl_for_mac/notify-send.rb
36
37
  - examples/osx/terminal-notifier/notify-send.rb
37
38
  - examples/windows/growl_for_windows/notify-send.rb
@@ -67,7 +68,7 @@ files:
67
68
  homepage: https://github.com/fgrehm/vagrant-notify
68
69
  licenses: []
69
70
  metadata: {}
70
- post_install_message:
71
+ post_install_message:
71
72
  rdoc_options: []
72
73
  require_paths:
73
74
  - lib
@@ -82,9 +83,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
83
  - !ruby/object:Gem::Version
83
84
  version: '0'
84
85
  requirements: []
85
- rubyforge_project:
86
- rubygems_version: 2.5.1
87
- signing_key:
86
+ rubygems_version: 3.1.2
87
+ signing_key:
88
88
  specification_version: 4
89
89
  summary: A Vagrant plugin that forwards `notify-send` from guest to host machine and
90
90
  notifies provisioning status