Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Install a custom/patched tarball #53

Closed
wants to merge 6 commits into from

2 participants

@dshaw

I love n, but sometimes I need test something we've patched. This makes that possible within the context of n.

@tj
Owner
tj commented

cool man, I'm down, do we need to dup that much of the original logic though? (just took a glance)

@dshaw

Yeah, there's definitely plenty of room to refactor the two install node functions and remove the duplication. Wanted to make sure what I had in mind worked and run the API past you. I was thinking about having install_node call install install_custom_node. I'll clean that up.

@dshaw

OK, cleaned up.

@tj
Owner
tj commented

awesome thanks man

@tj tj closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 55 additions and 28 deletions.
  1. +7 −2 Readme.md
  2. +48 −26 bin/n
View
9 Readme.md
@@ -1,4 +1,3 @@
-
# n
My own flavour of node binary management, no subshells, no profile setup, no convoluted api, just _simple_.
@@ -39,7 +38,11 @@ List installed binaries, config flags are shown:
Use or install the latest official release:
- $ n latest
+ $ n latest
+
+Install a custom or patched version of node from a tarball:
+
+ $ n custom 0.6.5 https://github.com/dshaw/node/tarball/patch/v0.6.5status
### Removing Binaries
@@ -83,6 +86,7 @@ Execute npm with 0.6.3 regardless of the active version:
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> <tarball> [config ...] Install custom node <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>
@@ -100,6 +104,7 @@ Execute npm with 0.6.3 regardless of the active version:
- rm
which bin
use as
+ custom c
## Details
View
74 bin/n
@@ -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> <tarball> [config ...] Install custom node <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>
@@ -76,6 +77,7 @@ display_help() {
which bin
use as
list ls
+ custom c
help
exit 0
@@ -144,40 +146,59 @@ install_node() {
# install
else
local tarball="node-v$version.tar.gz"
- local logpath="/tmp/n.log"
local url="http://nodejs.org/dist/$tarball"
# >= 0.5.x
local minor=$(echo $version | cut -d '.' -f 2)
test $minor -ge "5" && url="http://nodejs.org/dist/v$version/$tarball"
- # fetch and unpack
- cd $N_PREFIX/n \
- && $GET $url \
- > $tarball \
- && tar -zxf $tarball > $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
+ install_tarball $version $url $config
+ fi
+}
+
+#
+# Install node <version> <tarball> [config ...]
+#
+
+install_tarball() {
+ local version=$1
+ local url=$2; shift 2
+ local config=$@
- 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
+ # remove "v"
+ version=${version#v}
+
+ local dir=$VERSIONS_DIR/$version
+ local tarball="node-v$version.tar.gz"
+ local logpath="/tmp/n.log"
+
+ # 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
}
#
@@ -317,6 +338,7 @@ else
rm|-) remove_version $2; exit ;;
latest) install_node `n --latest`; exit ;;
ls|list) list_versions $2; exit ;;
+ c|custom) shift; install_tarball $@; exit ;;
*) install_node $@; exit ;;
esac
shift
Something went wrong with that request. Please try again.