Skip to content

Commit

Permalink
adding windows-efi template-#3
Browse files Browse the repository at this point in the history
for #3
  • Loading branch information
g-ramirez authored and alexsander-souza committed Nov 17, 2023
1 parent df342ef commit 1ea8744
Show file tree
Hide file tree
Showing 9 changed files with 572 additions and 0 deletions.
1 change: 1 addition & 0 deletions windows/curtin/curtin-hooks
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#!/bin/bash
11 changes: 11 additions & 0 deletions windows/curtin/finalize
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

export PYTHONPATH='/curtin'

# Ubuntu 16.04 only ships with Python 3 while previous versions only ship
# with Python 2.
if type -p python > /dev/null; then
exec python "$0.py" "$@"
else
exec python3 "$0.py" "$@"
fi
163 changes: 163 additions & 0 deletions windows/curtin/finalize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
#!/usr/bin/env python

from __future__ import (
absolute_import,
print_function,
unicode_literals,
)
from curtin import util
import os
import sys
import json


CLOUDBASE_INIT_CONFIG = """\
metadata_services=cloudbaseinit.metadata.services.maasservice.MaaSHttpService
maas_metadata_url={url}
maas_oauth_consumer_key={consumer_key}
maas_oauth_consumer_secret=''
maas_oauth_token_key={token_key}
maas_oauth_token_secret={token_secret}
"""


LICENSE_KEY_SCRIPT = """\
slmgr /ipk {license_key}
Remove-Item $MyInvocation.InvocationName
"""


def load_config(path):
"""Loads the curtin config."""
with open(path, 'r') as stream:
return json.load(stream)


def get_maas_debconf_selections(config):
"""Gets the debconf selections from the curtin config."""
try:
return config['debconf_selections']['maas']
except KeyError:
return None


def extract_maas_parameters(config):
"""Extracts the needed values from the debconf
entry."""
params = {}
for line in config.splitlines():
cloud, key, type, value = line.split()[:4]
if key == "cloud-init/maas-metadata-url":
params['url'] = value
elif key == "cloud-init/maas-metadata-credentials":
values = value.split("&")
for oauth in values:
key, value = oauth.split('=')
if key == 'oauth_token_key':
params['token_key'] = value
elif key == 'oauth_token_secret':
params['token_secret'] = value
elif key == 'oauth_consumer_key':
params['consumer_key'] = value
return params


def get_cloudbase_init_config(params):
"""Returns the cloudbase-init config file."""
config = CLOUDBASE_INIT_CONFIG.format(**params)
output = ""
for line in config.splitlines():
output += "%s\r\n" % line
return output


def write_cloudbase_init(target, params):
"""Writes the configuration files for cloudbase-init."""
cloudbase_init_cfg = os.path.join(
target,
"Program Files",
"Cloudbase Solutions",
"Cloudbase-Init",
"conf",
"cloudbase-init.conf")
cloudbase_init_unattended_cfg = os.path.join(
target,
"Program Files",
"Cloudbase Solutions",
"Cloudbase-Init",
"conf",
"cloudbase-init-unattend.conf")

config = get_cloudbase_init_config(params)
with open(cloudbase_init_cfg, 'a') as stream:
stream.write(config)
with open(cloudbase_init_unattended_cfg, 'a') as stream:
stream.write(config)


def get_license_key(config):
"""Return license_key from the curtin config."""
try:
license_key = config['license_key']
except KeyError:
return None
if license_key is None:
return None
license_key = license_key.strip()
if license_key == '':
return None
return license_key


def write_license_key_script(target, license_key):
local_scripts_path = os.path.join(
target,
"Program Files",
"Cloudbase Solutions",
"Cloudbase-Init",
"LocalScripts")
script_path = os.path.join(local_scripts_path, 'set_license_key.ps1')
set_key_script = LICENSE_KEY_SCRIPT.format(license_key=license_key)
with open(script_path, 'w') as stream:
for line in set_key_script.splitlines():
stream.write("%s\r\n" % line)


def write_network_config(target, config):
network_config_path = os.path.join(target, 'network.json')
config_json = config.get('network', None)
if config_json is not None:
config_json = json.dumps(config_json)
with open(network_config_path, 'w') as stream:
for line in config_json.splitlines():
stream.write("%s\r\n" % line)


def main():
state = util.load_command_environment()
target = state['target']
if target is None:
print("Target was not provided in the environment.")
sys.exit(1)
config_f = state['config']
if config_f is None:
print("Config was not provided in the environment.")
sys.exit(1)
config = load_config(config_f)

debconf = get_maas_debconf_selections(config)
if debconf is None:
print("Failed to get the debconf_selections.")
sys.exit(1)

params = extract_maas_parameters(debconf)
write_cloudbase_init(target, params)
write_network_config(target, config)

license_key = get_license_key(config)
if license_key is not None:
write_license_key_script(target, license_key)


if __name__ == "__main__":
main()
11 changes: 11 additions & 0 deletions windows/curtin/python_wrapper
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

export PYTHONPATH='/curtin'

# Ubuntu 16.04 only ships with Python 3 while previous versions only ship
# with Python 2.
if type -p python > /dev/null; then
exec python "$0.py" "$@"
else
exec python3 "$0.py" "$@"
fi
144 changes: 144 additions & 0 deletions windows/http/Autounattend.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
<settings pass="windowsPE">
<component name="Microsoft-Windows-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">
<DiskConfiguration>
<WillShowUI>OnError</WillShowUI>

<Disk wcm:action="add">
<CreatePartitions>
<CreatePartition wcm:action="add">
<Order>1</Order>
<Size>100</Size>
<Type>EFI</Type>
</CreatePartition>
<CreatePartition wcm:action="add">
<Order>2</Order>
<Size>128</Size>
<Type>MSR</Type>
</CreatePartition>
<CreatePartition wcm:action="add">
<Extend>true</Extend>
<Order>3</Order>
<Type>Primary</Type>
</CreatePartition>
</CreatePartitions>
<ModifyPartitions>
<ModifyPartition wcm:action="add">
<Label>EFI</Label>
<Format>FAT32</Format>
<Order>1</Order>
<PartitionID>1</PartitionID>
</ModifyPartition>
<ModifyPartition wcm:action="add">
<Format>NTFS</Format>
<Order>2</Order>
<PartitionID>3</PartitionID>
<Label>System</Label>
</ModifyPartition>
</ModifyPartitions>
<DiskID>0</DiskID>
<WillWipeDisk>true</WillWipeDisk>
</Disk>

</DiskConfiguration>
<ImageInstall>
<OSImage>
<InstallTo>

<PartitionID>3</PartitionID>
<DiskID>0</DiskID>

</InstallTo>
<InstallToAvailablePartition>false</InstallToAvailablePartition>
<WillShowUI>OnError</WillShowUI>
<InstallFrom>
<MetaData wcm:action="add">
<Key>/IMAGE/NAME</Key>
<Value>Windows Server 2016 SERVERSTANDARD</Value>
</MetaData>
</InstallFrom>
</OSImage>
</ImageInstall>
<UserData>
<AcceptEula>true</AcceptEula>

</UserData>
</component>
<component name="Microsoft-Windows-International-Core-WinPE" 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">
<SetupUILanguage>
<UILanguage>en-US</UILanguage>
</SetupUILanguage>
<InputLocale>en-US</InputLocale>
<UILanguage>en-US</UILanguage>
<SystemLocale>en-US</SystemLocale>
<UserLocale>en-US</UserLocale>
</component>
</settings>
<settings pass="oobeSystem">
<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">
<VisualEffects>
<FontSmoothing>ClearType</FontSmoothing>
</VisualEffects>
<OOBE>
<HideEULAPage>true</HideEULAPage>
<ProtectYourPC>3</ProtectYourPC>
<NetworkLocation>Work</NetworkLocation>
<HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE>
<!-- Comment the following two options on Windows Vista / 7 and Windows Server 2008 / 2008 R2 -->
<!--
<HideOnlineAccountScreens>true</HideOnlineAccountScreens>
<HideLocalAccountScreen>true</HideLocalAccountScreen>
-->
</OOBE>

<FirstLogonCommands>
<SynchronousCommand wcm:action="add">
<CommandLine>%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell -NoLogo -NonInteractive -ExecutionPolicy RemoteSigned -Command A:\logon.ps1 </CommandLine>
<Order>1</Order>
</SynchronousCommand>
</FirstLogonCommands>

<UserAccounts>
<AdministratorPassword>
<Value>Passw0rd</Value>
<PlainText>true</PlainText>
</AdministratorPassword>
</UserAccounts>
<AutoLogon>
<Password>
<Value>Passw0rd</Value>
<PlainText>true</PlainText>
</Password>
<Enabled>true</Enabled>
<LogonCount>50</LogonCount>
<Username>Administrator</Username>
</AutoLogon>
<ComputerName>*</ComputerName>
</component>
</settings>
<settings pass="specialize">
<component name="Microsoft-Windows-TerminalServices-LocalSessionManager" 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">
<fDenyTSConnections>false</fDenyTSConnections>
</component>
<component name="Microsoft-Windows-TerminalServices-RDP-WinStationExtensions" 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">
<UserAuthentication>0</UserAuthentication>
</component>
<component name="Networking-MPSSVC-Svc" 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">
<FirewallGroups>
<FirewallGroup wcm:action="add" wcm:keyValue="RemoteDesktop">
<Active>true</Active>
<Profile>all</Profile>
<Group>@FirewallAPI.dll,-28752</Group>
</FirewallGroup>
</FirewallGroups>
</component>
<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">
<TimeZone>UTC</TimeZone>
<ComputerName>*</ComputerName>
</component>
<component name="Microsoft-Windows-SQMApi" 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">
<CEIPEnabled>0</CEIPEnabled>
</component>
</settings>
</unattend>
Binary file added windows/http/cloudbase-init/cloudbase_init.zip
Binary file not shown.
Loading

0 comments on commit 1ea8744

Please sign in to comment.