Make the new code work in linux

This commit is contained in:
Micah Lee 2021-11-22 18:51:47 -05:00
parent a7e0c3994d
commit 9acfd2764e
No known key found for this signature in database
GPG key ID: 403C2657CD994F73
6 changed files with 40 additions and 116 deletions

View file

@ -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:

View file

@ -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")

View file

@ -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

View file

@ -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()

13
install/linux/build-image.sh Executable file
View file

@ -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