-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvless_install.sh
174 lines (154 loc) · 3.93 KB
/
vless_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
#!/bin/bash
# Ask if user is registered a domain name
echo "Have you registered a domain name and set the Nameservers? (y/n)"
# Read user input, if yes, continue, if no, exit
read -r DOMAIN_NAME
if [ "$DOMAIN_NAME" = "y" ]; then
echo "Please enter your domain name with www:"
read -r DOMAIN_NAME
else
echo "Please register a domain name first."
exit 1
fi
apt update && apt upgrade -y
apt install -y jq curl unzip
# Install firewall
apt install -y ufw
# Allow ports 22, 80, 443
ufw allow 22
ufw allow 80
ufw allow 443
# Enable firewall
ufw enable
# Install certbot
apt install -y certbot
# Get cert for domain (* without email address to be notified the 1yr expiration)
sudo certbot certonly --standalone --agree-tos --register-unsafely-without-email -d "$DOMAIN_NAME"
# /etc/letsencrypt/live/$DOMAIN_NAME/privkey.pem
# /etc/letsencrypt/live/$DOMAIN_NAME/fullchain.pem
# Check if certificate and private key exist
if [ ! -f /etc/letsencrypt/live/"$DOMAIN_NAME"/privkey.pem ]; then
echo -e "\033[31mPrivekey not found!\033[0m"
exit 1
fi
if [ ! -f /etc/letsencrypt/live/"$DOMAIN_NAME"/fullchain.pem ]; then
echo -e "\033[31mCertificate not found!\033[0m"
exit 1
fi
# Generate a random uuid
uuid=$(/usr/bin/uuidgen)
# Download latest release of Xray-core from git
LT_RELEASE_V=$(curl --silent "https://api.github.com/repos/XTLS/Xray-core/releases/latest" | jq -r .tag_name)
# Get machine architecture
ARCH=$(uname -m)
case $ARCH in
'i386' | 'i686')
MACHINE='32'
;;
'amd64' | 'x86_64')
MACHINE='64'
;;
'armv7' | 'armv7l')
MACHINE='arm32-v7a'
grep Features /proc/cpuinfo | grep -qw 'vfp' || MACHINE='arm32-v5'
;;
'armv8' | 'aarch64')
MACHINE='arm64-v8a'
;;
*)
echo "Unsupported architecture."
exit 1
;;
esac
# Download Xray-core
DOWNLOAD_LINK="https://github.com/XTLS/Xray-core/releases/download/$LT_RELEASE_V/Xray-linux-$MACHINE.zip"
curl -L -H "Cache-Control: no-cache" -o "Xray-linux-$MACHINE.zip" "$DOWNLOAD_LINK"
# Unzip Xray-core, install to /usr/bin/xray and remove zip file
unzip "Xray-linux-$MACHINE.zip" -d /usr/bin
rm -f "Xray-linux-$MACHINE.zip"
# Create log directory for v2ray
mkdir -p /var/log/v2ray
LOG_DIR="/var/log/v2ray"
# Create Xray config file
mkdir -p /etc/xray/
cat > /etc/xray/config.json << EOF
{
"log": {
"loglevel": "warning",
"access": "$LOG_DIR/access.log",
"error": "$LOG_DIR/error.log"
},
"inbounds": [
{
"listen": "0.0.0.0",
"port": 443,
"protocol": "vless",
"settings": {
"clients": [
{
"id": "$uuid",
}
],
"decryption": "none"
},
"streamSettings": {
"network": "tcp",
"security": "tls",
"tlsSettings": {
"certificates": [
{
"certificateFile": "/etc/letsencrypt/live/$DOMAIN_NAME/fullchain.pem",
"keyFile": "/etc/letsencrypt/live/$DOMAIN_NAME/privkey.pem"
}
]
}
},
"sniffing": {
"enabled": true,
"destOverride": [
"http",
"tls"
]
}
}
],
"outbounds": [
{
"protocol": "freedom",
"tag": "direct"
},
{
"protocol": "blackhole",
"tag": "block"
}
]
}
EOF
# Create Xray service file
cat > /etc/systemd/system/xray.service << EOF
[Unit]
Description=Xray - A unified platform for anti-censorship
Documentation=
After=network.target nss-lookup.target
Wants=network-online.target
[Service]
Type=simple
User=root
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
NoNewPrivileges=true
ExecStart=/usr/bin/xray run -config /etc/xray/config.json
Restart=on-failure
RestartPreventExitStatus=23
RestartSec=5s
[Install]
WantedBy=multi-user.target
EOF
# Reload systemd daemon
systemctl daemon-reload
# enable Xray service
systemctl enable xray
# start Xray service
systemctl start xray
# Check Xray status
systemctl status xray