Skip to content

Commit

Permalink
Support from-source installs.
Browse files Browse the repository at this point in the history
Example:

```
nodenv install v0.10.1 --source
```

Fixes #2
Fixes #3
Fixes #4
  • Loading branch information
wfarr committed Mar 24, 2013
1 parent efa03d4 commit b15076c
Showing 1 changed file with 61 additions and 24 deletions.
85 changes: 61 additions & 24 deletions libexec/nodenv-install
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/usr/bin/env bash
# Summary: Install a version of NodeJS.
#
# Usage: nodenv install <version>
# Usage: nodenv install <version> [--source]
#
# Versions should be in the form of vN.N.N
#
# If --source is given, tries to build NodeJS from source.

# Bomb out if we hit an error, ever
set -e
Expand All @@ -15,37 +17,72 @@ set -e

# Pull the desired version out of ARGV
version="$1"
version_dir="$NODENV_ROOT/versions/$version"

# Determine OS
os="darwin"

# Determine arch
arch="x64"

# URL to download from
download="http://nodejs.org/dist/${version}/node-${version}-${os}-${arch}.tar.gz"

# Save current PWD
# stash the pwd
OLDPWD=$(pwd)
version_dir="$NODENV_ROOT/versions/$version"

# Install from bin
# Are we going to compile this instead?
compile="$2"

# Make the version dir and get in there
mkdir -p "$version_dir"
cd "$version_dir"

# Can't get too clever here
set +e
if [ "$compile" = "--source" ]; then
# Let's fetch the source and build it
download="http://nodejs.org/dist/${version}/node-${version}.tar.gz"

# Download binary tarball and install
curl -s -f "$download" > /tmp/node-$version.tar.gz && \
tar zxf /tmp/node-$version.tar.gz --strip-components 1 || \
{
cd $OLDPWD
rmdir "$version_dir"
# Can't get too clever here
set +e

echo "nodenv: unable to install NodeJS \`${version}' from binary, download not available"
exit 1
}
# Download source and compile it
curl -s -f "$download" > /tmp/node-$version.tar.gz && \
tar zxf /tmp/node-$version.tar.gz -C /tmp && \
cd /tmp/node-$version && \
(./configure --prefix="$version_dir" && make && make install) 2>&1 > /tmp/nodenv-install-$version.log && \
rm /tmp/node-$version.tar.gz && \
rm -rf /tmp/node-$version || \
{
cd $OLDPWD
rm -rf "$version_dir" /tmp/node-$version.tar.gz /tmp/node-$version

echo "nodenv: installation of $version from source failed" >&2
exit 1
}
else
# Determine url to download from
if [ "$(uname -s)" = "Darwin" ]; then
platform="darwin"
else
platform="$(uname -s)"
fi

if [ "$(uname -m)" = "x86_64" ]; then
arch="x64"
else
arch="$(uname -p)"
fi

# URL to download from
download="http://nodejs.org/dist/${version}/node-${version}-${platform}-${arch}.tar.gz"

# Can't get too clever here
set +e

# Download binary tarball and install
curl -s -f "$download" > /tmp/node-$version.tar.gz && \
tar zxf /tmp/node-$version.tar.gz --strip-components 1 && \
rm /tmp/node-$version.tar.gz || \
{
cd $OLDPWD
rmdir "$version_dir"

echo "nodenv: unable to install NodeJS \`${version}' from binary, download not available"
exit 1
}
fi

echo "Installed ${version}"
cd $OLDPWD

0 comments on commit b15076c

Please sign in to comment.