-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnvm-node-update-check
executable file
·62 lines (50 loc) · 1.79 KB
/
nvm-node-update-check
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
#!/usr/bin/env bash
# Bash strict mode.
#set -eEo pipefail
# Returns 0 if you have the latest version of node, 1 if you don't,
# and 2 if you somehow have a later version of node than the latest.
# The "--lts" option may be passed in to just check long term service versions.
nvmNodeUpdateCheck() {
declare latestVersionRemote latestVersionLocal option
if [ "$#" -gt 1 ]; then
echo "Invalid number of arguments."
fi
option=""
if [[ "$1" != "--lts" ]] && [[ "$1" != "" ]]; then
echo "Option not recognized. Ignoring..."
option=""
else
option="$1"
fi
# One liner for getting the location of where this script is.
workingDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Import stuffs.
# shellcheck disable=SC1090
source "$workingDir/version-compare"
# If NVM exists, source it.
# Else exit.
# True if the file exists and has a size greater than zero.
if [[ -s "$HOME/.nvm/nvm.sh" ]]; then
# shellcheck disable=SC1090
. "$HOME/.nvm/nvm.sh"
else
echo "NVM doesn't exist on your system... :/"
exit 1
fi
latestVersionRemote=$(nvm version-remote "$option")
echo "The latest remote Node version is: '$latestVersionRemote'"
latestVersionLocal=$(nvm version "$option")
echo "The latest local Node version is: '$latestVersionLocal'"
versionCompare "$latestVersionRemote" "$latestVersionLocal"
comparison="$?"
if [[ "$comparison" == 0 ]]; then
# The latest version of Node is installed.
return "$comparison"
elif [[ "$comparison" == 1 ]]; then
# Don't have the latest version installed.
return "$comparison"
else
# Somehow a later version than the latest is installed...
return "$comparison"
fi
}