diff --git a/BUILD.md b/BUILD.md index 88ec885..0661c59 100644 --- a/BUILD.md +++ b/BUILD.md @@ -11,7 +11,7 @@ sudo apt install -y podman dh-python python3 python3-stdeb python3-pyside2.qtcor Build the latest container: ```sh -./install/linux/build-container.py +./install/linux/build-image.sh ``` Run from source tree: @@ -37,7 +37,7 @@ sudo dnf install -y rpm-build podman python3 python3-setuptools python3-pyside2 Build the latest container: ```sh -./install/linux/build-container.py +./install/linux/build-image.sh ``` Run from source tree: @@ -76,7 +76,7 @@ brew install create-dmg Build the dangerzone container image: ```sh -./install/build-image.sh +./install/macos/build-image.sh ``` Run from source tree: diff --git a/dangerzone/cli.py b/dangerzone/cli.py index 255b0d9..ccbd8e8 100644 --- a/dangerzone/cli.py +++ b/dangerzone/cli.py @@ -83,8 +83,7 @@ def cli_main(output_filename, ocr_lang, filename): return # Ensure container is installed - if not global_common.is_container_installed(): - global_common.install_container() + global_common.install_container() # Convert the document print_header("Converting document to safe PDF") diff --git a/dangerzone/global_common.py b/dangerzone/global_common.py index 03f9893..d306118 100644 --- a/dangerzone/global_common.py +++ b/dangerzone/global_common.py @@ -414,18 +414,6 @@ class GlobalCommon(object): def exec_dangerzone_container(self, input_filename, output_filename, ocr_lang): convert(self, input_filename, output_filename, ocr_lang) - # args = [self.dz_container_path] + args - # args_str = " ".join(pipes.quote(s) for s in args) - # print(Style.DIM + "> " + Style.NORMAL + Fore.CYAN + args_str) - - # # Execute dangerzone-container - # return subprocess.Popen( - # args, - # startupinfo=self.get_subprocess_startupinfo(), - # stdout=subprocess.PIPE, - # stderr=subprocess.PIPE, - # ) - def get_subprocess_startupinfo(self): if platform.system() == "Windows": startupinfo = subprocess.STARTUPINFO() @@ -470,7 +458,7 @@ class GlobalCommon(object): return # Load the container into podman - print("Installing Dangerzone container...") + print("Installing Dangerzone container image...") p = subprocess.Popen( [self.get_container_runtime(), "load"], stdin=subprocess.PIPE @@ -490,10 +478,10 @@ class GlobalCommon(object): p.communicate() if not self.is_container_installed(): - print("Failed to install the container") + print("Failed to install the container image") return False - print("Container installed") + print("Container image installed") return True def is_container_installed(self): @@ -506,42 +494,28 @@ class GlobalCommon(object): # See if this image is already installed installed = False + found_image_id = subprocess.check_output( + [ + self.get_container_runtime(), + "image", + "list", + "--format", + "{{.ID}}", + self.container_name, + ], + text=True, + ) + found_image_id = found_image_id.strip() - if platform.system() == "Linux": - # Podman - images = json.loads( - subprocess.check_output( - [self.get_container_runtime(), "image", "list", "--format", "json"] - ) - ) - for image in images: - if image["Id"] == expected_image_id: - installed = True - break + if found_image_id == expected_image_id: + installed = True + elif found_image_id == "": + pass else: - # Docker - found_image_id = subprocess.check_output( - [ - self.get_container_runtime(), - "image", - "list", - "--format", - "{{.ID}}", - self.container_name, - ], - text=True, - ) - found_image_id = found_image_id.strip() - if found_image_id == expected_image_id: - installed = True - elif found_image_id == "": - print("Dangerzone container image is not installed") - else: - print(f"Image {found_image_id} is installed, not {expected_image_id}") + print(f"Deleting old dangerzone container image") - # Delete the image that exists - subprocess.check_output( - [self.get_container_runtime(), "rmi", found_image_id] - ) + subprocess.check_output( + [self.get_container_runtime(), "rmi", found_image_id] + ) return installed diff --git a/install/linux/build-container.py b/install/linux/build-container.py deleted file mode 100755 index 2ed3edc..0000000 --- a/install/linux/build-container.py +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env python3 -import os -import subprocess -import shutil -import json - - -def main(): - root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) - - print("Creating dangerzone image") - subprocess.run( - [ - "podman", - "build", - "--pull-always", - "--tag", - "dangerzone.rocks/dangerzone", - ".", - ], - cwd=os.path.join(root, "dangerzone-converter"), - ) - - print("Cleaning up from last time") - container_dir = os.path.join(root, "share", "container") - shutil.rmtree(container_dir, ignore_errors=True) - os.makedirs(container_dir, exist_ok=True) - - print("Saving image ID") - image_id = None - images = json.loads( - subprocess.check_output(["podman", "image", "list", "--format", "json"]) - ) - for image in images: - if "dangerzone.rocks/dangerzone:latest" in image["Names"]: - image_id = image["Id"] - break - - if not image_id: - print("Could not find image, aborting") - return - - with open(os.path.join(container_dir, "image_id.txt"), "w") as f: - f.write(f"{image_id}") - - print("Saving image") - subprocess.run( - [ - "podman", - "save", - "-o", - os.path.join(container_dir, "dangerzone.tar"), - "dangerzone.rocks/dangerzone", - ] - ) - - print("Compressing image") - subprocess.run(["gzip", "dangerzone.tar"], cwd=container_dir) - - -if __name__ == "__main__": - main() diff --git a/install/linux/build-image.sh b/install/linux/build-image.sh new file mode 100755 index 0000000..5617564 --- /dev/null +++ b/install/linux/build-image.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +echo "Building dangerzone-converter image" +podman build dangerzone-converter --tag dangerzone.rocks/dangerzone + +echo "Saving dangerzone-converter image" +podman save dangerzone.rocks/dangerzone -o share/dangerzone-converter.tar + +echo "Compressing dangerzone-converter image" +gzip -f share/dangerzone-converter.tar + +echo "Looking up the image id" +podman image ls dangerzone.rocks/dangerzone | grep "dangerzone.rocks/dangerzone" | tr -s ' ' | cut -d' ' -f3 > share/image-id.txt diff --git a/install/build-image.sh b/install/macos/build-image.sh similarity index 100% rename from install/build-image.sh rename to install/macos/build-image.sh