When realpath or readlink is not available it will fallback to a
realpath implementation in bash. An extra check is also added for
"readlink -f", because not all platforms support the -f flag.

The readlink implementation in bash is borrowed from Debian's dpkg tools.

Signed-off-by: Yun Zheng Hu <[email protected]>
---
 scripts/repo-add.sh.in |   23 ++++++++++++++++++++---
 1 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
index c89e2a5..ea16731 100644
--- a/scripts/repo-add.sh.in
+++ b/scripts/repo-add.sh.in
@@ -297,11 +297,28 @@ fi
 # check for and store the name of a realpath-like program
 if [ $(type -t realpath) ]; then
        realpath='realpath'
-elif [ $(type -t readlink) ]; then
+elif [ $(type -t readlink) -a "$(readlink -f . 2>/dev/null)" != "" ]; then
        realpath='readlink -f'
 else
-       error "$(gettext "Either realpath or readlink are required by 
repo-add.")"
-       exit 1 # $E_MISSING_PROGRAM
+       realpath_bash()
+       {
+               fname=${1%/} # strips trailing '/'
+               while [ -L "$fname" ]; do
+                       oldfname="$fname"
+                       fname="$(command ls -l $fname)"
+                       fname="${fname#*\> }"
+                       if [ "$fname" = . ] ; then
+                               fname="$(dirname $oldfname)"
+                       elif echo $fname | grep -vq '^/' - ; then
+                               fname="$(dirname $oldfname)/$fname"
+                       fi
+               done
+               pushd $(dirname $fname) > /dev/null
+               fname=$(pwd -P)/$(basename $fname)
+               popd > /dev/null
+               echo $fname
+       }
+       realpath=realpath_bash
 fi

 # main routine
-- 
1.6.1.2
_______________________________________________
pacman-dev mailing list
[email protected]
http://www.archlinux.org/mailman/listinfo/pacman-dev

Reply via email to