aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucas C. Villa Real <lucasvr@gmail.com>2016-12-30 23:25:47 -0200
committerLucas C. Villa Real <lucasvr@gmail.com>2016-12-30 23:25:47 -0200
commit5c61846e16872fe524836e3a4c1c60b1d0f7d3a4 (patch)
treeeef8d153689864c6ddff66f721950c55a88ab091
parent04b153253a55d550f97eda95c4242512feee385f (diff)
downloadThirdPartyInstallers-5c61846e16872fe524836e3a4c1c60b1d0f7d3a4.tar.xz
Improve guessing of /opt hierarchy: when multiple RPM files are
provided as input, we now list the contents of all RPMs at once to determine how to create the /opt symlinks of the uncompressed packages.
-rwxr-xr-xbin/InstallPackage-RPM38
1 files changed, 31 insertions, 7 deletions
diff --git a/bin/InstallPackage-RPM b/bin/InstallPackage-RPM
index ae93772..3da39c6 100755
--- a/bin/InstallPackage-RPM
+++ b/bin/InstallPackage-RPM
@@ -58,6 +58,28 @@ function uncompress_rpm() {
rm -f -- "$cpiofile"
}
+function determine_flattening_level() {
+ local rootdirs="bin$\|sbin$\|lib$\|lib64$\|libexec$\|include$\|share$"
+ local filenames=$(for i in "${rpmfiles[@]}"; do rpminfo --filenames $i; done)
+
+ Log_Verbose "$filenames"
+ if echo "$filenames" | grep -q "/opt/$rootdirs"
+ then
+ # 1-level /opt hierarchy
+ echo "1"
+ elif echo "$filenames" | grep -q "/opt/[^/]*/$rootdirs"
+ then
+ # 2-level /opt hierarchy
+ echo "2"
+ elif echo "$filenames" | grep -q "/opt"
+ then
+ # TODO Make an educated guess based on where the first non-directory file object
+ # is located.
+ Log_Error "Could not determine this package's /opt structure, assuming 2-level"
+ echo "2"
+ fi
+}
+
function flatten_rpm() {
local rpmfile="$1"
@@ -131,20 +153,15 @@ function flatten_rpm() {
# Prevent the creation of backlinks to directories that would be pruned later on
find share -type d | xargs rmdir -p --ignore-fail-on-non-empty
rmdir * 2> /dev/null
-
- rootdirs="^bin$\|^sbin$\|^lib$\|^lib64$\|^libexec$\|^include$\|^share$"
mkdir -p Resources/Unmanaged/opt
- if ls ./opt/* 2> /dev/null | grep -q "$rootdirs"
+ if [ "$flatteninglevel" = "1" ]
then
Log_Verbose "Flattening 1-level /opt directory"
flatten_opt_1_level
- elif ls ./opt/*/* 2> /dev/null | grep -q "$rootdirs"
+ elif [ "$flatteninglevel" = "2" ]
then
Log_Verbose "Flattening 2-level /opt directory"
flatten_opt_2_levels
- else
- Log_Error "Could not determine this package's /opt structure, assuming 2-level"
- flatten_opt_2_levels
fi
rm -rf -- ./opt
fi
@@ -433,6 +450,13 @@ unset programname
unset programversion
unset target
+# Determine the flattening level of /opt. In other words, whether
+# we have something like:
+# /opt/pkgname/{bin,sbin...} (1-level), or
+# /opt/vendorname/pkgname/{bin,sbin...} (2-level)
+
+flatteninglevel=$(determine_flattening_level)
+
# Installation pipeline
for entry in "${rpmfiles[@]}"
do