Files
meteor/skybreak
2011-12-05 23:38:58 -08:00

85 lines
2.5 KiB
Bash
Executable File

#!/bin/bash
BUNDLE_VERSION=0.0.5
# Find the script dir, following one level of symlink.
if [ -L "$0" ] ; then
SCRIPT_DIR=$(dirname $(readlink "$0") )
else
SCRIPT_DIR=$(dirname "$0")
fi
# OS Check. Put here because here is where we download the precompiled
# bundles that are arch specific.
UNAME=$(uname)
if [ "$UNAME" != "Linux" -a "$UNAME" != "Darwin" ] ; then
echo "This OS is not supported."
exit 1
fi
if [ "$UNAME" = "Darwin" ] ; then
if [ "i386" != $(uname -p) -o "1" != $(sysctl -n hw.cpu64bit_capable 2>/dev/null || echo 0) ] ; then
# Can't just test uname -m = x86_64, because Snow Leopard can
# return other values.
echo "Only 64-bit Intel processors are supported at this time."
fi
elif [ "$UNAME" = "Linux" -a "x86_64" != $(uname -m) ] ; then
echo "Only 64-bit Intel processors are supported at this time."
fi
function install_dev_bundle {
set -e
trap "echo FAILED" INT TERM EXIT
TARBALL="dev_bundle_${UNAME}_${BUNDLE_VERSION}.tar.gz"
TMPDIR="$SCRIPT_DIR/dev_bundle.xxx"
rm -rf "$TMPDIR"
mkdir "$TMPDIR"
if [ -f "$SCRIPT_DIR/$TARBALL" ] ; then
echo "... installing from local tarball ..."
tar -xzf "$SCRIPT_DIR/$TARBALL" -C "$TMPDIR"
else
echo "... downloading ..."
curl -# https://d377jur38fl888.cloudfront.net/$TARBALL | tar -xzf - -C "$TMPDIR"
fi
mv "$TMPDIR" "$SCRIPT_DIR/dev_bundle"
echo "... installed runtime environment v${BUNDLE_VERSION} ..."
echo
trap - INT TERM EXIT
set +e
}
if [ -d "$SCRIPT_DIR/.git" ]; then
# In a checkout.
if [ ! -d "$SCRIPT_DIR/dev_bundle" ] ; then
# if this is the first time we've run skybreak, we may not have
# a dev_bundle yet. Set one up by downloading
echo "... runtime environment not found ..."
install_dev_bundle
elif [ ! -f "$SCRIPT_DIR/dev_bundle/.bundle_version.txt" ] ||
grep -qvx "$BUNDLE_VERSION" "$SCRIPT_DIR/dev_bundle/.bundle_version.txt" ; then
# Also check if dev bundle is out of date.
echo "... runtime environment out of date. upgrading. ..."
rm -rf "$SCRIPT_DIR/dev_bundle"
install_dev_bundle
fi
DEV_BUNDLE="$SCRIPT_DIR/dev_bundle"
SKYBREAK="$SCRIPT_DIR/app/skybreak/skybreak.js"
else
# In an install
DEV_BUNDLE=$(dirname "$SCRIPT_DIR")
SKYBREAK="$DEV_BUNDLE/app/skybreak/skybreak.js"
fi
export NODE_PATH="$DEV_BUNDLE/lib/node_modules"
exec "$DEV_BUNDLE/bin/node" "$SKYBREAK" "$@"