Initial version of PackageIsInstalled function

This commit is contained in:
Michael Boelen 2018-02-19 15:01:26 +01:00
parent dff56c740a
commit f0ef7fb785
No known key found for this signature in database
GPG Key ID: 26141F77A09D7F04
1 changed files with 35 additions and 0 deletions

View File

@ -68,6 +68,7 @@
# IsWorldWritable Check if a file is world writable
# LogText Log text strings to logfile, prefixed with date/time
# LogTextBreak Insert a separator in log file
# PackageIsInstalled Test for installed package
# ParseNginx Parse nginx configuration lines
# ParseProfiles Parse all available profiles
# ParseTestValues Parse a set of values
@ -1695,6 +1696,40 @@
}
################################################################################
# Name : PackageIsInstalled()
# Description : Add a separator to log file between sections, tests etc
# Returns : exit code
# Notes : this function is not used yet, but created in advance to allow
# the addition of support for all operating systems
################################################################################
PackageIsInstalled() {
exit_code=255
if [ $# -eq 1 ]; then
package="$1"
else
Fatal "Incorrect usage of PackageIsInstalled function"
fi
if [ ! -z "${RPMBINARY}" ]; then
output=$(${RPMBINARY} --quiet -q ${package} 2> /dev/null)
exit_code=$?
elif ! -z "${DPKGBINARY}" ]; then
output=$(${DPKGBINARY} -l ${package} 2> /dev/null)
exit_code=$?
elif [ ! -z "${ZYPPERBINARY}" ]; then
output=$(${ZYPPERBINARY} --quiet --non-interactive search --installed -i ${PACKAGE} 2> /dev/null | grep "^i")
if [ ! -z "${output}" ]; then exit_code=0; else exit_code=1; fi
else
ReportException "PackageIsInstalled:01"
fi
return ${exit_code}
}
################################################################################
# Name : ParseProfiles()
# Description : Check file permissions and parse data from profiles