From 3914141c45c574fb8d22a72af99165cb535f5f17 Mon Sep 17 00:00:00 2001 From: Andre F de Miranda Date: Fri, 14 Oct 2016 14:36:48 +1100 Subject: [PATCH] NIFI-1710 - Resolve path name to nifi.sh script This closes #1137. Signed-off-by: Andy LoPresto --- .../src/main/resources/bin/nifi.sh | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/bin/nifi.sh b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/bin/nifi.sh index 79850eecc2..ff8addd718 100755 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/bin/nifi.sh +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/bin/nifi.sh @@ -17,12 +17,36 @@ # Script structure inspired from Apache Karaf and other Apache projects with similar startup approaches -SCRIPT_DIR=$(dirname "$0") -SCRIPT_NAME=$(basename "$0") +# Discover the path of the file + + +# 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") . "$SCRIPT_DIR"/nifi-env.sh + + warn() { echo "${PROGNAME}: $*" }