Skip to content

Commit

Permalink
Added support for installing node with a tarball.
Browse files Browse the repository at this point in the history
  • Loading branch information
dshaw authored and tj committed Jan 26, 2012
1 parent 148939d commit 6c838cd
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions bin/n
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ display_help() {
n Output versions installed
n latest [config ...] Install or activate the latest node release
n <version> [config ...] Install and/or use node <version>
n custom <version> [config ...] Install custom node <version> <tarball> with [args ...]
n use <version> [args ...] Execute node <version> with [args ...]
n npm <version> [args ...] Execute npm <version> with [args ...]
n bin <version> Output bin path for <version>
Expand Down Expand Up @@ -180,6 +181,68 @@ install_node() {
fi
}

#
# Install custom node <version> tarball [config ...]
#

install_custom_node() {
local version=$1
local url=$2; shift 2
local config=$@
check_current_version

# remove "v"
version=${version#v}

echo "attempting to install $version | $url | $config"

# activate
local dir=$VERSIONS_DIR/$version
if test -d $dir; then
# TODO: refactor, this is lame
cd $dir \
&& mkdir -p $N_PREFIX/lib/node \
&& cp -fr $dir/include/node $N_PREFIX/include \
&& cp -f $dir/bin/node $N_PREFIX/bin/node \
&& cp -f $dir/bin/node-waf $N_PREFIX/bin/node-waf \
&& cp -fr $dir/lib/node/* $N_PREFIX/lib/node/.
# install
else
local tarball="node-v$version.tar.gz"
local logpath="/tmp/n.log"

echo "tarball $tarball"

# create build directory
mkdir -p $N_PREFIX/n/node-v$version

# fetch and unpack
cd $N_PREFIX/n/node-v$version \
&& $GET $url | tar xz --strip-components=1 > $logpath 2>&1

# see if things are alright
if test $? -gt 0; then
rm $tarball
echo "\033[31mError: installation failed\033[0m"
echo " node version $version does not exist,"
echo " n failed to fetch the tarball,"
echo " or tar failed. Try a different"
echo " version or view $logpath to view"
echo " error details."
exit 1
fi

cd "$N_PREFIX/n/node-v$version" \
&& ./configure --prefix $VERSIONS_DIR/$version $config\
&& JOBS=4 make install \
&& cd .. \
&& cleanup $version \
&& mkdir -p $dir \
&& echo $config > "$dir/.config" \
&& n $version
fi
}

#
# Cleanup after the given <version>
#
Expand Down Expand Up @@ -317,6 +380,7 @@ else
rm|-) remove_version $2; exit ;;
latest) install_node `n --latest`; exit ;;
ls|list) list_versions $2; exit ;;
c|custom) shift; install_custom_node $@; exit ;;
*) install_node $@; exit ;;
esac
shift
Expand Down

0 comments on commit 6c838cd

Please sign in to comment.