-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathtool.sh
executable file
·198 lines (194 loc) · 7.19 KB
/
tool.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
#! /bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
cur_dir=$(pwd)
ssr_origin_config=/root/shadowsocksR-Origin.json
ssrr_origin_config=/root/shadowsocksRR-Origin.json
set_text_color(){
COLOR_RED='\E[1;31m'
COLOR_GREEN='\E[1;32m'
COLOR_YELOW='\E[1;33m'
COLOR_BLUE='\E[1;34m'
COLOR_PINK='\E[1;35m'
COLOR_PINKBACK_WHITEFONT='\033[45;37m'
COLOR_GREEN_LIGHTNING='\033[32m \033[05m'
COLOR_END='\E[0m'
}
shell_update(){
echo "+ Check updates for shell..."
echo
version=`cat ss_ssr_ssrr_kcp_bbr.sh |sed -n '/'^version'/p' | cut -d\" -f2`
shell_download_link=`cat ss_ssr_ssrr_kcp_bbr.sh |sed -n '/'^shell_download_link'/p' | cut -d\" -f2`
remote_shell_version=`wget --no-check-certificate -qO- ${shell_download_link} | sed -n '/'^version'/p' | cut -d\" -f2`
echo -e "Shell remote version :${COLOR_GREEN}${remote_shell_version}${COLOR_END}"
echo -e "Shell local version :${COLOR_GREEN}${version}${COLOR_END}"
if [ ! -z ${remote_shell_version} ]; then
if [[ "${version}" != "${remote_shell_version}" ]];then
echo -e "${COLOR_GREEN}Found a new version of shell,please update shell!${COLOR_END}"
else
echo "Local shell is up-to-date!"
fi
fi
echo
}
Dispaly_Selection(){
def_Select=1
echo -e "${COLOR_YELOW}You have 3 options for your ss/ssr/ssrr/kcptun operation.${COLOR_END}"
echo "1: Update All Programe(SS-libev,SSR,SSRR,KCPTUN,Rinetd-BBR)"
echo "2: Switch ShadowsocksR(python) Config"
echo "3: Switch ShadowsocksRR(python) Config"
read -p "Enter your choice (1, 2,3 or exit. default [${def_Select}]): " Select
case "${Select}" in
1)
echo
echo -e "${COLOR_PINK}You will update programe!${COLOR_END}"
echo
;;
2)
echo
echo -e "${COLOR_PINK}You will switch ShadowsocksR(python) config!${COLOR_END}"
echo
;;
3)
echo
echo -e "${COLOR_PINK}You will switch ShadowsocksRR(python) config!${COLOR_END}"
echo
;;
[eE][xX][iI][tT])
echo -e "${COLOR_PINK}You select <Exit>, shell exit now!${COLOR_END}"
exit 1
;;
*)
echo
echo -e "${COLOR_PINK}No input,You will update programe.${COLOR_END}"
Select="${def_Select}"
esac
}
Press_Start(){
echo ""
echo -e "${COLOR_GREEN}Press any key to continue...or Press Ctrl+C to cancel${COLOR_END}"
OLDCONFIG=`stty -g`
stty -icanon -echo min 1 time 0
dd count=1 2>/dev/null
stty ${OLDCONFIG}
}
check_ssr_ssrr_installed(){
ssr_installed_flag=""
ssrr_installed_flag=""
if [ "${Select}" == "2" ]; then
if [[ ! -x /usr/local/shadowsocksR/shadowsocks/server.py ]] || [[ ! -s /usr/local/shadowsocksR/shadowsocks/__init__.py ]]; then
echo -e "${COLOR_RED}Error,ShadowsocksR not installed${COLOR_END}"
exit 1
fi
fi
if [ "${Select}" == "3" ]; then
if [[ ! -x /usr/local/shadowsocksRR/shadowsocks/server.py ]] || [[ ! -s /usr/local/shadowsocksRR/shadowsocks/__init__.py ]]; then
echo -e "${COLOR_RED}Error,ShadowsocksRR not installed${COLOR_END}"
exit 1
fi
fi
}
check_bbr_update(){
echo "+ Check updates for Rinetd-BBR..."
if [ ! -f /etc/rinetd-bbr/bbr.conf ] || [ ! -f /usr/bin/rinetd-bbr ]; then
echo -e "${COLOR_RED}Error,Rinetd-BBR not installed${COLOR_END}"
exit 1
fi
bbr_version=`cat /etc/rinetd-bbr/bbr.conf |sed -n '/'^#bbr_version='/p' | cut -d\" -f2 | sed s/v//g`
remote_bbr_version=$(wget --no-check-certificate -qO- https://api.github.com/repos/linhua55/lkl_study/releases/latest | grep 'tag_name' | cut -d\" -f4 | sed s/v//g )
RINET_BBR_URL="https://github.com/linhua55/lkl_study/releases/download/v${remote_bbr_version}/rinetd_bbr_powered"
echo -e "Rinetd-BBR remote version :${COLOR_GREEN}${remote_bbr_version}${COLOR_END}"
echo -e "Rinetd-BBR local version :${COLOR_GREEN}${bbr_version}${COLOR_END}"
if [ ! -z ${remote_bbr_version} ]; then
if [[ "${bbr_version}" != "${remote_bbr_version}" ]];then
echo -e "${COLOR_GREEN}Found a new version of Rinetd-BBR,update now...${COLOR_END}"
Press_Start
update_bbr
else
echo "Rinetd-BBR local version is up-to-date."
fi
else
echo -e "${COLOR_RED}Error: ${COLOR_END}Get Rinetd-BBR version failed!"
exit 1
fi
}
update_bbr(){
/etc/init.d/bbr stop
echo "starting update Rinetd-BBR..."
if [ -f /etc/rinetd-bbr/bbr.conf ]; then rm -rf /etc/rinetd-bbr/bbr.conf;fi
if [ -f /usr/bin/rinetd-bbr ]; then rm -rf /usr/bin/rinetd-bbr;fi
echo "Download rinetd-bbr from $RINET_BBR_URL"
curl -L "${RINET_BBR_URL}" >/usr/bin/rinetd-bbr
chmod +x /usr/bin/rinetd-bbr
cat <<EOF > /etc/rinetd-bbr/bbr.conf
#bbr_version="${remote_bbr_version}"
# bindadress bindport connectaddress connectport
0.0.0.0 443 0.0.0.0 443
EOF
echo "Rinetd-BBR updated."
/etc/init.d/bbr start
}
update_programe(){
./ss_ssr_ssrr_kcp_bbr.sh update
check_bbr_update
}
switch_ssr_config(){
if [ -f "$ssr_origin_config" ]; then
echo -e "${COLOR_PINK}You will switch config to ${COLOR_END}${COLOR_GREEN}shadowsocksR-Origin.json${COLOR_END}"
echo
mv -f /usr/local/shadowsocksR/shadowsocksR.json shadowsocksR.json > /dev/null
mv -f shadowsocksR-Origin.json /usr/local/shadowsocksR/shadowsocksR.json > /dev/null
/etc/init.d/ssr restart
echo -e "${COLOR_GREEN}currently config:${COLOR_END}"
/etc/init.d/ssr viewconfig
echo
else
echo -e "${COLOR_PINK}You will switch config to ${COLOR_END}${COLOR_GREEN}shadowsocksR.json${COLOR_END}"
echo
mv -f /usr/local/shadowsocksR/shadowsocksR.json shadowsocksR-Origin.json > /dev/null
mv -f shadowsocksR.json /usr/local/shadowsocksR/shadowsocksR.json > /dev/null
/etc/init.d/ssr restart
echo -e "${COLOR_GREEN}currently config:${COLOR_END}"
/etc/init.d/ssr viewconfig
echo
fi
}
switch_ssrr_config(){
if [ -f "$ssrr_origin_config" ]; then
echo -e "${COLOR_PINK}You will switch config to ${COLOR_END}${COLOR_GREEN}shadowsocksRR-Origin.json${COLOR_END}"
echo
mv -f /usr/local/shadowsocksRR/user-config.json shadowsocksRR.json > /dev/null
mv -f shadowsocksRR-Origin.json /usr/local/shadowsocksRR/user-config.json > /dev/null
/etc/init.d/ssrr restart
echo -e "${COLOR_GREEN}currently config:${COLOR_END}"
/etc/init.d/ssrr viewconfig
else
echo -e "${COLOR_PINK}You will switch config to ${COLOR_END}${COLOR_GREEN}shadowsocksRR.json${COLOR_END}"
echo
mv -f /usr/local/shadowsocksRR/user-config.json shadowsocksRR-Origin.json > /dev/null
mv -f shadowsocksRR.json /usr/local/shadowsocksRR/user-config.json > /dev/null
/etc/init.d/ssrr restart
echo -e "${COLOR_GREEN}currently config:${COLOR_END}"
/etc/init.d/ssrr viewconfig
fi
}
action(){
if [ "${Select}" == "1" ]; then
update_programe
fi
if [ "${Select}" == "2" ]; then
check_ssr_ssrr_installed
switch_ssr_config
shell_update
fi
if [ "${Select}" == "3" ]; then
check_ssr_ssrr_installed
switch_ssrr_config
shell_update
fi
}
set_text_color
clear
Dispaly_Selection
action
exit