forked from CloudWise-OpenSource/FlyFish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flyfish.sh
330 lines (262 loc) · 7.4 KB
/
flyfish.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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
#!/usr/bin/env bash
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
THIS_SCRIPT="${CURRENT_DIR}/$(basename $0)"
PROJECT_FOLDER="$(dirname ${CURRENT_DIR})"
function check_user() {
user=root
if [ $(whoami) != "${user}" ]; then
echo "You must use *** ${user} *** to execute this script!"
exit 1
fi
}
get_local_ip() {
ips=$(ip a | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | grep -v "127.0.0.1")
k=0
echo "通过命令获取本机ip如下:"
for ip in $ips; do
ip_list[k]=$ip
echo "若选择ip: $ip 请输入id: $k"
((k++))
done
echo ""
read -p "请选择本机ip对应的id,如果ip不在上述输出中请输入N > " index
if [[ $index == "N" ]] || [[ $index == "n" ]]; then
read -p "请输入本机ip:" local_ip
local_ip_grep=$(echo "$local_ip" | grep -oP "([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})")
if [ "$local_ip_grep" != "$local_ip" ]; then
echo "ip: $local_ip 格式不正确!"
exit 1
fi
elif [ -z "$(echo $index | sed -n "/^[0-9]\+$/p")" ]; then
echo "输入的id: $index 非法,请重新执行命令选择!"
exit 1
else
local_ip=${ip_list[$index]}
if [ ! -n "$local_ip" ]; then
echo "选择的ip不存在!"
exit 1
fi
fi
}
function init_system() {
echo "开始准备环境:git node.js nvm pm2 mongodb nginx"
echo "start install git"
yum install git -y
yum install at-spi2-atk libxkbcommon nss -y
# echo "start install node.js"
# mkdir -p /usr/local/node/
# cd /usr/local/node/
# wget -c https://nodejs.org/dist/v14.9.0/node-v14.9.0-linux-x64.tar.xz
# tar -xvf node-v14.9.0-linux-x64.tar.xz
# rm -rf node-v14.9.0-linux-x64.tar.xz
# echo "export NODE_HOME=/usr/local/node/node-v14.9.0-linux-x64" >>/etc/profile
# echo 'export PATH=$NODE_HOME/bin:$PATH' >>/etc/profile
# source /etc/profile
# npm config set registry=https://registry.npmmirror.com
# echo "node版本:" $(node -v)
echo "start install nvm"
cd ~
git clone https://gitee.com/mirrors/nvm
$(source nvm/nvm.sh)
echo "source ~/nvm/nvm.sh" >>~/.bashrc
source ~/.bashrc
NVM_NODEJS_ORG_MIRROR=https://npmmirror.com/mirrors/node
nvm install v14.19.3
nvm alias default v14.19.3
echo "start install pm2"
npm install -g [email protected]
echo "start install mongodb"
mongodb_repo=/etc/yum.repos.d/mongodb-org-4.0.repo
touch $mongodb_repo
echo "[mongodb-org]" >$mongodb_repo
echo "name=MongoDB Repository" >>$mongodb_repo
echo "baseurl=http://mirrors.aliyun.com/mongodb/yum/redhat/7Server/mongodb-org/4.0/x86_64/" >>$mongodb_repo
echo "gpgcheck=0" >>$mongodb_repo
echo "enabled=1" >>$mongodb_repo
yum -y install mongodb-org
systemctl start mongod.service
mongodb_conf=/etc/mongod.conf
sed -i "s/127.0.0.1/0.0.0.0/g" /etc/mongod.conf
systemctl restart mongod.service
systemctl status mongod.service
echo "start install nginx"
nginx_repo=/etc/yum.repos.d/nginx.repo
touch $nginx_repo
echo "[nginx]" >$nginx_repo
echo "name=nginx repo" >>$nginx_repo
echo 'baseurl=http://nginx.org/packages/centos/7/$basearch/' >>$nginx_repo
echo "gpgcheck=0" >>$nginx_repo
echo "enabled=1" >>$nginx_repo
yum install -y nginx-1.20.1
systemctl enable nginx
systemctl start nginx
echo "初始化环境结束。"
}
deploy_flyfish_web() {
echo "开始部署FLyFish前端:"
cd /data/app/FlyFish/lcapWeb
npm install
npm run build
sed -i "s/127.0.0.1/$local_ip/g" ./dist/conf/env-config.js
# 提示缺少 conf.d
cd /
tempPath="/etc/nginx/conf.d"
if [ ! -d "$tempPath" ]; then
mkdir $tempPath
fi
cd /data/app/FlyFish/lcapWeb
cp FlyFish-2.1.0.conf /etc/nginx/conf.d/FlyFish-2.1.0.conf
sed -i "s/IP/$local_ip/g" /etc/nginx/conf.d/FlyFish-2.1.0.conf
systemctl restart nginx
echo "部署前端结束。"
}
deploy_flyfish_server() {
echo "开始部署FlyFish后端:"
cd /data/app/FlyFish/lcapServer/changelog
npm install
cd /data/app/FlyFish/lcapServer/
npm install --unsafe-perm=true
echo "开始初始化数据库:"
npm run init-development-database
echo "初始化数据库结束。"
npm run development
echo "初始化组件开发环境:"
cd /data/app/FlyFish/lcapWww/components
npm install
echo "初始化大屏开发环境:"
sed -i "s/IP/$local_ip/g" /data/app/FlyFish/lcapWww/web/screen/config/env.js
echo "部署后端结束。"
}
deploy_flyfish_code_server() {
echo "开始部署FlyFish Code Server:"
cd /data/app/FlyFish/lcapCodeServer/
npm run linux-start
echo "部署FlyFish Code Server结束。"
}
function echo_flyfish_info() {
echo " "
echo "=========FlyFish访问信息================"
echo "平台访问地址:http://$local_ip:8089"
echo "平台默认用户:admin"
echo "平台默认密码:utq#SpV!"
echo "======================================="
echo " "
}
function install_flyfish() {
get_local_ip
init_system
deploy_flyfish_web
deploy_flyfish_server
deploy_flyfish_code_server
echo_flyfish_info
}
stop_flyfish() {
echo "停止运行FlyFish前端:"
systemctl stop nginx
cd ~
source nvm/nvm.sh
echo "停止运行FlyFish后端:"
cd /data/app/FlyFish/lcapServer/
npm run stop
echo "停止运行Code Server:"
cd /data/app/FlyFish/lcapCodeServer/
npm run stop
}
remove_system() {
echo "开始移除基础环境:nginx mongodb pm2 node.js nvm"
echo "start uninstall nginx"
# systemctl stop nginx
# chkconfig nginx off
systemctl disable nginx.service
yum remove nginx -y
rm -rf /usr/sbin/nginx
rm -rf /etc/nginx
rm -rf /etc/init.d/nginx
rm -rf /etc/yum.repos.d/nginx.repo
echo "start uninstall mongodb"
systemctl stop mongod.service
yum erase $(rpm -qa | grep mongodb-org) -y
rm -r /var/log/mongodb
rm -r /var/lib/mongo
rm -rf /etc/yum.repos.d/mongodb-org-4.0.repo
echo "start uninstall node.js && nvm"
npm uninstall -g pm2
rm -rf /usr/local/node/
sed -i '/NODE_HOME/d' /etc/profile
cd ~
rm -rf nvm
sed -i '/nvm/d' ~/.bashrc
echo "基础环境移除完毕。"
}
remove_flyfish() {
echo "开始删除FlyFish源码:"
cd /
rm -rf /data/app/FlyFish
}
function uninstall_flyfish() {
read -p "是否卸载FlyFish?是(Y),否(N)" value
if [[ $value == "Y" ]] || [[ $value == "y" ]]; then
stop_flyfish
remove_system
remove_flyfish
echo "卸载成功!"
exit 1
elif [[ $value == "N" ]] || [[ $value == "n" ]]; then
echo "取消卸载!"
exit 1
else
echo "请输入Y或者N"
exit 1
fi
}
get_source_code() {
echo "获取FlyFish最新代码"
git checkout main
git pull origin main
}
reinstall_flyfish() {
systemctl start nginx
deploy_flyfish_web
echo "开始部署FLyFish后端:"
cd /data/app/FlyFish/lcapServer/
npm install
npm run development
echo "部署后端结束。"
deploy_flyfish_code_server
}
function update_flyfish() {
read -p "是否更新FlyFish?是(Y),否(N)" value
if [[ $value == "Y" ]] || [[ $value == "y" ]]; then
get_local_ip
stop_flyfish
reinstall_flyfish
echo_flyfish_info
echo "更新成功!"
exit 1
elif [[ $value == "N" ]] || [[ $value == "n" ]]; then
echo "取消更新!"
exit 1
else
echo "请输入Y或者N"
exit 1
fi
}
check_user
if [[ $# -eq 0 ]]; then
echo "bash flyfish.sh [ install | uninstall | update ]"
else
case $1 in
install)
shift
install_flyfish
;;
uninstall)
shift
uninstall_flyfish
;;
update)
shift
update_flyfish
;;
esac
fi