forked from 4xmen/v2ray-script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vmess-upstream-installer.sh
183 lines (166 loc) · 3.43 KB
/
vmess-upstream-installer.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
#!/bin/bash
function isRoot() {
if [ "$EUID" -ne 0 ]; then
echo "Sorry, you need to run this as root"
return 1
fi
}
function tunAvailable() {
if [ ! -e /dev/net/tun ]; then
return 1
fi
}
function initialCheck() {
if ! isRoot; then
echo "Sorry, you need to run this as root"
exit 1
fi
if ! tunAvailable; then
echo "TUN is not available"
exit 1
fi
}
function updateOs() {
apt-get update
apt-get dist-upgrade -y
}
function installRequriment() {
apt-get install wget curl certbot git zsh unzip -y
}
function downloadV2() {
mkdir -p /opt/vmess
mkdir -p /var/log/v2ray/
cd /opt/vmess
FILE=/opt/vmess/v2ray
if [ -f "$FILE" ]; then
echo "Could not download any more... :)"
else
wget https://github.com/v2ray/v2ray-core/releases/download/v4.28.2/v2ray-linux-64.zip
unzip -o v2ray-linux-64.zip
rm v2ray-linux-64.zip
fi
}
function choosePort() {
echo ""
echo "What port do you want v2ray (vmess) to listen to?"
echo " 1) Default: 1935 (RTMP)"
echo " 2) Custom"
echo " 3) Random [49152-65535]"
until [[ $PORT_CHOICE =~ ^[1-3]$ ]]; do
read -rp "Port choice [1-3]: " -e -i 1 PORT_CHOICE
done
case $PORT_CHOICE in
1)
VPORT="1935"
;;
2)
until [[ $VPORT =~ ^[0-9]+$ ]] && [ "$VPORT" -ge 1 ] && [ "$VPORT" -le 65535 ]; do
read -rp "Custom port [1-65535]: " -e -i 1935 VPORT
done
;;
3)
# Generate random number within private ports range
VPORT=$(shuf -i49152-65535 -n1)
echo "Random Port: $VPORT"
;;
esac
}
function makeConfig() {
rm /opt/vmess/server.json
VPASS="991832cc-"$(shuf -i1000-9999 -n1)"-"$(shuf -i1000-9999 -n1)"-"$(shuf -i1000-9999 -n1)"-7731d533fffe"
{
echo '{
"log": {
"access": "/var/log/v2ray/access.log",
"error": "/var/log/v2ray/error.log",
"loglevel": "warning"
},
"inbounds": [
{
"listen": "0.0.0.0",
"port": '$VPORT',
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "'$VPASS'",
"alterId": 0,
"security": "auto"
}
]
},
"streamSettings": {
"network": "ws",
"wsSettings": {
"path": "/"
}
},
"mux": {
"enabled": true
}
}
],
"outbounds": [
{
"protocol": "freedom",
"tag": "freedom"
}
],
"dns": {
"servers": [
"8.8.8.8",
"8.8.4.4",
"localhost"
]
}
}'
} >>/opt/vmess/server.json
}
function makeService() {
rm /usr/bin/vmess.sh
{
echo '#!/bin/bash
/opt/vmess/v2ray -c=/opt/vmess/server.json'
} >>/usr/bin/vmess.sh
chmod +x /usr/bin/vmess.sh
rm /etc/systemd/system/vmess.service
{
echo '[Unit]
Description=Vmess Peoxy
Documentation=
[Service]
Type=simple
User=root
Group=root
TimeoutStartSec=0
Restart=on-failure
RestartSec=30s
#ExecStartPre=
ExecStart=/usr/bin/vmess.sh
SyslogIdentifier=Diskutilization
#ExecStop=
[Install]
WantedBy=multi-user.target'
} >>/etc/systemd/system/vmess.service
systemctl enable vmess.service
echo 'Service created'
systemctl restart vmess.service
echo 'Service started'
echo 'Check service: systemctl status vmess.service'
}
function getIP() {
VIP="$(curl https://api.ipify.org)"
}
initialCheck
updateOs
installRequriment
downloadV2
getIP
cd /opt/vmess
choosePort
makeConfig
makeService
echo 'Your server secret key: '$VPASS
echo 'Your IP: '$VIP
echo 'Your port: '$VPORT
echo 'N-joy :) - xStack|4xmen Team'