From 2340e7bbbc6b3e955c7df0069686c016e40d0a6d Mon Sep 17 00:00:00 2001 From: Michael Boelen Date: Sun, 23 Apr 2017 20:19:18 +0200 Subject: [PATCH] Added HasData and IsEmpty function --- include/functions | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/include/functions b/include/functions index ba8149de..c03022bc 100644 --- a/include/functions +++ b/include/functions @@ -50,12 +50,14 @@ # 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 +# HasData Checks for data in variable # InsertSection Insert a section block # InsertPluginSection Insert a section block for plugins # IsContainer Determine if program runs in a container # IsDebug Check if --debug is used # IsDeveloperMode Check if --developer is used # IsDeveloperVersion Check if program is a developer release +# IsEmpty Check for empty result or variable # IsNotebook System detection # IsOwnedByRoot Determine if file or directory is owned by root # IsRunning Check if a process is running @@ -1090,6 +1092,22 @@ fi } + ################################################################################ + # Name : HasData() + # Description : Check for a filled variable + # + # Returns : 0 = True, 1 = False + # Usage : if HasData "${FIND}"; then + ################################################################################ + + HasData() { + if [ $# -eq 1 ]; then + if [ ! -z "$1" ]; then return 0; else return 1; fi + else + ExitFatal "Function HasData called without parameters - look in log to determine where this happened, or use sh -x lynis to see all details." + fi + } + ################################################################################ # Name : InsertSection() @@ -1189,6 +1207,23 @@ } + ################################################################################ + # Name : IsEmpty() + # Description : Check for variable that has no data in it + # + # Returns : 0 = True, 1 = False + # Usage : if IsEmpty "${FIND}"; then + ################################################################################ + + IsEmpty() { + if [ $# -eq 1 ]; then + if [ -z "$1" ]; then return 0; else return 1; fi + else + ExitFatal "Function IsEmpty called without parameters - look in log to determine where this happened, or use sh -x lynis to see all details." + fi + } + + ################################################################################ # Name : IsRunning() # Description : Check if a process is running