From 37c7d0da887271f65bf2dc2900e735cc83977791 Mon Sep 17 00:00:00 2001 From: Rocco Bruyn Date: Sun, 28 Oct 2018 11:51:32 +0100 Subject: [PATCH] Fix resolving PGMODELER_ROOT from pgmodeler.vars When pgmodeler.vars is source'd the $0 variable expands to '-bash' which causes readlink to fail and PGMODELER_ROOT being set to the wrong directory. This is fixed by using a while loop that recursively changes directory following symlinks along the way util it reaches the end and then reads the current working directory. For more info, see: https://gist.github.com/TheMengzor/968e5ea87e99d9c41782 --- pgmodeler.vars | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pgmodeler.vars b/pgmodeler.vars index 7a7fbdddce..51572d259a 100644 --- a/pgmodeler.vars +++ b/pgmodeler.vars @@ -19,12 +19,12 @@ # If you have a custom Qt installation at /opt/qt-5.9.6 for example, the path to the command above should be # /opt/qt-5.9.6/5.9.6/gcc_64 # -# NOTE: Use the configuration below only if you have a custom Qt installation other than as defined by +# NOTE: Use the configuration below only if you have a custom Qt installation other than as defined by # your system or if Qt isn't included/installed by default on your distro. # Replace the value of this variable by the full path to "qtpaths" if you have a custom Qt installation -# export QT_PATHS_BIN=qtpaths +# export QT_PATHS_BIN=qtpaths # Qt's main environment variables # export QT_ROOT="$($QT_PATHS_BIN --install-prefix)" @@ -32,14 +32,22 @@ # export QT_PLUGIN_PATH="$($QT_PATHS_BIN --plugin-dir)" # Change the "lib64" by "lib" if you're running a 32 bit system -# export QT_LIBS="$QT_ROOT/lib64" +# export QT_LIBS="$QT_ROOT/lib64" # export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"$QT_LIBS" # export PATH=$PATH:"$QT_BIN" # --- [ End custom configuration ] --- +# Resolve absolute path to this file +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + PGMODELER_ROOT="$( 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 + # Specify here the full path to the pgmodeler's root directory -export PGMODELER_ROOT="$(dirname "$(readlink -f "$0")")" +export PGMODELER_ROOT="$( cd -P "$( dirname "$SOURCE" )" && pwd )" export PGMODELER_TMPL_CONF_DIR="$PGMODELER_ROOT/conf" export PGMODELER_SCHEMAS_DIR="$PGMODELER_ROOT/schemas"