Last active
November 23, 2016 15:53
-
-
Save iSkore/0e069c4bb172de468513a098a9699560 to your computer and use it in GitHub Desktop.
A relatively useless (to some) platform Node.JS updater. Being in shell - which isn't native to Windows (sorta) - this script attempts to be your Node.JS Updater. Works great for OSX and LINUX.
This file contains 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 | |
######### | |
# | |
# Once downloaded, run: `chmod 775 nodeupdate` and double click | |
# | |
######### | |
platform='unknown' | |
case "$OSTYPE" in | |
darwin*) platform="OSX" ;; | |
linux*) platform="LINUX" ;; | |
bsd*) platform="BSD" ;; | |
msys*) platform="WINDOWS" ;; | |
*) platform="unknown: $OSTYPE" ;; | |
esac | |
echo "Update starting for $platform" | |
process_exit() | |
{ | |
echo "Exiting: ${*}" | |
exit | |
} | |
process_install() | |
{ | |
echo "Performing installation with arguments [${*}]..." | |
if [[ "$1" = "OSX" ]]; then | |
curl "https://nodejs.org/dist/latest/node-$LATEST.pkg" > "$HOME/Downloads/node-latest.pkg" && sudo installer -store -pkg "$HOME/Downloads/node-latest.pkg" -target "/" | |
elif [[ "$1" == "LINUX" ]]; then | |
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash - | |
sudo apt-get install -y nodejs | |
elif [[ "$1" == "BSD" ]]; then | |
/usr/ports/www/node #? | |
pkg install node | |
elif [[ "$1" == "WINDOWS" ]]; then | |
cinst nodejs.install # sorry windows gota have cinst | |
scoop install nodejs # or scoop | |
fi | |
} | |
LOCAL=$(node -v) | |
LATEST=$(wget -qO- https://nodejs.org/dist/latest/ | sed -nE 's|.*>node-(.*)\.pkg</a>.*|\1|p') | |
echo "Latest: $LATEST" | |
echo "Local: $LOCAL" | |
if [ "$LATEST" = "$LOCAL" ] | |
then | |
process_exit "Node.JS is up to date with Version: $LOCAL" | |
else | |
echo "Updating Node.JS to Version: $LATEST" | |
process_install $platform | |
process_exit "Node.JS is up to date with Version: $LATEST" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment