Merge pull request #37 from prilka/credentials-with-env-vars

auto create myjdownloader config
This commit is contained in:
PlusMinus0 2019-08-05 21:30:03 +02:00 committed by GitHub
commit e2f81c7ccf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 48 additions and 26 deletions

2
.gitignore vendored
View file

@ -2,4 +2,4 @@
.\#*
\#*\#
.config/
goss.yaml
/goss.yaml

View file

@ -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`<config-dir>/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`.

View file

@ -4,7 +4,7 @@ MAINTAINER PlusMinus <piddlpiddl@gmail.com>
# 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

View file

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

View file

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

View file

@ -4,7 +4,7 @@ MAINTAINER PlusMinus <piddlpiddl@gmail.com>
# 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 && \

View file

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

View file

@ -30,6 +30,8 @@ file:
package:
ffmpeg:
installed: true
jq:
installed: true
user:
jdownloader:
exists: true