From 923b826989315fb0d0b292d72524bc3a442dd4dc Mon Sep 17 00:00:00 2001 From: "Lucas C. Villa Real" Date: Sun, 1 Jan 2017 19:15:09 -0200 Subject: Determine how many path levels we have at /opt based on the longest common prefix among the $filenames list. This approach is used when the RPM package does not have a {bin,lib,lib64,include,share,sbin,libexec} subdirectory in order to create the symlinks from /opt to /Programs. --- bin/InstallPackage-RPM | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'bin/InstallPackage-RPM') diff --git a/bin/InstallPackage-RPM b/bin/InstallPackage-RPM index 5488ebc..7b67266 100755 --- a/bin/InstallPackage-RPM +++ b/bin/InstallPackage-RPM @@ -73,10 +73,23 @@ function determine_flattening_level() { 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" + # Get the longest common prefix among the $filenames list that starts + # with "/opt" and then determine how many path levels we have there. + local commonprefix=$(echo "$filenames" | grep "/opt" | sed -e 'N;s/^\(.*\).*\n\1.*$/\1\n\1/;D') + local numslashes=$(echo "$commonprefix" | grep -o "/" | wc -l) + let numslashes=numslashes-1 + if [ "$numslashes" = 1 ] + then + Log_Verbose "Package seems to have a 1-level /opt structure" + echo "1" + elif [ "$numslashes" = 2 ] + then + Log_Verbose "Package seems to have a 2-level /opt structure" + echo "2" + else + Log_Error "Could not determine this package's /opt structure, assuming 2-level" + echo "2" + fi fi } -- cgit v1.1