|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# This is the Meteor install script! |
| 4 | +# |
| 5 | +# Are you looking at this in your web browser, and would like to install Meteor? |
| 6 | +# |
| 7 | +# MAC AND LINUX: |
| 8 | +# Just open up your terminal and type: |
| 9 | +# |
| 10 | +# curl https://install.meteor.com/ | sh |
| 11 | +# |
| 12 | +# Meteor currently supports: |
| 13 | +# - Mac: OS X 10.7 and above |
| 14 | +# - Linux: x86 and x86_64 systems |
| 15 | +# |
| 16 | +# WINDOWS: |
| 17 | +# Download the Windows installer from https://install.meteor.com/windows |
| 18 | +# |
| 19 | +# Meteor currently supports Windows 7, Windows 8.1, Windows Server 2008, |
| 20 | +# and Windows Server 2012. |
| 21 | + |
| 22 | +# We wrap this whole script in a function, so that we won't execute |
| 23 | +# until the entire script is downloaded. |
| 24 | +# That's good because it prevents our output overlapping with curl's. |
| 25 | +# It also means that we can't run a partially downloaded script. |
| 26 | +# We don't indent because it would be really confusing with the heredocs. |
| 27 | +run_it () { |
| 28 | + |
| 29 | +# This always does a clean install of the latest version of Meteor into your |
| 30 | +# ~/.meteor, replacing whatever is already there. (~/.meteor is only a cache of |
| 31 | +# packages and package metadata; no personal persistent data is stored there.) |
| 32 | + |
| 33 | +RELEASE="1.5.2" |
| 34 | + |
| 35 | + |
| 36 | +# Now, on to the actual installer! |
| 37 | + |
| 38 | +## NOTE sh NOT bash. This script should be POSIX sh only, since we don't |
| 39 | +## know what shell the user has. Debian uses 'dash' for 'sh', for |
| 40 | +## example. |
| 41 | + |
| 42 | +PREFIX="/usr/local" |
| 43 | + |
| 44 | +set -e |
| 45 | +set -u |
| 46 | + |
| 47 | +# Let's display everything on stderr. |
| 48 | +exec 1>&2 |
| 49 | + |
| 50 | + |
| 51 | +UNAME=$(uname) |
| 52 | +# Check to see if it starts with MINGW. |
| 53 | +if [ "$UNAME" ">" "MINGW" -a "$UNAME" "<" "MINGX" ] ; then |
| 54 | + echo "To install Meteor on Windows, download the installer from:" |
| 55 | + echo "https://install.meteor.com/windows" |
| 56 | + exit 1 |
| 57 | +fi |
| 58 | +if [ "$UNAME" != "Linux" -a "$UNAME" != "Darwin" ] ; then |
| 59 | + echo "Sorry, this OS is not supported yet via this installer." |
| 60 | + echo "For more details on supported platforms, see https://www.meteor.com/install" |
| 61 | + exit 1 |
| 62 | +fi |
| 63 | + |
| 64 | + |
| 65 | +if [ "$UNAME" = "Darwin" ] ; then |
| 66 | + ### OSX ### |
| 67 | + if [ "i386" != "$(uname -p)" -o "1" != "$(sysctl -n hw.cpu64bit_capable 2>/dev/null || echo 0)" ] ; then |
| 68 | + # Can't just test uname -m = x86_64, because Snow Leopard can |
| 69 | + # return other values. |
| 70 | + echo "Only 64-bit Intel processors are supported at this time." |
| 71 | + exit 1 |
| 72 | + fi |
| 73 | + |
| 74 | + # Running a version of Meteor older than 0.6.0 (April 2013)? |
| 75 | + if grep BUNDLE_VERSION /usr/local/bin/meteor >/dev/null 2>&1 ; then |
| 76 | + echo "You appear to have a very old version of Meteor installed." |
| 77 | + echo "Please remove it by running these commands:" |
| 78 | + echo " $ sudo rm /usr/local/bin/meteor" |
| 79 | + echo " $ sudo rm -rf /usr/local/meteor /usr/local/meteor.old" |
| 80 | + echo "and then run the installer command again:" |
| 81 | + echo " $ curl https://install.meteor.com/ | sh" |
| 82 | + exit 1 |
| 83 | + fi |
| 84 | + |
| 85 | + PLATFORM="os.osx.x86_64" |
| 86 | +elif [ "$UNAME" = "Linux" ] ; then |
| 87 | + ### Linux ### |
| 88 | + LINUX_ARCH=$(uname -m) |
| 89 | + if [ "${LINUX_ARCH}" = "i686" ] ; then |
| 90 | + PLATFORM="os.linux.x86_32" |
| 91 | + elif [ "${LINUX_ARCH}" = "x86_64" ] ; then |
| 92 | + PLATFORM="os.linux.x86_64" |
| 93 | + else |
| 94 | + echo "Unusable architecture: ${LINUX_ARCH}" |
| 95 | + echo "Meteor only supports i686 and x86_64 for now." |
| 96 | + exit 1 |
| 97 | + fi |
| 98 | + |
| 99 | + # Running a version of Meteor older than 0.6.0 (April 2013) on a dpkg system? |
| 100 | + if dpkg -s meteor >/dev/null 2>&1 ; then |
| 101 | + echo "You appear to have a very old version of Meteor installed." |
| 102 | + echo "Please remove it by running these commands:" |
| 103 | + echo " $ sudo dpkg -r meteor" |
| 104 | + echo " $ hash -r" |
| 105 | + echo "and then run the installer command again:" |
| 106 | + echo " $ curl https://install.meteor.com/ | sh" |
| 107 | + exit 1 |
| 108 | + fi |
| 109 | + |
| 110 | + # Running a version of Meteor older than 0.6.0 (April 2013) on an rpm system? |
| 111 | + if rpm -q meteor >/dev/null 2>&1 ; then |
| 112 | + echo "You appear to have a very old version of Meteor installed." |
| 113 | + echo "Please remove it by running these commands:" |
| 114 | + echo " $ sudo rpm -e meteor" |
| 115 | + echo " $ hash -r" |
| 116 | + echo "and then run the installer command again:" |
| 117 | + echo " $ curl https://install.meteor.com/ | sh" |
| 118 | + exit 1 |
| 119 | + fi |
| 120 | +fi |
| 121 | + |
| 122 | +trap "echo Installation failed." EXIT |
| 123 | + |
| 124 | +if [ -z $HOME ] || [ ! -d $HOME ]; then |
| 125 | + echo "The installation and use of Meteor requires the \$HOME environment variable be set to a directory where its files can be installed." |
| 126 | + exit 1 |
| 127 | +fi |
| 128 | + |
| 129 | +# If you already have a tropohouse/warehouse, we do a clean install here: |
| 130 | +if [ -e "$HOME/.meteor" ]; then |
| 131 | + echo "Removing your existing Meteor installation." |
| 132 | + rm -rf "$HOME/.meteor" |
| 133 | +fi |
| 134 | + |
| 135 | +TARBALL_URL="https://static-meteor.netdna-ssl.com/packages-bootstrap/${RELEASE}/meteor-bootstrap-${PLATFORM}.tar.gz" |
| 136 | +INSTALL_TMPDIR="$HOME/.meteor-install-tmp" |
| 137 | +TARBALL_FILE="$HOME/.meteor-tarball-tmp" |
| 138 | + |
| 139 | +cleanUp() { |
| 140 | + rm -rf "$TARBALL_FILE" |
| 141 | + rm -rf "$INSTALL_TMPDIR" |
| 142 | +} |
| 143 | + |
| 144 | +# Remove temporary files now in case they exist. |
| 145 | +cleanUp |
| 146 | + |
| 147 | +# Make sure cleanUp gets called if we exit abnormally. |
| 148 | +trap cleanUp EXIT |
| 149 | + |
| 150 | +mkdir "$INSTALL_TMPDIR" |
| 151 | + |
| 152 | +# Only show progress bar animations if we have a tty |
| 153 | +# (Prevents tons of console junk when installing within a pipe) |
| 154 | +VERBOSITY="--silent"; |
| 155 | +if [ -t 1 ]; then |
| 156 | + VERBOSITY="--progress-bar" |
| 157 | +fi |
| 158 | + |
| 159 | +echo "Downloading Meteor distribution" |
| 160 | +# keep trying to curl the file until it works (resuming where possible) |
| 161 | +MAX_ATTEMPTS=10 |
| 162 | +RETRY_DELAY_SECS=5 |
| 163 | +set +e |
| 164 | +ATTEMPTS=0 |
| 165 | +while [ $ATTEMPTS -lt $MAX_ATTEMPTS ] |
| 166 | +do |
| 167 | + ATTEMPTS=$((ATTEMPTS + 1)) |
| 168 | + |
| 169 | + curl $VERBOSITY --fail --continue-at - \ |
| 170 | + "$TARBALL_URL" --output "$TARBALL_FILE" |
| 171 | + |
| 172 | + if [ $? -eq 0 ] |
| 173 | + then |
| 174 | + break |
| 175 | + fi |
| 176 | + |
| 177 | + echo "Retrying download in $RETRY_DELAY_SECS seconds..." |
| 178 | + sleep $RETRY_DELAY_SECS |
| 179 | +done |
| 180 | +set -e |
| 181 | + |
| 182 | +# bomb out if it didn't work, eg no net |
| 183 | +test -e "${TARBALL_FILE}" |
| 184 | +tar -xzf "$TARBALL_FILE" -C "$INSTALL_TMPDIR" -o |
| 185 | + |
| 186 | +test -x "${INSTALL_TMPDIR}/.meteor/meteor" |
| 187 | +mv "${INSTALL_TMPDIR}/.meteor" "$HOME" |
| 188 | +# just double-checking :) |
| 189 | +test -x "$HOME/.meteor/meteor" |
| 190 | + |
| 191 | +# The `trap cleanUp EXIT` line above won't actually fire after the exec |
| 192 | +# call below, so call cleanUp manually. |
| 193 | +cleanUp |
| 194 | + |
| 195 | +echo |
| 196 | +echo "Meteor ${RELEASE} has been installed in your home directory (~/.meteor)." |
| 197 | + |
| 198 | +METEOR_SYMLINK_TARGET="$(readlink "$HOME/.meteor/meteor")" |
| 199 | +METEOR_TOOL_DIRECTORY="$(dirname "$METEOR_SYMLINK_TARGET")" |
| 200 | +LAUNCHER="$HOME/.meteor/$METEOR_TOOL_DIRECTORY/scripts/admin/launch-meteor" |
| 201 | + |
| 202 | +if cp "$LAUNCHER" "$PREFIX/bin/meteor" >/dev/null 2>&1; then |
| 203 | + echo "Writing a launcher script to $PREFIX/bin/meteor for your convenience." |
| 204 | + cat <<"EOF" |
| 205 | +
|
| 206 | +To get started fast: |
| 207 | +
|
| 208 | + $ meteor create ~/my_cool_app |
| 209 | + $ cd ~/my_cool_app |
| 210 | + $ meteor |
| 211 | +
|
| 212 | +Or see the docs at: |
| 213 | +
|
| 214 | + docs.meteor.com |
| 215 | +
|
| 216 | +EOF |
| 217 | +elif type sudo >/dev/null 2>&1; then |
| 218 | + echo "Writing a launcher script to $PREFIX/bin/meteor for your convenience." |
| 219 | + echo "This may prompt for your password." |
| 220 | + |
| 221 | + # New macs (10.9+) don't ship with /usr/local, however it is still in |
| 222 | + # the default PATH. We still install there, we just need to create the |
| 223 | + # directory first. |
| 224 | + # XXX this means that we can run sudo too many times. we should never |
| 225 | + # run it more than once if it fails the first time |
| 226 | + if [ ! -d "$PREFIX/bin" ] ; then |
| 227 | + sudo mkdir -m 755 "$PREFIX" || true |
| 228 | + sudo mkdir -m 755 "$PREFIX/bin" || true |
| 229 | + fi |
| 230 | + |
| 231 | + if sudo cp "$LAUNCHER" "$PREFIX/bin/meteor"; then |
| 232 | + cat <<"EOF" |
| 233 | +
|
| 234 | +To get started fast: |
| 235 | +
|
| 236 | + $ meteor create ~/my_cool_app |
| 237 | + $ cd ~/my_cool_app |
| 238 | + $ meteor |
| 239 | +
|
| 240 | +Or see the docs at: |
| 241 | +
|
| 242 | + docs.meteor.com |
| 243 | +
|
| 244 | +EOF |
| 245 | + else |
| 246 | + cat <<EOF |
| 247 | +
|
| 248 | +Couldn't write the launcher script. Please either: |
| 249 | +
|
| 250 | + (1) Run the following as root: |
| 251 | + cp "$LAUNCHER" /usr/bin/meteor |
| 252 | + (2) Add "\$HOME/.meteor" to your path, or |
| 253 | + (3) Rerun this command to try again. |
| 254 | +
|
| 255 | +Then to get started, take a look at 'meteor --help' or see the docs at |
| 256 | +docs.meteor.com. |
| 257 | +EOF |
| 258 | + fi |
| 259 | +else |
| 260 | + cat <<EOF |
| 261 | +
|
| 262 | +Now you need to do one of the following: |
| 263 | +
|
| 264 | + (1) Add "\$HOME/.meteor" to your path, or |
| 265 | + (2) Run this command as root: |
| 266 | + cp "$LAUNCHER" /usr/bin/meteor |
| 267 | +
|
| 268 | +Then to get started, take a look at 'meteor --help' or see the docs at |
| 269 | +docs.meteor.com. |
| 270 | +EOF |
| 271 | +fi |
| 272 | + |
| 273 | + |
| 274 | +trap - EXIT |
| 275 | +} |
| 276 | + |
| 277 | +run_it |
| 278 | + |
0 commit comments