From 29e9c92b298667170e1f6c6f448b9a1fd8f5c51c Mon Sep 17 00:00:00 2001 From: ulinja <56582668+ulinja@users.noreply.github.com> Date: Sat, 23 Apr 2022 17:27:15 +0200 Subject: [PATCH] fix: cpio modification not working --- udib/modiso.py | 19 +++++++++++++------ udib/udib.py | 12 ++++++++---- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/udib/modiso.py b/udib/modiso.py index 23a754a..42a86d3 100644 --- a/udib/modiso.py +++ b/udib/modiso.py @@ -97,6 +97,7 @@ def extract_iso(path_to_output_dir, path_to_input_file): "-extract", "/", path_to_output_dir.resolve() ], + capture_output=True, check=True) except subprocess.CalledProcessError: raise RuntimeError( @@ -164,12 +165,17 @@ def append_file_contents_to_initrd_archive(path_to_initrd_archive, try: # append contents of input_file to extracted archive using cpio - subprocess.run( - ["echo", str(path_to_input_file.resolve()), - "|", "cpio", "-H", "newc", "-o", "-A", - "-F", str(path_to_initrd_extracted.resolve())], - shell=True, - check=True) + # NOTE cpio must be called from within the input file's parent + # directory, and the input file's name is piped into it + completed_process = subprocess.Popen( + ["cpio", "-H", "newc", "-o", "-A", + "-F", str(path_to_initrd_extracted.resolve())], + cwd=path_to_input_file.resolve().parent, + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + completed_process.communicate( + input=str(path_to_input_file.name).encode()) except subprocess.CalledProcessError: raise RuntimeError(f"Failed while appending contents of " @@ -397,6 +403,7 @@ def repack_iso(path_to_output_iso, "-e", "boot/grub/efi.img", "-no-emul-boot", "-isohybrid-gpt-basdat", "-isohybrid-apm-hfsplus", path_to_input_files_root_dir.resolve()], + capture_output=True, check=True) except subprocess.CalledProcessError: diff --git a/udib/udib.py b/udib/udib.py index 08e316f..495a8c6 100755 --- a/udib/udib.py +++ b/udib/udib.py @@ -155,7 +155,7 @@ def _chmod_recursively(input_path, mode): def main(): # FIXME capture ISO filesystem name - iso_filesystem_name = "Debian 11.3.0 UDIB" + iso_filesystem_name = "Debian UDIB" parser = _get_argument_parser() args = parser.parse_args() @@ -277,9 +277,13 @@ def main(): # append preseed file to extracted initrd p.info("Appending preseed file...") - modiso.append_file_contents_to_initrd_archive( - path_to_extracted_iso_dir/"install.amd"/"initrd.gz", - path_to_preseed_file) + # make a temporary copy called 'preseed.cfg' + with tempfile.TemporaryDirectory() as tmpdir: + path_to_renamed_preseed_file = Path(tmpdir).resolve()/"preseed.cfg" + shutil.copy(path_to_preseed_file, path_to_renamed_preseed_file) + modiso.append_file_contents_to_initrd_archive( + path_to_extracted_iso_dir/"install.amd"/"initrd.gz", + path_to_renamed_preseed_file) # regenerate md5sum.txt p.info("Regenerating MD5 checksum...")