Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added cleanup()

  • Loading branch information...
commit 1abb735bb1497745dfd8d15515ab2c08914d5667 1 parent 0594bb0
TJ Holowaychuk authored
Showing with 38 additions and 7 deletions.
  1. +38 −7 bin/n
45 bin/n
View
@@ -3,6 +3,11 @@
# Library version
VERSION="0.0.1"
+PREFIX=/usr/local/n
+
+# setup
+
+test -d $PREFIX || mkdir -p $PREFIX
# curl / wget support
@@ -43,6 +48,11 @@ display_help() {
Usage: n [options] <version>
+ Commands:
+
+ n Output versions installed
+ n <version> Install node <version>
+
Options:
-V, --version Output current version of n
@@ -94,15 +104,36 @@ install_node() {
version=${version:1:${#version}}
fi
- log "installing $version"
- cd /tmp \
+ # install
+ local dir="node-v$version"
+ cd $PREFIX \
&& $GET "http://nodejs.org/dist/node-v$version.tar.gz" \
- > "node-v$version.tar.gz" \
- && tar -zxf "node-v$version.tar.gz" \
- && cd "node-v$version" \
- && ./configure \
+ > "$dir.tar.gz" \
+ && tar -zxf "$dir.tar.gz" \
+ && cd $dir \
+ && ./configure --prefix $PREFIX\
&& make install \
- && log "installation complete"
+ && cd .. \
+ && cleanup $version
+}
+
+#
+# Cleanup after the given <version>
+#
+
+cleanup() {
+ local version=$1
+ local dir="node-v$version"
+
+ if test -d $dir; then
+ log "removing source"
+ rm -fr $dir
+ fi
+
+ if test -d "$dir.tar.gz"; then
+ log "removing tarball"
+ rm -fr "$dir.tar.gz"
+ fi
}
# Handle arguments
Please sign in to comment.
Something went wrong with that request. Please try again.