diff options
author | Ulf Wiger <ulf@feuerlabs.com> | 2016-02-13 10:46:32 -0800 |
---|---|---|
committer | Ulf Wiger <ulf@feuerlabs.com> | 2016-02-13 10:46:32 -0800 |
commit | 7d62bffc14a7ea2bb1c31e61f38b0302f8aaee18 (patch) | |
tree | f8e4759dc9327330b9100eb7be6ab713a66a61aa | |
parent | def54b8c51ed340ea2939db4d67fc45bc9ecb347 (diff) | |
download | rvi_core-7d62bffc14a7ea2bb1c31e61f38b0302f8aaee18.tar.gz |
fix fqn() to also work for prefix
-rwxr-xr-x | scripts/rvi_install | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/scripts/rvi_install b/scripts/rvi_install index 0bcb045..7f6207e 100755 --- a/scripts/rvi_install +++ b/scripts/rvi_install @@ -12,10 +12,42 @@ # # -# fqn : fully qualified name (e.g. realpath, but portable) +# join two path names (avoid things like //foo or /foo/../bar) +join() +{ + if [ "$1" = "/" ] + then + echo "/$2" + else + if [ "$2" = ".." ] + then + echo $(fqn $(dirname $1)) + else + echo "$1/$2" + fi + fi +} + +# fqn : fully qualified name +# (e.g. realpath, but portable & works even if path doesn't exist) fqn() { - echo $(cd $(dirname $1); pwd)/$(basename $1) + if [ "$1" = "." ] + then + echo $(pwd) + else + if [ "$1" = "/" ] + then + echo "/" + else + if [ -e $1 ] + then + echo $(join $(cd $(dirname $1); pwd) $(basename $1)) + else + echo $(join $(fqn $(dirname $1)) $(basename $1)) + fi + fi + fi } SELF_DIR=$(dirname $(fqn "$0")) @@ -194,7 +226,7 @@ while getopts "r:d:c:k:s:l:n:" o; do ;; s) - PREFIX_STRIP=${OPTARG} + PREFIX_STRIP=$(fqn ${OPTARG}) ;; n) NAME=${OPTARG} |