-
Notifications
You must be signed in to change notification settings - Fork 484
/
trojanv1.0.sh
276 lines (242 loc) · 6.56 KB
/
trojanv1.0.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
#!/bin/bash
if [[ $(id -u) != 0 ]]; then
echo Please run this script as root.
exit 1
fi
#SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
#AIRTIMEROOT=${SCRIPT_DIR}
#YUM_CMD=$(which yum)
#APT_GET_CMD=$(which apt-get)
#OTHER_CMD=$(which <other installer>)
echo "Hello, "$USER". This script will help you set up a trojan-gfw server."
userinput(){
echo -n "Enter your domain and press [ENTER]: "
read domain
echo -n "It\'s nice to meet you $domain"
echo
echo -n "Enter your desired password1 and press [ENTER]: "
read password1
echo -n "Your password1 is $password1"
echo
echo -n "Enter your desired password2 and press [ENTER]: "
read password2
echo -n "Your password2 is $password2"
}
userinput
getoscode(){
# Validate the distribution and release is a supported one; set boolean flags.
echo "Detecting distribution and release ..."
is_debian_dist=false
is_debian_buster=false
is_debian_stretch=false
is_debian_jessie=false
is_debian_wheezy=false
is_ubuntu_dist=false
is_ubuntu_bionic=false
is_ubuntu_eoan=false
is_ubuntu_xenial=false
is_ubuntu_trusty=false
is_centos_dist=false
is_centos_7=false
if [ -e /etc/os-release ]; then
# Access $ID, $VERSION_CODENAME, $VERSION_ID and $PRETTY_NAME
source /etc/os-release
dist=$ID
code="${VERSION_CODENAME-$VERSION_ID}"
case "${dist}-${code}" in
ubuntu-eoan) #ubuntu 19.10
code="eoan"
is_ubuntu_dist=true
is_ubuntu_eoan=true
;;
ubuntu-bionic) #ubuntu 18.04
code="bionic"
is_ubuntu_dist=true
is_ubuntu_bionic=true
;;
ubuntu-xenial) #ubuntu 16.04
code="trusty"
is_ubuntu_dist=true
is_ubuntu_xenial=true
;;
ubuntu-14.04) #ubuntu 14.04
code="trusty"
is_ubuntu_dist=true
is_ubuntu_trusty=true
;;
debian-buster) #debian10
code="buster"
is_debian_dist=true
is_debian_buster=true
;;
debian-9) #debian9
code="stretch"
is_debian_dist=true
is_debian_stretch=true
;;
debian-8) #debian8
code="jessie"
is_debian_dist=true
is_debian_jessie=true
;;
debian-7) #debian7
code="wheezy"
is_debian_dist=true
is_debian_wheezy=true
;;
centos-7)
is_centos_dist=true
is_centos_7=true
;;
*)
echo "ERROR: Distribution \"$PRETTY_NAME\" is not supported!" >&2
exit 1
;;
esac
else
echo "ERROR: This is an unsupported distribution and/or version!" >&2
exit 1
fi
echo "Detected distribution: $PRETTY_NAME"
echo "Distribution id (dist): $dist"
echo "Distribution version (code): $code"
echo
$is_ubuntu_dist && echo "Dist: Ubuntu"
$is_debian_dist && echo "Dist: Debian"
$is_centos_dist && echo "Dist: CentOS"
echo "Distribution and release codename:"
$is_ubuntu_eoan && echo "Ubuntu Eoan"
$is_ubuntu_bionic && echo "Ubuntu Bionic"
$is_ubuntu_xenial && echo "Ubuntu Xenial"
$is_ubuntu_trusty && echo "Ubuntu Trusty"
$is_debian_buster && echo "Debian Buster"
$is_debian_stretch && echo "Debian Stretch"
$is_debian_jessie && echo "Debian Jessie"
$is_debian_wheezy && echo "Debian Wheezy"
$is_centos_7 && echo "CentOS 7"
}
getoscode
echo -n "Your os codename is $codename"
updatesystem(){
if [[ $dist = centos ]]; then
yum update
elif [[ $dist = ubuntu ]]; then
apt-get update
elif [[ $dist = debian ]]; then
apt-get update
else
echo "error can't update system"
exit 1;
fi
}
updatesystem
upgradesystem(){
if [[ $dist = centos ]]; then
yum upgrade -y
elif [[ $dist = ubuntu ]]; then
apt-get upgrade -y
elif [[ $dist = debian ]]; then
apt-get upgrade -y
else
echo "error can't upgrade system"
exit 1;
fi
}
installrely(){
echo installing trojan-gfw nginx and acme
if [[ $dist = centos ]]; then
yum install curl socat xz-utils wget apt-transport-https -y
elif [[ $dist = ubuntu ]]; then
apt-get install curl socat xz-utils wget apt-transport-https -y
elif [[ $dist = debian ]]; then
apt-get install curl socat xz-utils wget apt-transport-https -y
else
echo "error can't update system"
exit 1;
fi
}
installrely
installtrojan-gfw(){
bash -c "$(wget -O- https://raw.githubusercontent.com/trojan-gfw/trojan-quickstart/master/trojan-quickstart.sh)"
}
installtrojan-gfw
nginxyum(){
yum install nginx -y
}
nginxapt(){
wget https://nginx.org/keys/nginx_signing.key
apt-key add nginx_signing.key
echo "deb https://nginx.org/packages/mainline/debian/ $code nginx" >> /etc/apt/sources.list
echo "deb-src https://nginx.org/packages/mainline/debian/ $code nginx" >> /etc/apt/sources.list
apt-get update
apt-get install nginx -y
}
nginxubuntu(){
wget https://nginx.org/keys/nginx_signing.key
apt-key add nginx_signing.key
echo "deb https://nginx.org/packages/mainline/ubuntu/ $code nginx" >> /etc/apt/sources.list
echo "deb-src https://nginx.org/packages/mainline/ubuntu/ $code nginx" >> /etc/apt/sources.list
apt-get update
apt-get install nginx -y
}
installnignx(){
if [[ $dist = centos ]]; then
nginxyum
elif [[ $dist = ubuntu ]]; then
nginxubuntu
elif [[ $dist = debian ]]; then
nginxapt
else
echo "error can't install nginx"
exit 1;
fi
}
installnignx
installacme(){
curl https://get.acme.sh | sh
mkdir /etc/trojan/
}
installacme
issuecert(){
sudo ~/.acme.sh/acme.sh --issue -d $domain --standalone -k ec-256
}
echo "issueing let\'s encrypt certificate"
issuecert
installcert(){
sudo ~/.acme.sh/acme.sh --installcert -d $domain --fullchainpath /etc/trojan/trojan.crt --keypath /etc/trojan/trojan.key --ecc
}
echo "issue complete,installing certificate"
installcert
echo "certificate install complete!"
installkey(){
chmod +r /etc/trojan/trojan.key
}
echo "giving private key read authority"
installkey
changepasswd(){
sed -i 's/path/etc/g' /usr/local/etc/trojan/config.json
sed -i 's/to/trojan/g' /usr/local/etc/trojan/config.json
sed -i 's/certificate.crt/trojan.crt/g' /usr/local/etc/trojan/config.json
sed -i 's/private.key/trojan.key/g' /usr/local/etc/trojan/config.json
sed -i "s/password1/$password1/g" /usr/local/etc/trojan/config.json
sed -i "s/password2/$password2/g" /usr/local/etc/trojan/config.json
}
changepasswd
echo "trojan-gfw config complete!"
echo "starting trojan-gfw and nginx | setting up boot autostart"
autostart(){
systemctl start trojan
systemctl start nginx
systemctl enable nginx
systemctl enable trojan
}
autostart
tcp-bbr(){
echo "net.ipv4.tcp_slow_start_after_idle = 0" >> /etc/sysctl.d/99-sysctl.conf
echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.d/99-sysctl.conf
sysctl -p
}
echo "Setting up tcp-bbr boost technology"
tcp-bbr
echo "Install Success,Enjoy it!"