-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
install.sh
executable file
·252 lines (213 loc) · 6.09 KB
/
install.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#!/bin/bash
loading_animation() {
local -r chars="⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏"
local -r delay=0.1
local char
i=0
while true; do
i=$((i + 1))
char="${chars:i%10:1}"
printf "\r[$char]"
sleep $delay
done
printf "\r%*s\r" "${COLUMNS:-$(tput cols)}" ""
}
finish() {
if [ -n "$loading_animation_pid" ]; then
kill "$loading_animation_pid"
fi
}
check_os_type() {
if [ "x$(id -u)" != x0 ]; then
echo "You might have to run it as root user."
echo "Please run it again with 'sudo'."
echo
exit 1
fi
OPT="${@}"
echo -n " Checking OS..."
loading_animation &
loading_animation_pid=$!
source /etc/os-release
if [ ! -f /etc/os-release ]; then
printf "\r%*s\r" "${COLUMNS:-$(tput cols)}" ""
echo -e "\r[✘] Your distribution is not supported, so please install manually."
echo
exit 1
fi
distro=$(grep "^ID=" /etc/os-release | cut -d\= -f2 | sed -e 's/"//g')
id_like=$(grep "^ID_LIKE=" /etc/os-release | cut -d\= -f2 | sed -e 's/"//g')
case $distro in
"ubuntu" | "debian")
check_os_version $ID $VERSION_ID $PRETTY_NAME
;;
*)
printf "\r%*s\r" "${COLUMNS:-$(tput cols)}" ""
echo -e "\r[✘] \"$PRETTY_NAME\" is not supported yet, so please install manually."
exit 1
;;
esac
finish
}
check_os_version() {
if [[ "$1" == "ubuntu" ]]; then
major_version=${2%%.*}
if [[ "$major_version" -ge 22 ]]; then
echo -e "\r[✔] $3 $2 can use our service!"
else
echo -e "\r[✘] $3 $2 can't install node v18"
fi
elif [[ "$1" == "debian" ]]; then
if [[ "$2" -ge 10 ]]; then
echo -e "\r[✔] $3 can use our service!"
else
echo -e "\r[✘] $3 can't install node v18"
fi
else
echo "This is not an Ubuntu or Debian-based Linux distribution."
fi
}
check_nodejs_installed() {
echo -n " Checking Node.js installation..."
loading_animation &
loading_animation_pid=$!
if ! command -v node &>/dev/null; then
echo -e "\r[✘] Node.js is not installed!"
finish
install_nodejs_confirm
exit 0
else
printf "\r%*s\r" "${COLUMNS:-$(tput cols)}" ""
echo -e "\r[✔] Node.js is already installed!"
finish
fi
}
check_nodejs_version() {
echo -n " Checking Node.js version..."
loading_animation &
loading_animation_pid=$!
node_version=$(node -v)
version_without_v=${node_version#v}
major_version=${version_without_v%%.*}
if [ "$major_version" -ge 18 ]; then
printf "\r%*s\r" "${COLUMNS:-$(tput cols)}" ""
echo -e "\r[✔] Node.js version is $node_version!"
finish
else
printf "\r%*s\r" "${COLUMNS:-$(tput cols)}" ""
echo -e "\r[✘] Node.js version $node_version is not supported (should be 18 or higher)!"
finish
install_nodejs_confirm
exit 0
fi
}
install_nodejs() {
apt-get purge nodejs &&
rm -r /etc/apt/sources.list.d/nodesource.list &&
rm -r /etc/apt/keyrings/nodesource.gpg
curl -SLO https://deb.nodesource.com/nsolid_setup_deb.sh
chmod 500 nsolid_setup_deb.sh
./nsolid_setup_deb.sh $1
apt-get install nodejs -y
echo "-----------------------------------------"
echo
echo "node $(node -v) installed!"
echo "Re-launch install.sh!"
exit 0
}
install_nodejs_confirm() {
options+=("18" "20" "21" "exit")
select version in "${options[@]}"; do
if [[ "$version" == "exit" ]]; then
exit 0
fi
if [[ "$version" ]]; then
install_nodejs $version
break
else
exit 0
fi
done
}
check_yarn_installed() {
echo -n " Checking is yarn installed..."
loading_animation &
loading_animation_pid=$!
if command -v yarn &>/dev/null; then
printf "\r%*s\r" "${COLUMNS:-$(tput cols)}" ""
echo -e "\r[✔] yarn is already installed!"
finish
else
printf "\r%*s\r" "${COLUMNS:-$(tput cols)}" ""
echo -e "\r[✘] yarn isn't installed!"
finish
install_yarn_confirm
fi
}
install_yarn() {
echo -n " installing yarn..."
loading_animation &
loading_animation_pid=$!
npm install --global yarn -y &>/dev/null
finish
printf "\r%*s\r" "${COLUMNS:-$(tput cols)}" ""
echo -e "\r[✔] yarn installed!"
}
install_yarn_confirm() {
while true; do
read -p "If you wanted to install yarn enter \"y\" [y/n] : " yn
case $yn in
[Yy])
install_yarn
break
;;
*)
exit 0
break
;;
esac
done
}
git_submodule_init() {
echo -n " initializing submodules..."
loading_animation &
loading_animation_pid=$!
git submodule update --init --recursive &>/dev/null
finish
printf "\r%*s\r" "${COLUMNS:-$(tput cols)}" ""
echo -e "\r[✔] submodules initialized!"
}
dependency_install() {
echo -n " installing client dependencies..."
loading_animation &
loading_animation_pid=$!
cd ./client
yarn install &>/dev/null
finish
printf "\r%*s\r" "${COLUMNS:-$(tput cols)}" ""
echo -e "\r[✔] client's dependencies installed!"
echo -n " installing server dependencies..."
loading_animation &
loading_animation_pid=$!
cd ../server
yarn install &>/dev/null
finish
printf "\r%*s\r" "${COLUMNS:-$(tput cols)}" ""
echo -e "\r[✔] server's dependencies installed!"
}
check_os_type
chmod 600 env.sh
check_nodejs_installed
check_nodejs_version
check_yarn_installed
git_submodule_init
dependency_install
echo
echo "--------------------------------------------------------------------"
echo "All installation is successfully completed!"
echo "Excute ./env.sh to make your own environment variable!"
echo "Then, you can excute Open-Set-Go's client & server with \"yarn start\""
echo "--------------------------------------------------------------------"
echo
echo "Done."
exit 0