[gnome-boxes] Set timezone in case of express installation



commit 7d6c67c9b24f9df24239e563a34114a474d70c28
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Thu Dec 8 12:46:25 2011 +0200

    Set timezone in case of express installation
    
    This currently only works for Fedora.
    
    * Anaconds seems to expect full name of the timezone rather than
      abbreviation but it seems to accept and use abbreviations too.
    * Doing this for windows is another story: Windows XP/2k/2k3 would want
      some custom integer ID(1) and Windows 7/2k8 would want some long
      string name(2).
    
    1. http://blog.williambritt.com/index.php?/archives/23-XP-Unattend-Timezone-Settings.html
    2. http://technet.microsoft.com/en-us/library/cc749073%28WS.10%29.aspx
    
    https://bugzilla.gnome.org/show_bug.cgi?id=665803

 data/fedora.ks                |    2 +-
 src/unattended-installer.vala |   66 ++++++++++++++++++++++++++++-------------
 2 files changed, 46 insertions(+), 22 deletions(-)
---
diff --git a/data/fedora.ks b/data/fedora.ks
index 1efc074..e80d4d8 100644
--- a/data/fedora.ks
+++ b/data/fedora.ks
@@ -6,7 +6,7 @@ rootpw whatever
 firewall --disabled
 authconfig --enableshadow --enablemd5
 selinux --enforcing
-timezone --utc Europe/Helsinki
+timezone --utc BOXES_TZ
 bootloader --location=mbr
 zerombr
 clearpart --all --drives=sda
diff --git a/src/unattended-installer.vala b/src/unattended-installer.vala
index 30ba6fa..6c29cc3 100644
--- a/src/unattended-installer.vala
+++ b/src/unattended-installer.vala
@@ -40,8 +40,22 @@ private abstract class Boxes.UnattendedInstaller: InstallerMedia {
     protected Gtk.Entry username_entry;
     protected Gtk.Entry password_entry;
 
-    private Regex username_regex;
-    private Regex password_regex;
+    protected string timezone;
+
+    private static Regex username_regex;
+    private static Regex password_regex;
+    private static Regex timezone_regex;
+
+    static construct {
+        try {
+            username_regex = new Regex ("BOXES_USERNAME");
+            password_regex = new Regex ("BOXES_PASSWORD");
+            timezone_regex = new Regex ("BOXES_TZ");
+        } catch (RegexError error) {
+            // This just can't fail
+            assert_not_reached ();
+        }
+    }
 
     public UnattendedInstaller.copy (InstallerMedia media,
                                      string         unattended_src_path,
@@ -57,8 +71,9 @@ private abstract class Boxes.UnattendedInstaller: InstallerMedia {
         this.unattended_src_path = unattended_src_path;
         this.unattended_dest_name = unattended_dest_name;
 
-        username_regex = new Regex ("BOXES_USERNAME");
-        password_regex = new Regex ("BOXES_PASSWORD");
+        var time = TimeVal ();
+        var date = new DateTime.from_timeval_local (time);
+        timezone = date.get_timezone_abbreviation ();
 
         setup_ui ();
     }
@@ -219,23 +234,7 @@ private abstract class Boxes.UnattendedInstaller: InstallerMedia {
         var unattended_tmp_path = get_user_unattended_dir (unattended_dest_name);
         var unattended_tmp = File.new_for_path (unattended_tmp_path);
 
-        debug ("Creating unattended file at '%s'..", unattended_tmp_path);
-        var input_stream = yield unattended_src.read_async (Priority.DEFAULT, cancellable);
-        var output_stream = yield unattended_tmp.replace_async (null,
-                                                                false,
-                                                                FileCreateFlags.REPLACE_DESTINATION,
-                                                                Priority.DEFAULT,
-                                                                cancellable);
-        var buffer = new uint8[1024];
-        size_t bytes_read;
-        while ((bytes_read = yield input_stream.read_async (buffer, Priority.DEFAULT, cancellable)) > 0) {
-            var str = ((string) buffer).substring (0, (long) bytes_read);
-            str = username_regex.replace (str, str.length, 0, username_entry.text);
-            str = password_regex.replace (str, str.length, 0, password_entry.text);
-            yield output_stream.write_async (str.data, Priority.DEFAULT, cancellable);
-        }
-        yield output_stream.close_async (Priority.DEFAULT, cancellable);
-        debug ("Created unattended file at '%s'..", unattended_tmp_path);
+        create_unattended_file (unattended_src, unattended_tmp, cancellable);
 
         debug ("Copying unattended file '%s' into floppy drive/image '%s'", unattended_dest_name, floppy_path);
         // FIXME: Perhaps we should use libarchive for this?
@@ -250,6 +249,31 @@ private abstract class Boxes.UnattendedInstaller: InstallerMedia {
         debug ("Deleted temporary file '%s'", unattended_tmp_path);
     }
 
+    private async void create_unattended_file (File         source,
+                                               File         destination,
+                                               Cancellable? cancellable)  throws GLib.Error {
+        debug ("Creating unattended file at '%s'..", destination.get_path ());
+        var input_stream = yield source.read_async (Priority.DEFAULT, cancellable);
+        var output_stream = yield destination.replace_async (null,
+                                                             false,
+                                                             FileCreateFlags.REPLACE_DESTINATION,
+                                                             Priority.DEFAULT,
+                                                             cancellable);
+        var buffer = new uint8[1024];
+        size_t bytes_read;
+        while ((bytes_read = yield input_stream.read_async (buffer, Priority.DEFAULT, cancellable)) > 0) {
+            var str = ((string) buffer).substring (0, (long) bytes_read);
+
+            str = username_regex.replace (str, str.length, 0, username_entry.text);
+            str = password_regex.replace (str, str.length, 0, password_entry.text);
+            str = timezone_regex.replace (str, str.length, 0, timezone);
+
+            yield output_stream.write_async (str.data, Priority.DEFAULT, cancellable);
+        }
+        yield output_stream.close_async (Priority.DEFAULT, cancellable);
+        debug ("Created unattended file at '%s'..", destination.get_path ());
+    }
+
     private async bool unattended_floppy_exists (Cancellable? cancellable) {
         var file = File.new_for_path (floppy_path);
 



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