MyHush / hush3

Hush: Speak And Transact Freely
https://myhush.org
Other
15 stars 13 forks source link

readlink illegal option on OS X #8

Closed leto closed 5 years ago

leto commented 5 years ago

OS X is dumb:

$ ./hushd
readlink: illegal option -- f
usage: readlink [-n] [file ...]

This somehow doesn't lead to startup failure, only appears to be a warning?

@lukechilds suggestion?

lukechilds commented 5 years ago

Ahh, likely because MacOS has outdated BSD coreutils by default not up to date GNU coreutils.

-f gives the absolute path incase the symlink was set with a relative path:

lukechilds@notarynode-ar:~$ ln -sf ../bar foo
lukechilds@notarynode-ar:~$ readlink foo
../bar
lukechilds@notarynode-ar:~$ readlink -f foo
/home/bar

which is what we want. Relative path is relative to the symlink not the current working directory, so you can't cd directly to it.

cding to the source first and then to the relative readlink should work on both MacOS and Linux for relative and absolute symlinks.

Something like:

cd "$( dirname "${BASH_SOURCE[0]}" )"
cd "$( dirname "$( readlink "${BASH_SOURCE[0]}" )" )"

Not tested but should work.

If there's no symlink the second line should just resolve to cd . so won't negatively affect anything.