Last active
June 13, 2016 16:50
-
-
Save epety/f01b15603e2312a6c94179f8f6b828e0 to your computer and use it in GitHub Desktop.
Nodejs installation script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 Version Number..." | |
# Change URL to change | |
URL=https://nodejs.org/dist/v4.2.5/ | |
node_latest=$(curl $URL/ 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="$URL/$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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment