Don't overwrite C:\Unattend.xml in the windows
[snf-image] / snf-image-helper / tasks / 40InstallUnattend.in
index 8624f32..645dc11 100644 (file)
@@ -45,15 +45,23 @@ fi
 target=$SNF_IMAGE_TARGET
 mkdir -p "$target/Windows/Setup/Scripts"
 
-if [ -n "$SNF_IMAGE_UNATTEND" ]; then
-    echo "Installing custom Unattend.xml file..."
-    if [ -f "$SNF_IMAGE_UNATTEND" ]; then
-        cat "$SNF_IMAGE_UNATTEND" > "$target/Unattend.xml"
+# Workaround to search for C:\Unattend.xml in an case insensitive way.
+exists=$(find "$target"/ -maxdepth 1 -iname unattend.xml)
+
+if [ -n "$exists" -a -z "$SNF_IMAGE_PROPERTY_USE_DEFAULT_UNATTEND" ]; then
+    warn "Using the Unattend.xml file found in the image"
+else
+    xargs rm -f <<< "$exists"
+    if [ -n "$SNF_IMAGE_UNATTEND" ]; then
+        echo "Installing custom Unattend.xml file..."
+        if [ -f "$SNF_IMAGE_UNATTEND" ]; then
+            cat "$SNF_IMAGE_UNATTEND" > "$target/Unattend.xml"
+        else
+            log_error "Custom unattend file: \`"$SNF_IMAGE_UNATTEND"' is missing"
+        fi
     else
-        log_error "Custom unattend file: \`"$SNF_IMAGE_UNATTEND"' is missing"
+        cat "@commondir@/unattend.xml" > "$target/Unattend.xml"
     fi
-else
-    cat "@commondir@/unattend.xml" > "$target/Unattend.xml"
 fi
 
 echo "del /Q /F C:\Unattend.xml" > \