[Libguestfs] [libguestfs] Add ability to set a command for firstboot and not only a script (#7)

Richard W.M. Jones rjones at redhat.com
Thu Nov 7 17:34:32 UTC 2013


Attaching the patch to this email.

Note we don't do github pull requests:
http://libguestfs.org/guestfs-faq.1.html#where-do-i-send-patches

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top
-------------- next part --------------
>From a942b3d7d20dc842122ac489f2f58e5ffe844b05 Mon Sep 17 00:00:00 2001
From: Guilhem Lettron <guilhem at lettron.fr>
Date: Thu, 7 Nov 2013 17:29:54 +0100
Subject: [PATCH] Add ability to set a command for firstboot and not only a
 script

---
 sysprep/sysprep_operation_firstboot.ml | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/sysprep/sysprep_operation_firstboot.ml b/sysprep/sysprep_operation_firstboot.ml
index 3473c47..6f61d15 100644
--- a/sysprep/sysprep_operation_firstboot.ml
+++ b/sysprep/sysprep_operation_firstboot.ml
@@ -24,20 +24,23 @@ open Common_gettext.Gettext
 
 module G = Guestfs
 
-let files = ref []
+let params = ref []
 
 let firstboot_perform g root =
-  (* Read the files and add them using the {!Firstboot} module. *)
-  let files = List.rev !files in
+  (* Read command or files and add them using the {!Firstboot} module. *)
+  let params = List.rev !params in
   let i = ref 0 in
   List.iter (
-    fun filename ->
+    fun param->
       incr i;
       let i = !i in
-      let content = read_whole_file filename in
-      Firstboot.add_firstboot_script g root i content
-  ) files;
-  if files <> [] then [ `Created_files ] else []
+      if Sys.file_exists param then
+        let content = read_whole_file param in
+        Firstboot.add_firstboot_script g root i content
+      else
+        Firstboot.add_firstboot_script g root i param
+  ) params;
+  if params <> [] then [ `Created_files ] else []
 
 let op = {
   defaults with
@@ -65,7 +68,7 @@ Currently this is only implemented for Linux guests using
 either SysVinit-style scripts, Upstart or systemd.");
 
     extra_args = [
-      ("--firstboot", Arg.String (fun s -> files := s :: !files),
+      ("--firstboot", Arg.String (fun s -> params := s :: !params),
        s_"script" ^ " " ^ s_"run script once next time guest boots"),
       s_"\
 Run script(s) once next time the guest boots.  You can supply
-- 
1.8.4



More information about the Libguestfs mailing list