LeeKurnrun->优化install

This commit is contained in:
cxykevin 2024-02-13 18:53:43 +08:00
parent 2f498de3eb
commit 468d7bdede
1 changed files with 49 additions and 29 deletions

View File

@ -8,6 +8,7 @@
import os import os
import shutil import shutil
import json import json
import platform
############ Config ############ ############ Config ############
KEYWORD = "winpe" KEYWORD = "winpe"
@ -15,39 +16,51 @@ PYTHON = "python"
DISK = "{disk}" DISK = "{disk}"
################################ ################################
# Linux please run: mount /dev/sdX /mnt/disk --mkdir # if you using Linux based OS, please run this command: mount /dev/sdX /mnt/disk --mkdir
# DISK = "/mnt/disk" # DISK = "/mnt/disk"
def find_disk(): # This code from dashedgeless def find_disk():
disk_list = "CDEFGHIJKABLMNOPQRSTUVWYZ" if platform.system() == 'Linux':
for i in disk_list: if "{disk}" in DISK:
this_disk = i + ":" raise OSError(
if os.path.exists(this_disk + "/ventoy/ventoy.json"): "Cannot auto find the Ventoy disk in Linux! Please change \"DISK\"")
return this_disk elif platform.system() == 'Windows':
ventoy_drives = []
for i in "CDEFGHIJKABLMNOPQRSTUVWYZ":
this_disk = i+":"
if os.path.exists(this_disk + "/ventoy/ventoy.json"):
ventoy_drives.append(this_disk)
if len(ventoy_drives) != 1:
for (index, value) in enumerate(ventoy_drives):
print(f"{i}:{ventoy_drives[i]}", end=" ")
return ventoy_drives[int(input("Please choose your Ventoy device:"))]
else:
raise OSError(f"Unsupported operating system:{platform.system()}")
raise OSError( raise OSError(
"Cannot find the Ventoy disk!(try to run ventoyPlugson once)") "Cannot find the Ventoy disk!(try to run ventoyPlugson once)")
DISK = DISK.replace("{disk}", find_disk()) DISK = DISK.replace("{disk}", find_disk())
print("use disk: "+DISK) print("Use disk: "+DISK)
with open(DISK+"/ventoy/ventoy.json", "r") as file: with open(DISK+"/ventoy/ventoy.json", "r") as file:
vtoycfg = json.load(file) ventoy_cfg = json.load(file)
searchroot = "" searchroot = ""
searchlevel = 3 search_level = 3
if "control" in vtoycfg: if "control" in ventoy_cfg:
for i in vtoycfg["control"]: for i in ventoy_cfg["control"]:
if "VTOY_DEFAULT_SEARCH_ROOT" in i: if "VTOY_DEFAULT_SEARCH_ROOT" in i:
searchroot = i["VTOY_DEFAULT_SEARCH_ROOT"] searchroot = i["VTOY_DEFAULT_SEARCH_ROOT"]
if "VTOY_MAX_SEARCH_LEVEL" in i: if "VTOY_MAX_SEARCH_LEVEL" in i:
if i["VTOY_MAX_SEARCH_LEVEL"] != "max": if i["VTOY_MAX_SEARCH_LEVEL"] != "max":
searchlevel = int(i["VTOY_MAX_SEARCH_LEVEL"]) search_level = int(i["VTOY_MAX_SEARCH_LEVEL"])
filelist = [] filelist = []
def dfs(deep, dir): def dfs(deep, dir, search_level):
if deep > searchlevel: if deep > search_level:
return return
lists = os.listdir(DISK+dir) lists = os.listdir(DISK+dir)
for i in lists: for i in lists:
@ -55,30 +68,33 @@ def dfs(deep, dir):
if ".iso" in i.lower() and KEYWORD in i.lower(): if ".iso" in i.lower() and KEYWORD in i.lower():
filelist.append(dir+"/"+i) filelist.append(dir+"/"+i)
else: else:
dfs(deep+1, dir+"/"+i) dfs(deep+1, dir+"/"+i, search_level)
dfs(0, searchroot) dfs(0, searchroot, search_level)
if "injection" in vtoycfg: if "injection" in ventoy_cfg:
for i in vtoycfg["injection"]: for i in ventoy_cfg["injection"]:
if "image" in i: if "image" in i:
if i["image"] in filelist: if i["image"] in filelist:
filelist.remove(i["image"]) filelist.remove(i["image"])
else: else:
vtoycfg["injection"] = [] ventoy_cfg["injection"] = []
print("find iso:", filelist)
print("Found iso:", filelist)
for i in filelist: for i in filelist:
vtoycfg["injection"].append({ ventoy_cfg["injection"].append({
"image": i, "image": i,
"archive": "/PEinjector/PEinjector.7z" "archive": "/PEinjector/PEinjector.7z"
}) })
print("write config")
print("Writing config")
with open(DISK+"/ventoy/ventoy.json", "w") as file: with open(DISK+"/ventoy/ventoy.json", "w") as file:
file.write(json.dumps(vtoycfg)) file.write(json.dumps(ventoy_cfg))
print("copy file") print("Copying files")
if not os.path.exists(DISK+"/PEinjector"): if not os.path.exists(DISK+"/PEinjector"):
os.mkdir(DISK+"/PEinjector") os.mkdir(DISK+"/PEinjector")
if os.path.exists(DISK+"/PEinjector/PEinjector.7z"): if os.path.exists(DISK+"/PEinjector/PEinjector.7z"):
@ -88,14 +104,17 @@ if not os.path.exists(DISK+"/PEinjector/disable.txt"):
with open(DISK+"/PEinjector/disable.txt", "w") as file: with open(DISK+"/PEinjector/disable.txt", "w") as file:
pass pass
print("write version info")
print("Writing version info")
shutil.copyfile("version", DISK+"/PEinjector/VERSION") shutil.copyfile("version", DISK+"/PEinjector/VERSION")
print("make dir")
print("Making dir")
if not os.path.exists(DISK+"/PEinjector/install"): if not os.path.exists(DISK+"/PEinjector/install"):
os.mkdir(DISK+"/PEinjector/install") os.mkdir(DISK+"/PEinjector/install")
print("install basic package")
print("Installing basic package")
if not os.path.exists(DISK+"/PEinjector/package"): if not os.path.exists(DISK+"/PEinjector/package"):
os.mkdir(DISK+"/PEinjector/package") os.mkdir(DISK+"/PEinjector/package")
for i in os.listdir("package"): for i in os.listdir("package"):
@ -103,4 +122,5 @@ for i in os.listdir("package"):
shutil.rmtree(DISK+"/PEinjector/package/"+i) shutil.rmtree(DISK+"/PEinjector/package/"+i)
shutil.copytree("package/"+i, DISK+"/PEinjector/package/"+i) shutil.copytree("package/"+i, DISK+"/PEinjector/package/"+i)
print("done")
print("All done.")