vagrant-windows-sysprep 0.0.3 → 0.0.4

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
2
  SHA256:
3
- metadata.gz: 70a660b8e8daa69d230c68382ebcfd460aed717d9c2d2b1a4226ef31728719d3
4
- data.tar.gz: d6633967e882aa529e80e56d5f7e12ad468dd326ee7c1ab5f85c646d0e6a5d2b
3
+ metadata.gz: c54e69feb971b2d5962fa047273c8e9f2e14c6046127f785cd76459d8436126c
4
+ data.tar.gz: d04250e3e6792d9966469a8ec911ab70825b234ad83fbcc7b9511838b398dc07
5
5
  SHA512:
6
- metadata.gz: 929b5bd41f3f1fbdcc2e65b5802b731e5f12a081f29bb0bc57be9029ed3bd831ba4fbebd81e7b4a642ffdddee19de4bf99f386c907555fff3db022f7efcd552a
7
- data.tar.gz: 14ccef9e8a06deb9d100fbed0ebf5dd2e30a608d1af66acf1705140e2e3d6bbe3c186fd855c0b7c1647c849f7b3966d0db043511081953f613564259fd63db61
6
+ metadata.gz: 668461a1986b312481767ec3dd107fc13e94ad8fb4c03a98d7a1ce8bae0ae5c806a984eec9165df6d407aa8c02eb82f8efec58c0192144c828516972a1600652
7
+ data.tar.gz: '08d1f86777cd13c21133ec41b8d3497dc40c2dee54ef08e33c68f5de158a1fd895f4785434b3bf8fd1692b00af805d297047945c851d7f7f7bd595f854b398ef'
@@ -33,20 +33,27 @@ module VagrantPlugins
33
33
  ps = 'PowerShell -ExecutionPolicy Bypass -OutputFormat Text'
34
34
 
35
35
  original_machine_sid = ''
36
- show_sid_remote_path = "C:/Windows/Temp/vagrant-windows-sysprep-show-sid.ps1"
36
+ original_machine_computer_name = ''
37
+ info_remote_path = "C:/Windows/Temp/vagrant-windows-sysprep-info.ps1"
37
38
  @machine.communicate.upload(
38
- File.join(File.dirname(__FILE__), "vagrant-windows-sysprep", "show-sid.ps1"),
39
- show_sid_remote_path)
40
- show_sid_command = "#{ps} -File #{show_sid_remote_path}"
41
- @machine.communicate.sudo(show_sid_command, {elevated: true, interactive: false}) do |type, data|
39
+ File.join(File.dirname(__FILE__), "vagrant-windows-sysprep", "info.ps1"),
40
+ info_remote_path)
41
+ info_command = "#{ps} -File #{info_remote_path}"
42
+ @machine.communicate.sudo(info_command, {elevated: true, interactive: false}) do |type, data|
42
43
  original_machine_sid = $1.strip if data =~ /This Machine SID is (.+)/
44
+ original_machine_computer_name = $1.strip if data =~ /This Machine ComputerName is (.+)/
43
45
  end
44
46
 
45
- autounattend_remote_path = "C:/Windows/Temp/vagrant-windows-sysprep-autounattend.xml"
47
+ unattend_remote_path = "C:/Windows/Temp/vagrant-windows-sysprep-unattend.xml"
46
48
  @machine.communicate.upload(
47
- File.join(File.dirname(__FILE__), "vagrant-windows-sysprep", "autounattend.xml"),
48
- autounattend_remote_path)
49
- sysprep_command = "#{ps} -Command 'Start-Process -Wait C:/Windows/System32/Sysprep/sysprep /generalize,/oobe,/quiet,/shutdown,/unattend:#{autounattend_remote_path}'"
49
+ File.join(File.dirname(__FILE__), "vagrant-windows-sysprep", "unattend.xml"),
50
+ unattend_remote_path)
51
+
52
+ sysprep_remote_path = "C:/Windows/Temp/vagrant-windows-sysprep.ps1"
53
+ @machine.communicate.upload(
54
+ File.join(File.dirname(__FILE__), "vagrant-windows-sysprep", "sysprep.ps1"),
55
+ sysprep_remote_path)
56
+ sysprep_command = "#{ps} -File #{sysprep_remote_path}"
50
57
  begin
51
58
  @machine.communicate.sudo(sysprep_command, {elevated: true, interactive: false}) do |type, data|
52
59
  handle_comm(type, data)
@@ -67,9 +74,23 @@ module VagrantPlugins
67
74
  @machine.action(:up, options)
68
75
 
69
76
  machine_sid = ''
70
- @machine.communicate.sudo(show_sid_command, {elevated: true, interactive: false}) do |type, data|
77
+ machine_computer_name = ''
78
+ @machine.communicate.sudo(info_command, {elevated: true, interactive: false}) do |type, data|
71
79
  machine_sid = $1.strip if data =~ /This Machine SID is (.+)/
80
+ machine_computer_name = $1.strip if data =~ /This Machine ComputerName is (.+)/
72
81
  end
82
+
83
+ # NB there's a bug somewhere in windows sysprep machinery that prevents it from setting the
84
+ # ComputerName when the name doesn't really change (like when you use config.vm.hostname),
85
+ # it will instead set the ComputerName to something like WIN-0F47SUATAF5.
86
+ # this workaround will compensate for that by renaming the computer.
87
+ # NB sysprep works in Windows 2016 14393.2906.
88
+ # NB sysprep fails in Windows 2019 17763.437.
89
+ if machine_computer_name != original_machine_computer_name
90
+ @machine.ui.info "Sysprep did not correctly set ComputerName... renaming it from #{machine_computer_name} to #{original_machine_computer_name}..."
91
+ @machine.guest.capability(:change_host_name, original_machine_computer_name)
92
+ end
93
+
73
94
  @machine.ui.success "The Machine SID was changed from #{original_machine_sid} to #{machine_sid}"
74
95
  end
75
96
 
@@ -21,4 +21,5 @@ function Get-MachineSID {
21
21
  }
22
22
  }
23
23
 
24
- echo "This Machine SID is $(Get-MachineSID)"
24
+ Write-Output "This Machine SID is $(Get-MachineSID)"
25
+ Write-Output "This Machine ComputerName is $env:COMPUTERNAME"
@@ -0,0 +1,41 @@
1
+ param(
2
+ [string]$ComputerName = $null
3
+ )
4
+
5
+ Set-StrictMode -Version Latest
6
+ $ErrorActionPreference = 'Stop'
7
+ $ProgressPreference = 'SilentlyContinue'
8
+ trap {
9
+ Write-Output "ERROR: $_"
10
+ Write-Output (($_.ScriptStackTrace -split '\r?\n') -replace '^(.*)$','ERROR: $1')
11
+ Write-Output (($_.Exception.ToString() -split '\r?\n') -replace '^(.*)$','ERROR EXCEPTION: $1')
12
+ Exit 1
13
+ }
14
+
15
+ if (!$ComputerName) {
16
+ $ComputerName = $env:COMPUTERNAME
17
+ }
18
+
19
+ $unattendPath = "$PSScriptRoot\vagrant-windows-sysprep-unattend.xml"
20
+
21
+ # NB there's a bug somewhere in windows sysprep machinery that prevents it from setting the
22
+ # ComputerName when the name doesn't really change (like when you use config.vm.hostname),
23
+ # it will instead set the ComputerName to something like WIN-0F47SUATAF5.
24
+ # so this configuration will not really work... but its here to see when they fix this problem.
25
+ Write-Host "Configuring sysprep to set ComputerName to $ComputerName..."
26
+ Set-Content `
27
+ -Encoding UTF8 `
28
+ -Path $unattendPath `
29
+ -Value (
30
+ (Get-Content -Raw $unattendPath) `
31
+ -replace '@@COMPUTERNAME@@',$ComputerName
32
+ )
33
+
34
+ Write-Host 'Syspreping...'
35
+ C:/Windows/System32/Sysprep/sysprep.exe `
36
+ /generalize `
37
+ /oobe `
38
+ /quiet `
39
+ /shutdown `
40
+ "/unattend:$unattendPath" `
41
+ | Out-String -Stream
@@ -1,4 +1,8 @@
1
1
  <?xml version="1.0" encoding="utf-8"?>
2
+ <!--
3
+ sysprep copies this file to C:\Windows\Panther\unattend.xml
4
+ the logs are stored at C:\Windows\Panther\setupact.log
5
+ -->
2
6
  <unattend xmlns="urn:schemas-microsoft-com:unattend">
3
7
  <settings pass="generalize">
4
8
  <component name="Microsoft-Windows-Security-SPP" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
@@ -9,6 +13,11 @@
9
13
  <DoNotCleanUpNonPresentDevices>true</DoNotCleanUpNonPresentDevices>
10
14
  </component>
11
15
  </settings>
16
+ <settings pass="specialize">
17
+ <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
18
+ <ComputerName>@@COMPUTERNAME@@</ComputerName>
19
+ </component>
20
+ </settings>
12
21
  <settings pass="oobeSystem">
13
22
  <component name="Microsoft-Windows-International-Core" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
14
23
  <InputLocale>en-US</InputLocale>
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module WindowsSysprep
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-windows-sysprep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rui Lopes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-01 00:00:00.000000000 Z
11
+ date: 2019-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -31,8 +31,9 @@ extensions: []
31
31
  extra_rdoc_files: []
32
32
  files:
33
33
  - lib/vagrant-windows-sysprep.rb
34
- - lib/vagrant-windows-sysprep/autounattend.xml
35
- - lib/vagrant-windows-sysprep/show-sid.ps1
34
+ - lib/vagrant-windows-sysprep/info.ps1
35
+ - lib/vagrant-windows-sysprep/sysprep.ps1
36
+ - lib/vagrant-windows-sysprep/unattend.xml
36
37
  - lib/vagrant-windows-sysprep/version.rb
37
38
  homepage: https://github.com/rgl/vagrant-windows-sysprep
38
39
  licenses: