-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_latest_node.sh
executable file
·80 lines (68 loc) · 2.01 KB
/
install_latest_node.sh
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
RED="\033[31m" # Error message
GREEN="\033[32m" # Success message
YELLOW="\033[33m" # Warning message
BLUE="\033[36m" # Info message
PLAIN='\033[0m'
colorEcho() {
echo -e "${1}${@:2}${PLAIN}"
}
updateCommands() {
NPM_CMD="$(command -v npm)"
YARN_CMD="$(command -v yarn)"
NVM_CMD="$(command -v nvm)"
NODE_CMD="$(command -v node)"
}
echoCommands() {
echo
echo
echo
colorEcho $BLUE "########################################################################"
#colorEcho $BLUE "nvm:" "$(nvm --version)"
colorEcho $BLUE "node:" "$($NODE_CMD --version)"
colorEcho $BLUE "npm:" "$($NPM_CMD --version)"
colorEcho $BLUE "yarn:" "$($YARN_CMD --version)"
colorEcho $BLUE "########################################################################"
echo
echo
echo
}
installNvm() {
if [[ -z "$NVM_CMD" ]]; then
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
colorEcho $GREEN "You didn't have node package manager, so i installed nvm!"
updateCommands
fi
}
installNpm() {
if [[ -z "$NVM_CMD" ]]; then
installNvm
fi
$NVM_CMD install --lts
$NVM_CMD use --lts
colorEcho $GREEN "You didn't have nodejs on your system, so i installed it for you!"
updateCommands
}
installYarn() {
$NPM_CMD install -g yarn
colorEcho $GREEN "You didn't have yarn installed on your system, so i intalled it for you!"
updateCommands
}
install() {
if [[ -z "$NPM_CMD" ]]; then
installNpm
installYarn
elif [[ -z "$YARN_CMD" ]]; then
installYarn
fi
if [[ "$($NODE_CMD --version)" != "v18.12.1" ]]; then
installNpm
installYarn
fi
echoCommands
colorEcho $GREEN "Your node package manager is up to date!"
}
updateCommands
install