forked from cloudify-cosmo/cloudify-nodecellar-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-nodejs.sh
More file actions
executable file
·73 lines (54 loc) · 1.92 KB
/
Copy pathinstall-nodejs.sh
File metadata and controls
executable file
·73 lines (54 loc) · 1.92 KB
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
#!/bin/bash
set -e
function download() {
url=$1
name=$2
if [ -f "`pwd`/${name}" ]; then
ctx logger info "`pwd`/${name} already exists, No need to download"
else
# download to given directory
ctx logger info "Downloading ${url} to `pwd`/${name}"
set +e
curl_cmd=$(which curl)
wget_cmd=$(which wget)
set -e
if [[ ! -z ${curl_cmd} ]]; then
curl -L -o ${name} ${url}
elif [[ ! -z ${wget_cmd} ]]; then
wget -O ${name} ${url}
else
ctx logger error "Failed to download ${url}: Neither 'cURL' nor 'wget' were found on the system"
exit 1;
fi
fi
}
function untar() {
tar_archive=$1
destination=$2
inner_name=$(tar -tf "${tar_archive}" | grep -o '^[^/]\+' | sort -u)
if [ ! -d ${destination} ]; then
ctx logger info "Untaring ${tar_archive}"
tar -xf ${tar_archive}
ctx logger info "Moving ${inner_name} to ${destination}"
mv ${inner_name} ${destination}
fi
}
TEMP_DIR='/tmp'
NODEJS_TARBALL_NAME='node-v6.9.1-linux-x64.tar.xz'
################################
# Directory that will contain:
# - NodeJS binaries
################################
NODEJS_ROOT=${TEMP_DIR}/$(ctx execution-id)/nodejs
NODEJS_BINARIES_PATH=${NODEJS_ROOT}/nodejs-binaries
mkdir -p ${NODEJS_ROOT}
cd ${TEMP_DIR}
download https://nodejs.org/dist/v6.9.1/${NODEJS_TARBALL_NAME} ${NODEJS_TARBALL_NAME}
untar ${NODEJS_TARBALL_NAME} ${NODEJS_BINARIES_PATH}
# this runtime property is used by the start-nodecellar-app.sh
ctx instance runtime_properties nodejs_binaries_path ${NODEJS_BINARIES_PATH}
ctx logger info "Fixing node path in npm-cli.js..."
NPM_CLI_PATH=${NODEJS_BINARIES_PATH}/lib/node_modules/npm/bin/npm-cli.js
NPM_CLI_FIRST_LINE="\#\!${NODEJS_BINARIES_PATH}/bin/node"
sed -i "1s/.*/${NPM_CLI_FIRST_LINE//\//\\/}/" ${NPM_CLI_PATH}
ctx logger info "Sucessfully installed NodeJS"