mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
sysprep: add a update_system_ca_store side effect
Add a simple side effect to make operation flag that a regeneration of
the system CA store is needed. In case it is flagged, regenerate the
system CA store directly, or using a firstboot script in case of
incompatible architectures.
This change is almost a no-op, since no operation requires the
regeneration of the system CA store yet.
(cherry picked from commit bb7fc6d0a1)
This commit is contained in:
@@ -25,6 +25,7 @@ open Common_gettext.Gettext
|
||||
open Getopt.OptionName
|
||||
|
||||
open Sysprep_operation
|
||||
open Utils
|
||||
|
||||
module G = Guestfs
|
||||
|
||||
@@ -236,6 +237,10 @@ read the man page virt-sysprep(1).
|
||||
Sysprep_operation.perform_operations_on_filesystems
|
||||
?operations g root side_effects;
|
||||
|
||||
(* Do we need to update the system CA store? *)
|
||||
if side_effects#get_update_system_ca_store then
|
||||
update_system_ca_store g root;
|
||||
|
||||
(* Unmount everything in this guest. *)
|
||||
g#umount_all ();
|
||||
|
||||
|
||||
@@ -27,10 +27,13 @@ class filesystem_side_effects =
|
||||
object
|
||||
val mutable m_created_file = false
|
||||
val mutable m_changed_file = false
|
||||
val mutable m_update_system_ca_store = false
|
||||
method created_file () = m_created_file <- true
|
||||
method get_created_file = m_created_file
|
||||
method changed_file () = m_changed_file <- true
|
||||
method get_changed_file = m_changed_file
|
||||
method update_system_ca_store () = m_update_system_ca_store <- true
|
||||
method get_update_system_ca_store = m_update_system_ca_store
|
||||
end
|
||||
|
||||
class device_side_effects = object end
|
||||
|
||||
@@ -23,6 +23,8 @@ class filesystem_side_effects : object
|
||||
method get_created_file : bool
|
||||
method changed_file : unit -> unit
|
||||
method get_changed_file : bool
|
||||
method update_system_ca_store : unit -> unit
|
||||
method get_update_system_ca_store : bool
|
||||
end
|
||||
(** The callback should indicate if it has side effects by calling
|
||||
methods in this class. *)
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
|
||||
open Printf
|
||||
|
||||
open Tools_utils
|
||||
open Common_gettext.Gettext
|
||||
|
||||
let rec pod_of_list ?(style = `Dot) xs =
|
||||
match style with
|
||||
| `Verbatim -> String.concat "\n" (List.map ((^) " ") xs)
|
||||
@@ -31,3 +34,32 @@ and _pod_of_list delim xs =
|
||||
"=over 4\n\n" ^
|
||||
String.concat "" (List.map (sprintf "=item %s\n\n%s\n\n" delim) xs) ^
|
||||
"=back"
|
||||
|
||||
let rec update_system_ca_store g root =
|
||||
let cmd = update_system_ca_store_command g root in
|
||||
match cmd with
|
||||
| None -> ()
|
||||
| Some cmd ->
|
||||
(* Try to run the command directly if possible, adding it as
|
||||
* firstboot script in case of incompatible architectures.
|
||||
*)
|
||||
let cmd = String.concat " " cmd in
|
||||
let incompatible_fn () =
|
||||
Firstboot.add_firstboot_script g root cmd cmd
|
||||
in
|
||||
|
||||
run_in_guest_command g root ~incompatible_fn cmd
|
||||
|
||||
and update_system_ca_store_command g root =
|
||||
let typ = g#inspect_get_type root in
|
||||
let distro = g#inspect_get_distro root in
|
||||
match typ, distro with
|
||||
| "linux", ("fedora"|"rhel"|"centos"|"scientificlinux"|"oraclelinux"|"redhat-based") ->
|
||||
Some [ "update-ca-trust"; "extract" ]
|
||||
|
||||
| "linux", ("debian"|"ubuntu"|"kalilinux") ->
|
||||
Some [ "update-ca-certificates" ]
|
||||
|
||||
| _, _ ->
|
||||
warning (f_"updating the system CA store on this guest %s/%s is not supported") typ distro;
|
||||
None
|
||||
|
||||
@@ -26,3 +26,7 @@ val pod_of_list : ?style:[`Verbatim|`Star|`Dash|`Dot] -> string list -> string
|
||||
use a space-indented (verbatim) block. [`Star], [`Dash] or [`Dot]
|
||||
meaning use a real list with [*], [-] or [·]. The default
|
||||
style is [·] ([`Dot]). *)
|
||||
|
||||
val update_system_ca_store : Guestfs.guestfs -> string -> unit
|
||||
(** Update the system CA store on the guest for the specified root
|
||||
(which is fully mounted). *)
|
||||
|
||||
Reference in New Issue
Block a user