mirror of
https://github.com/natelandau/shell-scripting-templates.git
synced 2025-11-08 13:13:47 -05:00
Now sources all utility files in /lib dir.
This commit is contained in:
31
lib/utils.sh
31
lib/utils.sh
@@ -60,7 +60,7 @@ function _alert() { #my function
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Print to $logFile
|
# Print to $logFile
|
||||||
if [ ${printLog} = "true" ] || [ "${printLog}" == "1" ]; then
|
if [[ ${printLog} = "true" ]] || [ "${printLog}" == "1" ]; then
|
||||||
echo -e "$(date +"%m-%d-%Y %r") $(printf "[%9s]" ${1}) "${_message}"" >> $logFile;
|
echo -e "$(date +"%m-%d-%Y %r") $(printf "[%9s]" ${1}) "${_message}"" >> $logFile;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -87,9 +87,7 @@ verbose() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Source additional files
|
# Source additional /lib files
|
||||||
# ------------------------------------------------------
|
|
||||||
# The list of additional utility files to be sourced
|
|
||||||
# ------------------------------------------------------
|
# ------------------------------------------------------
|
||||||
|
|
||||||
# First we locate this script and populate the $SCRIPTPATH variable
|
# First we locate this script and populate the $SCRIPTPATH variable
|
||||||
@@ -102,19 +100,18 @@ while [ -h "${SOURCE}" ]; do # resolve ${SOURCE} until the file is no longer a s
|
|||||||
done
|
done
|
||||||
SOURCEPATH="$( cd -P "$( dirname "${SOURCE}" )" && pwd )"
|
SOURCEPATH="$( cd -P "$( dirname "${SOURCE}" )" && pwd )"
|
||||||
|
|
||||||
# Write the list of utility files to be sourced
|
if [ ! -d "${SOURCEPATH}" ]
|
||||||
FILES="
|
then
|
||||||
sharedVariables.sh
|
die "Failed to find library files expected in: ${SOURCEPATH}"
|
||||||
sharedFunctions.sh
|
fi
|
||||||
setupScriptFunctions.sh
|
for utility_file in "${SOURCEPATH}"/*.sh
|
||||||
"
|
|
||||||
|
|
||||||
# Source the Utility Files
|
|
||||||
for file in $FILES
|
|
||||||
do
|
do
|
||||||
if [ -f "${SOURCEPATH}/${file}" ]; then
|
if [ -e "${utility_file}" ]; then
|
||||||
source "${SOURCEPATH}/${file}"
|
# Don't source self
|
||||||
else
|
if [[ "${utility_file}" == *"utils.sh"* ]]; then
|
||||||
die "${file} does not exist."
|
continue
|
||||||
|
fi
|
||||||
|
echo "Attempting to source: $utility_file"
|
||||||
|
source "$utility_file"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user