Output the get_image_element_array function like d-i-b does, together
with the eval stuff needed to make it work.
get_image_element_array is basically a bash array, with the keys are the
used elements, and the values are the paths of each element; it is a new
addition in d-i-b 2.0.
This is used so far only for the extra-data.d phase.
---
dib/dib.ml | 25 ++++++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/dib/dib.ml b/dib/dib.ml
index 2e4da4b..0d128e3 100644
--- a/dib/dib.ml
+++ b/dib/dib.ml
@@ -74,9 +74,15 @@ let envvars_string l =
let prepare_external ~envvars ~dib_args ~dib_vars ~out_name ~root_label
~rootfs_uuid ~image_cache ~arch ~network ~debug ~fs_type ~checksum
- destdir libdir fakebindir all_elements element_paths =
+ destdir libdir fakebindir loaded_elements all_elements element_paths =
let network_string = if network then "" else "1" in
let checksum_string = if checksum then "1" else "" in
+ let elements_paths_array =
+ List.map (
+ fun e ->
+ sprintf "[%s]=%s" e (quote (Hashtbl.find loaded_elements e).directory)
+ ) (StringSet.elements all_elements) in
+ let elements_paths_array = String.concat " " elements_paths_array in
let run_extra = sprintf "\
#!/bin/bash
@@ -91,6 +97,8 @@ shift
script=$1
shift
+VIRT_DIB_OURPATH=$(dirname $(realpath $0))
+
# user variables
%s
@@ -116,6 +124,9 @@ export DIB_DEBUG_TRACE=%d
export FS_TYPE=%s
export DIB_CHECKSUM=%s
+elinfo_out=$(<${VIRT_DIB_OURPATH}/elinfo_out)
+eval \"$elinfo_out\"
+
ENVIRONMENT_D_DIR=$target_dir/../environment.d
if [ -d $ENVIRONMENT_D_DIR ] ; then
@@ -148,7 +159,15 @@ $target_dir/$script
debug
fs_type
checksum_string in
- write_script (destdir // "run-part-extra.sh") run_extra
+ write_script (destdir // "run-part-extra.sh") run_extra;
+ let elinfo_out = sprintf "\
+function get_image_element_array {
+ echo \"%s\"
+};
+export -f get_image_element_array;
+"
+ elements_paths_array in
+ write_script (destdir // "elinfo_out") elinfo_out
let prepare_aux ~envvars ~dib_args ~dib_vars ~log_file ~out_name ~rootfs_uuid
~arch ~network ~root_label ~install_type ~debug ~extra_packages ~fs_type
@@ -636,7 +655,7 @@ let main () =
~checksum:cmdline.checksum
tmpdir cmdline.basepath
(auxtmpdir // "fake-bin")
- all_elements cmdline.element_paths;
+ loaded_elements all_elements cmdline.element_paths;
let run_hook ~blockdev ~sysroot ?(new_wd = "") (g : Guestfs.guestfs) hook =
try
--
2.9.3