diff options
| author | 0xf00sec <159052166+0xf00sec@users.noreply.github.com> | 2025-08-09 20:14:37 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-09 20:14:37 +0000 |
| commit | cfd80c4212d449c9b33cc9d18b05da6b3d2c52bc (patch) | |
| tree | 77d15a66a6d600b72ddf69ff257a7692ed485ae5 /tools/mk_img.py | |
| parent | d9f1a4f656ced76df3f23eeec678e1a3be1fd432 (diff) | |
| parent | 7ada9006860084ba5d72b517649d1b2d51e4484a (diff) | |
Merge branch 'nekernel-org:dev' into dev
Diffstat (limited to 'tools/mk_img.py')
| -rw-r--r-- | tools/mk_img.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tools/mk_img.py b/tools/mk_img.py new file mode 100644 index 00000000..f0fa0609 --- /dev/null +++ b/tools/mk_img.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import os +import sys +import subprocess +import glob as file_glob + +def copy_to_fat(image_path, source_dir): + if not os.path.isfile(image_path): + print(f"Error: FAT32 image {image_path} does not exist.") + sys.exit(1) + + if not os.path.isdir(source_dir): + print(f"Error: {source_dir} is not a valid directory.") + sys.exit(1) + + try: + files_to_copy = file_glob.glob(os.path.join(source_dir, "*")) + + if not files_to_copy: + print(f"Warning: No files found in {source_dir}, nothing to copy.") + sys.exit(1) + + command = ["mcopy", "-spm", "-i", image_path] + files_to_copy + ["::"] + subprocess.run(command, check=True) + except Exception as e: + print(f"Error: failed: {e}") + sys.exit(1) + +if __name__ == "__main__": + if len(sys.argv) != 3: + print("HELP: mk_img.py <fat32_image> <source_directory>") + sys.exit(1) + + image_path = sys.argv[1] + source_dir = sys.argv[2] + + copy_to_fat(image_path, source_dir) + + print("INFO: Image created successfully.") |
