-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathnode-install.sh
executable file
·76 lines (59 loc) · 1.9 KB
/
node-install.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
echo "Node Linux Installer by www.github.com/taaem"
if [[ $EUID -ne 0 ]]; then
echo "Need Root for installing NodeJS"
sudo sh -c 'echo "Got Root!"'
else
echo "Running as Root User"
fi
echo "Get Latest Version Number..."
node_latest=$(curl http://nodejs.org/dist/latest/ 2>/dev/null)
if [[ ! $node_latest ]]
then
echo "ERROR: No Internet Connection" >&2
exit 1
fi
ARCH=$(uname -m)
if [ $ARCH = arm64 ] || [ $ARCH = aarch64 ]
then
NAME=$(echo "$node_latest" | grep -o '>node-v.*-linux-arm64.tar.gz' )
VER=$(echo "$NAME" | grep -o 'node-v.*-linux-arm64.tar.gz')
elif [ $ARCH = armv6l ]
then
NAME=$(echo "$node_latest" | grep -o '>node-v.*-linux-armv6l.tar.gz' )
VER=$(echo "$NAME" | grep -o 'node-v.*-linux-armv6l.tar.gz')
elif [ $ARCH = armv7l ]
then
NAME=$(echo "$node_latest" | grep -o '>node-v.*-linux-armv7l.tar.gz' )
VER=$(echo "$NAME" | grep -o 'node-v.*-linux-armv7l.tar.gz')
elif [ $ARCH = x86_64 ]
then
NAME=$(echo "$node_latest" | grep -o '>node-v.*-linux-x64.tar.gz' )
VER=$(echo "$NAME" | grep -o 'node-v.*-linux-x64.tar.gz')
else
NAME=$(echo "$node_latest" | grep -o '>node-v.*-linux-x86.tar.gz' )
VER=$(echo "$NAME" | grep -o 'node-v.*-linux-x86.tar.gz')
fi
echo "Done"
echo "Downloading latest stable Version $VER..."
URL=http://nodejs.org/dist/latest/$VER
FILE_PATH=/tmp/node.tar.gz
curl -o $FILE_PATH $URL 2>/dev/null
exit_status=$(echo "$?")
if [[ $exit_status -ne "0" ]]
then
echo "ERROR: Target tar not found"
exit $exit_status
fi
echo "Done"
echo "Installing..."
cd /usr/local && sudo tar --strip-components 1 -xzf /tmp/node.tar.gz
exit_status=$(echo "$?")
if [[ $exit_status -ne "0" ]]
then
echo "ERROR: Couldn't extract tar"
exit $exit_status
fi
rm $FILE_PATH
echo "Finished installing!"
exit 0