From 605701e9b99870ff59cad30c4ec5b7b527835f43 Mon Sep 17 00:00:00 2001 From: Huaqi Fang <578567190@qq.com> Date: Fri, 29 Dec 2023 21:46:26 +0800 Subject: [PATCH] ci: fix nuclei studio extracted file path Signed-off-by: Huaqi Fang <578567190@qq.com> --- .github/prepare_tools.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/prepare_tools.py b/.github/prepare_tools.py index 3dc5a37..99d57aa 100644 --- a/.github/prepare_tools.py +++ b/.github/prepare_tools.py @@ -45,8 +45,8 @@ def md5sum_file(file_path): if os.path.isfile(file_path) == False: print("{file_path} not existed!") return False - print("{file_path} size %s bytes" % (get_file_size(file_path))) - print("{file_path} md5 %s" % (calculate_md5(file_path))) + print(f"{file_path} size %s bytes" % (get_file_size(file_path))) + print(f"{file_path} md5 %s" % (calculate_md5(file_path))) return True def download_with_progress(url, destination_folder, reuse=False): @@ -76,11 +76,11 @@ def download_and_extract(url, extract_folder, reuse=False): print("Extracting %s to %s" % (file_name, extract_folder)) # Extract the contents if file_name.endswith(".zip"): - print("Unzip {file_name}") + print(f"Unzip {file_name}") with zipfile.ZipFile(file_name, "r") as zip_ref: zip_ref.extractall(extract_folder) elif file_name.endswith(".tar.gz") or file_name.endswith(".tgz"): - print("Untar {file_name}") + print(f"Untar {file_name}") with tarfile.open(file_name, "r:gz") as tar_ref: tar_ref.extractall(extract_folder) else: @@ -112,6 +112,18 @@ def setup_nuclei_studio(toolsdir, nuclei_url, system_value, reuse): nuclei_folder = toolsdir download_and_extract(nuclei_url, nuclei_folder, reuse) + # Fix nuclei studio path + for item in os.listdir(nuclei_folder): + if os.path.isdir(item) and item.startswith("NucleiStudio") and item != "NucleiStudio": + nsidepath = os.path.join(nuclei_folder, item) + newpath = os.path.join(nuclei_folder, "NucleiStudio") + if len(os.listdir(nsidepath)) == 1: + nsidepath = os.path.join(nsidepath, "NucleiStudio") + # rename old ide path to new ide path + # such as NucleiStudio_IDE_202310/NucleiStudio -> NucleiStudio + os.rename(nsidepath, newpath) + break + # Copy and modify nuclei_openocd.json openocd_json_path = os.path.join(nuclei_folder, "NucleiStudio", "toolchain", "openocd", "package.json") modify_json_file(os.path.join(PIOJSONLOC, "openocd.json"), openocd_json_path, system_value)