Class: VagrantVbguest::Installers::Windows
- Inherits:
-
Base
- Object
- Base
- VagrantVbguest::Installers::Windows
show all
- Defined in:
- lib/vagrant-vbguest/installers/windows.rb
Instance Attribute Summary
Attributes inherited from Base
#env, #host, #options, #vm
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
distro, #host_version, #initialize, #installer_options, #iso_file, #provides_vboxadd_tools?, #rebuild, #start, #upload, #vboxadd_tools_available?, #yield_installation_warning, #yield_rebuild_warning
#communicate, #driver, included
Class Method Details
.match?(vm) ⇒ Boolean
7
8
9
10
|
# File 'lib/vagrant-vbguest/installers/windows.rb', line 7
def self.match?(vm)
raise Error, _key: :do_not_inherit_match_method if self != Windows
communicate_to(vm).test("(Get-WMIObject win32_operatingsystem).name")
end
|
.os_release(vm) ⇒ Object
12
13
14
15
16
17
18
19
20
|
# File 'lib/vagrant-vbguest/installers/windows.rb', line 12
def self.os_release(vm)
@@os_release_info ||= {}
if !@@os_release_info.has_key?(vm_id(vm)) && communicate_to(vm).test("(Get-WMIObject win32_operatingsystem).Name")
communicate.execute("(Get-WMIObject win32_operatingsystem).Name") do |type, data|
@@os_release_info[vm_id(vm)] = data
end
end
@@os_release_info[vm_id(vm)]
end
|
Instance Method Details
#cleanup(opts = nil, &block) ⇒ Object
119
120
121
122
123
124
|
# File 'lib/vagrant-vbguest/installers/windows.rb', line 119
def cleanup(opts = nil, &block)
unless options[:no_cleanup]
unmount_iso(opts, &block)
super
end
end
|
#execute_installer(opts = nil, &block) ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/vagrant-vbguest/installers/windows.rb', line 84
def execute_installer(opts = nil, &block)
cert_dir = File.join("#{mount_point}:", 'cert')
installer = File.join("#{mount_point}:", "VBoxWindowsAdditions.exe")
yield_installation_warning(installer)
opts = { elevated: true }.merge(opts || {})
communicate.execute(<<-SHELL, opts.merge(error_check: false), &block)
cd #{cert_dir}; ./VBoxCertUtil.exe add-trusted-publisher *.cer --root *.cer
SHELL
exit_status = communicate.execute(<<-SHELL, opts, &block)
cd #{cert_dir}; #{installer} /S
SHELL
yield_installation_error_warning(installer) unless exit_status == 0
exit_status
end
|
#guest_version(reload = false) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/vagrant-vbguest/installers/windows.rb', line 64
def guest_version(reload = false)
return @guest_version if @guest_version && !reload
driver_version = VagrantVbguest::Version(super)
communicate.execute("VBoxService --version", error_check: false) do |type,data|
service_version = VagrantVbguest::Version(data)
if service_version
if driver_version != service_version
@env.ui.warn(I18n.t(
"vagrant_vbguest.guest_version_reports_differ",
driver: driver_version, service: service_version
))
end
@guest_version = service_version
end
end
@guest_version
end
|
#install(opts = nil, &block) ⇒ Object
50
51
52
53
54
|
# File 'lib/vagrant-vbguest/installers/windows.rb', line 50
def install(opts = nil, &block)
upload(iso_file)
mount_iso(opts, &block)
execute_installer(opts, &block)
end
|
#installer_version(path_to_installer) ⇒ Object
40
41
42
43
44
45
46
47
48
|
# File 'lib/vagrant-vbguest/installers/windows.rb', line 40
def installer_version(path_to_installer)
version = nil
communicate.execute("(get-item #{path_to_installer}).VersionInfo.ProductVersion") do |type, data|
if (v = data.to_s.match(/(\d+\.\d+.\d+)/i))
version = v[1]
end
end
version
end
|
#mount_iso(opts = nil, &block) ⇒ Object
104
105
106
107
108
|
# File 'lib/vagrant-vbguest/installers/windows.rb', line 104
def mount_iso(opts = nil, &block)
communicate.execute("Mount-DiskImage -ImagePath #{tmp_path}", opts, &block)
env.ui.info(I18n.t("vagrant_vbguest.mounting_iso", mount_point: mount_point))
@mounted = true
end
|
#mount_point ⇒ Object
30
31
32
33
34
35
36
37
38
|
# File 'lib/vagrant-vbguest/installers/windows.rb', line 30
def mount_point
communicate.execute(<<-SHELL) do |type, data|
(Get-DiskImage -DevicePath (
Get-DiskImage -ImagePath #{tmp_path}
).DevicePath | Get-Volume).DriveLetter
SHELL
return data.strip
end
end
|
#os_release ⇒ Object
22
23
24
|
# File 'lib/vagrant-vbguest/installers/windows.rb', line 22
def os_release
self.class.os_release(vm)
end
|
#reboot_after_install?(opts = nil, &block) ⇒ Boolean
56
57
58
|
# File 'lib/vagrant-vbguest/installers/windows.rb', line 56
def reboot_after_install?(opts = nil, &block)
true
end
|
#running?(opts = nil, &block) ⇒ Boolean
60
61
62
|
# File 'lib/vagrant-vbguest/installers/windows.rb', line 60
def running?(opts = nil, &block)
communicate.test("'Running' -eq (Get-Service VBoxService)")
end
|
#tmp_path ⇒ Object
26
27
28
|
# File 'lib/vagrant-vbguest/installers/windows.rb', line 26
def tmp_path
options[:iso_upload_path] || "$env:TEMP/VBoxGuestAdditions.iso"
end
|
#unmount_iso(opts = nil, &block) ⇒ Object
110
111
112
113
114
115
116
117
|
# File 'lib/vagrant-vbguest/installers/windows.rb', line 110
def unmount_iso(opts = nil, &block)
return unless @mounted
env.ui.info(I18n.t("vagrant_vbguest.unmounting_iso",mount_point: mount_point))
opts = (opts || {}).merge(:error_check => false)
communicate.execute("Dismount-DiskImage -ImagePath #{tmp_path}", opts, &block)
communicate.execute("Remove-Item -Path #{tmp_path}", opts, &block)
@mounted = false
end
|
#yield_installation_error_warning(path_to_installer) ⇒ Object
126
127
128
129
130
131
|
# File 'lib/vagrant-vbguest/installers/windows.rb', line 126
def yield_installation_error_warning(path_to_installer)
@env.ui.warn I18n.t(
"vagrant_vbguest.windows.install_error",
installer_version: installer_version(path_to_installer) || I18n.t("vagrant_vbguest.unknown")
)
end
|