Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix connection check and re-enabled i386 and armv6l support #11

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 50 additions & 52 deletions node-install.sh
Original file line number Diff line number Diff line change
@@ -1,76 +1,74 @@
#!/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 ]]
echo 'Node Linux Installer by www.github.com/taaem'
if [[ $EUID -ne 0 ]]
then
echo "ERROR: No Internet Connection" >&2
exit 1
echo 'Need root for installing NodeJS'
sudo sh -c 'echo "Got root!"'
else
echo 'Running as root user'
fi

ARCH=$(uname -m)

if [ $ARCH = arm64 ] || [ $ARCH = aarch64 ]
echo "Getting latest stable version for $ARCH ..."
URL='https://nodejs.org/dist/'
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')
URL+='latest/'
NAME=$(curl -sf "$URL" | grep -o '>node-v.*-linux-arm64.tar.gz')
VER=$(echo "$NAME" | grep -o 'node-v.*-linux-arm64.tar.gz')

elif [ $ARCH = armv6l ]
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')
URL+='latest-v11.x/'
NAME=$(curl -sf "$URL" | grep -o '>node-v.*-linux-armv6l.tar.gz')
VER=$(echo "$NAME" | grep -o 'node-v.*-linux-armv6l.tar.gz')

elif [ $ARCH = armv7l ]
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 ]
URL+='latest/'
NAME=$(curl -sf "$URL" | 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')
URL+='latest/'
NAME=$(curl -sf "$URL" | 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')
URL+='latest-v9.x/'
NAME=$(curl -sf "$URL" | 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" ]]
if [[ ! $VER ]]
then
echo "ERROR: Failed to find latest stable version for $ARCH" >&2
exit 1
fi
echo "Found latest stable version for $ARCH: $VER"

URL+="$VER"
echo "Downloading $URL ..."
FILE_PATH='/tmp/node.tar.gz'
curl -fo "$FILE_PATH" "$URL"
exit_status=$?
if [[ $exit_status -ne 0 ]]
then
echo "ERROR: Target tar not found"
echo "ERROR: Failed to download $URL" >&2
exit $exit_status
fi
echo 'Finished downloading!'

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" ]]
echo "Installing $FILE_PATH ..."
cd /usr/local && sudo tar --strip-components 1 -xzf "$FILE_PATH"
exit_status=$?
if [[ $exit_status -ne 0 ]]
then
echo "ERROR: Couldn't extract tar"
echo "ERROR: Failed to extract $FILE_PATH" >&2
exit $exit_status
fi
rm "$FILE_PATH"
echo 'Finished installing!'

rm $FILE_PATH

echo "Finished installing!"
exit 0