-
Notifications
You must be signed in to change notification settings - Fork 60
/
install.sh
192 lines (173 loc) · 4.18 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
#!/bin/bash
red='\e[91m'
green='\e[92m'
yellow='\e[93m'
magenta='\e[95m'
cyan='\e[96m'
none='\e[0m'
[[ $(id -u) != 0 ]] && echo -e " \n哎呀……请使用 ${red}root ${none}用户运行 ${yellow}~(^_^) ${none}\n" && exit 1
cmd="apt-get"
sys_bit=$(uname -m)
# 笨笨的检测方法
if [[ -f /usr/bin/apt-get || -f /usr/bin/yum ]] && [[ -f /bin/systemctl ]]; then
if [[ -f /usr/bin/yum ]]; then
cmd="yum"
fi
else
echo -e " \n哈哈……这个 ${red}辣鸡脚本${none} 不支持你的系统。 ${yellow}(-_-) ${none}\n" && exit 1
fi
if [[ $sys_bit == "i386" || $sys_bit == "i686" ]]; then
brook="brook_linux_386"
elif [[ $sys_bit == "x86_64" ]]; then
brook="brook"
else
echo -e " \n哈哈……这个 ${red}辣鸡脚本${none} 不支持你的系统。 ${yellow}(-_-) ${none}\n" && exit 1
fi
config() {
echo
_random=$RANDOM
while :; do
echo -e "请输入 Brook 端口 ["$magenta"1-65535"$none"]"
read -p "$(echo -e "(默认端口: ${cyan}$_random$none):")" port
[ -z "$port" ] && port=$_random
case $port in
[1-9] | [1-9][0-9] | [1-9][0-9][0-9] | [1-9][0-9][0-9][0-9] | [1-5][0-9][0-9][0-9][0-9] | 6[0-4][0-9][0-9][0-9] | 65[0-4][0-9][0-9] | 655[0-3][0-5])
echo
echo
echo -e "$yellow Brook 端口 = $cyan$port$none"
echo "----------------------------------------------------------------"
echo
break
;;
*)
error
;;
esac
done
echo
while :; do
echo -e "请输入 Brook 密码"
read -p "$(echo -e "(默认密码: ${cyan}233blog.com$none):")" pass
[ -z "$pass" ] && pass="233blog.com"
case $pass in
*)
echo
echo
echo -e "$yellow Brook 密码 = $cyan$pass$none"
echo "----------------------------------------------------------------"
echo
break
;;
esac
done
echo
pause
}
_download() {
[[ ! $(command -v wget) ]] && $cmd install wget -y
ver=$(curl -s https://api.github.com/repos/txthinking/brook/releases/latest | grep 'tag_name' | cut -d\" -f4)
_link="https://github.com/txthinking/Brook/releases/download/$ver/$brook"
if ! wget --no-check-certificate --no-cache -O "/usr/bin/brook" $_link; then
echo -e "$red 下载 Brook 失败!$none" && exit 1
fi
if [[ -f /usr/bin/brook ]]; then
chmod +x /usr/bin/brook
cat >/lib/systemd/system/brook.service <<-EOF
[Unit]
Description=brook Service
After=network.target
Wants=network.target
[Service]
Type=simple
PIDFile=/var/run/brook.pid
ExecStart=/usr/bin/brook server -l :$port -p $pass
Restart=always
[Install]
WantedBy=multi-user.target
EOF
systemctl enable brook
systemctl start brook
else
echo -e "\n$red 安装出错啦...$none\n" && exit 1
fi
}
info() {
get_ip
clear
echo
echo "........... Brook 安装成功啦 .........."
echo
echo -e " 服务器地址: ${cyan}$ip$none"
echo
echo -e " 端口: ${cyan}$port$none"
echo
echo -e " 密码: ${cyan}$pass$none"
echo
}
install() {
config
try_enable_bbr
_download
info
}
uninstall() {
if [[ -f /usr/bin/brook ]]; then
brook_pid=$(pgrep "brook")
[[ $brook_pid ]] && systemctl stop brook
systemctl disable brook >/dev/null 2>&1
rm -rf /usr/bin/brook
rm -rf /lib/systemd/system/brook.service
echo -e " \n$green卸载完成...$none\n" && exit 1
else
echo -e " \n$red大胸弟...你貌似毛有安装 brook ....卸载个鸡鸡哦...$none\n" && exit 1
fi
}
try_enable_bbr() {
if [[ $(uname -r | cut -b 1) -eq 4 ]]; then
case $(uname -r | cut -b 3-4) in
9. | [1-9][0-9])
sed -i '/net.ipv4.tcp_congestion_control/d' /etc/sysctl.conf
sed -i '/net.core.default_qdisc/d' /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control = bbr" >>/etc/sysctl.conf
echo "net.core.default_qdisc = fq" >>/etc/sysctl.conf
sysctl -p >/dev/null 2>&1
;;
esac
fi
}
get_ip() {
ip=$(curl -s ipinfo.io/ip)
}
pause() {
read -rsp "$(echo -e "按$green Enter 回车键 $none继续....或按$red Ctrl + C $none取消.")" -d $'\n'
echo
}
error() {
echo -e "\n$red 输入错误!$none\n"
}
clear
while :; do
echo
echo "........... Brook 一键安装脚本 by 233blog.com .........."
echo
echo "帮助说明: https://233blog.com/post/35/"
echo
echo " 1. 安装"
echo
echo " 2. 卸载"
echo
read -p "请选择 [1-2]:" choose
case $choose in
1)
install
break
;;
2)
uninstall
break
;;
*)
error
;;
esac
done