mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-29 18:22:37 +02:00
Make the new code work in linux
This commit is contained in:
parent
a7e0c3994d
commit
9acfd2764e
6 changed files with 40 additions and 116 deletions
6
BUILD.md
6
BUILD.md
|
@ -11,7 +11,7 @@ sudo apt install -y podman dh-python python3 python3-stdeb python3-pyside2.qtcor
|
||||||
Build the latest container:
|
Build the latest container:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
./install/linux/build-container.py
|
./install/linux/build-image.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
Run from source tree:
|
Run from source tree:
|
||||||
|
@ -37,7 +37,7 @@ sudo dnf install -y rpm-build podman python3 python3-setuptools python3-pyside2
|
||||||
Build the latest container:
|
Build the latest container:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
./install/linux/build-container.py
|
./install/linux/build-image.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
Run from source tree:
|
Run from source tree:
|
||||||
|
@ -76,7 +76,7 @@ brew install create-dmg
|
||||||
Build the dangerzone container image:
|
Build the dangerzone container image:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
./install/build-image.sh
|
./install/macos/build-image.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
Run from source tree:
|
Run from source tree:
|
||||||
|
|
|
@ -83,7 +83,6 @@ def cli_main(output_filename, ocr_lang, filename):
|
||||||
return
|
return
|
||||||
|
|
||||||
# Ensure container is installed
|
# Ensure container is installed
|
||||||
if not global_common.is_container_installed():
|
|
||||||
global_common.install_container()
|
global_common.install_container()
|
||||||
|
|
||||||
# Convert the document
|
# Convert the document
|
||||||
|
|
|
@ -414,18 +414,6 @@ class GlobalCommon(object):
|
||||||
def exec_dangerzone_container(self, input_filename, output_filename, ocr_lang):
|
def exec_dangerzone_container(self, input_filename, output_filename, ocr_lang):
|
||||||
convert(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):
|
def get_subprocess_startupinfo(self):
|
||||||
if platform.system() == "Windows":
|
if platform.system() == "Windows":
|
||||||
startupinfo = subprocess.STARTUPINFO()
|
startupinfo = subprocess.STARTUPINFO()
|
||||||
|
@ -470,7 +458,7 @@ class GlobalCommon(object):
|
||||||
return
|
return
|
||||||
|
|
||||||
# Load the container into podman
|
# Load the container into podman
|
||||||
print("Installing Dangerzone container...")
|
print("Installing Dangerzone container image...")
|
||||||
|
|
||||||
p = subprocess.Popen(
|
p = subprocess.Popen(
|
||||||
[self.get_container_runtime(), "load"], stdin=subprocess.PIPE
|
[self.get_container_runtime(), "load"], stdin=subprocess.PIPE
|
||||||
|
@ -490,10 +478,10 @@ class GlobalCommon(object):
|
||||||
p.communicate()
|
p.communicate()
|
||||||
|
|
||||||
if not self.is_container_installed():
|
if not self.is_container_installed():
|
||||||
print("Failed to install the container")
|
print("Failed to install the container image")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
print("Container installed")
|
print("Container image installed")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def is_container_installed(self):
|
def is_container_installed(self):
|
||||||
|
@ -506,20 +494,6 @@ class GlobalCommon(object):
|
||||||
|
|
||||||
# See if this image is already installed
|
# See if this image is already installed
|
||||||
installed = False
|
installed = False
|
||||||
|
|
||||||
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
|
|
||||||
else:
|
|
||||||
# Docker
|
|
||||||
found_image_id = subprocess.check_output(
|
found_image_id = subprocess.check_output(
|
||||||
[
|
[
|
||||||
self.get_container_runtime(),
|
self.get_container_runtime(),
|
||||||
|
@ -532,14 +506,14 @@ class GlobalCommon(object):
|
||||||
text=True,
|
text=True,
|
||||||
)
|
)
|
||||||
found_image_id = found_image_id.strip()
|
found_image_id = found_image_id.strip()
|
||||||
|
|
||||||
if found_image_id == expected_image_id:
|
if found_image_id == expected_image_id:
|
||||||
installed = True
|
installed = True
|
||||||
elif found_image_id == "":
|
elif found_image_id == "":
|
||||||
print("Dangerzone container image is not installed")
|
pass
|
||||||
else:
|
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(
|
subprocess.check_output(
|
||||||
[self.get_container_runtime(), "rmi", found_image_id]
|
[self.get_container_runtime(), "rmi", found_image_id]
|
||||||
)
|
)
|
||||||
|
|
|
@ -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
13
install/linux/build-image.sh
Executable 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
|
Loading…
Reference in a new issue