[PATCH] Set arch in win7 unattended installation XML



Currently, the CPU arch for unattended win7 installations is
hardcoded to amd64. This means unattended install of 32 bit
ISOs will not work. This patch adds a new BOXES_CPU string to
the template xml file which will get substituted with the actual
CPU arch.
---
 data/win7.xml            |    6 +++---
 src/installer-media.vala |   17 +++++++++++++++++
 src/win7-installer.vala  |   22 ++++++++++++++++++++++
 3 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/data/win7.xml b/data/win7.xml
index c14d76c..69a2595 100644
--- a/data/win7.xml
+++ b/data/win7.xml
@@ -1,7 +1,7 @@
 <?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";>
+    <component name="Microsoft-Windows-Setup" processorArchitecture="BOXES_CPU" 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>
@@ -46,7 +46,7 @@
 	<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";>
+    <component name="Microsoft-Windows-International-Core-WinPE" processorArchitecture="BOXES_CPU" 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>BOXES_LANG</UILanguage>
       </SetupUILanguage>
@@ -56,7 +56,7 @@
     </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";>
+    <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="BOXES_CPU" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
       <UserAccounts>
 	<AdministratorPassword>
 	  <Value>BOXES_PASSWORD</Value>
diff --git a/src/installer-media.vala b/src/installer-media.vala
index e7ab93a..6744052 100644
--- a/src/installer-media.vala
+++ b/src/installer-media.vala
@@ -3,6 +3,12 @@
 using Osinfo;
 using GUdev;
 
+public enum Boxes.CpuArch {
+    UNKNOWN,
+    X86,
+    X86_64
+}
+
 private class Boxes.InstallerMedia : Object {
     public Os os;
     public Media os_media;
@@ -13,6 +19,17 @@ private class Boxes.InstallerMedia : Object {
 
     public bool live { get { return os_media == null || os_media.live; } }
 
+    public Boxes.CpuArch get_arch() {
+        switch (os_media.architecture) {
+            case "i386":
+                return Boxes.CpuArch.X86;
+            case "x86_64":
+                return Boxes.CpuArch.X86_64;
+        }
+
+        return Boxes.CpuArch.UNKNOWN;
+    }
+
     public static async InstallerMedia instantiate (string       path,
                                                     OSDatabase   os_db,
                                                     Client       client,
diff --git a/src/win7-installer.vala b/src/win7-installer.vala
index 88ea01d..bfaca65 100644
--- a/src/win7-installer.vala
+++ b/src/win7-installer.vala
@@ -1,7 +1,29 @@
 // This file is part of GNOME Boxes. License: LGPLv2+
 
 // Automated installer media for Windows 7 and 2008
+
 private class Boxes.Win7Installer: WindowsInstaller {
+    private static Regex arch_regex;
+
+    static construct {
+        try {
+            arch_regex = new Regex ("BOXES_CPU");
+        } catch (RegexError error) {
+            // This just can't fail
+            assert_not_reached ();
+        }
+    }
+
+    protected override string fill_unattended_data (string data) throws RegexError {
+        var str = base.fill_unattended_data (data);
+        switch (get_arch()) {
+            case Boxes.CpuArch.X86_64:
+                return arch_regex.replace (str, str.length, 0, "amd64");
+            default:
+                return arch_regex.replace (str, str.length, 0, "x86");
+        }
+    }
+
     public Win7Installer.copy (InstallerMedia media) throws GLib.Error {
         var unattended_source = get_unattended_dir (media.os.short_id + ".xml");
         base.copy (media, unattended_source, "Autounattend.xml");
-- 
1.7.7.5



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]