fingolfin / gap-osx-bundle

Bundle GAP and related software into a binary installer for Mac OS X
5 stars 3 forks source link

Get rid of realpath? #28

Closed fingolfin closed 7 years ago

fingolfin commented 8 years ago

The realpath executable works well, but it creates a chicken and egg problem: In order to use it, scripts need to locate it. But I think we can rewrite scripts to work without it. Consider this shell script:

#!/bin/sh
LINK="$@"
while [ "$LINK" ]; do
  cd "$(dirname $LINK)"
  LINK="$(readlink $(basename $LINK))"
done
echo "$PWD"

This takes a file path as argument, and returns the "real" path of its parent dir (not quite "real", because it doesn't expand symlinks up to the top, but that shouldn't matter for our purposes).

For example, in gap.sh, right now we have

GAP_DIR="$(cd "$(dirname "$(realpath "$0")")"/.. && pwd)

which could be replaced by

OLDDIR="$PWD"
LINK="$0"
while [ "$LINK" ]; do
  cd "$(dirname $LINK)"
  LINK="$(readlink $(basename $LINK))"
done
cd ..
GAP_DIR="$PWD"
cd "$OLDDIR"
fingolfin commented 7 years ago

Done in 24e0d7657e36318bb9fb2b2509727f80b3492888