From 177c0955be7907eef60e9363aa6092c3118e07de Mon Sep 17 00:00:00 2001 From: prilka Date: Sat, 3 Aug 2019 11:05:11 +0200 Subject: [PATCH 1/4] auto create myjdownloader config --- alpine.Dockerfile | 2 +- common/entrypoint.sh | 11 +++++++++++ debian.Dockerfile | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/alpine.Dockerfile b/alpine.Dockerfile index 19f6ba0..001a6f4 100644 --- a/alpine.Dockerfile +++ b/alpine.Dockerfile @@ -4,7 +4,7 @@ MAINTAINER PlusMinus # Create directory, and start JD2 for the initial update and creation of config files. RUN apk update && apk upgrade && \ - apk add --no-cache --quiet tini su-exec shadow ffmpeg && \ + apk add --no-cache --quiet tini su-exec shadow ffmpeg jq && \ mkdir -p /opt/JDownloader/libs && \ wget -O /opt/JDownloader/JDownloader.jar --user-agent="https://hub.docker.com/r/plusminus/jdownloader2-headless/" http://installer.jdownloader.org/JDownloader.jar && \ java -Djava.awt.headless=true -jar /opt/JDownloader/JDownloader.jar diff --git a/common/entrypoint.sh b/common/entrypoint.sh index 6f2f589..4df666f 100755 --- a/common/entrypoint.sh +++ b/common/entrypoint.sh @@ -21,6 +21,17 @@ else usermod -ag $GID fi +# Set MyJDownloader credentials +CONFIG_FILE="/opt/JDownloader/cfg/org.jdownloader.api.myjdownloader.MyJDownloaderSettings.json" +if [ ! -z "$EMAIL" ] ; then + if [ ! -f "$CONFIG_FILE" ] || [ ! -s "$CONFIG_FILE" ] ; then + echo '{}' > "$CONFIG_FILE" + fi + + CFG=$(jq -r --arg EMAIL "$EMAIL" --arg PASSWORD "$PASSWORD" '.email = $EMAIL | .password = $PASSWORD' "$CONFIG_FILE") + [ ! -z "$CFG" ] && echo "$CFG" > "$CONFIG_FILE" +fi + chown -R $UID:$GID /opt/JDownloader # Sometimes this gets deleted. Just copy it every time. diff --git a/debian.Dockerfile b/debian.Dockerfile index b6c0577..c955418 100644 --- a/debian.Dockerfile +++ b/debian.Dockerfile @@ -4,7 +4,7 @@ MAINTAINER PlusMinus # Create directory, and start JD2 for the initial update and creation of config files. RUN apt-get update && apt-get dist-upgrade -yqq && \ - apt-get install -yqq tini ffmpeg wget make gcc && \ + apt-get install -yqq tini ffmpeg wget make gcc jq && \ mkdir -p /opt/JDownloader/libs && \ wget -O /opt/JDownloader/JDownloader.jar --user-agent="https://hub.docker.com/r/plusminus/jdownloader2-headless/" http://installer.jdownloader.org/JDownloader.jar && \ java -Djava.awt.headless=true -jar /opt/JDownloader/JDownloader.jar && \ From 8a636a7f50d0bfebdfd71f3f8b1efd4c6e96077c Mon Sep 17 00:00:00 2001 From: prilka Date: Sat, 3 Aug 2019 14:07:27 +0200 Subject: [PATCH 2/4] reorganize goss-tests --- .gitignore | 2 +- build-n-test.sh | 8 ++++---- goss-default.yaml => tests/default/goss.yaml | 0 goss-uid-test.yaml => tests/uid-test/goss.yaml | 0 4 files changed, 5 insertions(+), 5 deletions(-) rename goss-default.yaml => tests/default/goss.yaml (100%) rename goss-uid-test.yaml => tests/uid-test/goss.yaml (100%) diff --git a/.gitignore b/.gitignore index ba0d5b3..f4bd660 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ .\#* \#*\# .config/ -goss.yaml +/goss.yaml diff --git a/build-n-test.sh b/build-n-test.sh index 3d0a77d..667499d 100755 --- a/build-n-test.sh +++ b/build-n-test.sh @@ -1,6 +1,8 @@ #!/bin/bash set -e +cd $(dirname $0) + images=('alpine' 'debian') if [ "$(docker version --format '{{.Server.Experimental}}')" = 'true' ]; then @@ -15,12 +17,10 @@ for image in "${images[@]}"; do docker build -t $tag -f $image.Dockerfile . echo "Testing image" - cp goss-default.yaml goss.yaml - dgoss run $tag + GOSS_FILES_PATH=./tests/default dgoss run $tag echo "Testing again with UID and GID" - cp goss-uid-test.yaml goss.yaml - dgoss run -e UID=1001 -e GID=101 $tag + GOSS_FILES_PATH=./tests/uid-test dgoss run -e UID=1001 -e GID=101 $tag done diff --git a/goss-default.yaml b/tests/default/goss.yaml similarity index 100% rename from goss-default.yaml rename to tests/default/goss.yaml diff --git a/goss-uid-test.yaml b/tests/uid-test/goss.yaml similarity index 100% rename from goss-uid-test.yaml rename to tests/uid-test/goss.yaml From 712249d5c68c8bb0eb36f753f21d20a76c9e7578 Mon Sep 17 00:00:00 2001 From: prilka Date: Sat, 3 Aug 2019 14:13:07 +0200 Subject: [PATCH 3/4] add test for myjdownloader credentials/config --- build-n-test.sh | 3 +++ tests/credentials-test/goss.yaml | 11 +++++++++++ tests/default/goss.yaml | 2 ++ 3 files changed, 16 insertions(+) create mode 100644 tests/credentials-test/goss.yaml diff --git a/build-n-test.sh b/build-n-test.sh index 667499d..5372d76 100755 --- a/build-n-test.sh +++ b/build-n-test.sh @@ -21,6 +21,9 @@ for image in "${images[@]}"; do echo "Testing again with UID and GID" GOSS_FILES_PATH=./tests/uid-test dgoss run -e UID=1001 -e GID=101 $tag + + echo "Testing again with EMAIL and PASSWORD" + GOSS_FILES_PATH=./tests/credentials-test dgoss run -e EMAIL=mymail@example.com -e PASSWORD=mypassword $tag done diff --git a/tests/credentials-test/goss.yaml b/tests/credentials-test/goss.yaml new file mode 100644 index 0000000..b36ed8d --- /dev/null +++ b/tests/credentials-test/goss.yaml @@ -0,0 +1,11 @@ +file: + /opt/JDownloader/cfg/org.jdownloader.api.myjdownloader.MyJDownloaderSettings.json: + exists: true + mode: + or: + - "0664" + - "0644" + filetype: file + contains: + - mymail@example.com + - mypassword diff --git a/tests/default/goss.yaml b/tests/default/goss.yaml index 27e53cf..412b931 100644 --- a/tests/default/goss.yaml +++ b/tests/default/goss.yaml @@ -30,6 +30,8 @@ file: package: ffmpeg: installed: true + jq: + installed: true user: jdownloader: exists: true From a2d2bc4a284d22d63a76bbc68b5735de4f6e5fbd Mon Sep 17 00:00:00 2001 From: prilka Date: Mon, 5 Aug 2019 21:25:38 +0200 Subject: [PATCH 4/4] update README.md new environment variables documented and example updated --- README.md | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 9768276..f01e907 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ # Running the container + 0. Become root if your user is not part of the docker group: ``` @@ -19,31 +20,25 @@ ``` docker run -d --name jd2 \ + -e EMAIL=my@mail.com -e PASSWORD=my_secret_password -v /config/jd2:/opt/JDownloader/cfg \ -v /home/user/Downloads:/opt/JDownloader/Downloads \ plusminus/jdownloader2-headless ``` -3. Wait a minute for the container to initialize -4. Stop the container: - ``` - docker stop jd2 - ``` -5. On your host, enter your credentials (in quotes) to the file `org.jdownloader.api.myjdownloader.MyJDownloaderSettings.json` as in: +If you don't want to specify your credentials on the command line, remove them from the command above (`-e EMAIL=... -e PASSWORD=...`) +and add them manually to the file`/org.jdownloader.api.myjdownloader.MyJDownloaderSettings.json` as in - ``` - { "email" : "email@home.org", "password" : "mypasswort" } - ``` -6. Start the container: - - ``` - docker start jd2 - ``` +``` +{ "email" : "my@mail.com", "password" : "my_secret_password" } +``` # Optional environment variables -|Environment Variable|Description| -|--------------------|-----------| -|UID|Specifies the UID the daemon should run as. All created files will be owned by this UID. Defaults to 1000.| -|GID|Specifies the GID for all created files. This only works in combination with the UID. Defaults to 100 for users.| +Environment Variable | Description +---------------------|------------ +EMAIL | The MyJDownloader account e-mail. Is written automatically to config-file, if set. +PASSWORD | The MyJDownloader account password. Is written automatically to config-file, if set. +UID | Specifies the UID the daemon should run as. All created files will be owned by this UID. Defaults to 1000. +GID | Specifies the GID for all created files. This only works in combination with the UID. Defaults to 100 for users. -Not setting these will default to 1000:100. +Not setting `UID` / `GID` will default to `1000`:`100`.