Alter 3 files

Update `README.md`
Delete `node.md`
Add `node.sh`
This commit is contained in:
akp 2022-08-07 12:08:42 +01:00
parent 1e8aa09bb6
commit 339153bfab
No known key found for this signature in database
GPG key ID: AA5726202C8879B7
3 changed files with 60 additions and 8 deletions

View file

@ -57,7 +57,7 @@ Markdown docs and shell scripts for automating installation of things and docume
* [`gophernotes.sh`](gophernotes.sh) for the the GopherNotes Juypter kernel
* [`jetbrainsToolbox.md`](jetbrainsToolbox.md) for installing the JetBrains Toolbox tool
* [`nim.md`](nim.md) for installing the Nim programming language
* [`node.md`](node.md) for installing Node.JS
* [`node.sh`](node.sh) for installing Node.JS
* [`ohmyposh.sh`](ohmyposh.sh) for installing the Oh My Posh command line prompt
* [`poetry.sh`](poetry.sh) for installing Python Poetry
* [`profobuf.md`](protobuf.md) for installing the various things related to Protocol Buffers

View file

@ -1,7 +0,0 @@
# Node JS
2021-05-04
1. Download from https://nodejs.org/en/download/current/
2. Extract to `/opt/node-vx.x.x-linux-x64`
3. Add `/opt/node-vx.x.x-linux-x64/bin` to PATH (in `~/.bashrc`

59
node.sh Executable file
View file

@ -0,0 +1,59 @@
#!/bin/bash
# - Assumes your Go installation goes in /opt/node
# - Assumes you're using Bash
# - Assumes you want the Linux amd64 build
function getStatusCode() {
set +e
bash -c "$1" > /dev/null 2>&1
echo $?
set -e
}
if [ "$1" == "" ]; then
echo "Usage: $0 [VERSION]"
echo "Please specify a version."
exit 1
fi
TEMP_DIR=$(mktemp --directory)
set -ex
VERSION=$1
INSTALL_DIR="/opt/node"
# eg: https://nodejs.org/dist/v16.16.0/node-v16.16.0-linux-x64.tar.xz
FILENAME="node-v$VERSION-linux-x64.tar.xz"
DL_URL="https://nodejs.org/dist/v$VERSION/$FILENAME"
FILENAME="$TEMP_DIR/$FILENAME"
BASH_PROFILE="$HOME/.bashrc"
# Remove old installation temp dirs
if [ -e "$TEMP_DIR" ]; then
rm -rf $TEMP_DIR
fi
mkdir -p $TEMP_DIR
wget --output-document=$FILENAME $DL_URL
tar -C $TEMP_DIR -xf $FILENAME
# In the instance we're not installing fresh...
if [ -e $INSTALL_DIR ]; then
sudo rm -r $INSTALL_DIR
fi
sudo mv $TEMP_DIR/node-v16.16.0-linux-x64 $INSTALL_DIR
# Check Bash profile to see if we've got env vars set yet
if [ $(getStatusCode "cat $BASH_PROFILE | grep /opt/node/bin") != "0" ]; then
echo "Adding Node binaries to PATH"
echo 'export PATH=$PATH:"/opt/node/bin"' >> $BASH_PROFILE
fi
# Tidy up
rm -r $TEMP_DIR