From b7ecbcc3bad023df43f350f56cd421e344bbfddc Mon Sep 17 00:00:00 2001
From: Scott Little <scott.little@windriver.com>
Date: Fri, 29 Apr 2022 11:13:46 -0400
Subject: [PATCH] build-iso: Create package_checksums file within iso

Extended build-iso to create the package_checksums file
after the Packages subdirectory has been created and all rpms
are signed.  It can be found in the root directory of the
mounted iso.

The kickstarts will have to be extended to copy the
package_checksums from the iso to the final location
on the controller.

Story: 2009948
Task: 45219
Signed-off-by: Scott Little <scott.little@windriver.com>
Change-Id: I4cf064911600f89e356527ee274f40c6ce14a990
---
 build-tools/build-iso | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/build-tools/build-iso b/build-tools/build-iso
index 1ff2210a..fc366699 100755
--- a/build-tools/build-iso
+++ b/build-tools/build-iso
@@ -449,6 +449,18 @@ function init_output_dir {
    echo ""
 }
 
+function package_content_checksum {
+    local p=$1
+    local md5
+    local r
+    r=$(basename $p)
+    md5=$( ( rpm2cpio $p;
+             rpm -q --info -p $p;
+             rpm -q --dump -p $p;
+             rpm -q --scripts -p $p ) | md5sum | cut -d ' ' -f 1)
+    echo "$r $md5"
+}
+
 function final_touches {
    OLD_PWD=$PWD
 
@@ -480,7 +492,13 @@ function final_touches {
    # create the repo
    \cd $OUTPUT_DIST_DIR/isolinux
    $CREATEREPO -q -g ../comps.xml .
- 
+
+   # Create package_checksums
+   printf "creating package_checksums file\n"
+   for r in $(ls Packages/*rpm); do
+      package_content_checksum $r
+   done > package_checksums
+
    # build the ISO
    printf "Building image $OUTPUT_FILE\n"
    \cd $OUTPUT_DIST_DIR