vagrant-notify 0.5.2 → 0.6.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 +5 -5
- data/.gitignore +1 -0
- data/.travis.yml +3 -2
- data/CHANGELOG.md +51 -1
- data/LICENSE.txt +1 -1
- data/README.md +37 -21
- data/examples/README.md +37 -8
- data/examples/osx/applescript/notify-send.rb +34 -0
- data/examples/osx/{notify-send_growl_for_mac → growl_for_mac/notify-send.rb} +0 -0
- data/examples/osx/{notify-send_terminal-notifier → terminal-notifier/notify-send.rb} +0 -0
- data/examples/windows/{notify-send_growl_for_windows → growl_for_windows/notify-send.rb} +0 -0
- data/examples/windows/notification-center/notify-send.ps1 +93 -0
- data/examples/windows/{notify-send_snarl → snarl/notify-send.rb} +0 -0
- data/files/notify-send.erb +18 -24
- data/lib/vagrant-notify/action.rb +2 -1
- data/lib/vagrant-notify/action/install_command.rb +20 -5
- data/lib/vagrant-notify/action/notify_provisioning_status.rb +23 -3
- data/lib/vagrant-notify/action/server_is_running.rb +4 -0
- data/lib/vagrant-notify/action/set_shared_folder.rb +2 -2
- data/lib/vagrant-notify/action/start_server.rb +7 -2
- data/lib/vagrant-notify/action/stop_server.rb +5 -2
- data/lib/vagrant-notify/command.rb +11 -6
- data/lib/vagrant-notify/config.rb +26 -6
- data/lib/vagrant-notify/plugin.rb +10 -3
- data/lib/vagrant-notify/server.rb +70 -10
- data/lib/vagrant-notify/version.rb +1 -1
- data/spec/action/install_command_spec.rb +7 -2
- data/spec/action/server_is_running_spec.rb +1 -1
- data/spec/action/start_server_spec.rb +4 -3
- data/spec/server_spec.rb +9 -5
- metadata +12 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8409030b38ffe90cf4f105a0ca94d95cf3e4a7dfb733cf7eb97d645d98f47cf1
|
4
|
+
data.tar.gz: c0a08020ba70555cbb88a1faad8be6923dcdbf4eea186dade504a1ad497c9825
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac522b11e032bec6c29efd6f49e9d2c570a06247e098a65bbba53a97a850c9ce13812f68a33fd77519c85c6d2c3f0c3a2dcb018a83ece3ced342b0d890d89bb0
|
7
|
+
data.tar.gz: 9b10bfc83de8be00ae61b77e4fa82415df1aaf39374f5e88cbfec267dd4c52a4d32e257d46848c066357c909fb90010016aa324592ce7232711078ba4a37bfa9
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,57 @@
|
|
1
|
+
## [0.6.0](https://github.com/fgrehm/vagrant-notify/compare/v0.5.6...v0.6.0) (September 5, 2020)
|
2
|
+
IMPROVEMENTS
|
3
|
+
|
4
|
+
- Support for custom notifcation application without the need of a notify-send wrapper script.
|
5
|
+
- Ensure plugin plays nice with read-only boxes.
|
6
|
+
- Updating gem dependencies versions and newer version of Ruby for Travis CI testing.
|
7
|
+
|
8
|
+
BUG FIXES
|
9
|
+
|
10
|
+
- Fixnum deprecation warning. [[GH-40]](https://github.com/fgrehm/vagrant-notify/issues/40)
|
11
|
+
|
12
|
+
## [0.5.6](https://github.com/fgrehm/vagrant-notify/compare/v0.5.5...v0.5.6) (September 29, 2017)
|
13
|
+
IMPROVEMENTS
|
14
|
+
|
15
|
+
- AppleScript wrapper script.
|
16
|
+
|
17
|
+
BUG FIXES
|
18
|
+
|
19
|
+
- `vagrant resume` bug fix. [[GH-39]](https://github.com/fgrehm/vagrant-notify/issues/39)
|
20
|
+
|
21
|
+
## [0.5.5](https://github.com/fgrehm/vagrant-notify/compare/v0.5.4...v0.5.5) (May 13, 2017)
|
22
|
+
IMPROVEMENTS
|
23
|
+
|
24
|
+
- 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)
|
25
|
+
- Disable plugin for google, vultr, vcloudair, skytap, and scaleway cloud providers.
|
26
|
+
|
27
|
+
BUG FIXES
|
28
|
+
- Notifcation server suspend fix on VMWare Fusion.
|
29
|
+
|
30
|
+
## [0.5.4](https://github.com/fgrehm/vagrant-notify/compare/v0.5.3...v0.5.4) (May 4, 2017)
|
31
|
+
IMPROVEMENTS
|
32
|
+
|
33
|
+
- Display warning if Ruby is not installed on guest. [[GH-35]](https://github.com/fgrehm/vagrant-notify/issues/35)
|
34
|
+
- Shell name included in provision notify message. [[GH-21]](https://github.com/fgrehm/vagrant-notify/issues/21)
|
35
|
+
|
36
|
+
## [0.5.3](https://github.com/fgrehm/vagrant-notify/compare/v0.5.2...v0.5.3) (November 18, 2016)
|
37
|
+
IMPROVEMENTS
|
38
|
+
|
39
|
+
- Command line operations work on multi-VM configurations.
|
40
|
+
- Notification when provisioning fails. [[GH-23]](https://github.com/fgrehm/vagrant-notify/issues/23)
|
41
|
+
- Do not start notification server if the guest is not running or has not been created.
|
42
|
+
- New Windows 10 notify-send notification center PowerShell script.
|
43
|
+
|
44
|
+
BUG FIXES
|
45
|
+
|
46
|
+
- Correctly identify guest shared folder capability. [[GH-31]](https://github.com/fgrehm/vagrant-notify/issues/31)
|
47
|
+
- Properly manually restart notification server.
|
48
|
+
- Don't send notify-send notices to host when doing a provision if plugin is disabled.
|
49
|
+
|
50
|
+
|
1
51
|
## [0.5.2](https://github.com/fgrehm/vagrant-notify/compare/v0.5.1...v0.5.2) (October 7, 2016)
|
2
52
|
IMPROVEMENTS
|
3
53
|
|
4
|
-
- Support for docker, lxc,
|
54
|
+
- Support for docker, lxc, parallels, and vmware fusion providers. [[GH-13]](https://github.com/fgrehm/vagrant-notify/issues/13)
|
5
55
|
- More reliable notification server status notices.
|
6
56
|
- New `bind_ip` configuration option.
|
7
57
|
|
data/LICENSE.txt
CHANGED
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://
|
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.
|
@@ -42,41 +42,55 @@ Since Linux distributions have `notify-send` pre-installed, everything should wo
|
|
42
42
|
|
43
43
|
### OS X
|
44
44
|
|
45
|
-
You will need to create a `notify-send` script, available on `$PATH`. The script can forward the message to either
|
46
|
-
[Growl](http://growl.info/) with [GrowlNotify](http://growl.info/downloads) (version 1.2.2 is free but unreliable)
|
47
|
-
or to the [Notification Center](http://support.apple.com/kb/HT5362) available on OS X 10.8+
|
48
|
-
using f.ex. [terminal-notifier](https://github.com/alloy/terminal-notifier).
|
49
|
-
|
50
|
-
A (too) primitive script integrating with Growl:
|
51
|
-
|
52
|
-
```bash
|
53
|
-
#!/bin/bash
|
54
|
-
growlnotify -t "Vagrant VM" -m "$*"
|
55
|
-
```
|
56
|
-
|
57
45
|
Check out our OS X notify-send compatible [scripts](https://github.com/fgrehm/vagrant-notify/tree/master/examples#os-x).
|
58
46
|
|
59
|
-
### Windows
|
60
|
-
|
61
|
-
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`.
|
47
|
+
### Windows
|
62
48
|
|
63
49
|
Check out our Windows notify-send compatible [scripts](https://github.com/fgrehm/vagrant-notify/tree/master/examples#windows).
|
64
50
|
|
65
51
|
## Configuration
|
66
52
|
|
67
|
-
Notification server is enabled by default on all guests. You can individually disable the plugin by adding
|
53
|
+
Notification server is enabled by default on all guests. You can individually disable the plugin by adding a false boolean to the ***notify.enable*** option in your `Vagrantfile` configuration block
|
68
54
|
|
69
55
|
```ruby
|
70
|
-
|
56
|
+
Vagrant.configure(2) do |config|
|
57
|
+
config.vm.box = "ubuntu/trusty64"
|
58
|
+
config.notify.enable = false
|
59
|
+
end
|
71
60
|
```
|
72
61
|
|
73
62
|
_Please note that as of v0.5.1, the notification server will automatically be disabled for any of the following
|
74
|
-
[cloud providers](lib/vagrant-notify/plugin.rb#
|
63
|
+
[cloud providers](lib/vagrant-notify/plugin.rb#L81-L84)._
|
64
|
+
|
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.
|
75
66
|
|
76
|
-
|
67
|
+
```ruby
|
68
|
+
Vagrant.configure(2) do |config|
|
69
|
+
config.vm.box = "ubuntu/trusty64"
|
70
|
+
config.notify.bind_ip = "192.68.56.20"
|
71
|
+
end
|
72
|
+
```
|
77
73
|
|
74
|
+
By default local server uses ***notify_send*** command 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:
|
78
87
|
```ruby
|
79
|
-
|
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
|
80
94
|
```
|
81
95
|
|
82
96
|
**WARNING**
|
@@ -89,9 +103,11 @@ vagrant-notify supports the following providers:
|
|
89
103
|
|
90
104
|
- VirtualBox
|
91
105
|
- Docker
|
106
|
+
- Hyper-V
|
92
107
|
- [LXC](https://github.com/fgrehm/vagrant-lxc)
|
93
108
|
- [Parallels](https://github.com/Parallels/vagrant-parallels)
|
94
109
|
- [VMWare Fusion](https://www.vagrantup.com/vmware)
|
110
|
+
- [VMWare Workstation](https://www.vagrantup.com/vmware)
|
95
111
|
|
96
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)
|
97
113
|
|
data/examples/README.md
CHANGED
@@ -1,22 +1,51 @@
|
|
1
1
|
# Example notify-send wrapper scripts
|
2
2
|
|
3
|
+
You will need to create a `notify-send` script, available on `$PATH`.
|
4
|
+
A (too) primitive script integrating with Growl for OS X:
|
5
|
+
|
6
|
+
```bash
|
7
|
+
#!/bin/bash
|
8
|
+
growlnotify -t "Vagrant VM" -m "$*"
|
9
|
+
```
|
10
|
+
|
11
|
+
|
3
12
|
## OS X
|
4
13
|
|
5
|
-
|
6
|
-
|
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
|
+
[Growl](http://growl.info/) with [GrowlNotify](http://growl.info/downloads) (version 1.2.2 is free but unreliable)
|
16
|
+
or to the [Notification Center](http://support.apple.com/kb/HT5362) available on OS X 10.8+
|
17
|
+
using f.ex. [terminal-notifier](https://github.com/alloy/terminal-notifier).
|
7
18
|
|
19
|
+
* [AppleScript wrapper script](https://github.com/fgrehm/vagrant-notify/blob/master/examples/osx/applescript/notify-send.rb)
|
20
|
+
* [terminal-notifier wrapper script](https://github.com/fgrehm/vagrant-notify/blob/master/examples/osx/terminal-notifier/notify-send.rb)
|
21
|
+
* [growlnotify wrapper script](https://github.com/fgrehm/vagrant-notify/blob/master/examples/osx/growl_for_mac/notify-send.rb)
|
8
22
|
|
9
23
|
## Windows
|
10
24
|
|
11
|
-
|
12
|
-
|
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.
|
26
|
+
|
27
|
+
|
28
|
+
Compile using ocra:
|
29
|
+
|
30
|
+
ocra --output notify-send examples/windows/snarl/notify-send.rb
|
31
|
+
|
32
|
+
|
33
|
+
* [Growl for Windows wrapper script](https://github.com/fgrehm/vagrant-notify/blob/master/examples/windows/growl_for_windows/notify-send.rb) (`growlnotify.exe` needs to be is in your `Path`.)
|
34
|
+
* [Snarl wrapper script](https://github.com/fgrehm/vagrant-notify/blob/master/examples/windows/snarl/notify-send.rb)
|
35
|
+
|
36
|
+
### Windows 10
|
37
|
+
|
38
|
+
You can use our [wrapper script](https://github.com/fgrehm/vagrant-notify/blob/master/examples/windows/notification-center/notify-send.ps1) to send messages to the native Windows 10 notification center.
|
39
|
+
|
40
|
+
Compile using [PS1toEXE](https://github.com/aravindvcyber/PS1toEXE):
|
13
41
|
|
14
|
-
|
42
|
+
ps c:> .\PS1toEXE.ps1 -inputfile examples/windows/notification-center/notify-send.ps1 notify-send.exe
|
15
43
|
|
16
44
|
|
17
|
-
* [
|
45
|
+
* [Notification Center](https://github.com/fgrehm/vagrant-notify/blob/master/examples/windows/notification-center/notify-send.ps1)
|
18
46
|
|
19
|
-
|
47
|
+
##### Hyper-V
|
20
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
|
21
50
|
|
22
|
-
|
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\"'"
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,93 @@
|
|
1
|
+
|
2
|
+
# Example Windows 10 Notification Center notify-send wrapper PowerShell script. (I apologize if you find this script a bit messy, PowerShell is not my forte)
|
3
|
+
|
4
|
+
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
|
5
|
+
[Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] > $null
|
6
|
+
[Windows.UI.Notifications.ToastNotification, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
|
7
|
+
|
8
|
+
$arguments = @{};
|
9
|
+
$non_opt = @();
|
10
|
+
$title = "";
|
11
|
+
$message = "";
|
12
|
+
$icon = "";
|
13
|
+
$help = "Usage:
|
14
|
+
notify-send [Options][body]
|
15
|
+
-i, --icon ICON
|
16
|
+
--help
|
17
|
+
";
|
18
|
+
|
19
|
+
|
20
|
+
for ( $i = 0; $i -lt $args.count; $i++ ) {
|
21
|
+
switch -regex ($args[ $i ]) {
|
22
|
+
"^\-u=" { $arguments.Add("-u", $args[ $i ]); } # Option gets ignored
|
23
|
+
"^\-u$" { $arguments.Add("-u", $args[ $i+1 ]); $i+=1; } # Option gets ignored
|
24
|
+
"^\-\-urgency=" { $arguments.Add("-u", $args[ $i ]); } # Option gets ignored
|
25
|
+
"^\-\-urgency$" { $arguments.Add("-u", $args[ $i+1 ]); $i+=1; } # Option gets ignored
|
26
|
+
"^\-t=" { $arguments.Add("-t", $args[ $i ]); } # Option gets ignored
|
27
|
+
"^\-t$" { $arguments.Add("-t", $args[ $i+1 ]); $i+=1; } # Option gets ignored
|
28
|
+
"^\-\-expire\-time=" { $arguments.Add("-t", $args[ $i ]); } # Option gets ignored
|
29
|
+
"^\-\-expire\-time$" { $arguments.Add("-t", $args[ $i+1 ]); $i+=1; } # Option gets ignored
|
30
|
+
"^\-a=" { $arguments.Add("-a", $args[ $i ]); } # Option gets ignored
|
31
|
+
"^\-a$" { $arguments.Add("-a", $args[ $i+1 ]); $i+=1; } # Option gets ignored
|
32
|
+
"^\-\-app\-name=" { $arguments.Add("-a", $args[ $i ]); } # Option gets ignored
|
33
|
+
"^\-\-app\-name$" { $arguments.Add("-a", $args[ $i+1 ]); $i+=1; } # Option gets ignored
|
34
|
+
"^\-i=(.*)" { $args[ $i ] -match '=(.*)'; $arguments.Add("-i", $matches[1]); }
|
35
|
+
"^\-i$" { $arguments.Add("-i", $args[ $i+1 ]); $i+=1; }
|
36
|
+
"^\-\-icon=" { $args[ $i ] -match '=(.*)'; $arguments.Add("-i", $matches[1]); }
|
37
|
+
"^\-\-icon$" { $arguments.Add("-i", $args[ $i +1]); $i+=1; }
|
38
|
+
"^\-h=" { $arguments.Add("-h", $args[ $i ]); } # Option gets ignored
|
39
|
+
"^\-h$" { $arguments.Add("-h", $args[ $i+1 ]); $i+=1; } # Option gets ignored
|
40
|
+
"^\-\-hint=" { $arguments.Add("-h", $args[ $i ]); } # Option gets ignored
|
41
|
+
"^\-\-hint$" { $arguments.Add("-h", $args[ $i+1 ]); $i+=1; } # Option gets ignored
|
42
|
+
"^\-v$" { $arguments.Add("-v", "vagrant-notify"); } # Option gets ignored
|
43
|
+
"^\-\-version$" { $arguments.Add("-v", "vagrant-notify"); } # Option gets ignored
|
44
|
+
"^\-\-help$" { $arguments.Add("--help", $help); }
|
45
|
+
default { $non_opt += $args[ $i ]; }
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
#Write-Host "Num Args:" $args.Length;
|
50
|
+
#Write-Host "CLI is: " $arguments.Count;
|
51
|
+
#Write-Host "MSG is: " $non_opt.Count;
|
52
|
+
|
53
|
+
If ($arguments.Get_Item("--help")) {
|
54
|
+
Write-Host $help
|
55
|
+
exit 1;
|
56
|
+
}
|
57
|
+
If ($arguments.Get_Item("-i")) {
|
58
|
+
$icon = $arguments."-i";
|
59
|
+
}
|
60
|
+
|
61
|
+
|
62
|
+
If ($args.Length -eq 0 ) {
|
63
|
+
Write-Host "No Summary Specified";
|
64
|
+
exit 1;
|
65
|
+
|
66
|
+
} ElseIf ($non_opt.Count -eq 1) {
|
67
|
+
$message = $non_opt[0];
|
68
|
+
|
69
|
+
If($arguments.Get_Item("-i")) { $icon = $arguments."-i"; }
|
70
|
+
|
71
|
+
} ElseIf ($non_opt.Count -eq 2) {
|
72
|
+
$title = $non_opt[0];
|
73
|
+
$message = $non_opt[1];
|
74
|
+
|
75
|
+
If($arguments.Get_Item("-i")) { $icon = $arguments."-i"; }
|
76
|
+
|
77
|
+
} ElseIf ($non_opt.Length -gt 2) {
|
78
|
+
Write-Host "Invalid number of options";
|
79
|
+
exit 1;
|
80
|
+
|
81
|
+
} Else {
|
82
|
+
Write-Host $help
|
83
|
+
exit 1;
|
84
|
+
}
|
85
|
+
|
86
|
+
|
87
|
+
$xml = New-Object Windows.Data.Xml.Dom.XmlDocument
|
88
|
+
$template = "<toast><visual><binding template=`"ToastImageAndText02`"><image id=`"1`" src=`"$icon`" alt=`"image`"/><text id=`"1`">$title</text><text id=`"2`">$message</text></binding></visual></toast>"
|
89
|
+
|
90
|
+
$xml.LoadXml($template)
|
91
|
+
$toast = New-Object Windows.UI.Notifications.ToastNotification $xml
|
92
|
+
|
93
|
+
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("(notify-send)").Show($toast)
|
File without changes
|
data/files/notify-send.erb
CHANGED
@@ -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
|
-
|
15
|
-
|
16
|
-
opts.on('-u', '--urgency LEVEL') { |v| options[:
|
17
|
-
opts.on('-t', '--expire-time TIME') { |v| options[:
|
18
|
-
opts.on('-a', '--app-name APP_NAME') { |v| options[:
|
19
|
-
opts.on('-i', '--icon ICON[,ICON...]') { |v| options[:
|
20
|
-
opts.on('-c', '--category TYPE[,TYPE...]') { |v| options[:
|
21
|
-
opts.on('-h', '--hint TYPE:NAME:VALUE') { |v| options[:
|
22
|
-
opts.on('-v', '--version') { |v| options[:
|
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[:
|
29
|
-
new_filename = options[:
|
30
|
-
FileUtils.cp options[:
|
31
|
-
options[:
|
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
|
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
51
|
TCPSocket.open client_ip, <%= host_port %> do |s|
|
58
52
|
s.send cmd, 0
|
59
53
|
end
|
@@ -31,7 +31,8 @@ module Vagrant
|
|
31
31
|
if env3[:result]
|
32
32
|
env3[:machine].ui.success("vagrant-notify-server pid: #{env3[:notify_data][:pid]}")
|
33
33
|
else
|
34
|
-
env3[:machine].ui.error("Unable to start notification server using #{env3[:
|
34
|
+
env3[:machine].ui.error("Unable to start notification server using #{env3[:notify_data][:bind_ip]}")
|
35
|
+
env3[:notify_data][:pid] = env3[:notify_data][:port] = env3[:notify_data][:bind_ip] = nil
|
35
36
|
end
|
36
37
|
end
|
37
38
|
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
|
@@ -19,8 +20,9 @@ module Vagrant
|
|
19
20
|
|
20
21
|
def compile_command(env, template_file)
|
21
22
|
host_port = env[:notify_data][:port]
|
23
|
+
client_ip = env[:notify_data][:bind_ip]
|
22
24
|
provider_name = env[:machine].provider_name
|
23
|
-
template_binding = OpenStruct.new(:host_port => host_port, :shared_folder => '/tmp/vagrant-notify', :provider_name => provider_name, :client_ip =>
|
25
|
+
template_binding = OpenStruct.new(:host_port => host_port, :shared_folder => '/tmp/vagrant-notify', :provider_name => provider_name, :client_ip => client_ip)
|
24
26
|
command_template = ERB.new(Vagrant::Notify.files_path.join(template_file).read)
|
25
27
|
command = command_template.result(template_binding.instance_eval { binding })
|
26
28
|
|
@@ -30,10 +32,23 @@ module Vagrant
|
|
30
32
|
def install_command_on_guest(env, command_path)
|
31
33
|
source = env[:tmp_path].join 'vagrant-notify-send'
|
32
34
|
env[:machine].communicate.upload(source.to_s, '/tmp/notify-send')
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
env[:machine].communicate.sudo(
|
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.")
|
37
52
|
end
|
38
53
|
end
|
39
54
|
end
|
@@ -7,9 +7,29 @@ module Vagrant
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def call(env)
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
+
|
13
|
+
begin
|
14
|
+
@app.call(env)
|
15
|
+
rescue => msg
|
16
|
+
system("notify-send '[#{env[:machine].name}] \"#{env[:provisioner_name]}\" provision failed!'") unless env[:machine].config.notify.enable == false
|
17
|
+
env[:machine].ui.error("#{msg}")
|
18
|
+
else
|
19
|
+
system(message[:end]) unless env[:machine].config.notify.enable == false
|
20
|
+
end
|
21
|
+
end
|
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
|
13
33
|
end
|
14
34
|
end
|
15
35
|
end
|
@@ -12,6 +12,10 @@ module Vagrant
|
|
12
12
|
def call(env)
|
13
13
|
env[:result] = valid_process?(env[:notify_data][:pid])
|
14
14
|
|
15
|
+
unless env[:notify_data][:bind_ip]
|
16
|
+
env[:notify_data][:bind_ip] = env[:machine].config.notify.bind_ip if env[:machine].config.notify.bind_ip.is_a?(String)
|
17
|
+
end
|
18
|
+
|
15
19
|
# Call the next if we have one (but we shouldn't, since this
|
16
20
|
# middleware is built to run with the Call-type middlewares)
|
17
21
|
@app.call env
|
@@ -9,12 +9,12 @@ 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].
|
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
|
16
16
|
@app.call(env)
|
17
|
-
rescue
|
17
|
+
rescue Vagrant::Errors::GuestCapabilityNotFound
|
18
18
|
env[:machine].ui.warn("vagrant-notify: guest does not support the shared folder capability.")
|
19
19
|
end
|
20
20
|
end
|
@@ -20,10 +20,15 @@ module Vagrant
|
|
20
20
|
|
21
21
|
return if env[:machine].config.notify.enable == false
|
22
22
|
|
23
|
-
|
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]
|
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
|
-
|
15
|
-
|
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
|
@@ -30,6 +32,7 @@ module Vagrant
|
|
30
32
|
|
31
33
|
env[:notify_data][:pid] = nil
|
32
34
|
env[:notify_data][:port] = nil
|
35
|
+
env[:notify_data][:bind_ip] = nil unless env[:notify_restart]
|
33
36
|
end
|
34
37
|
end
|
35
38
|
end
|
@@ -27,40 +27,45 @@ module Vagrant
|
|
27
27
|
argv = parse_options(opts)
|
28
28
|
|
29
29
|
with_target_vms(argv, options) do |machine|
|
30
|
+
|
31
|
+
if machine.state.id != :running
|
32
|
+
@env.ui.info("Guest '#{machine.name}' is not running.")
|
33
|
+
next
|
34
|
+
end
|
35
|
+
|
30
36
|
if options[:help]
|
31
37
|
@env.ui.info(opts)
|
32
|
-
return 0
|
33
38
|
end
|
39
|
+
|
34
40
|
if options[:status] || options.length == 0
|
35
41
|
@env.action_runner.run(Vagrant::Notify::Action.action_status_server, {
|
36
42
|
:machine => machine,
|
37
43
|
})
|
38
|
-
return 0
|
39
44
|
end
|
45
|
+
|
40
46
|
if options[:stop]
|
41
47
|
@env.action_runner.run(Vagrant::Notify::Action.action_stop_server, {
|
42
48
|
:machine => machine,
|
43
49
|
})
|
44
|
-
return 0
|
45
50
|
end
|
51
|
+
|
46
52
|
if options[:start]
|
47
53
|
@env.action_runner.run(Vagrant::Notify::Action.action_start_server, {
|
48
54
|
:machine => machine,
|
49
55
|
})
|
50
|
-
return 0
|
51
56
|
end
|
57
|
+
|
52
58
|
if options[:restart]
|
53
59
|
@env.action_runner.run(Vagrant::Notify::Action.action_stop_server, {
|
54
60
|
:machine => machine,
|
61
|
+
:notify_restart => true
|
55
62
|
})
|
56
63
|
@env.action_runner.run(Vagrant::Notify::Action.action_start_server, {
|
57
64
|
:machine => machine,
|
58
65
|
})
|
59
|
-
return 0
|
60
66
|
end
|
61
67
|
end
|
62
68
|
end
|
63
|
-
|
64
69
|
end
|
65
70
|
end
|
66
71
|
end
|
@@ -1,11 +1,27 @@
|
|
1
1
|
module Vagrant
|
2
2
|
module Notify
|
3
3
|
class Config < Vagrant.plugin(2, :config)
|
4
|
-
|
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
|
8
|
-
@
|
22
|
+
@sender_app = UNSET_VALUE
|
23
|
+
@sender_params_str = UNSET_VALUE
|
24
|
+
@sender_params_escape = UNSET_VALUE
|
9
25
|
end
|
10
26
|
|
11
27
|
def validate(machine)
|
@@ -19,18 +35,20 @@ module Vagrant
|
|
19
35
|
|
20
36
|
if @enable != 0
|
21
37
|
if @enable != false && @enable != true
|
22
|
-
errors << "Unknown option: #{@enable}"
|
38
|
+
errors << "Unknown option for enable: #{@enable}"
|
23
39
|
end
|
24
40
|
end
|
25
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
|
+
|
26
46
|
if backed_by_supported_provider?(machine)
|
27
47
|
if @bind_ip.is_a?(String)
|
28
48
|
require "resolv"
|
29
49
|
unless @bind_ip =~ Resolv::IPv4::Regex
|
30
50
|
errors << "Invalid bind IP address: #{@bind_ip}"
|
31
51
|
end
|
32
|
-
elsif @bind_ip.is_a?(FalseClass) || @bind_ip.is_a?(Fixnum) || @bind_ip.is_a?(Array) || @bind_ip.is_a?(Hash)
|
33
|
-
errors << "Unknown bind IP address: #{@bind_ip}"
|
34
52
|
else
|
35
53
|
@bind_ip = SUPPORTED_PROVIDERS[machine.provider_name]
|
36
54
|
end
|
@@ -45,7 +63,9 @@ module Vagrant
|
|
45
63
|
|
46
64
|
def finalize!
|
47
65
|
@enable = 0 if @enable == UNSET_VALUE
|
48
|
-
@
|
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
|
49
69
|
end
|
50
70
|
|
51
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-
|
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
|
10
|
-
#machine_name
|
11
|
-
#provider
|
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
|
-
|
48
|
-
|
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(
|
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
|
152
|
+
Vagrant::Notify::Server.run id, port, bind_ip, sender_app, sender_params_str, sender_params_escape
|
@@ -8,7 +8,9 @@ describe Vagrant::Notify::Action::InstallCommand do
|
|
8
8
|
let(:config) { mock(notify: stub(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(:
|
11
|
+
let(:ui) { mock(warn: true)}
|
12
|
+
let(:name) { 'test-vm' }
|
13
|
+
let(:machine) { mock(communicate: communicator, config: config, provider_name: provider_name, ui: ui, name: name) }
|
12
14
|
let(:communicator) { mock(upload: true, sudo: true) }
|
13
15
|
let(:host_ip) { '192.168.1.2' }
|
14
16
|
let(:provider_name) { 'virtualbox' }
|
@@ -17,7 +19,6 @@ describe Vagrant::Notify::Action::InstallCommand do
|
|
17
19
|
let(:guest_tmp_path) { '/tmp/notify-send' }
|
18
20
|
let(:guest_path) { '/usr/bin/notify-send' }
|
19
21
|
let(:stubbed_template) { ERB.new('<%= host_port %>') }
|
20
|
-
let(:stubbed_template2) { ERB.new('<%= provider_name %>') }
|
21
22
|
|
22
23
|
subject { described_class.new(app, env) }
|
23
24
|
|
@@ -43,4 +44,8 @@ describe Vagrant::Notify::Action::InstallCommand do
|
|
43
44
|
it 'installs command for all users' do
|
44
45
|
communicator.should have_received(:sudo).with("mv #{guest_tmp_path} #{guest_path} && chmod +x #{guest_path}")
|
45
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")
|
50
|
+
end
|
46
51
|
end
|
@@ -4,7 +4,7 @@ require 'vagrant-notify/action/server_is_running'
|
|
4
4
|
|
5
5
|
describe Vagrant::Notify::Action::ServerIsRunning do
|
6
6
|
let(:app) { lambda { |env| } }
|
7
|
-
let(:env) { {notify_data: {pid: pid}} }
|
7
|
+
let(:env) { {notify_data: {pid: pid, bind_ip: "127.0.0.1"}} }
|
8
8
|
|
9
9
|
subject { described_class.new(app, env) }
|
10
10
|
|
@@ -6,12 +6,13 @@ require 'vagrant-notify/server'
|
|
6
6
|
|
7
7
|
describe Vagrant::Notify::Action::StartServer do
|
8
8
|
let(:app) { lambda { |env| } }
|
9
|
-
let(:
|
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) { mock(notify: stub(enable: true, sender_app: 'notify-send', sender_params_str: sender_params_str, sender_params_escape: false)) }
|
10
11
|
let(:ui) { mock(success: true)}
|
11
12
|
let(:id) { '425e799c-1293-4939-bo39-263lcc7457e8' }
|
12
13
|
let(:provider_name) { 'virtualbox' }
|
13
14
|
let(:machine) { mock(state: stub(id: :stopped), ui: ui, id: id, config: config, provider_name: provider_name) }
|
14
|
-
let(:env) { {notify_data: {}, machine: machine} }
|
15
|
+
let(:env) { {notify_data: {bind_ip: "127.0.0.1"}, machine: machine} }
|
15
16
|
let(:pid) { '42' }
|
16
17
|
let(:port) { '1234' }
|
17
18
|
|
@@ -37,4 +38,4 @@ describe Vagrant::Notify::Action::StartServer do
|
|
37
38
|
# end
|
38
39
|
|
39
40
|
pending 'identifies the next available port'
|
40
|
-
end
|
41
|
+
end
|
data/spec/server_spec.rb
CHANGED
@@ -1,16 +1,20 @@
|
|
1
1
|
require 'vagrant-notify/server'
|
2
2
|
|
3
3
|
describe Vagrant::Notify::Server do
|
4
|
-
let(:arguments) { "
|
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("
|
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) { "-
|
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("
|
32
|
+
subject.should have_received(:system).with("#{sender_app} --icon \"-tmp-foo-bar.jpg\" \"Test message\"")
|
29
33
|
end
|
30
34
|
end
|
31
35
|
|
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.
|
4
|
+
version: 0.6.0
|
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:
|
12
|
+
date: 2020-09-06 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,10 +32,12 @@ files:
|
|
32
32
|
- Rakefile
|
33
33
|
- development/Vagrantfile
|
34
34
|
- examples/README.md
|
35
|
-
- examples/osx/notify-
|
36
|
-
- examples/osx/notify-
|
37
|
-
- examples/
|
38
|
-
- examples/windows/notify-
|
35
|
+
- examples/osx/applescript/notify-send.rb
|
36
|
+
- examples/osx/growl_for_mac/notify-send.rb
|
37
|
+
- examples/osx/terminal-notifier/notify-send.rb
|
38
|
+
- examples/windows/growl_for_windows/notify-send.rb
|
39
|
+
- examples/windows/notification-center/notify-send.ps1
|
40
|
+
- examples/windows/snarl/notify-send.rb
|
39
41
|
- files/notify-send.erb
|
40
42
|
- lib/vagrant-notify.rb
|
41
43
|
- lib/vagrant-notify/action.rb
|
@@ -66,7 +68,7 @@ files:
|
|
66
68
|
homepage: https://github.com/fgrehm/vagrant-notify
|
67
69
|
licenses: []
|
68
70
|
metadata: {}
|
69
|
-
post_install_message:
|
71
|
+
post_install_message:
|
70
72
|
rdoc_options: []
|
71
73
|
require_paths:
|
72
74
|
- lib
|
@@ -81,9 +83,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
83
|
- !ruby/object:Gem::Version
|
82
84
|
version: '0'
|
83
85
|
requirements: []
|
84
|
-
|
85
|
-
|
86
|
-
signing_key:
|
86
|
+
rubygems_version: 3.1.2
|
87
|
+
signing_key:
|
87
88
|
specification_version: 4
|
88
89
|
summary: A Vagrant plugin that forwards `notify-send` from guest to host machine and
|
89
90
|
notifies provisioning status
|