Commit 85ea3ed5 authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

Make unattend.xml updating more rebust

 * Use the default namespace instead of defining it
 * Fetch the wcm namespace from the unattend.xml file
 * Add the needed XML nodes if missing
parent 25e8ab8e
......@@ -61,7 +61,7 @@ windows-legacy_hostname() {
}
windows_hostname() {
local target hostname unattend tmp_unattend namespace
local target hostname unattend xpath
target="$1"
hostname="$2"
......@@ -72,15 +72,24 @@ windows_hostname() {
echo -n "Assigning new computer name..."
namespace="urn:schemas-microsoft-com:unattend"
unattend=$(get_unattend "$target")
if [ -z "$unattend" ]; then
log_error "No Unattend.xml found in the instance."
fi
"$XMLSTARLET" ed -N x=$namespace -u "/x:unattend/x:settings/x:component/x:ComputerName" -v "$hostname" "$unattend" > "$tmp_unattend"
cat "$tmp_unattend" > "$unattend"
xpath='/_:unattend/_:settings[@pass="specialize"]/_:component[@name="Microsoft-Windows-Shell-Setup"]'
if ! $XMLSTARLET sel -t -v "$xpath" "$unattend" &> /dev/null; then
log_error 'Error in unattend.xml: Component "Microsoft-Windows-Shell-Setup" '\
'is needed but missing from "specialize" pass.'
fi
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
echo done
}
......
......@@ -75,7 +75,7 @@ netbsd_change_shadow_entry() {
}
windows_password() {
local target password sam names namespace wcm xpath unattend
local target password sam names wcm xpath unattend
target="$1"
password="$2"
sam="$target/windows/system32/config/sam"
......@@ -99,14 +99,19 @@ windows_password() {
if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = 'windows' ]; then
# Add the users that get created by the unattend.xml file
unattend="$(get_unattend "$target")"
namespace="urn:schemas-microsoft-com:unattend"
wcm="http://schemas.microsoft.com/WMIConfig/2002/State"
xpath='/x:unattend/x:settings/x:component/x:UserAccounts/'
xpath+='x:LocalAccounts/x:LocalAccount[@wcm:action="add"]/x:Name'
if [ -z "$unattend" ]; then
log_error "No unattend.xml file found in the image."
fi
# Find the wcm namespace value
wcm=$($XMLSTARLET sel -t -v '(//namespace::*[name()="wcm"])[1]' "$unattend")
xpath='/_:unattend/_:settings/_:component/_:UserAccounts/'
xpath+='_:LocalAccounts/_:LocalAccount[@wcm:action="add"]/_:Name'
names+=$($XMLSTARLET sel -N x="$namespace" -N wcm="$wcm" -t -v \
"$xpath" "$unattend") || true
names+=$($XMLSTARLET sel -N wcm="$wcm" -t -v "$xpath" "$unattend") || true
fi
for usr in $SNF_IMAGE_PROPERTY_USERS; do
......
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