From b5ba154f867989af198596ce94e7233af43c223d Mon Sep 17 00:00:00 2001
From: Patrick Jentsch
Date: Mon, 3 Jun 2019 13:32:42 +0200
Subject: [PATCH] Update for unprivileged usage 2
---
README.md | 2 ++
wrapper/ocr | 29 ++++++++++++++++++-----------
2 files changed, 20 insertions(+), 11 deletions(-)
diff --git a/README.md b/README.md
index dc40133..062100c 100644
--- a/README.md
+++ b/README.md
@@ -42,6 +42,7 @@ mkdir -p //files_for_ocr //files_from_ocr
docker run \
--rm \
-it \
+ -u $(id -u $USER):$(id -g $USER) \
-v //files_for_ocr:/input \
-v //files_from_ocr:/output \
sfb1288inf/ocr:latest \
@@ -82,6 +83,7 @@ Example with all arguments used:
docker run \
--rm \
-it \
+ -u $(id -u $USER):$(id -g $USER) \
-v "$HOME"/ocr/files_for_ocr:/input \
-v "$HOME"/ocr/files_from_ocr:/output \
sfb1288inf/ocr:latest \
diff --git a/wrapper/ocr b/wrapper/ocr
index 398f06a..c6886e4 100755
--- a/wrapper/ocr
+++ b/wrapper/ocr
@@ -2,31 +2,38 @@
# coding=utf-8
import argparse
+import os
import subprocess
container_image = 'gitlab.ub.uni-bielefeld.de:4567/sfb1288inf/ocr:latest'
+container_input_dir = '/input'
+container_output_dir = '/output'
+uid = str(os.getuid())
+gid = str(os.getgid())
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument(
'-i',
dest='input_dir',
- required=False
+ required=True
)
parser.add_argument(
'-o',
dest='output_dir',
- required=False
+ required=True
)
-dirs, args = parser.parse_known_args()
+args, remaining_args = parser.parse_known_args()
-cmd = ['docker', 'run', '--rm', '-it']
-if dirs.input_dir is not None:
- cmd += ['-v', dirs.input_dir + ':/input']
- args += ['-i', '/input']
-if dirs.output_dir is not None:
- cmd += ['-v', dirs.output_dir + ':/output']
- args += ['-o', '/output']
+cmd = ['docker', 'run', '--rm', '-it', '-u', uid + ':' + gid]
+if args.input_dir is not None:
+ host_input_dir = os.path.abspath(args.input_dir)
+ cmd += ['-v', host_input_dir + ':' + container_input_dir]
+ remaining_args += ['-i', '/input']
+if args.output_dir is not None:
+ host_output_dir = os.path.abspath(args.output_dir)
+ cmd += ['-v', host_output_dir + ':' + container_output_dir]
+ remaining_args += ['-o', '/output']
cmd.append(container_image)
-cmd += args
+cmd += remaining_args
subprocess.run(cmd)