open-balena/scripts/_realpath
Roman Mazur e1bfb7f7b0 scripts: Handle missing coreutils on Mac
For convenience, also add instructions what to install.
Tha change also addresses invalid usage of 'local' outside of a function.

Change-type: patch
Signed-off-by: Roman Mazur <mazur.roman@gmail.com>
2019-04-16 18:05:16 +03:00

36 lines
696 B
Bash

#!/bin/bash -e
echo_error() {
local RED=`tput setaf 1`
local RESET=`tput sgr0`
echo "${RED}ERROR: ${1}${RESET}"
}
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
echo_error 'Unable to find suitable command for realpath.'
if [ $(uname) == 'Darwin' ]; then
echo 'GNU coreutils are required to build openBalena on MacOS. To install with brew, run'
echo ''
echo ' brew install coreutils'
echo ''
fi
exit 1
fi
realpath() {
echo $(command ${REALPATH} "$@")
}