-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-env.py
143 lines (107 loc) · 4.08 KB
/
check-env.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
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
#!/usr/bin/python3
"""
check_mirror_env.py
https://github.com/COSI-Lab/
"""
import subprocess
import re
import os
def runCommandWithOutput(args: list[str]) -> str:
try:
return subprocess.run(
args, stdout=subprocess.PIPE
).stdout.decode("utf-8").strip()
except FileNotFoundError:
return ""
def matches(regex: str, compare: str) -> bool:
match = re.match(regex, compare)
return not match == None
# ----- Docker -----
def checkDocker() -> bool:
print("Checking presence of Docker..................", end="")
return matches(
r"^Docker version \d+\.\d+\.\d+.*",
runCommandWithOutput(["docker", "--version"])
)
def checkDockerCompose() -> bool:
print("Checking presence of docker-compose v2.......", end="")
return matches(
r"^Docker Compose version .*\d+\.\d+\.\d+.*",
runCommandWithOutput(["docker", "compose", "version"])
)
# ----- Toolchain -----
def checkGit() -> bool:
print("Checking presence of git.....................", end="")
return matches(
r"^git version \d+\.\d+\.\d+.*",
runCommandWithOutput(["git", "--version"])
)
def checkGCC() -> bool:
print("Checking presence of g++.....................", end="")
return matches(
r"^g\+\+ \(.*\) \d+\.\d+\.\d+.*",
runCommandWithOutput(["g++", "--version"])
)
def checkJDK() -> bool:
print("Checking presence of openjdk 17..............", end="")
return matches(
r"^openjdk 17\.\d+\.\d+.*",
runCommandWithOutput(["java", "--version"])
)
def checkMaven() -> bool:
print("Checking presence of Maven...................", end="")
return matches(
r"^.{0,4}Apache Maven \d+\.\d+\.\d+.*",
runCommandWithOutput(["mvn", "--version"])
)
# ----- Libraries -----
def checkLibZMQ(libs: str) -> bool:
print("Checking presence of libzmq..................", end="")
return not libs.find("libzmq.so") == -1
def checkLibCurl(libs: str) -> bool:
print("Checking presence of libcurl.................", end="")
return not libs.find("libcurl.so") == -1
def checkLibZ(libs: str) -> bool:
print("Checking presence of libz....................", end="")
return not libs.find("libz.so") == -1
# ----- Directories -----
def checkStorage() -> bool:
print("Checking presence of /storage dir............", end="")
return os.path.exists("/storage")
def checkEtcNginx() -> bool:
print("Checking presence of /etc/nginx dir..........", end="")
return os.path.exists("/etc/nginx")
def checkVarNginx() -> bool:
print("Checking presence of /var/log/nginx dir......", end="")
return os.path.exists("/var/log/nginx")
def main():
print("")
print("----- Checking requirements for production... -----")
print("")
# Check Docker
print("OK" if checkDocker() == True else "Could not find Docker.")
print("OK" if checkDockerCompose() == True else "Could not find docker-compose v2.")
# Check Git
print("OK" if checkGit() == True else "Could not find git.")
# Check dirs
print("OK" if checkStorage() == True else "Directory /storage does not exist.")
print("OK" if checkEtcNginx() == True else "Directory /etc/nginx does not exist.")
print("OK" if checkVarNginx() == True else "Directory /var/log/nginx does not exist.")
print("")
print("----- Checking requirements for development... -----")
print("")
# Check tools
print("OK" if checkGCC() == True else "Could not find g++.")
print("OK" if checkJDK() == True else "Could not find openjdk 17.")
print("OK" if checkMaven() == True else "Could not find Maven.")
# Check libraries
libs: str = runCommandWithOutput(["ldconfig", "-p"])
print("OK" if checkLibZMQ(libs) == True else "Could not find libzmq.")
print("OK" if checkLibCurl(libs) == True else "Could not find libcurl.")
print("OK" if checkLibZ(libs) == True else "Could not find libz.")
if(__name__ == "__main__"):
try:
main()
except KeyboardInterrupt:
print("CTRL-C")
pass