Fix a bug introduced in 9fca5245a2eae67af86719bb0f
authorNikos Skalkotos <skalkoto@grnet.gr>
Mon, 19 Nov 2012 16:40:18 +0000 (18:40 +0200)
committerNikos Skalkotos <skalkoto@grnet.gr>
Thu, 22 Nov 2012 12:15:01 +0000 (14:15 +0200)
AssignHostname task did not search for Unattend.xml in a case
insensitive way.

snf-image-helper/common.sh
snf-image-helper/tasks/40InstallUnattend.in
snf-image-helper/tasks/50AssignHostname.in

index 08ad40e..d666e4f 100644 (file)
@@ -340,6 +340,18 @@ get_last_free_sector() {
     fi
 }
 
+get_unattend() {
+    local target="$1"
+
+    # Workaround to search for $target/Unattend.xml in an case insensitive way.
+    exists=$(find "$target"/ -maxdepth 1 -iname unattend.xml)
+    if [ $(wc -l <<< "$exists") -gt 1 ]; then
+        log_error "Found multiple Unattend.xml files in the image:" $exists
+    fi
+
+    echo "$exists"
+}
+
 cleanup() {
     # if something fails here, it shouldn't call cleanup again...
     trap - EXIT
index 645dc11..2dea065 100644 (file)
@@ -45,13 +45,12 @@ fi
 target=$SNF_IMAGE_TARGET
 mkdir -p "$target/Windows/Setup/Scripts"
 
-# Workaround to search for C:\Unattend.xml in an case insensitive way.
-exists=$(find "$target"/ -maxdepth 1 -iname unattend.xml)
+unattend=$(get_unattend "$target")
 
-if [ -n "$exists" -a -z "$SNF_IMAGE_PROPERTY_USE_DEFAULT_UNATTEND" ]; then
+if [ -n "$unattend" -a -z "$SNF_IMAGE_PROPERTY_USE_DEFAULT_UNATTEND" ]; then
     warn "Using the Unattend.xml file found in the image"
 else
-    xargs rm -f <<< "$exists"
+    rm -f "$unattend"
     if [ -n "$SNF_IMAGE_UNATTEND" ]; then
         echo "Installing custom Unattend.xml file..."
         if [ -f "$SNF_IMAGE_UNATTEND" ]; then
index a45434d..d1bc9bf 100644 (file)
@@ -37,16 +37,21 @@ windows_hostname() {
     local target="$1"
     local password="$2"
 
-    local tmp_unattend=`mktemp` || exit 1
+    local tmp_unattend=$(mktemp) || exit 1
     add_cleanup rm "$tmp_unattend"
 
     echo -n "Assigning new computer name..."
 
     local namespace="urn:schemas-microsoft-com:unattend"
+
+    unattend=$(get_unattend "$target")
+    if [ -z "$unattend" ]; then
+        log_error "Unattend.xml is missing."
+    fi
     
-    "$XMLSTARLET" ed -N x=$namespace -u "/x:unattend/x:settings/x:component/x:ComputerName" -v "$password" "$target/Unattend.xml" > "$tmp_unattend"
+    "$XMLSTARLET" ed -N x=$namespace -u "/x:unattend/x:settings/x:component/x:ComputerName" -v "$password" "$unattend" > "$tmp_unattend"
 
-    cat "$tmp_unattend" > "$target/Unattend.xml"
+    cat "$tmp_unattend" > "$unattend"
     echo done
 }