-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathinstall.py
64 lines (53 loc) · 1.78 KB
/
install.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
import sys
import subprocess
VSERSION = "1.0.3"
def cmd(cmd: str):
try:
subprocess.run(cmd, shell=True, check=True)
return True
except subprocess.CalledProcessError as e:
sys.exit(1)
def shell(cmd: str) -> str:
"""
Execute a shell statement and return the output.
"""
r = subprocess.run(
cmd, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
return r.stdout.decode()
def main():
# clone cfw
cmd("git clone -b {} https://github.com/Cyberbolt/cfw.git /etc/cfw/".format(VSERSION))
# choose linux architecture
architecture = shell("uname -m").strip()
if architecture != "aarch64" and architecture != "x86_64":
print(
"This CPU architecture is not supported, only x86_64 and arm64 are supported."
)
sys.exit(1)
cmd(
"curl -# -OL https://github.com/Cyberbolt/cfw/releases/download/1.0.0/py39-Linux-{}.tar.gz".format(
architecture
)
)
# Unzip the python3.9 version
cmd("tar -zxvf py39-Linux-{}.tar.gz".format(architecture))
cmd("mv py39 /etc/cfw/py39")
cmd("rm -rf py39-Linux-{}.tar.gz".format(architecture))
# Install Python dependencies
cmd("/etc/cfw/py39/bin/python -m pip install -r /etc/cfw/requirements.txt")
# run with systemd
cmd("cp /etc/cfw/cfw.service /etc/systemd/system/cfw.service")
cmd("systemctl daemon-reload")
cmd("systemctl enable cfw")
cmd("systemctl start cfw")
# add environment variable
cmd("""echo "alias cfw='/etc/cfw/py39/bin/python /etc/cfw/client.py'">>~/.bashrc""")
print(
"""
CFW installation is complete, please enter the following command to activate 'cfw'.
source ~/.bashrc
"""
)
if __name__ == "__main__":
main()