I have a POSIX shell script that tries to find manual install paths for tomcat on an ubuntu (20.04) system. I run dpkg-query
to make a list of installs that were installed using the package manager. Then I iterate over a list of common install paths. If any of the installs found using dpkg-query
match, I need to exclude those from my discovery. But, I can't seem to figure out an efficient way to do this.
Code:
#/bin/sh
APP="Apache Tomcat"
# Common install paths to iterate over
set -- "/opt/" "/usr/share/" "/var/" "/var/lib/" "/usr/" "/usr/local/"
# Create exclusion list for managed installs from apt and yum
EXCLUSION_LIST=""
if [ -x "$(command -v dpkg-query)" ]; then
dpkg_check=$(dpkg-query -l | grep -Eo 'tomcat[0-9]?' | sort -u)
EXCLUSION_LIST=$dpkg_check
echo $EXCLUSION_LIST
# Check for manual installs
for _i in "$@"; do
find_tomcat=$(ls $_i | grep -E '^tomcat[0-9]{0,2}$')
excluded_list=$(echo $EXCLUSION_LIST)
for match in $excluded_list; do
if [ $find_tomcat == $match ]; then
echo "$match is excluded"
else
echo $_i$find_tomcat
done
done
else
echo "DPKG not found."
fi
Desired Output:
Install path of manual version not installed by the package manager.
E.g., /usr/share/tomcat