Commit 81d46bd2 authored by Michał 'rysiek' Woźniak's avatar Michał 'rysiek' Woźniak
Browse files

readlink-f function added for Mac OS X support

parent 29d1d44e
......@@ -138,6 +138,48 @@ function keyringer_dispatch {
fi
}
# Mac OS X's readlink version does not support '-f'
# fixing that
if readlink -f "$0"; then
# great, a regular readlink -f will do!
function readlink-f {
readlink -f "$@"
return $?
}
elif greadlink -f "$0"; then
# ah, we have greadlink available, let's use that then.
function readlink-f {
readlink -f "$@"
return $?
}
else
# apparently we have to do this manually
# based on http://stackoverflow.com/a/1116890
function readlink-f {
# save the working directory
WORKDIR="$( pwd )"
# iterate through all the files in question
for TARGET_FILE in "$@"; do
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.
echo "$( pwd -P )/$TARGET_FILE"
done
# get back to the original workdir
cd "$WORKDIR"
}
fi
# Config
NAME="keyringer"
KEYRINGER_VERSION="0.3.8"
......@@ -152,30 +194,30 @@ ACTION="$2"
set -f
# Set functions location
if [ -e "`dirname $(readlink -f $0)`/lib/$NAME/functions" ]; then
if [ -e "`dirname $(readlink-f $0)`/lib/$NAME/functions" ]; then
# Development or local installation layout
LIB="`dirname $(readlink -f $0)`/lib/$NAME/functions"
LIB="`dirname $(readlink-f $0)`/lib/$NAME/functions"
else
# System installation layout
LIB="`dirname $(readlink -f $0)`/../lib/$NAME/functions"
LIB="`dirname $(readlink-f $0)`/../lib/$NAME/functions"
fi
# Set shared files location
if [ -e "`dirname $(readlink -f $0)`/share/$NAME" ]; then
if [ -e "`dirname $(readlink-f $0)`/share/$NAME" ]; then
# Development or local installation layout
SHARE="`dirname $(readlink -f $0)`/share/$NAME"
SHARE="`dirname $(readlink-f $0)`/share/$NAME"
else
# System installation layout
SHARE="`dirname $(readlink -f $0)`/../share/$NAME"
SHARE="`dirname $(readlink-f $0)`/../share/$NAME"
fi
# Set actions location
if [ -e "`dirname $(readlink -f $0)`/lib/$NAME/actions" ]; then
if [ -e "`dirname $(readlink-f $0)`/lib/$NAME/actions" ]; then
# Development or local installation layout
ACTIONS="`dirname $(readlink -f $0)`/lib/$NAME/actions"
ACTIONS="`dirname $(readlink-f $0)`/lib/$NAME/actions"
else
# System installation layout
ACTIONS="`dirname $(readlink -f $0)`/../lib/$NAME/actions"
ACTIONS="`dirname $(readlink-f $0)`/../lib/$NAME/actions"
fi
# Export globals for other scripts
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment