balena-cli/bin/resin

65 lines
1.4 KiB
Plaintext
Raw Normal View History

#!/bin/bash
function unsupported_platform() {
echo "Your platform (`uname -a`) is not supported." && exit 1
}
# Detect CPU arch.
ARCHITECTURE=`uname -m`
case "$ARCHITECTURE" in
i?86) ARCHITECTURE="x86" ;;
x86_64) ARCHITECTURE="x64" ;;
esac
# Detect current OS, see http://stackoverflow.com/q/3466166/682252.
# Darwin
if [ "`uname`" == "Darwin" ]; then
NODE_BIN="node-darwin-$ARCHITECTURE"
# Linux
elif [ "`expr substr $(uname -s) 1 5`" == "Linux" ]; then
NODE_BIN="node-linux-$ARCHITECTURE"
# Win32
elif [ "`expr substr $(uname -s) 1 10`" == "MINGW32_NT" ]; then
NODE_BIN="node-win32-$ARCHITECTURE.exe"
# SunOS
elif [ "`uname`" == "SunOS" ]; then
NODE_BIN="node-sunos-$ARCHITECTURE"
else
unsupported_platform
fi
2015-02-27 14:20:56 -04:00
BIN_RESIN=$0
while [ -L "$BIN_RESIN" ]; do
BIN_RESIN=`readlink "$BIN_RESIN"`
done
2015-03-03 13:52:18 -04:00
# If a link was resolved (ie BIN_RESIN != $0) and the resolved link is relative,
# we assume the link is relative to the dirname of the link location
if [[ "$BIN_RESIN" != "$0" ]] && [[ "$BIN_RESIN" != /* ]]; then
BIN_RESIN=`dirname $0`/$BIN_RESIN
fi
2015-02-27 14:20:56 -04:00
BIN_DIRECTORY=`dirname $BIN_RESIN`
NODE_PATH=$BIN_DIRECTORY/node/$NODE_BIN
if [ ! -x $NODE_PATH ]; then
2015-03-03 13:52:18 -04:00
echo "Warning: $NODE_PATH does not exist"
2015-02-27 14:20:56 -04:00
# As a last resource, try to use an already available node
if command -v node >/dev/null 2>&1; then
NODE_PATH="node"
else
unsupported_platform
fi
fi
2015-02-27 14:20:56 -04:00
$NODE_PATH "$BIN_DIRECTORY/../build/app.js" "$@"