Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added support for installing node with a tarball.

  • Loading branch information...
commit 9b09e820f1f9b394ea408600ce85748c717c225e 1 parent 148939d
Daniel Shaw authored

Showing 1 changed file with 64 additions and 0 deletions. Show diff stats Hide diff stats

  1. 64  bin/n
64  bin/n
@@ -58,6 +58,7 @@ display_help() {
58 58
     n                           Output versions installed
59 59
     n latest [config ...]       Install or activate the latest node release
60 60
     n <version> [config ...]    Install and/or use node <version>
  61
+    n custom <version> [config ...]    Install custom node <version> <tarball> with [args ...]
61 62
     n use <version> [args ...]  Execute node <version> with [args ...]
62 63
     n npm <version> [args ...]  Execute npm <version> with [args ...]
63 64
     n bin <version>             Output bin path for <version>
@@ -181,6 +182,68 @@ install_node() {
181 182
 }
182 183
 
183 184
 #
  185
+# Install custom node <version> tarball [config ...]
  186
+#
  187
+
  188
+install_custom_node() {
  189
+  local version=$1
  190
+  local url=$2; shift 2
  191
+  local config=$@
  192
+  check_current_version
  193
+
  194
+  # remove "v"
  195
+  version=${version#v}
  196
+
  197
+  echo "attempting to install $version |  $url | $config"
  198
+
  199
+  # activate
  200
+  local dir=$VERSIONS_DIR/$version
  201
+  if test -d $dir; then
  202
+    # TODO: refactor, this is lame
  203
+    cd $dir \
  204
+      && mkdir -p $N_PREFIX/lib/node \
  205
+      && cp -fr $dir/include/node $N_PREFIX/include \
  206
+      && cp -f $dir/bin/node $N_PREFIX/bin/node \
  207
+      && cp -f $dir/bin/node-waf $N_PREFIX/bin/node-waf \
  208
+      && cp -fr $dir/lib/node/* $N_PREFIX/lib/node/.
  209
+  # install
  210
+  else
  211
+    local tarball="node-v$version.tar.gz"
  212
+    local logpath="/tmp/n.log"
  213
+
  214
+    echo "tarball $tarball"
  215
+
  216
+    # create build directory
  217
+    mkdir -p $N_PREFIX/n/node-v$version
  218
+
  219
+    # fetch and unpack
  220
+    cd $N_PREFIX/n/node-v$version \
  221
+      && $GET $url | tar xz --strip-components=1 > $logpath 2>&1
  222
+
  223
+    # see if things are alright
  224
+    if test $? -gt 0; then
  225
+      rm $tarball
  226
+      echo "\033[31mError: installation failed\033[0m"
  227
+      echo "  node version $version does not exist,"
  228
+      echo "  n failed to fetch the tarball,"
  229
+      echo "  or tar failed. Try a different"
  230
+      echo "  version or view $logpath to view"
  231
+      echo "  error details."
  232
+      exit 1
  233
+    fi
  234
+
  235
+    cd "$N_PREFIX/n/node-v$version" \
  236
+      && ./configure --prefix $VERSIONS_DIR/$version $config\
  237
+      && JOBS=4 make install \
  238
+      && cd .. \
  239
+      && cleanup $version \
  240
+      && mkdir -p $dir \
  241
+      && echo $config > "$dir/.config" \
  242
+      && n $version
  243
+  fi
  244
+}
  245
+
  246
+#
184 247
 # Cleanup after the given <version>
185 248
 #
186 249
 
@@ -317,6 +380,7 @@ else
317 380
       rm|-) remove_version $2; exit ;;
318 381
       latest) install_node `n --latest`; exit ;;
319 382
       ls|list) list_versions $2; exit ;;
  383
+      c|custom) shift; install_custom_node $@; exit ;;
320 384
       *) install_node $@; exit ;;
321 385
     esac
322 386
     shift

0 notes on commit 9b09e82

Please sign in to comment.
Something went wrong with that request. Please try again.