-
Notifications
You must be signed in to change notification settings - Fork 3
/
install.sh
190 lines (185 loc) · 8.4 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
#! /bin/bash
###
# @Author: coderzhaolu && izhaicy@163.com
# @Date: 2022-08-27 18:40:50
# @LastEditors: coderzhaolu && izhaicy@163.com
# @LastEditTime: 2022-11-17 12:14:58
# @FilePath: /pinkmoe_admin/Users/zhaolu/Desktop/project/go_vue_gin/pinkmoe/install.sh
# @Description: https://github.com/Coder-ZhaoLu/pinkmoe (如需用于商业用途或者二开,请联系作者捐助任意金额即可)
# QQ:2419857357;支付宝:13135986153
# Copyright (c) 2022 by coderzhaolu, All Rights Reserved.
###
#!/bin/bash
#file:docker_install.sh
function docker_install()
{
echo -e "\033[32m 检查Docker......\033[0m"
docker -v
if [ $? -eq 0 ]; then
echo -e "\033[32m 检查到Docker已安装!\033[0m"
else
echo -e "\033[32m 安装docker环境...\033[0m"
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun && systemctl enable docker && systemctl start docker && curl -L "https://github.com/docker/compose/releases/download/v2.7.0/docker-compose-$(uname -s)-$(uname -m)" > /usr/bin/docker-compose && chmod +x /usr/bin/docker-compose
echo -e "\033[32m 安装docker环境...安装完成!\033[0m"
fi
# 创建公用网络==bridge模式
#docker network create share_network
}
function write_conf()
{
ip=$(curl ifconfig.me)
export DOCKER_GATEWAY_HOST=$ip
cp ./pinkmoe_server/config.yaml.example ./pinkmoe_server/config.yaml
echo -e "\033[34m 请输入网站mysql密码(直接回车默认为pinkmoe_mysql_pwd):\033[0m"
read passwordMysql
if [ -z $passwordMysql ]
then
passwordMysql="pinkmoe_mysql_pwd"
fi
echo $passwordMysql
sed -i "s/pinkmoe_mysql_pwd/$passwordMysql/g" ./docker-compose.yaml
sed -i "s/pinkmoe_mysql_pwd/$passwordMysql/g" ./pinkmoe_server/config.yaml
echo -e "\033[34m 请输入网站前台域名(多个域名用英文空格隔开,如:pinkmoe.com www.pinkmoe.com;直接回车默认为pinkmoe.com www.pinkmoe.com):\033[0m"
sed -i "s/ListenAndServe()/ListenAndServeTLS(\".\/ssl\/pinkmoe.crt\", \".\/ssl\/pinkmoe.key\")/g" ./pinkmoe_server/initialize/server.go
read headDomain
if [ -z $headDomain ]
then
headDomain="pinkmoe.com www.pinkmoe.com"
fi
echo $headDomain
sed -i "s/pinkmoe.com www.pinkmoe.com/$headDomain/g" ./pinkmoe_index/nginx/pinkmoe_ssl.conf
sed -i "s/pinkmoe.com www.pinkmoe.com/$headDomain/g" ./pinkmoe_index/nginx/pinkmoe.conf
echo -e "\033[34m 请输入网站主域名(如:pinkmoe.com;直接回车默认为pinkmoe.com):\033[0m"
read mainDomain
if [ -z $mainDomain ]
then
mainDomain="pinkmoe.com"
fi
echo $mainDomain
sed -i "s/pinkmoe.com/$mainDomain/g" ./pinkmoe_server/config.yaml
echo "export const BASEURL = 'https://${mainDomain}:9527/api/v1'" > ./pinkmoe_index/constant.ts
echo -e "\033[34m 请输入网站后台域名(多个域名用英文空格隔开,如:admin.pinkmoe.com;直接回车默认为admin.pinkmoe.com):\033[0m"
read backgroundDomain
if [ -z $backgroundDomain ]
then
backgroundDomain="admin.pinkmoe.com"
fi
echo $backgroundDomain
sed -i "s/admin.pinkmoe.com/$backgroundDomain/g" ./pinkmoe_server/config.yaml
sed -i "s/admin.pinkmoe.com/$backgroundDomain/g" ./pinkmoe_admin/nginx/admin_pinkmoe_ssl.conf
sed -i "s/admin.pinkmoe.com/$backgroundDomain/g" ./pinkmoe_admin/nginx/admin_pinkmoe.conf
}
function write_ssl()
{
read -d$ -p "请输入前台ssl域名的key文件字符串(直接文本打开key文件后复制到这里),输入$符号退出以完成输入:" pinkmoeKey
echo "$pinkmoeKey"
echo "$pinkmoeKey" > ./pinkmoe_index/nginx/ssl/pinkmoe.key
echo "$pinkmoeKey" > ./pinkmoe_server/ssl/pinkmoe.key
read -d$ -p "请输入前台ssl域名的crt文件字符串(直接文本打开crt文件后复制到这里),输入$符号退出以完成输入:" pinkmoeCrt
echo "$pinkmoeCrt"
echo "$pinkmoeCrt" > ./pinkmoe_index/nginx/ssl/pinkmoe.crt
echo "$pinkmoeCrt" > ./pinkmoe_server/ssl/pinkmoe.crt
read -d$ -p "请输入后台ssl域名的key文件字符串(直接文本打开key文件后复制到这里),输入$符号退出以完成输入:" dminPinkmoeKey
echo "$dminPinkmoeKey"
echo "$dminPinkmoeKey" > ./pinkmoe_admin/nginx/ssl/admin.pinkmoe.key
read -d$ -p "请输入后台ssl域名的crt文件字符串(直接文本打开crt文件后复制到这里),输入$符号退出以完成输入:" adminPinkmoeCrt
echo "$adminPinkmoeCrt"
echo "$adminPinkmoeCrt" > ./pinkmoe_admin/nginx/ssl/admin.pinkmoe.crt
}
function install()
{
echo -e "\033[32m 开始更新本机软件包:\033[0m"
cd /
sudo yum update -y
docker_install
echo -e "\033[32m 开始下载pinkmoe软件包:\033[0m"
yum install git -y && git clone https://github.com/Coder-ZhaoLu/pinkmoe && cd pinkmoe/
# 配置网站信息
echo -e "\033[32m 开始配置网站基本信息:\033[0m"
write_conf
# 配置ssl文件
write_ssl
}
echo -e "\033[32m #########################################################################\033[0m"
echo -e "\033[32m ## 欢迎使用PinkMoe程序 ##\033[0m"
echo -e "\033[32m ## ##\033[0m"
echo -e "\033[32m ## 1. 开始安装程序 ##\033[0m"
echo -e "\033[32m ## 2. 增加swap内存(低于2g内存建议执行) ##\033[0m"
echo -e "\033[32m ## 3. 重启后台(适用于修改后台设置后) ##\033[0m"
echo -e "\033[32m ## 4. 重新安装(适用于安装失败后) ##\033[0m"
echo -e "\033[32m ## 5. 卸载程序(适用于完整安装后卸载) ##\033[0m"
echo -e "\033[32m ## 6. 清除docker残余镜像 ##\033[0m"
echo -e "\033[32m ## 7. 退出命令 ##\033[0m"
echo -e "\033[32m ## ##\033[0m"
echo -e "\033[32m #########################################################################\033[0m"
while true
do
read -p "请输入安装序号:" num
if [ $num == "1" ]
then
install
# 开始安装
echo -e "\033[32m 启动docker开始部署服务...\033[0m"
docker-compose up -d
if [ $? -eq 0 ]; then
echo -e "\033[32m 恭喜你安装成功!!!\033[0m"
else
echo -e "\033[31m 安装失败!\033[0m"
fi
break
elif [ $num == "2" ]
then
# 开始申请swap内存
if [ -f "/var/swap" ];then
swapoff /var/swap && rm -rf /var/swap
fi
read -p "请输入分配内存大小(GB):" swapNum
echo "$swapNum GB"
swapNum=`expr $swapNum \* 1024000`
echo -e "\033[32m 开始申请swap内存...\033[0m"
dd if=/dev/zero of=/var/swap bs=1024 count=$swapNum && mkswap -f /var/swap && swapon /var/swap
if [ $? -eq 0 ]; then
echo -e "\033[32m 恭喜你申请成功!!!\033[0m"
else
echo -e "\033[31m 申请失败!\033[0m"
fi
break
elif [ $num == "3" ]
then
# 开始重启后台
echo -e "\033[32m 开始重启后台...\033[0m"
docker restart pinkmoe_server
if [ $? -eq 0 ]; then
echo -e "\033[32m 恭喜你重启成功!!!\033[0m"
else
echo -e "\033[31m 重启失败!\033[0m"
fi
break
elif [ $num == "4" ]
then
cd / && rm -rf /pinkmoe && docker system prune
install
# 开始安装
echo -e "\033[32m 启动docker开始部署服务...\033[0m"
docker-compose up -d
if [ $? -eq 0 ]; then
echo -e "\033[32m 恭喜你安装成功!!!\033[0m"
else
echo -e "\033[31m 安装失败!\033[0m"
fi
break
elif [ $num == "5" ]
then
cd / && rm -rf /pinkmoe && docker stop pinkmoe_mysql pinkmoe_redis pinkmoe_server pinkmoe_index_admin && docker rm pinkmoe_mysql pinkmoe_redis pinkmoe_server pinkmoe_index_admin && docker rmi pinkmoe_server pinkmoe_index_admin && docker rmi daff57b7d2d1 1319b1eaa0b7 && docker system prune
break
elif [ $num == "6" ]
then
docker system prune
break
elif [ $num == "7" ]
then
break
else
echo -e "\033[31m 请输入正确的序号\033[0m"
fi
done