2023-12-29 22:54:46 +08:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
import subprocess
|
|
|
|
import os
|
|
|
|
|
|
|
|
color = {
|
|
|
|
'black': '\033[30m',
|
|
|
|
'red': '\033[31m',
|
|
|
|
'green': '\033[32m',
|
|
|
|
'yellow': '\033[33m',
|
|
|
|
'blue': '\033[34m',
|
|
|
|
'pink': '\033[35m',
|
|
|
|
'cyan': '\033[36m',
|
|
|
|
'white': '\033[37m',
|
|
|
|
'lblack': '\033[1;30m',
|
|
|
|
'lred': '\033[1;31m',
|
|
|
|
'lgreen': '\033[1;32m',
|
|
|
|
'lyellow': '\033[1;33m',
|
|
|
|
'lblue': '\033[1;34m',
|
|
|
|
'lpink': '\033[1;35m',
|
|
|
|
'lcyan': '\033[1;36m',
|
|
|
|
'lwhite': '\033[1;37m',
|
|
|
|
'reset': '\033[0m',
|
|
|
|
}
|
|
|
|
|
|
|
|
arch = subprocess.check_output("uname -m", shell=True).decode().strip()
|
|
|
|
|
|
|
|
|
|
|
|
kernel_modules = [
|
|
|
|
"nbd",
|
|
|
|
]
|
|
|
|
|
|
|
|
softwares = {
|
|
|
|
"doas": ["doas"],
|
|
|
|
"gcc": ["gcc"],
|
|
|
|
"nasm": ["nasm"],
|
2024-01-16 23:58:11 +08:00
|
|
|
"rust": ["rustup", "rustc", "rustdoc", "rust-lldb"],
|
2023-12-29 22:54:46 +08:00
|
|
|
"qemu": ["qemu-img", "qemu-nbd", "qemu-system-"+arch],
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# 检查内核模块
|
|
|
|
lsmodoutput = subprocess.check_output("lsmod", shell=True).decode()
|
|
|
|
print("Checking kernel modules ...")
|
|
|
|
for mod in kernel_modules:
|
|
|
|
mmod = "\n" + mod
|
|
|
|
mmod += " "
|
|
|
|
if mmod in lsmodoutput:
|
|
|
|
print(" " + color['lpink'] + f"{mod}" + color['reset'] + " exists.")
|
|
|
|
else:
|
|
|
|
print(" " + color['lred'] + f"{mod}" + color['reset'] + " not found.")
|
2024-04-04 20:55:46 +08:00
|
|
|
print(
|
|
|
|
"Kernel module " +
|
|
|
|
color['lred'] + f"{mod}" + color['reset'] + " is not installed.")
|
2023-12-29 22:54:46 +08:00
|
|
|
exit(-1)
|
|
|
|
|
|
|
|
# 检查软件依赖
|
|
|
|
pathsenv = os.environ.get("PATH").split(":")
|
|
|
|
for software, progs in softwares.items():
|
2024-04-04 20:55:46 +08:00
|
|
|
print(
|
|
|
|
"Checking " + color['lcyan'] +
|
|
|
|
f"{software}" + color['reset'] + " ...")
|
2023-12-29 22:54:46 +08:00
|
|
|
for program in progs:
|
|
|
|
exists = False
|
|
|
|
for path in pathsenv:
|
|
|
|
if os.path.isfile(os.path.join(path, program)):
|
|
|
|
exists = True
|
|
|
|
break
|
|
|
|
if exists:
|
2024-04-04 20:55:46 +08:00
|
|
|
print(
|
|
|
|
" " + color['lyellow'] +
|
|
|
|
f"{program}" + color['reset'] + " existed.")
|
2023-12-29 22:54:46 +08:00
|
|
|
else:
|
2024-04-04 20:55:46 +08:00
|
|
|
print(
|
|
|
|
" " + color['lred'] +
|
|
|
|
f"{program}" + color['reset'] + " not found.")
|
2023-12-29 22:54:46 +08:00
|
|
|
|
2024-04-04 20:55:46 +08:00
|
|
|
print(
|
|
|
|
"Software " + color['lred'] + f"{software}" +
|
|
|
|
color['reset'] + " is not installed or completed.")
|
2023-12-29 22:54:46 +08:00
|
|
|
exit(-2)
|
|
|
|
|
2024-04-04 20:55:46 +08:00
|
|
|
print(
|
|
|
|
"All dependencies are " +
|
|
|
|
color['lgreen'] + "satisfied." + color['reset'])
|