-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathntest.sh
executable file
·135 lines (114 loc) · 3.81 KB
/
ntest.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
# check if the users system is windows, as N is not supported
if [[ "$OSTYPE" == 'msys' ]] || [[ "$OSTYPE" == 'cygwin' ]]; then
echo "n is not supported on Windows systems"
else
# check if we want to fix broken permissions
if [ ! -w "/usr/local/n/versions" ]; then
echo "/usr/local/n/versions is not writable"
read -p "would you like to fix permissions? (y/n) " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
printf '\n'
sudo chown -R `whoami` /usr/local/n/versions
sudo chmod u+w /usr/local/n/versions
else
echo -e '\nYou will have to use sudo every time you run n\n'
fi
fi
install() {
if [ ! -w "/usr/local/n/versions" ]; then
sudo n $@
else
n $@
fi
}
# check for n current versions
# change path depending on custom path set or not
if [ -z ${N_PREFIX+x} ]; then
vers=`find /usr/local/n/versions/node -type d | sed 's|'/usr/local/n/versions'/||g' | egrep "/[0-9]+\.[0-9]+\.[0-9]+$" | sort -k 1,1 -k 2,2n -k 3,3n -t . | awk -F/ '{print $2}'`
else
vers=`find $N_PREFIX/n/versions/node -type d | sed 's|'/usr/local/n/versions'/||g' | egrep "/[0-9]+\.[0-9]+\.[0-9]+$" | sort -k 1,1 -k 2,2n -k 3,3n -t . | awk -F/ '{print $2}'`
fi
echo "-Checking installed Node.js Versions-"
# print to screen current installed versions
echo -e "Installed versions:"
if [ -z ${vers+x} ]; then
echo "$vers"
else
echo "No versions are installed through n..."
vers=`node -v | cut -d v -f2`
echo "node -v : $vers"
fi
printf '\n'
# variables check for versions available through n
latest=`n --latest`
stable=`n --stable`
lts=`n --lts`
echo "-Checking available node.js versions-"
echo "Latest is: $latest"
echo "Stable is: $stable"
echo "LTS is: $lts"
printf '\n'
sleep 2
# ask if user wants n latest or n stable
# since vers is stored in a variables of all versions installed,
# check from highest version to lowest
case $vers in
*$latest*)
echo "You are currently on Latest version" ;;
*$stable*)
echo "You are currently on Stable version"
printf '\n'
echo "-Which node.js version would you like to install?-"
read -p "( Latest [L], LTS [T] ) " -n 1 -r
printf '\n'
if [[ $REPLY =~ ^[Ll]$ ]]; then
install latest
elif [[ $REPLY =~ ^[Tt]$ ]]; then
install lts
elif [[ ! $REPLY =~ ^[LlTt]$ ]]; then
echo "Skipping node.js update through n"
fi
;;
*$lts*)
echo "You are currently on LTS version"
printf '\n'
echo "-Which node.js version would you like to install?-"
read -p "( Latest [L], Stable [S] ) " -n 1 -r
printf '\n'
if [[ $REPLY =~ ^[Ll]$ ]]; then
install latest
elif [[ $REPLY =~ ^[Ss]$ ]]; then
install stable
elif [[ ! $REPLY =~ ^[LlSs]$ ]]; then
echo "Skipping node.js update through n"
fi
;;
*)
if (( $(echo "$vers $latest" | awk '{print ($1 > $2)}') )); then
echo "How in the hell do you have this version?"
else
echo "You are currently on an outdated version"
fi
printf '\n'
echo "-Which node.js version would you like to install?-"
read -p "( Latest [L], Stable [S], LTS [T] ) " -n 1 -r
printf '\n'
if [[ $REPLY =~ ^[Ll]$ ]]; then
echo "installing Latest"
install latest
elif [[ $REPLY =~ ^[Ss]$ ]]; then
echo "Install Stable"
install stable
elif [[ $REPLY =~ ^[Tt]$ ]]; then
echo "Install LTS"
install lts
elif [[ ! $REPLY =~ ^[LlSsTt]$ ]]; then
echo "Skipping node.js update through n"
fi
;;
esac # end version compare and update check
fi # end windows check
# set a windows only option?
# scoop and chocolatey install node
# need a check for chocolatey and scoop