forked from icflorescu/openshift-cartridge-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil
44 lines (35 loc) · 1.22 KB
/
util
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
#!/bin/bash
function update_nodejs {
if [ -f "$OPENSHIFT_REPO_DIR/.openshift/NODE_VERSION_URL" ]; then
local VERSION_URL=$(cat $OPENSHIFT_REPO_DIR/.openshift/NODE_VERSION_URL)
else
local VERSION_URL="https://semver.io/node/stable"
fi
local LATEST="v$(curl --silent --max-time 5 ${VERSION_URL})"
local NODE_URL=https://nodejs.org/dist/${LATEST}/node-${LATEST}-linux-x64.tar.gz
if [ "$LATEST" = "v" ]; then
echo "Could not retrieve node version information from $VERSION_URL"
return 1
fi
# Update Node.js if necessary
if [ $(node --version) != ${LATEST} ]; then
# Download
if ! curl -L -o ${OPENSHIFT_DATA_DIR}tmp.tgz $NODE_URL; then
return 1
fi
# Remove old files
rm -rf ${OPENSHIFT_DATA_DIR}.nodejs
# Copy binaries
mkdir ${OPENSHIFT_DATA_DIR}.nodejs
tar -xvzf ${OPENSHIFT_DATA_DIR}tmp.tgz --strip-components=1 -C ${OPENSHIFT_DATA_DIR}.nodejs
# Remove downloaded archive
rm ${OPENSHIFT_DATA_DIR}tmp.tgz
# Output result
echo "Node.js updated to $(node --version) with npm $(npm --version)."
fi
# Update global npm if necessary
if [ $(npm view npm version) != $(npm --version) ]; then
npm i -g npm
echo "Npm updated to $(npm --version)."
fi
}