mirror of
https://github.com/natelandau/shell-scripting-templates.git
synced 2025-11-09 05:33:48 -05:00
Better sourcing of lib files
This commit is contained in:
69
lib/utils.sh
69
lib/utils.sh
@@ -15,41 +15,6 @@
|
||||
#
|
||||
# ##################################################
|
||||
|
||||
|
||||
# Source additional files
|
||||
# ------------------------------------------------------
|
||||
# The list of additional utility files to be sourced
|
||||
# ------------------------------------------------------
|
||||
|
||||
# First we locate this script and populate the $SCRIPTPATH variable
|
||||
# Doing so allows us to source additional files from this utils file.
|
||||
SOURCE="${BASH_SOURCE[0]}"
|
||||
while [ -h "${SOURCE}" ]; do # resolve ${SOURCE} until the file is no longer a symlink
|
||||
DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )"
|
||||
SOURCE="$(readlink "${SOURCE}")"
|
||||
[[ ${SOURCE} != /* ]] && SOURCE="${DIR}/${SOURCE}" # if ${SOURCE} was a relative symlink, we need to resolve it relative to the path where the symlink file was located
|
||||
done
|
||||
SOURCEPATH="$( cd -P "$( dirname "${SOURCE}" )" && pwd )"
|
||||
|
||||
# Write the list of utility files to be sourced
|
||||
FILES="
|
||||
sharedVariables.sh
|
||||
sharedFunctions.sh
|
||||
setupScriptFunctions.sh
|
||||
"
|
||||
|
||||
# Source the Utility Files
|
||||
for file in $FILES
|
||||
do
|
||||
if [ -f "${SOURCEPATH}/${file}" ]; then
|
||||
source "${SOURCEPATH}/${file}"
|
||||
else
|
||||
error "${file} does not exist. Exiting"
|
||||
Exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
# Logging and Colors
|
||||
# ------------------------------------------------------
|
||||
# Here we set the colors for our script feedback.
|
||||
@@ -121,6 +86,40 @@ verbose() {
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# Source additional files
|
||||
# ------------------------------------------------------
|
||||
# The list of additional utility files to be sourced
|
||||
# ------------------------------------------------------
|
||||
|
||||
# First we locate this script and populate the $SCRIPTPATH variable
|
||||
# Doing so allows us to source additional files from this utils file.
|
||||
SOURCE="${BASH_SOURCE[0]}"
|
||||
while [ -h "${SOURCE}" ]; do # resolve ${SOURCE} until the file is no longer a symlink
|
||||
DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )"
|
||||
SOURCE="$(readlink "${SOURCE}")"
|
||||
[[ ${SOURCE} != /* ]] && SOURCE="${DIR}/${SOURCE}" # if ${SOURCE} was a relative symlink, we need to resolve it relative to the path where the symlink file was located
|
||||
done
|
||||
SOURCEPATH="$( cd -P "$( dirname "${SOURCE}" )" && pwd )"
|
||||
|
||||
# Write the list of utility files to be sourced
|
||||
FILES="
|
||||
sharedVariables.sh
|
||||
sharedFunctions.sh
|
||||
setupScriptFunctions.sh
|
||||
"
|
||||
|
||||
# Source the Utility Files
|
||||
for file in $FILES
|
||||
do
|
||||
if [ -f "${SOURCEPATH}/${file}" ]; then
|
||||
source "${SOURCEPATH}/${file}"
|
||||
else
|
||||
die "${file} does not exist."
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
# Notes to self
|
||||
# ####################
|
||||
# This is how you create a variable with multiple lines
|
||||
|
||||
Reference in New Issue
Block a user