mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
firstboot: Ensure firstboot scripts run in command line order.
Previously they ran in effectively random order.
This commit is contained in:
@@ -556,24 +556,23 @@ exec >>%s 2>&1
|
||||
|
||||
(* Firstboot scripts/commands/install. *)
|
||||
let () =
|
||||
let id = ref 0 in
|
||||
let i = ref 0 in
|
||||
List.iter (
|
||||
fun op ->
|
||||
incr id;
|
||||
let id = sprintf "%03d" !id in
|
||||
incr i;
|
||||
match op with
|
||||
| `Script script ->
|
||||
msg (f_"Installing firstboot script: [%s] %s") id script;
|
||||
msg (f_"Installing firstboot script: [%d] %s") !i script;
|
||||
let cmd = read_whole_file script in
|
||||
Firstboot.add_firstboot_script g root id cmd
|
||||
Firstboot.add_firstboot_script g root !i cmd
|
||||
| `Command cmd ->
|
||||
msg (f_"Installing firstboot command: [%s] %s") id cmd;
|
||||
Firstboot.add_firstboot_script g root id cmd
|
||||
msg (f_"Installing firstboot command: [%d] %s") !i cmd;
|
||||
Firstboot.add_firstboot_script g root !i cmd
|
||||
| `Packages pkgs ->
|
||||
msg (f_"Installing firstboot packages: [%s] %s") id
|
||||
msg (f_"Installing firstboot packages: [%d] %s") !i
|
||||
(String.concat " " pkgs);
|
||||
let cmd = guest_install_command pkgs in
|
||||
Firstboot.add_firstboot_script g root id cmd
|
||||
Firstboot.add_firstboot_script g root !i cmd
|
||||
) firstboot in
|
||||
|
||||
(* Run scripts. *)
|
||||
|
||||
@@ -153,7 +153,7 @@ and install_sysvinit_debian g =
|
||||
g#ln_sf "/etc/init.d/virt-sysprep-firstboot"
|
||||
"/etc/rc5.d/S99virt-sysprep-firstboot"
|
||||
|
||||
let add_firstboot_script (g : Guestfs.guestfs) root id content =
|
||||
let add_firstboot_script (g : Guestfs.guestfs) root i content =
|
||||
let typ = g#inspect_get_type root in
|
||||
let distro = g#inspect_get_distro root in
|
||||
match typ, distro with
|
||||
@@ -161,7 +161,7 @@ let add_firstboot_script (g : Guestfs.guestfs) root id content =
|
||||
install_service g distro;
|
||||
let t = Int64.of_float (Unix.time ()) in
|
||||
let r = string_random8 () in
|
||||
let filename = sprintf "%s/scripts/%Ld-%s-%s" firstboot_dir t r id in
|
||||
let filename = sprintf "%s/scripts/%04d-%Ld-%s" firstboot_dir i t r in
|
||||
g#write filename content;
|
||||
g#chmod 0o755 filename
|
||||
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*)
|
||||
|
||||
val add_firstboot_script : Guestfs.guestfs -> string -> string -> string -> unit
|
||||
(** [add_firstboot_script g root id content] adds a firstboot
|
||||
val add_firstboot_script : Guestfs.guestfs -> string -> int -> string -> unit
|
||||
(** [add_firstboot_script g root idx content] adds a firstboot
|
||||
script called [shortname] containing [content].
|
||||
|
||||
NB. [content] is the contents of the script, {b not} a filename.
|
||||
|
||||
[id] should be a short name containing only 7 bit ASCII [-a-z0-9].
|
||||
The scripts run in index ([idx]) order.
|
||||
|
||||
You should make sure the filesystem is relabelled after calling this. *)
|
||||
|
||||
@@ -26,27 +26,18 @@ module G = Guestfs
|
||||
|
||||
let files = ref []
|
||||
|
||||
let make_id_from_filename filename =
|
||||
let ret = String.copy filename in
|
||||
for i = 0 to String.length ret - 1 do
|
||||
let c = String.unsafe_get ret i in
|
||||
if not ((c >= 'a' && c <= 'z') ||
|
||||
(c >= 'A' && c <= 'Z') ||
|
||||
(c >= '0' && c <= '9')) then
|
||||
String.unsafe_set ret i '-'
|
||||
done;
|
||||
ret
|
||||
|
||||
let firstboot_perform g root =
|
||||
(* Read the files and add them using the {!Firstboot} module. *)
|
||||
let files = List.rev !files in
|
||||
let i = ref 0 in
|
||||
List.iter (
|
||||
fun filename ->
|
||||
incr i;
|
||||
let i = !i in
|
||||
let content = read_whole_file filename in
|
||||
let basename = Filename.basename filename in
|
||||
let id = make_id_from_filename basename in
|
||||
Firstboot.add_firstboot_script g root id content
|
||||
) !files;
|
||||
if !files <> [] then [ `Created_files ] else []
|
||||
Firstboot.add_firstboot_script g root i content
|
||||
) files;
|
||||
if files <> [] then [ `Created_files ] else []
|
||||
|
||||
let op = {
|
||||
defaults with
|
||||
|
||||
Reference in New Issue
Block a user