Added FileInstalledByPackage function

This commit is contained in:
Michael Boelen 2017-03-12 16:36:02 +01:00
parent 32b9af0767
commit 88b37d16ca
1 changed files with 26 additions and 0 deletions

View File

@ -46,6 +46,7 @@
# ExitCustom Stop the program (cleanly), with custom exit code
# ExitFatal Stop the program (cleanly), with exit code 1
# FileExists Check if a file exists on the disk
# FileInstalledByPackage Check if a file is linked to a package
# FileIsEmpty Check if a file is empty
# FileIsReadable Check if a file is readable or directory accessible
# GetHostID Retrieve an unique ID for this host
@ -684,6 +685,31 @@
}
################################################################################
# Name : FileInstalledByPackage()
# Description : Check if a file is part of a package
# Returns : 0 (true), 1 (default: unknown or false)
################################################################################
FileInstalledByPackage() {
exitcode=1
file=$1
find=""
if [ ! -z "${DPKGBINARY}" ]; then
find=$(${DPKGBINARY} -S ${file} 2> /dev/null | ${AWKBINARY} -F: '{print $1}')
elif [ ! -z "${RPMBINARY}" ]; then
find=$(${RPMBINARY} -qf ${file} 2> /dev/null | ${AWKBINARY} -F- '{print $1}')
fi
if [ ! -z "${find}" ]; then
LogText "Result: file ${file} belongs to package (${find})"
exitcode=0
else
LogText "Result: file ${file} does most likely not belong to a package"
fi
return ${exitcode}
}
################################################################################
# Name : FileIsEmpty()
# Description : Check if a file is empty