-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathinit.sh
More file actions
executable file
·204 lines (191 loc) · 4.24 KB
/
Copy pathinit.sh
File metadata and controls
executable file
·204 lines (191 loc) · 4.24 KB
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
#!/bin/bash
if [ $# -ne 2 ] && [ $# -ne 4 ]; then
echo "[+] Usage: $0 <url> <port> [username] [password]"
exit 1
fi
url=$1
port=$2
if [ $# -gt 2 ]; then
username=$3
password=$4
authtype="password"
else
username="user"
password="pass"
authtype="noauth"
fi
# 检查是否安装了curl
if ! command -v curl >/dev/null; then
echo "[x] curl is required. Exiting."
exit 1
fi
# 请求URL获取配置信息, 如果返回不包含 "protocol": "vless", 则认为配置不存在
echo "[*] Requesting configuration from $url"
response=$(curl --connect-timeout 3 -s "$url")
if [[ ! $response =~ "protocol\": \"vless\"" ]]; then
echo "[x] Configuration not found. Exiting."
exit 1
fi
mkdir -p config
# 检查是否安装了Docker
if ! command -v docker >/dev/null; then
echo "[*] Docker is not installed. Do you want to install it? (yes/no)"
read -r answer
if [ "$answer" = "yes" ]; then
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
rm get-docker.sh
else
echo "[x] Docker is required. Exiting."
exit 1
fi
fi
# 检查是否安装了Docker Compose
if ! command -v docker-compose >/dev/null; then
echo "[*] Docker Compose is not installed. Do you want to install it? (yes/no)"
read -r answer
if [ "$answer" = "yes" ]; then
# 获取最新版本
COMPOSE_VERSION=$(curl -s https://api.github.com/repos/docker/compose/releases/latest | grep '"tag_name":' | cut -d '"' -f 4)
sudo curl -L "https://github.com/docker/compose/releases/download/$COMPOSE_VERSION/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
else
echo "[x] Docker Compose is required. Exiting."
exit 1
fi
fi
# 重新生成xray配置文件进行替换
cat > config/config.json <<EOL
{
"api": {
"services": [
"HandlerService",
"LoggerService",
"StatsService"
],
"tag": "api"
},
"dns": null,
"fakeDns": null,
"inbounds": [
{
"listen": "127.0.0.1",
"port": 62789,
"protocol": "dokodemo-door",
"settings": {
"address": "127.0.0.1"
},
"sniffing": null,
"streamSettings": null,
"tag": "api"
},
{
"listen": null,
"port": $port,
"protocol": "socks",
"settings": {
"accounts": [
{
"pass": "$password",
"user": "$username"
}
],
"auth": "$authtype",
"ip": "127.0.0.1",
"udp": false
},
"sniffing": null,
"streamSettings": null,
"tag": "inbound-31445"
}
],
"log": {
"error": "./error.log",
"loglevel": "warning"
},
"outbounds": [
{
"protocol": "freedom",
"settings": {}
},
$response,
{
"protocol": "blackhole",
"settings": {},
"tag": "blocked"
}
],
"policy": {
"levels": {
"0": {
"statsUserDownlink": true,
"statsUserUplink": true
}
},
"system": {
"statsInboundDownlink": true,
"statsInboundUplink": true
}
},
"reverse": null,
"routing": {
"domainStrategy": "IPIfNonMatch",
"rules": [
{
"inboundTag": [
"api"
],
"outboundTag": "api",
"type": "field"
},
{
"domain": [
"regexp:.*"
],
"outboundTag": "cloudflare",
"type": "field"
},
{
"ip": [
"0.0.0.0/0",
"::/0"
],
"outboundTag": "cloudflare",
"type": "field"
},
{
"ip": [
"geoip:private"
],
"outboundTag": "blocked",
"type": "field"
},
{
"outboundTag": "blocked",
"protocol": [
"bittorrent"
],
"type": "field"
}
]
},
"stats": {},
"transport": null
}
EOL
# 生成Docker Compose文件
cat > docker-compose.yml <<EOL
services:
cf_proxy:
image: teddysun/xray:latest
container_name: cf_proxy
hostname: cf_proxy
volumes:
- ./config/config.json:/etc/xray/config.json
tty: true
restart: unless-stopped
ports:
- $port:$port
EOL
docker-compose down
docker-compose up -d