diff options
author | Michael Boelen <michael.boelen@cisofy.com> | 2017-03-12 18:36:02 +0300 |
---|---|---|
committer | Michael Boelen <michael.boelen@cisofy.com> | 2017-03-12 18:36:02 +0300 |
commit | 88b37d16ca2c4bb03b80b0509ad35266a2bccc3e (patch) | |
tree | 06c0aa3c126bd69b522b8e6d9476c49c405621cd | |
parent | 32b9af07672d65cfde0c0bb657be32a45e39d0d8 (diff) |
Added FileInstalledByPackage function
-rw-r--r-- | include/functions | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/include/functions b/include/functions index a9078d43..f8d919d6 100644 --- a/include/functions +++ b/include/functions @@ -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 @@ -685,6 +686,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 # |