vagrant-windows-sysprep 0.0.1
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
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8078a7925b21e80208697c82e503da2308732d89
|
4
|
+
data.tar.gz: f0dc8365fcfd11ba0c278a9d656e3e7ff69abfc1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 30dfdba5eb2a85553916a05722257c51c2a43b2956783fd2be4b51d31165aa255759a73c71fd59de72fe8532188895c25823677fc5e81adf1cee15e9d45f61c1
|
7
|
+
data.tar.gz: 7f8ca252fa6e5dbb9fed612d873c69803dfaba34cc278509f739ace9c9b3c21ccfd4cdcb047e9e1e3fdaef88bfbbfa218ef624345e3e4b150a506b932861087c
|
@@ -0,0 +1,99 @@
|
|
1
|
+
begin
|
2
|
+
require "vagrant"
|
3
|
+
rescue LoadError
|
4
|
+
raise "The Vagrant Windows Sysprep plugin must be run within Vagrant."
|
5
|
+
end
|
6
|
+
|
7
|
+
if Vagrant::VERSION < "1.9.0"
|
8
|
+
raise "The Vagrant Windows Sysprep plugin is only compatible with Vagrant 1.9+"
|
9
|
+
end
|
10
|
+
|
11
|
+
module VagrantPlugins
|
12
|
+
module WindowsSysprep
|
13
|
+
class Plugin < Vagrant.plugin("2")
|
14
|
+
name "Windows Sysprep"
|
15
|
+
description "Vagrant plugin to run Windows sysprep as a provisioning step."
|
16
|
+
|
17
|
+
provisioner "windows-sysprep" do
|
18
|
+
class Provisioner < Vagrant.plugin("2", :provisioner)
|
19
|
+
def initialize(machine, config)
|
20
|
+
super
|
21
|
+
end
|
22
|
+
|
23
|
+
def configure(root_config)
|
24
|
+
end
|
25
|
+
|
26
|
+
# see https://github.com/mitchellh/vagrant/blob/master/lib/vagrant/machine.rb
|
27
|
+
# see https://github.com/mitchellh/vagrant/blob/master/lib/vagrant/machine_state.rb
|
28
|
+
# see https://github.com/mitchellh/vagrant/blob/master/lib/vagrant/ui.rb
|
29
|
+
# see https://github.com/mitchellh/vagrant/blob/master/lib/vagrant/plugin/v2/provisioner.rb
|
30
|
+
# see https://github.com/mitchellh/vagrant/blob/master/lib/vagrant/plugin/v2/communicator.rb
|
31
|
+
# see https://github.com/mitchellh/vagrant/blob/master/plugins/provisioners/shell/provisioner.rb
|
32
|
+
def provision
|
33
|
+
ps = 'PowerShell -ExecutionPolicy Bypass -OutputFormat Text'
|
34
|
+
|
35
|
+
original_machine_sid = ''
|
36
|
+
show_sid_remote_path = "C:/Windows/Temp/vagrant-windows-sysprep-show-sid.ps1"
|
37
|
+
@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|
|
42
|
+
original_machine_sid = $1.strip if data =~ /This Machine SID is (.+)/
|
43
|
+
end
|
44
|
+
|
45
|
+
autounattend_remote_path = "C:/Windows/Temp/vagrant-windows-sysprep-autounattend.xml"
|
46
|
+
@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}'"
|
50
|
+
begin
|
51
|
+
@machine.communicate.sudo(sysprep_command, {elevated: true, interactive: false}) do |type, data|
|
52
|
+
handle_comm(type, data)
|
53
|
+
end
|
54
|
+
rescue
|
55
|
+
# ignored. this should be due to the shutdown that sysprep does.
|
56
|
+
end
|
57
|
+
until @machine.state.id == :poweroff
|
58
|
+
sleep 10
|
59
|
+
end
|
60
|
+
|
61
|
+
options = {}
|
62
|
+
options[:provision_ignore_sentinel] = false
|
63
|
+
@machine.action(:up, options)
|
64
|
+
|
65
|
+
machine_sid = ''
|
66
|
+
@machine.communicate.sudo(show_sid_command, {elevated: true, interactive: false}) do |type, data|
|
67
|
+
machine_sid = $1.strip if data =~ /This Machine SID is (.+)/
|
68
|
+
end
|
69
|
+
@machine.ui.success "The Machine SID was changed from #{original_machine_sid} to #{machine_sid}"
|
70
|
+
end
|
71
|
+
|
72
|
+
def cleanup
|
73
|
+
end
|
74
|
+
|
75
|
+
protected
|
76
|
+
|
77
|
+
# This handles outputting the communication data back to the UI
|
78
|
+
def handle_comm(type, data)
|
79
|
+
if [:stderr, :stdout].include?(type)
|
80
|
+
# Output the data with the proper color based on the stream.
|
81
|
+
color = type == :stdout ? :green : :red
|
82
|
+
|
83
|
+
# Clear out the newline since we add one
|
84
|
+
data = data.chomp
|
85
|
+
return if data.empty?
|
86
|
+
|
87
|
+
options = {}
|
88
|
+
options[:color] = color if !config.keep_color
|
89
|
+
|
90
|
+
@machine.ui.info(data.chomp, options)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
Provisioner
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<unattend xmlns="urn:schemas-microsoft-com:unattend">
|
3
|
+
<settings pass="generalize">
|
4
|
+
<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">
|
5
|
+
<SkipRearm>1</SkipRearm>
|
6
|
+
</component>
|
7
|
+
<component name="Microsoft-Windows-PnpSysprep" 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">
|
8
|
+
<PersistAllDeviceInstalls>true</PersistAllDeviceInstalls>
|
9
|
+
<DoNotCleanUpNonPresentDevices>true</DoNotCleanUpNonPresentDevices>
|
10
|
+
</component>
|
11
|
+
</settings>
|
12
|
+
<settings pass="oobeSystem">
|
13
|
+
<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
|
+
<InputLocale>en-US</InputLocale>
|
15
|
+
<SystemLocale>en-US</SystemLocale>
|
16
|
+
<UILanguage>en-US</UILanguage>
|
17
|
+
<UserLocale>en-US</UserLocale>
|
18
|
+
</component>
|
19
|
+
<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">
|
20
|
+
<OOBE>
|
21
|
+
<HideEULAPage>true</HideEULAPage>
|
22
|
+
<HideLocalAccountScreen>true</HideLocalAccountScreen>
|
23
|
+
<HideOEMRegistrationScreen>true</HideOEMRegistrationScreen>
|
24
|
+
<HideOnlineAccountScreens>true</HideOnlineAccountScreens>
|
25
|
+
<HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE>
|
26
|
+
<NetworkLocation>Home</NetworkLocation>
|
27
|
+
<ProtectYourPC>1</ProtectYourPC>
|
28
|
+
</OOBE>
|
29
|
+
</component>
|
30
|
+
</settings>
|
31
|
+
</unattend>
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# see https://gist.github.com/IISResetMe/36ef331484a770e23a81
|
2
|
+
function Get-MachineSID {
|
3
|
+
param(
|
4
|
+
[switch]$DomainSID
|
5
|
+
)
|
6
|
+
|
7
|
+
# Retrieve the Win32_ComputerSystem class and determine if machine is a Domain Controller
|
8
|
+
$WmiComputerSystem = Get-WmiObject -Class Win32_ComputerSystem
|
9
|
+
$IsDomainController = $WmiComputerSystem.DomainRole -ge 4
|
10
|
+
|
11
|
+
if ($IsDomainController -or $DomainSID) {
|
12
|
+
# We grab the Domain SID from the DomainDNS object (root object in the default NC)
|
13
|
+
$Domain = $WmiComputerSystem.Domain
|
14
|
+
$SIDBytes = ([ADSI]"LDAP://$Domain").objectSid | %{$_}
|
15
|
+
New-Object System.Security.Principal.SecurityIdentifier -ArgumentList ([Byte[]]$SIDBytes),0
|
16
|
+
} else {
|
17
|
+
# Going for the local SID by finding a local account and removing its Relative ID (RID)
|
18
|
+
$LocalAccountSID = Get-WmiObject -Query "SELECT SID FROM Win32_UserAccount WHERE LocalAccount = 'True'" | Select-Object -First 1 -ExpandProperty SID
|
19
|
+
$MachineSID = ($p = $LocalAccountSID -split "-")[0..($p.Length-2)]-join"-"
|
20
|
+
New-Object System.Security.Principal.SecurityIdentifier -ArgumentList $MachineSID
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
echo "This Machine SID is $(Get-MachineSID)"
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant-windows-sysprep
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rui Lopes
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Vagrant plugin for running Windows sysprep.
|
28
|
+
email: rgl@ruilopes.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/vagrant-windows-sysprep.rb
|
34
|
+
- lib/vagrant-windows-sysprep/autounattend.xml
|
35
|
+
- lib/vagrant-windows-sysprep/show-sid.ps1
|
36
|
+
- lib/vagrant-windows-sysprep/version.rb
|
37
|
+
homepage: https://github.com/rgl/vagrant-windows-sysprep
|
38
|
+
licenses:
|
39
|
+
- LGPLv3
|
40
|
+
metadata: {}
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 2.5.2
|
58
|
+
signing_key:
|
59
|
+
specification_version: 4
|
60
|
+
summary: Vagrant plugin for running Windows sysprep.
|
61
|
+
test_files: []
|