NIFI-1710 - Resolve path name to nifi.sh script

This closes #1137.

Signed-off-by: Andy LoPresto <alopresto@apache.org>
This commit is contained in:
Andre F de Miranda 2016-10-14 14:36:48 +11:00 committed by Andy LoPresto
parent 27dba60f27
commit 3914141c45
No known key found for this signature in database
GPG Key ID: 3C6EF65B2F7DEF69
1 changed files with 26 additions and 2 deletions

View File

@ -17,12 +17,36 @@
# Script structure inspired from Apache Karaf and other Apache projects with similar startup approaches # Script structure inspired from Apache Karaf and other Apache projects with similar startup approaches
SCRIPT_DIR=$(dirname "$0") # Discover the path of the file
SCRIPT_NAME=$(basename "$0")
# Since MacOS X, FreeBSD and some other systems lack gnu readlink, we use a more portable
# approach based on following StackOverflow comment http://stackoverflow.com/a/1116890/888876
TARGET_FILE=$0
cd $(dirname $TARGET_FILE)
TARGET_FILE=$(basename $TARGET_FILE)
# Iterate down a (possible) chain of symlinks
while [ -L "$TARGET_FILE" ]
do
TARGET_FILE=$(readlink $TARGET_FILE)
cd $(dirname $TARGET_FILE)
TARGET_FILE=$(basename $TARGET_FILE)
done
# Compute the canonicalized name by finding the physical path
# for the directory we're in and appending the target file.
PHYS_DIR=`pwd -P`
SCRIPT_DIR=$PHYS_DIR
PROGNAME=$(basename "$0") PROGNAME=$(basename "$0")
. "$SCRIPT_DIR"/nifi-env.sh . "$SCRIPT_DIR"/nifi-env.sh
warn() { warn() {
echo "${PROGNAME}: $*" echo "${PROGNAME}: $*"
} }