Skip to content
This repository
Newer
Older
100755 121 lines (91 sloc) 1.719 kb
73896ff4 »
2011-01-05 Initial commit
1 #!/usr/bin/env sh
2
1667a31d »
2011-01-05 Started n(1)
3 # Library version
4
5 VERSION="0.0.1"
6
7 # curl / wget support
8
9 GET=
10
11 # wget support
12 which wget > /dev/null && GET="wget -q -O-"
13
14 # curl support
15 which curl > /dev/null && GET="curl -# -L"
16
d3ac35d2 »
2011-01-05 abort
17 # Ensure we have curl or wget
18
19 test -z "$GET" && abort "curl or wget required"
20
1667a31d »
2011-01-05 Started n(1)
21 #
22 # Log the given <msg ...>
23 #
24
25 log() {
26 echo "... $@"
27 }
28
29 #
d3ac35d2 »
2011-01-05 abort
30 # Exit with the given <msg ...>
31 #
32
33 abort() {
34 echo "Error: $@" && exit 1
35 }
36
37 #
1667a31d »
2011-01-05 Started n(1)
38 # Output usage information.
39 #
40
41 display_help() {
42 cat <<-help
43
44 Usage: n [options] <version>
45
46 Options:
47
48 -V, --version Output current version of n
49 -h, --help Display help information
50
51 help
52 exit 0
53 }
54
55 #
56 # Output n version.
57 #
58
59 display_n_version() {
60 echo $VERSION && exit 0
61 }
62
3017360b »
2011-01-05 installing
63 #
0594bb0e »
2011-01-05 Added display_current_version()
64 # Display current node --version
65 #
66
67 display_current_version() {
68 if test `which node`; then
69 local version=`node --version`
70 echo " current: $version"
71 else
72 echo " current: none"
73 fi
74 }
75
76 #
77 # Display current node --version
78 # and others installed.
79 #
80
81 display_versions() {
82 display_current_version
83 }
84
85 #
3017360b »
2011-01-05 installing
86 # Install node <version>
87 #
88
89 install_node() {
90 local version=$1
91
92 # remove "v"
93 if test "${version:0:1}" = "v"; then
94 version=${version:1:${#version}}
95 fi
96
97 log "installing $version"
98 cd /tmp \
99 && $GET "http://nodejs.org/dist/node-v$version.tar.gz" \
100 > "node-v$version.tar.gz" \
101 && tar -zxf "node-v$version.tar.gz" \
102 && cd "node-v$version" \
ed8f539d »
2011-01-05 typo
103 && ./configure \
104 && make install \
3017360b »
2011-01-05 installing
105 && log "installation complete"
106 }
107
1667a31d »
2011-01-05 Started n(1)
108 # Handle arguments
109
110 if test $# -eq 0; then
111 display_versions
112 else
113 while test $# -ne 0; do
114 case $1 in
115 -V|--version) display_n_version ;;
116 -h|--help) display_help ;;
3017360b »
2011-01-05 installing
117 *) install_node $1 ;;
1667a31d »
2011-01-05 Started n(1)
118 esac
119 shift
120 done
121 fi
Something went wrong with that request. Please try again.