-
Notifications
You must be signed in to change notification settings - Fork 4
/
node_setup.sh
76 lines (64 loc) · 1.42 KB
/
node_setup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
# install and configure nodejs
# USAGE: sh node_setup.sh version , e.g. sh node_setup.sh 0.8.2
# bjzllou 2012-08-13
if [ $# -eq 0 ]; then
VERSION=0.6.4
else
VERSION=$1
fi
echo "install v$VERSION of node..."
sleep 1
NODE_VERSION=node-v$VERSION
NODE_TAR=${NODE_VERSION}.tar.gz
APP_HOME=/home/app
DOWNLOAD_HOME=/home/download
echo -n 'Checking APP_HOME : '
if [ ! -f $APP_HOME ]; then
echo 'not found, create it...'
mkdir -p $APP_HOME
else
echo 'found'
fi
echo -n 'Checking DOWNLOAD_HOME : '
if [ ! -f $DOWNLOAD_HOME ]; then
echo 'not found, create it...'
mkdir -p $DOWNLOAD_HOME
else
echo 'found'
fi
cd $DOWNLOAD_HOME
rm -rf $NODE_VERSION
rm -rf ${APP_HOME}/${NODE_VERSION}
echo -n "Checking $NODE_VERSION : "
if [ -f $NODE_TAR ]; then
echo 'found'
else
echo "download $NODE_VERSION..."
wget http://nodejs.org/dist/${NODE_TAR}
fi
tar -zxvf $NODE_TAR
cd $NODE_VERSION
./configure --prefix=${APP_HOME}/${NODE_VERSION}
make
make install
rm /home/node
ln -s ${APP_HOME}/${NODE_VERSION} /home/node
echo -n 'Checking node : '
node_exists=`which node`
if [ -z $node_exists ]; then
echo 'add node to PATH...'
echo 'export PATH=$PATH:/home/node/bin' >> /etc/profile
source /etc/profile
else
echo 'found'
fi
echo -n 'Checking NODE_PATH : '
if [ -z $NODE_PATH ]; then
echo 'set NODE_PATH...'
echo 'export NODE_PATH=/home/node/lib/node_modules' >> /etc/profile
source /etc/profile
else
echo 'found'
fi
echo 'done'