Better sourcing of lib files

This commit is contained in:
Nathaniel Landau
2015-02-14 13:32:06 -05:00
parent d58b895240
commit dadc3632ae
13 changed files with 86 additions and 63 deletions

View File

@@ -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