diff --git a/jlmkr.py b/jlmkr.py index c57c442..61d3233 100755 --- a/jlmkr.py +++ b/jlmkr.py @@ -113,7 +113,7 @@ JAILS_DIR_PATH = "jails" JAIL_CONFIG_NAME = "config" JAIL_ROOTFS_NAME = "rootfs" DOWNLOAD_SCRIPT_DIGEST = ( - "6cca2eda73c7358c232fecb4e750b3bf0afa9636efb5de6a9517b7df78be12a4" + "d11fc7e5950d0e01bbca89ad8f663a698880ef7f4b0473453ba46a693cec4d12" ) SCRIPT_PATH = os.path.realpath(__file__) SCRIPT_NAME = os.path.basename(SCRIPT_PATH) @@ -787,6 +787,22 @@ def validate_sha256(file_path, digest): return False +def remove_lines_after_line_number(file_path, line_number): + with open(file_path, "r+") as file: + current_line_number = 1 + + # Read the last line to keep + while current_line_number <= line_number: + file.readline() + current_line_number += 1 + + # Seek to the last line to keep + # https://stackoverflow.com/a/78176770 + file.seek(file.tell()) + # Remove everything after line_number + file.truncate() + + def run_lxc_download_script( jail_name=None, jail_path=None, jail_rootfs_path=None, distro=None, release=None ): @@ -810,9 +826,13 @@ def run_lxc_download_script( # Fetch the lxc download script if not present locally (or hash doesn't match) if not validate_sha256(lxc_download_script, DOWNLOAD_SCRIPT_DIGEST): urllib.request.urlretrieve( - "https://raw.githubusercontent.com/Jip-Hop/lxc/58520263041b6864cadad96278848f9b8ce78ee9/templates/lxc-download.in", + "https://raw.githubusercontent.com/Jip-Hop/lxc/97f93be72ebf380f3966259410b70b1c966b0ff0/templates/lxc-download.in", lxc_download_script, ) + + # Throw away the last part of the download script, jailmaker doesn't need it + remove_lines_after_line_number(lxc_download_script, 404) + if not validate_sha256(lxc_download_script, DOWNLOAD_SCRIPT_DIGEST): eprint("Abort! Downloaded script has unexpected contents.") return 1