-
Notifications
You must be signed in to change notification settings - Fork 6
/
ie-box-automation-plugin.rb
127 lines (100 loc) · 4.21 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# -*- 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'
require 'logger'
require 'log4r'
# TODO
# ====
#
# 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 initialize(machine, config)
super
@logger = Log4r::Logger.new("vagrant::ieautomation")
end
def execute_command(ssh, command, show)
@logger.debug ("command: #{command}")
res = ssh.exec!(command)
@logger.debug ("result: #{res}")
puts res if show
end
def provision
#result = system "#{config.command}"
begin
ssh_info = nil
while true
ssh_info = @machine.ssh_info
break if ssh_info
sleep 1
@logger.debug ("wait ssh_info")
end
ssh = Net::SSH.start(ssh_info[:host], ssh_info[:username], :password => ssh_info[:password], :port => ssh_info[:port])
execute_command(ssh, "ls -la", false)
execute_command(ssh, "[ ! ./tools.zip ] && echo 'ERROR! File ./tools.zip not found on guest machine. Was the file provisioner executed?'", true)
execute_command(ssh, "./7z.exe e tools.zip -y", false)
puts "Disabling firewall..."
execute_command(ssh, "NetSh Advfirewall set allprofiles state off", false)
puts "Changing network location..."
execute_command(ssh, "./NLMtool_staticlib.exe -setcategory private", false)
puts "Turn off User Account Control..."
execute_command(ssh, "cmd /c \"reg add HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System /v EnableLUA /d 0 /t REG_DWORD /f /reg:64\"", false)
puts "Creating link to config WinRM on Startup..."
execute_command(ssh, "mv ./configWinRM.bat.lnk \"/cygdrive/c/Users/IEUser/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup\"", false)
puts 'Shutting down guest machine...'
execute_command(ssh, "shutdown -t 0 -s -f", false)
$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...'
raise
end
end
ssh.close
rescue Exception => e
puts "uncaught #{e} exception while handling connection: #{e.message}"
raise
end
end
end
end