-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·187 lines (174 loc) · 5.21 KB
/
entrypoint.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
#!/bin/sh
set -e
corepack enable && corepack prepare yarn@stable --activate
sleep 5
_X_SERVER=example.com
_X_PORT=443
_X_AUTH=passwd
X_SERVER="${X_SERVER:-$_X_SERVER}"
X_PORT="${X_PORT:-$_X_PORT}"
X_AUTH="${X_AUTH:-$_X_AUTH}"
if [ -n "$X_SERVER" ] && [ -n "$X_PORT" ] && [ -n "$X_AUTH" ]; then
PROXY_PART=$(cat <<EOF
{
"tag": "Proxy",
"type": "hysteria2",
"server": "$X_SERVER",
"server_port": $X_PORT,
"up_mbps": 1000,
"down_mbps": 1000,
"password": "$X_AUTH",
"connect_timeout": "5s",
"tcp_fast_open": true,
"tls": {
"enabled": true,
"server_name": "$X_SERVER",
"alpn": [
"h3"
]
}
}
EOF
)
else
PROXY_PART=""
fi
MAIN_PART=$(cat <<EOF
{
"log": {
"disabled": false,
"level": "debug",
"timestamp": true
},
"experimental": {
"cache_file": {
"enabled": true,
"path": "cache.db",
"cache_id": "v1",
"store_fakeip": true
}
},
"outbounds": [
{
"tag": "direct-out",
"type": "direct",
"udp_fragment": true
},
{
"type": "dns",
"tag": "dns-out"
},
{
"type": "block",
"tag": "block"
},
$PROXY_PART
],
"dns": {
"servers": [
{
"tag": "ND-h3",
"address": "h3://dns.nextdns.io/x",
"address_resolver": "dns-direct",
"detour": "direct-out"
},
{
"tag": "dns-direct",
"address": "udp://223.5.5.5",
"detour": "direct-out"
}
],
"strategy": "ipv4_only",
"final": "ND-h3",
"reverse_mapping": true,
"disable_cache": false,
"disable_expire": false
},
"route": {
"rules": [
{
"protocol": "dns",
"outbound": "dns-out"
},
{
"ip_is_private": true,
"outbound": "direct-out"
},
{
"ip_cidr": [
"0.0.0.0/8",
"10.0.0.0/8",
"127.0.0.0/8",
"169.254.0.0/16",
"172.16.0.0/12",
"192.168.0.0/16",
"224.0.0.0/4",
"240.0.0.0/4",
"52.80.0.0/16"
],
"outbound": "direct-out"
}
],
"auto_detect_interface": true,
"final": "Proxy"
},
"inbounds": [
{
"type": "tproxy",
"listen": "::",
"listen_port": 60091,
"sniff": true,
"udp_fragment": true,
"tcp_fast_open": true,
"tcp_multi_path": false,
"udp_timeout": "5m",
"sniff_override_destination": false,
"domain_strategy": "prefer_ipv4"
}
]
}
EOF
)
if [ ! -e "/etc/sing-box/x.json" ]; then
echo "$MAIN_PART" | tee /etc/sing-box/x.json
fi
if ip rule list | grep -q "fwmark 0x1 lookup 100"; then
echo "Rules exist..."
else
ip rule add fwmark 0x1 lookup 100
ip route add local default dev lo table 100
iptables -t mangle -N DEV
iptables -t mangle -A DEV -m mark --mark 0xff -j RETURN
iptables -t mangle -A DEV -d 0.0.0.0/8 -j RETURN
iptables -t mangle -A DEV -d 10.0.0.0/8 -j RETURN
iptables -t mangle -A DEV -d 127.0.0.0/8 -j RETURN
iptables -t mangle -A DEV -d 169.254.0.0/16 -j RETURN
iptables -t mangle -A DEV -d 172.16.0.0/12 -j RETURN
iptables -t mangle -A DEV -d 192.168.0.0/16 -j RETURN
iptables -t mangle -A DEV -d 224.0.0.0/4 -j RETURN
iptables -t mangle -A DEV -d 240.0.0.0/4 -j RETURN
iptables -t mangle -A DEV -p tcp --dport 22 -j RETURN
iptables -t mangle -A DEV -p tcp --sport 22 -j RETURN
iptables -t mangle -A DEV -p tcp -j TPROXY --on-port 60091 --on-ip 127.0.0.1 --tproxy-mark 0x1
iptables -t mangle -A DEV -p udp -j TPROXY --on-port 60091 --on-ip 127.0.0.1 --tproxy-mark 0x1
iptables -t mangle -A PREROUTING -j DEV
iptables -t mangle -N DEV_MASK
iptables -t mangle -A DEV_MASK -m mark --mark 0xff -j RETURN
iptables -t mangle -A DEV_MASK -d 0.0.0.0/8 -j RETURN
iptables -t mangle -A DEV_MASK -d 10.0.0.0/8 -j RETURN
iptables -t mangle -A DEV_MASK -d 127.0.0.0/8 -j RETURN
iptables -t mangle -A DEV_MASK -d 169.254.0.0/16 -j RETURN
iptables -t mangle -A DEV_MASK -d 172.16.0.0/12 -j RETURN
iptables -t mangle -A DEV_MASK -d 192.168.0.0/16 -j RETURN
iptables -t mangle -A DEV_MASK -d 224.0.0.0/4 -j RETURN
iptables -t mangle -A DEV_MASK -d 240.0.0.0/4 -j RETURN
iptables -t mangle -A DEV_MASK -p tcp --dport 22 -j RETURN
iptables -t mangle -A DEV_MASK -p tcp --sport 22 -j RETURN
iptables -t mangle -A DEV_MASK -p tcp -j MARK --set-mark 0x1
iptables -t mangle -A DEV_MASK -p udp -j MARK --set-mark 0x1
iptables -t mangle -A OUTPUT -j DEV_MASK
fi
if [ ! -e "/usr/bin/dev-cli" ]; then
echo "sing-box -c /etc/sing-box/x.json run" > /usr/bin/dev-cli && chmod +x /usr/bin/dev-cli
fi
exec "$@"