diff options
author | Lucas C. Villa Real <lucasvr@gmail.com> | 2017-01-01 19:15:09 -0200 |
---|---|---|
committer | Lucas C. Villa Real <lucasvr@gmail.com> | 2017-01-01 19:15:09 -0200 |
commit | 923b826989315fb0d0b292d72524bc3a442dd4dc (patch) | |
tree | f1042f4c6b1aaca8cb12b2bbf9a72947163c446d /bin/InstallPackage-RPM | |
parent | d5cf060a484c018b077619654659b631ba1b061f (diff) | |
download | ThirdPartyInstallers-923b826989315fb0d0b292d72524bc3a442dd4dc.tar.xz |
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.
Diffstat (limited to 'bin/InstallPackage-RPM')
-rwxr-xr-x | bin/InstallPackage-RPM | 21 |
1 files changed, 17 insertions, 4 deletions
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 } |