vagrant-windows-sysprep 0.0.4 → 0.0.9

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: c54e69feb971b2d5962fa047273c8e9f2e14c6046127f785cd76459d8436126c
4
- data.tar.gz: d04250e3e6792d9966469a8ec911ab70825b234ad83fbcc7b9511838b398dc07
3
+ metadata.gz: 5073b3be5e3d52840ea1fde18a2cd0ad05c7a4d1f4324fa732a0688654a3130f
4
+ data.tar.gz: 553d29dc27c82d72502cb870fcb6bf9326e9981297cc23b98e28be91517e2f94
5
5
  SHA512:
6
- metadata.gz: 668461a1986b312481767ec3dd107fc13e94ad8fb4c03a98d7a1ce8bae0ae5c806a984eec9165df6d407aa8c02eb82f8efec58c0192144c828516972a1600652
7
- data.tar.gz: '08d1f86777cd13c21133ec41b8d3497dc40c2dee54ef08e33c68f5de158a1fd895f4785434b3bf8fd1692b00af805d297047945c851d7f7f7bd595f854b398ef'
6
+ metadata.gz: 30a83102bdd16b9389ed4c198d8f25de01f2fcb1f76604c8c9dad13cf6c7d41958c381f437f224c7c2c6df507f5e1e7de049365abd5daa5cc5c8ac4f0f3a146a
7
+ data.tar.gz: b0bdf379b3c121a31737a176f412bff34ab6f13a186412f5e2137e92e5b2af3251d672bb9aea5eab6588b44dc07a9e86f75a2042b288df75c746f6ba7b51bc8d
@@ -53,7 +53,7 @@ module VagrantPlugins
53
53
  @machine.communicate.upload(
54
54
  File.join(File.dirname(__FILE__), "vagrant-windows-sysprep", "sysprep.ps1"),
55
55
  sysprep_remote_path)
56
- sysprep_command = "#{ps} -File #{sysprep_remote_path}"
56
+ sysprep_command = "#{ps} -File #{sysprep_remote_path} -Username \"#{@machine.config.winrm.username}\" -Password \"#{@machine.config.winrm.password}\""
57
57
  begin
58
58
  @machine.communicate.sudo(sysprep_command, {elevated: true, interactive: false}) do |type, data|
59
59
  handle_comm(type, data)
@@ -65,7 +65,8 @@ module VagrantPlugins
65
65
  # wait for the machine to be shutdown.
66
66
  # NB :poweroff is used by the VirtualBox provider.
67
67
  # NB :shutoff is used by the libvirt provider.
68
- until [:poweroff, :shutoff].include? @machine.state.id
68
+ # NB :off is used by the Hyper-V provider.
69
+ until [:poweroff, :shutoff, :off].include? @machine.state.id
69
70
  sleep 10
70
71
  end
71
72
 
@@ -1,5 +1,7 @@
1
1
  param(
2
- [string]$ComputerName = $null
2
+ [string]$ComputerName = $null,
3
+ [string]$Username = 'vagrant',
4
+ [string]$Password = 'vagrant'
3
5
  )
4
6
 
5
7
  Set-StrictMode -Version Latest
@@ -17,19 +19,115 @@ if (!$ComputerName) {
17
19
  }
18
20
 
19
21
  $unattendPath = "$PSScriptRoot\vagrant-windows-sysprep-unattend.xml"
22
+ $unattendPs1Path = "$PSScriptRoot\vagrant-windows-sysprep-unattend.ps1"
20
23
 
24
+ # sysprep renames the user that has the well-known Administrator SID
25
+ # to the Administrator name, when $Username has that SID, we must
26
+ # rename Administrator back to the $Username name.
27
+ # NB this SID always has the format S-1-5-21-<domain>-500.
28
+ # see https://support.microsoft.com/en-us/help/243330/well-known-security-identifiers-in-windows-operating-systems
29
+ $administratorLocalUser = Get-LocalUser | Where-Object {$_.SID.Value -match '^S-1-5-21-.+-500$'}
30
+ $enableAdministrator = $administratorLocalUser.Enabled
31
+ $renameAdministratorToUsername = $administratorLocalUser.Name -eq $Username
32
+
33
+ # NB doing an auto-logon after a sysprep has two effects:
34
+ # 1. make Windows 10 1809 not ask for an account creation (regardless of the
35
+ # value of SkipUserOOBE/SkipMachineOOBE).
36
+ # NB even when you disable the local accounts security questions with:
37
+ # # Windows 10 1803 started to require local account security questions but provided
38
+ # # no way to configure or skip those on sysprep, so we have to manually disable
39
+ # # that feature.
40
+ # # NB even with this windows stills asks for a Password Hint.
41
+ # # see https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/customize-oobe
42
+ # Write-Host 'Disabling the use of Security Questions for Local Accounts...'
43
+ # Set-ItemProperty `
44
+ # -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\System `
45
+ # -Name NoLocalPasswordResetQuestions `
46
+ # -Value 1
47
+ # Windows will still ask for a password hint...
48
+ # 2. make vagrant be able to go through the stage (on Windows 10 1809):
49
+ # ==> default: Mounting SMB shared folders...
50
+ # default: /home/rgl/Projects/windows-2016-vagrant/example => /vagrant
21
51
  # NB there's a bug somewhere in windows sysprep machinery that prevents it from setting the
22
52
  # ComputerName when the name doesn't really change (like when you use config.vm.hostname),
23
53
  # it will instead set the ComputerName to something like WIN-0F47SUATAF5.
24
54
  # 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..."
55
+ Write-Host 'Configuring sysprep...'
26
56
  Set-Content `
27
57
  -Encoding UTF8 `
28
58
  -Path $unattendPath `
29
59
  -Value (
30
60
  (Get-Content -Raw $unattendPath) `
31
- -replace '@@COMPUTERNAME@@',$ComputerName
61
+ -replace '@@COMPUTERNAME@@',$ComputerName `
62
+ -replace '@@USERNAME@@',$Username `
63
+ -replace '@@PASSWORD@@',$Password `
64
+ -replace '@@UNATTENDPS1PATH@@',$unattendPs1Path
32
65
  )
66
+ $unattendPs1 = @'
67
+ Set-StrictMode -Version Latest
68
+ $ErrorActionPreference = 'Stop'
69
+ $ProgressPreference = 'SilentlyContinue'
70
+ trap {
71
+ Write-Host "ERROR: $_"
72
+ Write-Host (($_.ScriptStackTrace -split '\r?\n') -replace '^(.*)$','ERROR: $1')
73
+ Write-Host (($_.Exception.ToString() -split '\r?\n') -replace '^(.*)$','ERROR EXCEPTION: $1')
74
+ Write-Host
75
+ Write-Host 'Sleeping during 60 minutes to give you time to see this error message...'
76
+ Start-Sleep -Seconds (60*60)
77
+ Exit 1
78
+ }
79
+
80
+ Write-Host @"
81
+ WARNING WARNING WARNING WARNING WARNING WARNING
82
+
83
+ this is being run by vagrant-windows-sysprep
84
+
85
+ do NOT touch anything
86
+
87
+ WARNING WARNING WARNING WARNING WARNING WARNING
88
+
89
+ "@
90
+
91
+ if ($enableAdministrator) {
92
+ Get-LocalUser -Name Administrator | Enable-LocalUser
93
+ } else {
94
+ Get-LocalUser -Name Administrator | Disable-LocalUser
95
+ }
96
+
97
+ if ($renameAdministratorToUsername) {
98
+ Get-LocalUser -Name Administrator | Rename-LocalUser -NewName $Username
99
+ }
100
+
101
+ Write-Host 'Waiting for WinRM to be running...'
102
+ while ((Get-Service WinRM).Status -ne 'Running') {
103
+ Start-Sleep -Seconds 5
104
+ }
105
+
106
+ Write-Host 'Disabling auto logon...'
107
+ $autoLogonKeyPath = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon'
108
+ Set-ItemProperty `
109
+ -Path $autoLogonKeyPath `
110
+ -Name AutoAdminLogon `
111
+ -Value 0
112
+ Remove-ItemProperty `
113
+ -Path $autoLogonKeyPath `
114
+ -Name @(
115
+ 'DefaultDomainName',
116
+ 'DefaultUserName',
117
+ 'DefaultPassword'
118
+ ) `
119
+ -ErrorAction SilentlyContinue
120
+
121
+ Write-Host 'Logging off...'
122
+ logoff
123
+ '@ `
124
+ -replace '\$enableAdministrator',"$(if ($enableAdministrator) {'$true'} else {'$false'})" `
125
+ -replace '\$renameAdministratorToUsername',"$(if ($renameAdministratorToUsername) {'$true'} else {'$false'})" `
126
+ -replace '\$Username',"'$Username'"
127
+ Set-Content `
128
+ -Encoding UTF8 `
129
+ -Path $unattendPs1Path `
130
+ -Value $unattendPs1
33
131
 
34
132
  Write-Host 'Syspreping...'
35
133
  C:/Windows/System32/Sysprep/sysprep.exe `
@@ -35,6 +35,26 @@
35
35
  <NetworkLocation>Home</NetworkLocation>
36
36
  <ProtectYourPC>1</ProtectYourPC>
37
37
  </OOBE>
38
+ <AutoLogon>
39
+ <Password>
40
+ <Value>@@PASSWORD@@</Value>
41
+ <PlainText>true</PlainText>
42
+ </Password>
43
+ <Enabled>true</Enabled>
44
+ <Username>Administrator</Username>
45
+ </AutoLogon>
46
+ <UserAccounts>
47
+ <AdministratorPassword>
48
+ <Value>@@PASSWORD@@</Value>
49
+ <PlainText>true</PlainText>
50
+ </AdministratorPassword>
51
+ </UserAccounts>
52
+ <FirstLogonCommands>
53
+ <SynchronousCommand wcm:action="add">
54
+ <Order>1</Order>
55
+ <CommandLine>PowerShell -File @@UNATTENDPS1PATH@@</CommandLine>
56
+ </SynchronousCommand>
57
+ </FirstLogonCommands>
38
58
  </component>
39
59
  </settings>
40
60
  </unattend>
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module WindowsSysprep
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.9"
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.4
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rui Lopes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-15 00:00:00.000000000 Z
11
+ date: 2021-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -54,8 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
56
  requirements: []
57
- rubyforge_project:
58
- rubygems_version: 2.7.6
57
+ rubygems_version: 3.1.2
59
58
  signing_key:
60
59
  specification_version: 4
61
60
  summary: Vagrant plugin for running Windows sysprep.