#!/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"], "rust": ["rustup", "rustc", "rustdoc", "rust-lldb"], "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.") print("Kernel module " + color['lred'] + f"{mod}" + color['reset'] + " is not installed.") exit(-1) # 检查软件依赖 pathsenv = os.environ.get("PATH").split(":") for software, progs in softwares.items(): print("Checking " + color['lcyan'] + f"{software}" + color['reset'] + " ...") for program in progs: exists = False for path in pathsenv: if os.path.isfile(os.path.join(path, program)): exists = True break if exists: print(" " + color['lyellow'] + f"{program}" + color['reset'] + " existed.") else: print(" " + color['lred'] + f"{program}" + color['reset'] + " not found.") print("Software " + color['lred'] + f"{software}" + color['reset'] + " is not installed or completed.") exit(-2) print("All dependencies are " + color['lgreen'] + "satisfied." + color['reset'])