[Pkg-libvirt-commits] [libguestfs] 30/72: firstboot: consolidate line ending conversion

Hilko Bengen bengen at moszumanska.debian.org
Sun Apr 5 15:19:49 UTC 2015


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to branch master
in repository libguestfs.

commit 5ece174c95f981443fdad1cfb59df2f90a4d990c
Author: Roman Kagan <rkagan at parallels.com>
Date:   Fri Feb 27 15:20:15 2015 +0300

    firstboot: consolidate line ending conversion
    
    This patch moves line ending conversion for windows scripts into a
    separate helper function.
    
    This simplifies code a bit, and fixes the problem that actual firstboot
    scripts used to remain with unix-style line endings.
    
    Signed-off-by: Roman Kagan <rkagan at parallels.com>
    (cherry picked from commit 3edd770b09bf3f58cf22bf00acba58e7ba656038)
---
 customize/firstboot.ml | 33 ++++++++++++++++-----------------
 1 file changed, 16 insertions(+), 17 deletions(-)

diff --git a/customize/firstboot.ml b/customize/firstboot.ml
index 0b95708..520a212 100644
--- a/customize/firstboot.ml
+++ b/customize/firstboot.ml
@@ -24,6 +24,9 @@ open Common_gettext.Gettext
 open Customize_utils
 open Regedit
 
+let unix2dos s =
+  String.concat "\r\n" (Str.split_delim (Str.regexp_string "\n") s)
+
 (* For Linux guests. *)
 module Linux = struct
   let firstboot_dir = "/usr/lib/virt-sysprep"
@@ -207,22 +210,18 @@ module Windows = struct
      * scripts in the directory.  Note we need to use CRLF line endings
      * in this script.
      *)
-    let firstboot_script = [
-      "@echo off";
-      "echo starting firstboot service >>log.txt";
-      (* Notes:
-       * - You have to use double %% inside the batch file, but NOT
-       * when typing the same commands on the command line.
-       * - You have to use 'call' in front of every external command
-       * else it basically exec's the command and never returns.
-       * FFS.
-       *)
-      "for /f %%f in ('dir /b scripts') do call \"scripts\\%%f\" >>log.txt";
-      "echo uninstalling firstboot service >>log.txt";
-      "rhsrvany.exe -s firstboot uninstall >>log.txt";
-    ] in
-    let firstboot_script = String.concat "\r\n" firstboot_script ^ "\r\n" in
-    g#write (firstboot_dir // "firstboot.bat") firstboot_script;
+    let firstboot_script = "\
+ at echo off
+
+echo starting firstboot service >>log.txt
+
+for /f %%f in ('dir /b scripts') do call \"scripts\\%%f\" >>log.txt
+
+echo uninstalling firstboot service >>log.txt
+rhsrvany.exe -s firstboot uninstall >>log.txt
+" in
+
+    g#write (firstboot_dir // "firstboot.bat") (unix2dos firstboot_script);
 
     (* Open the SYSTEM hive. *)
     let systemroot = g#inspect_get_windows_systemroot root in
@@ -284,7 +283,7 @@ let add_firstboot_script (g : Guestfs.guestfs) root i content =
     let t = Int64.of_float (Unix.time ()) in
     let r = string_random8 () in
     let filename = sprintf "%s/scripts/%04d-%Ld-%s.bat" firstboot_dir i t r in
-    g#write filename content
+    g#write filename (unix2dos content)
 
   | _ ->
     error (f_"guest type %s/%s is not supported") typ distro

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list