Skip to content

Commit

Permalink
Fix: ADEPT key paths handling (#6)
Browse files Browse the repository at this point in the history
Closes #5
* add checks for KEY_PATH to handle both relative and ~/.. style paths
* update README
* cleanup comments
* minor cleanup on dockerfile
  • Loading branch information
bcliang committed Sep 14, 2022
1 parent 51c6d24 commit bd4fa36
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 20 deletions.
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# FROM python:3.10-slim-bullseye
FROM ubuntu:jammy

RUN apt-get update && \
Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ This container compiles the reference implementation utilities for libgourou (ma

### DockerHub

```
```bash
> docker pull bcliang/docker-libgourou:latest
```

Expand All @@ -45,9 +45,9 @@ By default, the container will process an inputted *.acsm file ($1) through both
[name_of_adept_metafile.acsm]
```

Notes: The shell script assumes that activated device configuration files (via Adobe ID credentials) have been mounted in the home directory (e.g. in `/home/libgourou`, `/home/libgourou/.adept/`, or `/home/libgourou/adobe-digital-editions/`).

To generate ADEPT configuration files (`activation.xml`, `devicesalt`, `device.xml`), use the interactive terminal and run `adept_activate`
Notes:
1. The shell script assumes that activated device configuration files (via Adobe ID credentials) have been mounted in the home directory (e.g. in `/home/libgourou`, `/home/libgourou/.adept/`, or `/home/libgourou/adobe-digital-editions/`).
2. To generate ADEPT configuration files (`activation.xml`, `devicesalt`, `device.xml`), use the interactive terminal and run the `adept_activate` utility

### Interactive Terminal

Expand Down Expand Up @@ -119,6 +119,10 @@ To launch an interactive terminal with access to the libgourou utils:
!!! acsmdownloader -f "./files/{ACSM_FILE}" -o output.drm
!!! adept_remove -v -f output.drm -o "/home/libgourou/files/{OUTPUT_FILE}"
!!!

Mounted Volumes
(current path e.g. $pwd) --> /home/libgourou/files/

username@..:/home/libgourou#
```
Expand Down
63 changes: 48 additions & 15 deletions scripts/dedrm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,32 @@
ACSM_FILE=$1
KEY_PATH=$2

if [[ -z "$KEY_PATH" ]] || [[ ! -d "$KEY_PATH" ]]
# Docker container needs a well-defined path for mounting volumes (paths should start with /* or ./*).
# Check $KEY_PATH and attempt to convert relative paths when necessary
if [[ ! -z "$KEY_PATH" ]] && [[ -d "$KEY_PATH" ]]
then
if [[ -d "$(pwd)/$KEY_PATH" ]]
# user specified a path AND bash found the directory
case $KEY_PATH in
/*)
# absolute path, do nothing
;;
~*)
# home directory, convert to absolute path
HOME_DIR="$(getent passwd $USER | awk -F ':' '{print $6}')"
KEY_PATH="$HOME_DIR/${KEY_PATH:1}"
;;
*)
# relative path, convert
KEY_PATH="$(pwd)/$KEY_PATH"
;;
esac
else
# user didn't specify a path
if [[ -z "$KEY_PATH" ]]
then
KEY_PATH="$(pwd)/$KEY_PATH"
else

if [[ -d "$(pwd)/.adept" ]]
then
# check the script's "default" path
KEY_PATH="$(pwd)/.adept"
else
echo "!!!"
Expand All @@ -27,6 +44,7 @@ then
fi
fi

# *.acsm file not specified, or specified file doesn't exist
if [[ -z "$ACSM_FILE" ]] || [[ ! -f "$ACSM_FILE" ]]
then
echo "!!!"
Expand All @@ -38,21 +56,36 @@ then
echo "!!!"
fi

if [[ -z "$KEY_PATH" ]] || [[ -z "$ACSM_FILE" ]] || [[ ! -f "$ACSM_FILE" ]]
if [[ -z "$KEY_PATH" ]]
then
echo "Note: the current path ($(pwd)) will be mounted at /home/libgourou/files"
# ADEPT keys missing; can't run libgourou utils
echo -e "\nMounted Volumes"
echo -e " $(pwd) --> /home/libgourou/files/\n"
docker run \
-v "$(pwd)":/home/libgourou/files \
-v "$(pwd)/$KEY_PATH":/home/libgourou/.adept \
-it --entrypoint /bin/bash \
--rm bcliang/docker-libgourou
else
echo "> acsmdownloader -f \"/home/libgourou/files/$ACSM_FILE\" -o \"output.drm\""
echo "> adept_remove -v -f \"output.drm\" -o \"/home/libgourou/files/{OUTPUT_FILE}\""
docker run \
-v "$(pwd)":/home/libgourou/files \
-v "$KEY_PATH":/home/libgourou/.adept \
--rm bcliang/docker-libgourou \
$ACSM_FILE
if [[ -z "$ACSM_FILE" ]] || [[ ! -f "$ACSM_FILE" ]]
then
# ADEPT keys were found but no *.acsm file
echo -e "\nMounted Volumes"
echo -e " $(pwd) --> /home/libgourou/files/"
echo -e " $KEY_PATH --> mounted at /home/libgourou/.adept/\n"
docker run \
-v "$(pwd)":/home/libgourou/files \
-v "$KEY_PATH":/home/libgourou/.adept \
-it --entrypoint /bin/bash \
--rm bcliang/docker-libgourou
else
# both ADEPT keys and *.acsm file were found
echo "> acsmdownloader -f \"/home/libgourou/files/$ACSM_FILE\" -o \"output.drm\""
echo "> adept_remove -v -f \"output.drm\" -o \"/home/libgourou/files/{OUTPUT_FILE}\""
docker run \
-v "$(pwd)":/home/libgourou/files \
-v "$KEY_PATH":/home/libgourou/.adept \
--rm bcliang/docker-libgourou \
$ACSM_FILE
fi
fi

0 comments on commit bd4fa36

Please sign in to comment.