This repository has been archived by the owner on Jun 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
thirdparty.py
executable file
·70 lines (54 loc) · 2.29 KB
/
thirdparty.py
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
#! /usr/bin/env python3
import os
import tempfile
def build_any_proxy(output_path):
with tempfile.TemporaryDirectory() as tmp_dir:
proj_dir = os.path.join(tmp_dir, "go-any-proxy")
exe_path = os.path.join(proj_dir, "any_proxy")
os.system(
f"cd {tmp_dir} && git clone --depth 1 https://github.com/louchenyao/go-any-proxy.git")
os.system(f"cd {proj_dir} && GOOS=linux GOARCH=amd64 ./make.bash")
os.system(f"cp {exe_path} {output_path}")
def build_freedns_go(output_path):
with tempfile.TemporaryDirectory() as tmp_dir:
proj_dir = os.path.join(tmp_dir, "freedns-go")
exe_path = os.path.join(proj_dir, "freedns-go")
assert(os.system(
f"cd {tmp_dir} && git clone --depth 1 https://github.com/tuna/freedns-go.git") == 0)
assert(
os.system(f"cd {proj_dir} && GOOS=linux GOARCH=amd64 go build") == 0)
assert(os.system(f"cp {exe_path} {output_path}") == 0)
def install_wireguard():
assert(os.system("sudo apt update") == 0)
assert(os.system("sudo apt install -y wireguard") == 0)
assert(os.system("wg --help") == 0)
def install_golang():
assert(os.system("sudo apt update") == 0)
assert(os.system("sudo apt install -y golang-go") == 0)
assert(os.system("go version") == 0)
def install_utils():
assert(os.system("sudo apt update") == 0)
assert(os.system("sudo apt install -y ipset traceroute") == 0)
def conf_sysctl():
with tempfile.TemporaryDirectory() as tmp_dir:
conf_path = os.path.join(tmp_dir, "999-custom-net.conf")
with open(conf_path, "w") as f:
f.write("net.core.default_qdisc=fq\n")
f.write("net.ipv4.tcp_congestion_control=bbr\n")
f.write("net.ipv4.ip_forward = 1\n")
f.write("net.ipv4.conf.all.rp_filter = 0\n")
f.write("net.ipv4.conf.default.rp_filter = 0\n")
assert(os.system(f"sudo cp {conf_path} /etc/sysctl.d") == 0)
assert(os.system(f"sudo sysctl --system") == 0)
if __name__ == "__main__":
install_utils()
install_golang()
install_wireguard()
conf_sysctl()
bin_dir = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
"bin"
)
os.system(f"mkdir -p {bin_dir}")
build_freedns_go(bin_dir)
build_any_proxy(bin_dir)