balena-cli/bin/resin

58 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
function unsupported_platform() {
echo "Your platform (`uname -a`) is not supported." && exit 1
}
NODE_VERSION="v0.12.0"
# 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-$NODE_VERSION-darwin-$ARCHITECTURE"
# Linux
elif [ "`expr substr $(uname -s) 1 5`" == "Linux" ]; then
NODE_BIN="node-$NODE_VERSION-linux-$ARCHITECTURE"
# Win32
elif [ "`expr substr $(uname -s) 1 10`" == "MINGW32_NT" ]; then
NODE_BIN="node-$NODE_VERSION-win32-$ARCHITECTURE.exe"
# SunOS
elif [ "`uname`" == "SunOS" ]; then
NODE_BIN="node-$NODE_VERSION-sunos-$ARCHITECTURE.bin"
else
unsupported_platform
fi
NODE_PATH="./bin/node/$NODE_BIN"
echo $NODE_PATH
if [ ! -x $NODE_PATH ]; then
# 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
# Support calling bin/resin from within bin/
if [ `dirname $0` == '.' ]; then
$NODE_PATH "../lib/resin.js" "$@"
else
$NODE_PATH "./lib/resin.js" "$@"
fi