open-balena/scripts/_realpath
Rich Bayliss 709d00b898
init: Make scripts macOS compatible
The quickstart script should be able to run on macOS machines
and not just Linux ones.

Signed-off-by: Rich Bayliss <rich@balena.io>
Change-type: patch
2018-12-20 10:42:50 +00:00

25 lines
403 B
Bash

#!/bin/bash -e
REALPATH=
REALPATHS=(
'realpath'
'grealpath'
'greadlink -f'
)
for cmd in "${REALPATHS[@]}"; do
if command -v "${cmd%% *}" &>/dev/null; then
REALPATH="${cmd}"
break
fi
done
if [ -z "${REALPATH}" ]; then
local RED=`tput setaf 1`
echo "${RED}ERROR: Unable to find suitable command for realpath."
exit 1
fi
realpath() {
echo $(command ${REALPATH} "$@")
}