Commit 6f9666e4 authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

Add new os_product_key parameter

This can be used to license a Windows deployment
parent 71fa3598
......@@ -242,6 +242,8 @@ environment variables that are present when the configuration tasks run.
+---------------------+-------------------------------------------------------+
|PASSWD_HASH |The value of the img_passwd_hash OS parameter. |
+---------------------+-------------------------------------------------------+
|OS_PRODUCT_KEY |The value of the os_product_key parameter. |
+---------------------+-------------------------------------------------------+
|PROPERTY_* |The value of a specific image property that was |
| |specified in json through the img_properties OS |
| |parameter. |
......
......@@ -581,6 +581,8 @@ create_unattend_component() {
-i "$component" -t attr -n xmlns:xsi -v "http://www.w3.org/2001/XMLSchema-instance" \
"$unattend"
fi
echo "$component"
}
windows_add_synchronous_command() {
......@@ -593,10 +595,7 @@ windows_add_synchronous_command() {
path="$5"
# Create 'Microsoft-Windows-Deployment' if missing
create_unattend_component "$unattend" specialize 'Microsoft-Windows-Deployment' "$arch"
component='/_:unattend/_:settings[@pass="specialize"]'
component+='/_:component[@name="Microsoft-Windows-Deployment" and @processorArchitecture="'"$arch"'"]'
component="$(create_unattend_component "$unattend" specialize 'Microsoft-Windows-Deployment' "$arch")"
if ! $XMLSTARLET sel -t -v "$component/_:RunSynchronous" "$unattend" &>/dev/null; then
$XMLSTARLET ed -L -s "$component" -t elem -n RunSynchronous "$unattend"
......@@ -615,6 +614,27 @@ windows_add_synchronous_command() {
-d "$rsc/@randomToken" "$unattend"
}
windows_update_unattend_node() {
local unattend pass component arch name value xpath
unattend="$1"
pass=$2
component=$3
arch="$4"
name="$5"
value="$6"
# Create component if missing
xpath="$(create_unattend_component "$unattend" "$pass" "$component" "$arch")"
if $XMLSTARLET sel -t -v "$xpath/_:$name" "$unattend" &> /dev/null; then
# The node exists. Updating its value.
$XMLSTARLET ed -L -u "$xpath/_:$name" -v "$value" "$unattend"
else
# Creating the node.
$XMLSTARLET ed -L -s "$xpath" -t elem -n $name -v "$value" "$unattend"
fi
}
bsd2linux() {
local partition device
partition="$1"
......
......@@ -124,6 +124,13 @@ if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = windows ]; then
"$((order++))" \
'diskpart.exe /s C:\Windows\SnfScripts\ExtendFilesystem'
fi
if [ -n "${SNF_IMAGE_OS_PRODUCT_KEY+dummy}" ]; then
windows_update_unattend_node "$unattend" specialize \
"Microsoft-Windows-Shell-Setup" "$arch" ProductKey \
"$SNF_IMAGE_OS_PRODUCT_KEY"
fi
elif [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "windows-legacy" ]; then
# If using an old-style (XP / Server 2003) SYSPREP.INF answer file,
# ensure C:\SnfScripts\SetupComplete.cmd is executed via CmdLines.txt
......@@ -164,6 +171,11 @@ elif [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "windows-legacy" ]; then
echo '"C:\Windows\SnfScripts\ChangeAdminPassword.cmd"' >>"$cmdlinestxt"
echo '"C:\Windows\Setup\Scripts\SetupComplete.cmd"' >>"$cmdlinestxt"
#Install a product key if defined
if [ -n "${SNF_IMAGE_OS_PRODUCT_KEY+dummy}" ]; then
$h "$sysprepinf" set UserData ProductKey "$SNF_IMAGE_OS_PRODUCT_KEY"
fi
fi
fi
......
......@@ -61,7 +61,7 @@ windows-legacy_hostname() {
}
windows_hostname() {
local target hostname unattend arch xpath
local target hostname unattend arch component
target="$1"
hostname="$2"
......@@ -81,19 +81,8 @@ windows_hostname() {
log_error "Unable to determine windows architecture"
fi
# Create Microsoft-Windows-Shell-Setup component if missing
create_unattend_component "$unattend" specialize Microsoft-Windows-Shell-Setup "$arch"
xpath='/_:unattend/_:settings[@pass="specialize"]/'
xpath+='_:component[@name="Microsoft-Windows-Shell-Setup" and @processorArchitecture="'"${arch}"'"]'
if $XMLSTARLET sel -t -v "$xpath/_:ComputerName" "$unattend" &> /dev/null; then
# ComputerName node exists. Updating its value.
$XMLSTARLET ed -L -u "$xpath/_:ComputerName" -v "$hostname" "$unattend"
else
# Creating ComputerName subnode.
$XMLSTARLET ed -L -s "$xpath" -t elem -n ComputerName -v "$hostname" "$unattend"
fi
windows_update_unattend_node "$unattend" specialize \
"Microsoft-Windows-Shell-Setup" "$arch" ComputerName "$hostname"
echo done
}
......
......@@ -130,7 +130,7 @@ get_api20_arguments() {
get_api10_arguments
if [ "$SCRIPT_NAME" = "create" ]; then
local osparams="IMG_ID IMG_FORMAT IMG_PASSWD IMG_PASSWD_HASH IMG_PROPERTIES IMG_PERSONALITY CONFIG_URL"
local osparams="IMG_ID IMG_FORMAT IMG_PASSWD IMG_PASSWD_HASH IMG_PROPERTIES IMG_PERSONALITY CONFIG_URL OS_PRODUCT_KEY"
local osp
# Store OSP_VAR in VAR
......
......@@ -206,6 +206,10 @@ if [ -n "$IMG_PERSONALITY" ]; then
snf_export_PERSONALITY="$IMG_PERSONALITY"
fi
if [ -n "${OS_PRODUCT_KEY+dummy}" ]; then
snf_export_OS_PRODUCT_KEY="$OS_PRODUCT_KEY"
fi
assign_disk_devices_to snf_export_DEV
create_floppy "$floppy"
......
......@@ -4,4 +4,5 @@ img_passwd The password to be assigned to the user accounts
img_passwd_hash Hashed version of the password to be assigned to the user accounts (conflicts with img_passwd)
img_properties The image properties that are used to customize the image (json.dumps format)
img_personality The files to be injected into the image (base64 encoded in a json.dumps format)
os_product_key A product key to be used to license a Windows deployment (windows-only)
config_url The URL to download configuration data from
......@@ -24,7 +24,7 @@ set -e
check_required() {
local required_params="IMG_ID IMG_FORMAT"
local osparams="$required_params IMG_PASSWD IMG_PROPERTIES IMG_PERSONALITY CONFIG_URL"
local osparams="$required_params IMG_PASSWD IMG_PROPERTIES IMG_PERSONALITY CONFIG_URL OS_PRODUCT_KEY"
local osp
source_variant
......@@ -41,10 +41,18 @@ check_required() {
for var in $required_params; do
if [ -z "${!var}" ]; then
log_error "Missing OS API Parameter: ${var}"
log_error "Missing OS API Parameter: ${var,,}"
exit 1
fi
done
if [ -n "${OS_PRODUCT_KEY+dummy}" ]; then
if [[ ! "${OS_PRODUCT_KEY}" =~ ^([a-zA-Z0-9]{5}-){3}[a-zA-Z0-9]{5}$ ]]; then
log_error "Invalid OS API Parameter: os_product_key."
log_error "Valid format is: XXXXX-XXXXX-XXXXX-XXXXX"
exit 1
fi
fi
}
if [ -z "$OSP_CONFIG_URL" ]; then
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment