forked from danielmenezesbr/modernie-winrm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathie-box-automation-plugin.rb
102 lines (85 loc) · 3.47 KB
/
ie-box-automation-plugin.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# -*- mode: ruby -*-
# vi: set ft=ruby :
##
# If you copy this file, dont't delete this comment.
# This Vagrantfile was created by Daniel Menezes:
# https://github.com/danielmenezesbr/modernie-winrm
# E-mail: danielmenezes at gmail dot com
##
require 'rubygems'
require 'net/ssh'
# TODO
# ====
# Uses config.ssh in Net::SSH.start
# test in win8/10
# add activate (view desktop information)
# use logger for debug
# Function to check whether VM was already provisioned
def provisioned?(vm_name='default', provider='virtualbox')
File.exist?(".vagrant/machines/#{vm_name}/#{provider}/action_provision")
end
module LocalCommand
class Config < Vagrant.plugin("2", :config)
#attr_accessor :command
end
class MyPlugin < Vagrant.plugin("2")
name "ie_box_automation"
config(:ie_box_automation, :provisioner) do
Config
end
provisioner(:ie_box_automation) do
Provisioner
end
end
class Provisioner < Vagrant.plugin("2", :provisioner)
def provision
#result = system "#{config.command}"
begin
ssh = Net::SSH.start("localhost", "IEUser", :password => "Passw0rd!", :port => 2222)
puts "Disabling firewall..."
res = ssh.exec!("NetSh Advfirewall set allprofiles state off")
#for debug
#puts res
puts "Changing network location..."
res = ssh.exec!("./tools/NLMtool_staticlib.exe -setcategory private")
#for debug
#puts res
puts "Turn off User Account Control..."
res = ssh.exec!("cmd /c \"reg add HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System /v EnableLUA /d 0 /t REG_DWORD /f /reg:64\"")
puts "Creating link to config WinRM on Startup..."
res = ssh.exec!("mv ./tools/ConfigWinRM.lnk \"/cygdrive/c/Users/IEUser/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup\"")
#for debug
#puts res
puts 'Shutting down guest machine...'
ssh.exec!("shutdown -t 0 -s -f")
$done = false;
while !$done do
begin
result = Vagrant::Util::Subprocess.execute(
'vagrant',
'status',
:notify => [:stdout, :stderr],
#:workdir => config.cwd,
:env => {PATH: ENV["VAGRANT_OLD_ENV_PATH"]},
) do |io_name, data|
#@machine.env.ui.debug "[#{io_name}] #{data}"
if data.include? "The VM is running"
puts 'The VM is running... Waiting shutdown...'
else
$done = true
puts 'The VM is not running. Next command should be vagrant up...'
end
end
sleep(50)
rescue Exception => e
$done = true
puts 'Exception...'
end
end
ssh.close
rescue Exception => e
puts "uncaught #{e} exception while handling connection: #{e.message}"
end
end
end
end