From 048d08fabaaf0719ac86ce78dbc384c7c9e0748f Mon Sep 17 00:00:00 2001 From: Andrew Leonard <anleonar@redhat.com> Date: Tue, 12 Nov 2024 09:56:23 +0000 Subject: [PATCH 01/13] debug Signed-off-by: Andrew Leonard <anleonar@redhat.com> --- get.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/get.sh b/get.sh index 6cf074e191..d5e3d6390a 100755 --- a/get.sh +++ b/get.sh @@ -411,6 +411,7 @@ getBinaryOpenjdk() len=${#jar_dir_array[@]} if [ "$len" == 1 ]; then jar_dir_name=${jar_dir_array[0]} +echo "PROCESSING: ${jar_dir_name}" if [[ "$jar_dir_name" =~ "test-image" ]] || [[ "$jar_dir_name" =~ "tests-" ]]; then if [ "$jar_dir_name" != "openjdk-test-image" ]; then mv $jar_dir_name ../openjdk-test-image @@ -448,6 +449,7 @@ getBinaryOpenjdk() echo "RI JDK version:" $SDKDIR/additionaljdkbinary/bin/java -version else +echo "MOVING: mv $jar_dir_name ../j2sdk-image" mv $jar_dir_name ../j2sdk-image fi # The following only needed if openj9 has a different image name convention @@ -458,6 +460,12 @@ getBinaryOpenjdk() mv ../tmp ../j2sdk-image fi cd $SDKDIR/jdkbinary +echo "$SDKDIR/jdkbinary:" +ls -l +echo "----" +echo "j2sdk-image:" +ls -l j2sdk-image +echo "----" fi fi done From bf7216ba068ac2a6242e7464a29db0dc804c25bb Mon Sep 17 00:00:00 2001 From: Andrew Leonard <anleonar@redhat.com> Date: Wed, 13 Nov 2024 10:30:03 +0000 Subject: [PATCH 02/13] Fix getjdkbinary so it safely handles uncompressing to target folders Signed-off-by: Andrew Leonard <anleonar@redhat.com> --- get.sh | 59 ++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 12 deletions(-) diff --git a/get.sh b/get.sh index d5e3d6390a..383d21d334 100755 --- a/get.sh +++ b/get.sh @@ -160,6 +160,32 @@ parseCommandLineArgs() echo "TESTDIR: $TESTDIR" } +# If the current directory contains only a single directory then squash that directory into the current directory +squashSingleFolderContentsToCurrentDir() +{ + if [[ `ls -d */ | wc -l` -eq 1 ]] && [[ `find . -maxdepth 1 -mindepth 1 | wc -l` -eq 1 ]]; then + folder=`ls -d */` + echo "Removing top-level folder ${folder}" + mv ${folder}* . + rmdir "${folder}" + fi +} + +# Moves the given directory safely, ensuring the target does not exist, fail with error if it does exist +moveDirectorySafely() +{ + if [[ -z ${1+x} ]] || [[ -z ${2+x} ]]; then + echo "Syntax: moveDirectorySafely <sourceDirectory> <targetDirectory>" + exit 1 + fi + if [ -d "$2" ]; then + echo "ERROR: moveDirectorySafely $1 $2 : target directory $2 already exists" + exit 1 + else + mv "$1" "$2" + fi +} + getBinaryOpenjdk() { echo "get jdk binary..." @@ -375,16 +401,25 @@ getBinaryOpenjdk() extract_dir="./j2sdk-image/jre" fi echo "Uncompressing $file_name over $extract_dir..." + + # Debug image tarballs vary in top-level folders between Vendors, eg.location of bin folder + # temurin: jdk-21.0.5+11-debug-image/jdk-21.0.5+11/bin + # semeru: jdk-21.0.4+7-debug-image/bin + + # Unpack into a temp directory, remove 1 or maybe 2 top-level single folders, then copy over extract_dir + mkdir dir.$$ && cd dir.$$ if [[ $file_name == *zip ]] || [[ $file_name == *jar ]]; then - unzip -q $file_name -d $extract_dir + unzip -q $file_name else - # some debug-image tar has parent folder ... strip it - if tar --version 2>&1 | grep GNU 2>&1; then - gzip -cd $file_name | tar xof - -C $extract_dir --strip 1 - else - mkdir dir.$$ && cd dir.$$ && gzip -cd ../$file_name | tar xof - && cd * && tar cf - . | (cd ../../$extract_dir && tar xpf -) && cd ../.. && rm -rf dir.$$ - fi + gzip -cd ../$file_name | tar xof - fi + + # Remove 1 possibly 2 top-level folders + squashSingleFolderContentsToCurrentDir + squashSingleFolderContentsToCurrentDir + + # Copy to extract_dir + cp -R * "../${extract_dir}" && cd .. && rm -rf dir.$$ else if [ -d "$SDKDIR/jdkbinary/tmp" ]; then rm -rf $SDKDIR/jdkbinary/tmp/* @@ -414,10 +449,10 @@ getBinaryOpenjdk() echo "PROCESSING: ${jar_dir_name}" if [[ "$jar_dir_name" =~ "test-image" ]] || [[ "$jar_dir_name" =~ "tests-" ]]; then if [ "$jar_dir_name" != "openjdk-test-image" ]; then - mv $jar_dir_name ../openjdk-test-image + moveDirectorySafely $jar_dir_name ../openjdk-test-image fi elif [[ "$jar_dir_name" =~ jre* ]] && [ "$jar_dir_name" != "j2re-image" ]; then - mv $jar_dir_name ../j2re-image + moveDirectorySafely $jar_dir_name ../j2re-image elif [[ "$jar_dir_name" =~ jdk* ]] && [ "$jar_dir_name" != "j2sdk-image" ]; then # If test sdk has already been expanded, this one must be the additional sdk isAdditional=0 @@ -450,14 +485,14 @@ echo "PROCESSING: ${jar_dir_name}" $SDKDIR/additionaljdkbinary/bin/java -version else echo "MOVING: mv $jar_dir_name ../j2sdk-image" - mv $jar_dir_name ../j2sdk-image + moveDirectorySafely $jar_dir_name ../j2sdk-image fi # The following only needed if openj9 has a different image name convention elif [ "$jar_dir_name" != "j2sdk-image" ]; then - mv $jar_dir_name ../j2sdk-image + moveDirectorySafely $jar_dir_name ../j2sdk-image fi elif [ "$len" -gt 1 ]; then - mv ../tmp ../j2sdk-image + moveDirectorySafely ../tmp ../j2sdk-image fi cd $SDKDIR/jdkbinary echo "$SDKDIR/jdkbinary:" From 713f68fde2321db13070a98f07c44d85dde2c6f5 Mon Sep 17 00:00:00 2001 From: Andrew Leonard <anleonar@redhat.com> Date: Wed, 13 Nov 2024 11:04:57 +0000 Subject: [PATCH 03/13] Fix getjdkbinary so it safely handles uncompressing to target folders Signed-off-by: Andrew Leonard <anleonar@redhat.com> --- get.sh | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/get.sh b/get.sh index 383d21d334..5e9be8cef3 100755 --- a/get.sh +++ b/get.sh @@ -174,16 +174,17 @@ squashSingleFolderContentsToCurrentDir() # Moves the given directory safely, ensuring the target does not exist, fail with error if it does exist moveDirectorySafely() { - if [[ -z ${1+x} ]] || [[ -z ${2+x} ]]; then - echo "Syntax: moveDirectorySafely <sourceDirectory> <targetDirectory>" - exit 1 - fi - if [ -d "$2" ]; then - echo "ERROR: moveDirectorySafely $1 $2 : target directory $2 already exists" - exit 1 - else - mv "$1" "$2" - fi + if [[ -z ${1+x} ]] || [[ -z ${2+x} ]]; then + echo "Syntax: moveDirectorySafely <sourceDirectory> <targetDirectory>" + exit 1 + fi + if [ -d "$2" ]; then + echo "ERROR: moveDirectorySafely $1 $2 : target directory $2 already exists" + exit 1 + else + echo "Moving directory $1 to $2" + mv "$1" "$2" + fi } getBinaryOpenjdk() From 1b7f30500d00105892a01783b137f15503ac1980 Mon Sep 17 00:00:00 2001 From: Andrew Leonard <anleonar@redhat.com> Date: Wed, 13 Nov 2024 11:09:45 +0000 Subject: [PATCH 04/13] Fix getjdkbinary so it safely handles uncompressing to target folders Signed-off-by: Andrew Leonard <anleonar@redhat.com> --- get.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/get.sh b/get.sh index 5e9be8cef3..c727ea12b0 100755 --- a/get.sh +++ b/get.sh @@ -452,6 +452,8 @@ echo "PROCESSING: ${jar_dir_name}" if [ "$jar_dir_name" != "openjdk-test-image" ]; then moveDirectorySafely $jar_dir_name ../openjdk-test-image fi + elif [[ "$jar_dir_name" =~ "static-libs" ]]; then + moveDirectorySafely $jar_dir_name ../static-libs elif [[ "$jar_dir_name" =~ jre* ]] && [ "$jar_dir_name" != "j2re-image" ]; then moveDirectorySafely $jar_dir_name ../j2re-image elif [[ "$jar_dir_name" =~ jdk* ]] && [ "$jar_dir_name" != "j2sdk-image" ]; then From 38f0027ad6bc53883880464e4007683fb121f09a Mon Sep 17 00:00:00 2001 From: Andrew Leonard <anleonar@redhat.com> Date: Wed, 13 Nov 2024 11:15:15 +0000 Subject: [PATCH 05/13] Fix getjdkbinary so it safely handles uncompressing to target folders Signed-off-by: Andrew Leonard <anleonar@redhat.com> --- get.sh | 8 -------- 1 file changed, 8 deletions(-) diff --git a/get.sh b/get.sh index c727ea12b0..2b9d7bfd09 100755 --- a/get.sh +++ b/get.sh @@ -447,7 +447,6 @@ getBinaryOpenjdk() len=${#jar_dir_array[@]} if [ "$len" == 1 ]; then jar_dir_name=${jar_dir_array[0]} -echo "PROCESSING: ${jar_dir_name}" if [[ "$jar_dir_name" =~ "test-image" ]] || [[ "$jar_dir_name" =~ "tests-" ]]; then if [ "$jar_dir_name" != "openjdk-test-image" ]; then moveDirectorySafely $jar_dir_name ../openjdk-test-image @@ -487,7 +486,6 @@ echo "PROCESSING: ${jar_dir_name}" echo "RI JDK version:" $SDKDIR/additionaljdkbinary/bin/java -version else -echo "MOVING: mv $jar_dir_name ../j2sdk-image" moveDirectorySafely $jar_dir_name ../j2sdk-image fi # The following only needed if openj9 has a different image name convention @@ -498,12 +496,6 @@ echo "MOVING: mv $jar_dir_name ../j2sdk-image" moveDirectorySafely ../tmp ../j2sdk-image fi cd $SDKDIR/jdkbinary -echo "$SDKDIR/jdkbinary:" -ls -l -echo "----" -echo "j2sdk-image:" -ls -l j2sdk-image -echo "----" fi fi done From 7302b1da5c66f690e0303f2f3410c442757897a7 Mon Sep 17 00:00:00 2001 From: Andrew Leonard <anleonar@redhat.com> Date: Fri, 15 Nov 2024 09:30:24 +0000 Subject: [PATCH 06/13] Fix getjdkbinary so it safely handles uncompressing to target folders Signed-off-by: Andrew Leonard <anleonar@redhat.com> --- get.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/get.sh b/get.sh index 2b9d7bfd09..335099a9b4 100755 --- a/get.sh +++ b/get.sh @@ -410,7 +410,7 @@ getBinaryOpenjdk() # Unpack into a temp directory, remove 1 or maybe 2 top-level single folders, then copy over extract_dir mkdir dir.$$ && cd dir.$$ if [[ $file_name == *zip ]] || [[ $file_name == *jar ]]; then - unzip -q $file_name + unzip -q ../$file_name else gzip -cd ../$file_name | tar xof - fi From 3147dfefa724a7e9936bb22891c9259c03b8b123 Mon Sep 17 00:00:00 2001 From: Andrew Leonard <anleonar@redhat.com> Date: Mon, 18 Nov 2024 14:15:52 +0000 Subject: [PATCH 07/13] Fix getjdkbinary so it safely handles uncompressing to target folders Signed-off-by: Andrew Leonard <anleonar@redhat.com> --- get.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/get.sh b/get.sh index 335099a9b4..3fb8fbecf3 100755 --- a/get.sh +++ b/get.sh @@ -163,7 +163,8 @@ parseCommandLineArgs() # If the current directory contains only a single directory then squash that directory into the current directory squashSingleFolderContentsToCurrentDir() { - if [[ `ls -d */ | wc -l` -eq 1 ]] && [[ `find . -maxdepth 1 -mindepth 1 | wc -l` -eq 1 ]]; then + # Does current directory contain one and ONLY one directory? + if [[ `ls -d */ | wc -l` -eq 1 ]] && [[ `ls -d * | wc -l` -eq 1 ]]; then folder=`ls -d */` echo "Removing top-level folder ${folder}" mv ${folder}* . From bb9160f551c094fe61e70b79707940118be9523e Mon Sep 17 00:00:00 2001 From: Andrew Leonard <anleonar@redhat.com> Date: Mon, 18 Nov 2024 15:02:11 +0000 Subject: [PATCH 08/13] Fix getjdkbinary so it safely handles uncompressing to target folders Signed-off-by: Andrew Leonard <anleonar@redhat.com> --- get.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/get.sh b/get.sh index 3fb8fbecf3..11ca426e31 100755 --- a/get.sh +++ b/get.sh @@ -454,6 +454,8 @@ getBinaryOpenjdk() fi elif [[ "$jar_dir_name" =~ "static-libs" ]]; then moveDirectorySafely $jar_dir_name ../static-libs + elif [[ "$jar_dir_name" =~ jdk.*-src$ ]]; then + moveDirectorySafely $jar_dir_name ../source-image elif [[ "$jar_dir_name" =~ jre* ]] && [ "$jar_dir_name" != "j2re-image" ]; then moveDirectorySafely $jar_dir_name ../j2re-image elif [[ "$jar_dir_name" =~ jdk* ]] && [ "$jar_dir_name" != "j2sdk-image" ]; then From e035757c6bd1fe3714ab8fd5a4bc92e2da78fb7a Mon Sep 17 00:00:00 2001 From: Andrew Leonard <anleonar@redhat.com> Date: Mon, 18 Nov 2024 15:22:18 +0000 Subject: [PATCH 09/13] Fix getjdkbinary so it safely handles uncompressing to target folders Signed-off-by: Andrew Leonard <anleonar@redhat.com> --- get.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/get.sh b/get.sh index 11ca426e31..d632ee33b8 100755 --- a/get.sh +++ b/get.sh @@ -454,7 +454,7 @@ getBinaryOpenjdk() fi elif [[ "$jar_dir_name" =~ "static-libs" ]]; then moveDirectorySafely $jar_dir_name ../static-libs - elif [[ "$jar_dir_name" =~ jdk.*-src$ ]]; then + elif [[ "$jar_dir_name" =~ jdk.*-src/ ]]; then moveDirectorySafely $jar_dir_name ../source-image elif [[ "$jar_dir_name" =~ jre* ]] && [ "$jar_dir_name" != "j2re-image" ]; then moveDirectorySafely $jar_dir_name ../j2re-image From 660113adbf4fb7e07f70cfce127c2b49fa65b6d4 Mon Sep 17 00:00:00 2001 From: Andrew Leonard <31470007+andrew-m-leonard@users.noreply.github.com> Date: Tue, 19 Nov 2024 13:05:26 +0000 Subject: [PATCH 10/13] Update get.sh Co-authored-by: Stewart X Addison <6487691+sxa@users.noreply.github.com> --- get.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/get.sh b/get.sh index d632ee33b8..844cfc0de8 100755 --- a/get.sh +++ b/get.sh @@ -175,7 +175,7 @@ squashSingleFolderContentsToCurrentDir() # Moves the given directory safely, ensuring the target does not exist, fail with error if it does exist moveDirectorySafely() { - if [[ -z ${1+x} ]] || [[ -z ${2+x} ]]; then + if [ $# -lt 2 ]; then echo "Syntax: moveDirectorySafely <sourceDirectory> <targetDirectory>" exit 1 fi From a58fef63be44283642b3cb2f9d941755956b7fa2 Mon Sep 17 00:00:00 2001 From: Andrew Leonard <31470007+andrew-m-leonard@users.noreply.github.com> Date: Tue, 19 Nov 2024 13:05:42 +0000 Subject: [PATCH 11/13] Update get.sh Co-authored-by: Stewart X Addison <6487691+sxa@users.noreply.github.com> --- get.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/get.sh b/get.sh index 844cfc0de8..e53df3907f 100755 --- a/get.sh +++ b/get.sh @@ -416,7 +416,7 @@ getBinaryOpenjdk() gzip -cd ../$file_name | tar xof - fi - # Remove 1 possibly 2 top-level folders + # Remove 1 possibly 2 top-level folders (debugimage has 2) squashSingleFolderContentsToCurrentDir squashSingleFolderContentsToCurrentDir From 57c01aee3afb962b7505ab72fec034f4dfc0f044 Mon Sep 17 00:00:00 2001 From: Andrew Leonard <31470007+andrew-m-leonard@users.noreply.github.com> Date: Tue, 19 Nov 2024 13:08:29 +0000 Subject: [PATCH 12/13] Update get.sh Co-authored-by: Stewart X Addison <6487691+sxa@users.noreply.github.com> --- get.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/get.sh b/get.sh index e53df3907f..5f0baf4e3f 100755 --- a/get.sh +++ b/get.sh @@ -164,7 +164,7 @@ parseCommandLineArgs() squashSingleFolderContentsToCurrentDir() { # Does current directory contain one and ONLY one directory? - if [[ `ls -d */ | wc -l` -eq 1 ]] && [[ `ls -d * | wc -l` -eq 1 ]]; then + if [[ `ls -1d */ | wc -l` -eq 1 ]] && [[ `ls | wc -l` -eq 1 ]]; then folder=`ls -d */` echo "Removing top-level folder ${folder}" mv ${folder}* . From 0faec4b2a95f8f473fe7e7a390baad1a261650bb Mon Sep 17 00:00:00 2001 From: Andrew Leonard <anleonar@redhat.com> Date: Tue, 19 Nov 2024 13:16:14 +0000 Subject: [PATCH 13/13] Fix getjdkbinary so it safely handles uncompressing to target folders Signed-off-by: Andrew Leonard <anleonar@redhat.com> --- get.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/get.sh b/get.sh index 5f0baf4e3f..5aab96a7f6 100755 --- a/get.sh +++ b/get.sh @@ -164,11 +164,13 @@ parseCommandLineArgs() squashSingleFolderContentsToCurrentDir() { # Does current directory contain one and ONLY one directory? - if [[ `ls -1d */ | wc -l` -eq 1 ]] && [[ `ls | wc -l` -eq 1 ]]; then - folder=`ls -d */` - echo "Removing top-level folder ${folder}" - mv ${folder}* . - rmdir "${folder}" + if [[ $(ls -1 | wc -l) -eq 1 ]]; then + folder=$(ls -d */) + if [ -d "$folder" ]; then + echo "Removing top-level folder ${folder}" + mv ${folder}* . + rmdir "${folder}" + fi fi }